11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * net-3-driver for the NI5210 card (i82586 Ethernet chip)
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This is an extension to the Linux operating system, and is covered by the
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * same GNU General Public License that covers that work.
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later)
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de)
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    [feel free to mail ....]
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * when using as module: (no autoprobing!)
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   run with e.g:
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *       insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!.
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If you find a bug, please report me:
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   The kernel panic output and any kmsg from the ni52 driver
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   the ni5210-driver-version and the linux-kernel version
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   how many shared memory (memsize) on the netcard,
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   bootprom: yes/no, base_addr, mem_start
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   maybe the ni5210-card revision and the i82586 version
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *                mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000,
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *                           0xd8000,0xcc000,0xce000,0xda000,0xdc000
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * sources:
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   skeleton.c from Donald Becker
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * I have also done a look in the following sources: (mail me if you need them)
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   crynwr-packet-driver by Russ Nelson
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   Garret A. Wollman's (fourth) i82586-driver for BSD
34a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *   (before getting an i82596 (yes 596 not 586) manual, the existing drivers
35a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *    helped me a lot to understand this tricky chip.)
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Known Problems:
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   The internal sysbus seems to be slow. So we often lose packets because of
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   overruns while receiving from a fast remote host.
40a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *   This can slow down TCP connections. Maybe the newer ni5210 cards are
41a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *   better. My experience is, that if a machine sends with more than about
42a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *   500-600K/s the fifo/sysbus overflows.
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IMPORTANT NOTE:
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   On fast networks, it's a (very) good idea to have 16K shared memory. With
46a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *   8K, we can store only 4 receive frames, so it can (easily) happen that a
47a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *   remote machine 'overruns' our system.
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Known i82586/card problems (I'm sure, there are many more!):
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   Running the NOP-mode, the i82586 sometimes seems to forget to report
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   every xmit-interrupt until we restart the CU.
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   in the RBD-Struct which indicates an end of the RBD queue.
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   Instead, the RU fetches another (randomly selected and
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   usually used) RBD and begins to fill it. (Maybe, this happens only if
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   the last buffer from the previous RFD fits exact into the queue and
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   the next RFD can't fetch an initial RBD. Anyone knows more? )
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * results from ftp performance tests with Linux 1.2.5
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *   send and receive about 350-400 KByte/s (peak up to 460 kbytes/s)
61a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *   sending in NOP-mode: peak performance up to 530K/s (but better don't
62a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *   run this mode)
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 29.Sept.96: virt_to_bus changes for new memory scheme
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 19.Feb.96: more Mcast changes, module support (MH)
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18.Nov.95: Mcast changes (AC).
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 23.April.95: fixed(?) receiving problems by configuring a RFD more
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *              than the number of RBD's. Can maybe cause other problems.
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18.April.95: Added MODULE support (MH)
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 17.April.95: MC related changes in init586() and set_multicast_list().
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *              removed use of 'jiffies' in init586() (MH)
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 19.Sep.94: Added Multicast support (not tested yet) (MH)
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling.
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *            Now, every RFD has exact one RBD. (MH)
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 14.Sep.94: added promiscuous mode, a few cleanups (MH)
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 19.Aug.94: changed request_irq() parameter (MH)
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH)
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 19.July.94: lotsa cleanups .. (MH)
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 17.July.94: some patches ... verified to run with 1.1.29 (MH)
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 4.July.94: patches for Linux 1.1.24  (MH)
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH)
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
96a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff,
97a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox *				too (MH)
981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * < 30.Sep.93: first versions
1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int debuglevel;	/* debug-printk 0: off 1: a few 2: more */
1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int automatic_resume; /* experimental .. better should be zero */
1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int rfdadd;	/* rfdadd=1 may be better for 8K MEM cards */
105a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstatic int fifo = 0x8;	/* don't change */
1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h>
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/kernel.h>
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/string.h>
1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/errno.h>
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/ioport.h>
1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/interrupt.h>
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/delay.h>
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h>
1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/bitops.h>
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/io.h>
1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/netdevice.h>
1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/etherdevice.h>
1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/skbuff.h>
1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "ni52.h"
1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DRV_NAME "ni52"
1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEBUG       /* debug on */
1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SYSBUSVAL 1 /* 8 Bit */
1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
129a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox#define ni_attn586()  { outb(0, dev->base_addr + NI52_ATTENTION); }
130a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox#define ni_reset586() { outb(0, dev->base_addr + NI52_RESET); }
131a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox#define ni_disint()   { outb(0, dev->base_addr + NI52_INTDIS); }
132a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox#define ni_enaint()   { outb(0, dev->base_addr + NI52_INTENA); }
1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
13405bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro#define make32(ptr16) ((void __iomem *)(p->memtop + (short) (ptr16)))
135e06ee2bb03f936c57265e447bc05e8324db61207Al Viro#define make24(ptr32) ((char __iomem *)(ptr32)) - p->base
136e06ee2bb03f936c57265e447bc05e8324db61207Al Viro#define make16(ptr32) ((unsigned short) ((char __iomem *)(ptr32)\
137e06ee2bb03f936c57265e447bc05e8324db61207Al Viro					- p->memtop))
1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/******************* how to calculate the buffers *****************************
1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds  * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds  * --------------- in a different (more stable?) mode. Only in this mode it's
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds  *                 possible to configure the driver with 'NO_NOPCOMMANDS'
1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldssizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldssizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldssizeof(rfd) = 24; sizeof(rbd) = 12;
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldssizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldssizeof(nop_cmd) = 8;
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds  * if you don't know the driver, better do not change these values: */
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RECV_BUFF_SIZE 1524 /* slightly oversized */
1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define XMIT_BUFF_SIZE 1524 /* slightly oversized */
1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NUM_XMIT_BUFFS 1    /* config for both, 8K and 16K shmem */
1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NUM_RECV_BUFFS_8  4 /* config for 8K shared mem */
1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NO_NOPCOMMANDS      /* only possible with NUM_XMIT_BUFFS=1 */
1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**************************************************************************/
1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NI52_TOTAL_SIZE 16
1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NI52_ADDR0 0x02
1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NI52_ADDR1 0x07
1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NI52_ADDR2 0x01
1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
168a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstatic int     ni52_probe1(struct net_device *dev, int ioaddr);
169a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstatic irqreturn_t ni52_interrupt(int irq, void *dev_id);
1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int     ni52_open(struct net_device *dev);
1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int     ni52_close(struct net_device *dev);
17261357325f377889a1daffa14962d705dc814dd0eStephen Hemmingerstatic netdev_tx_t ni52_send_packet(struct sk_buff *, struct net_device *);
1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct  net_device_stats *ni52_get_stats(struct net_device *dev);
1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void    set_multicast_list(struct net_device *dev);
1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void    ni52_timeout(struct net_device *dev);
1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* helper-functions */
1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int     init586(struct net_device *dev);
179de5971462fe27885290d8c95d9446a8b6d012448Al Virostatic int     check586(struct net_device *dev, unsigned size);
1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void    alloc586(struct net_device *dev);
1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void    startrecv586(struct net_device *dev);
1822d76c267e90aafef72df1318b49cb8f43a59ac94Al Virostatic void   __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr);
1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void    ni52_rcv_int(struct net_device *dev);
1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void    ni52_xmt_int(struct net_device *dev);
1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void    ni52_rnr_int(struct net_device *dev);
1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
187a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstruct priv {
188e06ee2bb03f936c57265e447bc05e8324db61207Al Viro	char __iomem *base;
189e06ee2bb03f936c57265e447bc05e8324db61207Al Viro	char __iomem *mapped;
1902d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	char __iomem *memtop;
191a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	spinlock_t spinlock;
192a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int reset;
1932d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct rfd_struct __iomem *rfd_last, *rfd_top, *rfd_first;
1942d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct scp_struct __iomem *scp;
1952d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct iscp_struct __iomem *iscp;
1962d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct scb_struct __iomem *scb;
1972d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct tbd_struct __iomem *xmit_buffs[NUM_XMIT_BUFFS];
1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if (NUM_XMIT_BUFFS == 1)
1992d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct transmit_cmd_struct __iomem *xmit_cmds[2];
2002d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct nop_cmd_struct __iomem *nop_cmds[2];
2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
2022d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct transmit_cmd_struct __iomem *xmit_cmds[NUM_XMIT_BUFFS];
2032d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct nop_cmd_struct __iomem *nop_cmds[NUM_XMIT_BUFFS];
2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
205a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int nop_point, num_recv_buffs;
2062d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	char __iomem *xmit_cbuffs[NUM_XMIT_BUFFS];
207a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int xmit_count, xmit_last;
2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
210a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox/* wait for command with timeout: */
211a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstatic void wait_for_scb_cmd(struct net_device *dev)
212a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox{
2134cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
214a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int i;
215a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < 16384; i++) {
216a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (readb(&p->scb->cmd_cuc) == 0)
217a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		      break;
218a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		udelay(4);
219a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (i == 16383) {
220a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",
221a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name, readb(&p->scb->cmd_cuc), readb(&p->scb->cus));
222a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			if (!p->reset) {
223a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				p->reset = 1;
224a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				ni_reset586();
225a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			}
226a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		}
227a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	}
228a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox}
229a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox
230a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstatic void wait_for_scb_cmd_ruc(struct net_device *dev)
231a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox{
2324cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
233a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int i;
234a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < 16384; i++) {
235a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (readb(&p->scb->cmd_ruc) == 0)
236a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			break;
237a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		udelay(4);
238a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (i == 16383) {
239a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",
24005bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro				dev->name, readb(&p->scb->cmd_ruc),
24105bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro				readb(&p->scb->rus));
242a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			if (!p->reset) {
243a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				p->reset = 1;
244a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				ni_reset586();
245a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			}
246a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		}
247a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	}
248a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox}
249a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox
2502d76c267e90aafef72df1318b49cb8f43a59ac94Al Virostatic void wait_for_stat_compl(void __iomem *p)
251a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox{
2522d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct nop_cmd_struct __iomem *addr = p;
253a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int i;
254a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < 32767; i++) {
255a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (readw(&((addr)->cmd_status)) & STAT_COMPL)
256a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			break;
257a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		udelay(32);
258a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	}
259a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox}
260a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox
2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**********************************************
2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * close device
2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int ni52_close(struct net_device *dev)
2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	free_irq(dev->irq, dev);
2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_reset586(); /* the hard way to stop the receiver */
2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	netif_stop_queue(dev);
2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return 0;
2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**********************************************
2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * open device
2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int ni52_open(struct net_device *dev)
2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int ret;
2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_disint();
2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	alloc586(dev);
2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	init586(dev);
2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	startrecv586(dev);
2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_enaint();
2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
285a0607fd3a25ba1848a63a0d925e36d914735ab47Joe Perches	ret = request_irq(dev->irq, ni52_interrupt, 0, dev->name, dev);
286a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (ret) {
2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni_reset586();
2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return ret;
2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	netif_start_queue(dev);
2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return 0; /* most done by init */
2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
29476af5699a359c3683f1c94444826d78be8d42513Al Virostatic int check_iscp(struct net_device *dev, void __iomem *addr)
29576af5699a359c3683f1c94444826d78be8d42513Al Viro{
29676af5699a359c3683f1c94444826d78be8d42513Al Viro	struct iscp_struct __iomem *iscp = addr;
2974cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
29876af5699a359c3683f1c94444826d78be8d42513Al Viro	memset_io(iscp, 0, sizeof(struct iscp_struct));
29976af5699a359c3683f1c94444826d78be8d42513Al Viro
30076af5699a359c3683f1c94444826d78be8d42513Al Viro	writel(make24(iscp), &p->scp->iscp);
30176af5699a359c3683f1c94444826d78be8d42513Al Viro	writeb(1, &iscp->busy);
30276af5699a359c3683f1c94444826d78be8d42513Al Viro
30376af5699a359c3683f1c94444826d78be8d42513Al Viro	ni_reset586();
30476af5699a359c3683f1c94444826d78be8d42513Al Viro	ni_attn586();
30576af5699a359c3683f1c94444826d78be8d42513Al Viro	mdelay(32);	/* wait a while... */
30676af5699a359c3683f1c94444826d78be8d42513Al Viro	/* i82586 clears 'busy' after successful init */
30776af5699a359c3683f1c94444826d78be8d42513Al Viro	if (readb(&iscp->busy))
30876af5699a359c3683f1c94444826d78be8d42513Al Viro		return 0;
30976af5699a359c3683f1c94444826d78be8d42513Al Viro	return 1;
31076af5699a359c3683f1c94444826d78be8d42513Al Viro}
31176af5699a359c3683f1c94444826d78be8d42513Al Viro
3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**********************************************
3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Check to see if there's an 82586 out there.
3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
315de5971462fe27885290d8c95d9446a8b6d012448Al Virostatic int check586(struct net_device *dev, unsigned size)
3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
3174cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int i;
3191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
320176f65f3efb55723518d018c8020867f44d05147Al Viro	p->mapped = ioremap(dev->mem_start, size);
321176f65f3efb55723518d018c8020867f44d05147Al Viro	if (!p->mapped)
322176f65f3efb55723518d018c8020867f44d05147Al Viro		return 0;
323176f65f3efb55723518d018c8020867f44d05147Al Viro
324e06ee2bb03f936c57265e447bc05e8324db61207Al Viro	p->base = p->mapped + size - 0x01000000;
325e06ee2bb03f936c57265e447bc05e8324db61207Al Viro	p->memtop = p->mapped + size;
3262d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	p->scp = (struct scp_struct __iomem *)(p->base + SCP_DEFAULT_ADDRESS);
3277f8cfd560875fd643024c02ea25d4f3b8f1fd31cAl Viro	p->scb	= (struct scb_struct __iomem *)	p->mapped;
32876af5699a359c3683f1c94444826d78be8d42513Al Viro	p->iscp = (struct iscp_struct __iomem *)p->scp - 1;
3292d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	memset_io(p->scp, 0, sizeof(struct scp_struct));
330a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < sizeof(struct scp_struct); i++)
331a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		/* memory was writeable? */
3322d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		if (readb((char __iomem *)p->scp + i))
333176f65f3efb55723518d018c8020867f44d05147Al Viro			goto Enodev;
334a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(SYSBUSVAL, &p->scp->sysbus);	/* 1 = 8Bit-Bus, 0 = 16 Bit */
335a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (readb(&p->scp->sysbus) != SYSBUSVAL)
336176f65f3efb55723518d018c8020867f44d05147Al Viro		goto Enodev;
3371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
33876af5699a359c3683f1c94444826d78be8d42513Al Viro	if (!check_iscp(dev, p->mapped))
339176f65f3efb55723518d018c8020867f44d05147Al Viro		goto Enodev;
34076af5699a359c3683f1c94444826d78be8d42513Al Viro	if (!check_iscp(dev, p->iscp))
341176f65f3efb55723518d018c8020867f44d05147Al Viro		goto Enodev;
3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return 1;
343176f65f3efb55723518d018c8020867f44d05147Al ViroEnodev:
344176f65f3efb55723518d018c8020867f44d05147Al Viro	iounmap(p->mapped);
345176f65f3efb55723518d018c8020867f44d05147Al Viro	return 0;
3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
3471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/******************************************************************
3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * set iscp at the right place, called by ni52_probe1 and open586.
3501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
3511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void alloc586(struct net_device *dev)
3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
3534cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_reset586();
356a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	mdelay(32);
357a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox
358a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	memset_io(p->iscp, 0, sizeof(struct iscp_struct));
359a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	memset_io(p->scp , 0, sizeof(struct scp_struct));
3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
361a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writel(make24(p->iscp), &p->scp->iscp);
362a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(SYSBUSVAL, &p->scp->sysbus);
363a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->scb), &p->iscp->scb_offset);
3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
365a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(1, &p->iscp->busy);
3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_reset586();
3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_attn586();
3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
369a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	mdelay(32);
3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
371a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (readb(&p->iscp->busy))
372a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
374a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	p->reset = 0;
3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3762d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	memset_io(p->scb, 0, sizeof(struct scb_struct));
3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* set: io,irq,memstart,memend or set it when calling insmod */
380a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstatic int irq = 9;
381a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstatic int io = 0x300;
3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic long memstart;	/* e.g 0xd0000 */
3831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic long memend;	/* e.g 0xd4000 */
3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**********************************************
3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * probe the ni5210-card
3871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
3881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct net_device * __init ni52_probe(int unit)
3891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct net_device *dev = alloc_etherdev(sizeof(struct priv));
391b6bc765067ece933cc3dc7f5e95665a89100b1d5Joe Perches	static const int ports[] = {0x300, 0x280, 0x360, 0x320, 0x340, 0};
392b6bc765067ece933cc3dc7f5e95665a89100b1d5Joe Perches	const int *port;
393176f65f3efb55723518d018c8020867f44d05147Al Viro	struct priv *p;
3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int err = 0;
3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (!dev)
3971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return ERR_PTR(-ENOMEM);
3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3994cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	p = netdev_priv(dev);
400176f65f3efb55723518d018c8020867f44d05147Al Viro
4011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (unit >= 0) {
4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		sprintf(dev->name, "eth%d", unit);
4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		netdev_boot_setup_check(dev);
4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		io = dev->base_addr;
4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		irq = dev->irq;
4061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		memstart = dev->mem_start;
4071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		memend = dev->mem_end;
4081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
4091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (io > 0x1ff)	{	/* Check a single specified location. */
4111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		err = ni52_probe1(dev, io);
4121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} else if (io > 0) {		/* Don't probe at all. */
4131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		err = -ENXIO;
4141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} else {
4151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		for (port = ports; *port && ni52_probe1(dev, *port) ; port++)
4161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			;
4171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (*port)
4181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			goto got_it;
4191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef FULL_IO_PROBE
4201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8)
4211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			;
4221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (io < 0x400)
4231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			goto got_it;
4241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
4251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		err = -ENODEV;
4261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
4271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (err)
4281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto out;
4291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsgot_it:
4301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	err = register_netdev(dev);
4311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (err)
4321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto out1;
4331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return dev;
4341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout1:
435176f65f3efb55723518d018c8020867f44d05147Al Viro	iounmap(p->mapped);
4361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	release_region(dev->base_addr, NI52_TOTAL_SIZE);
4371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout:
4381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	free_netdev(dev);
4391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return ERR_PTR(err);
4401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
4411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4422c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemmingerstatic const struct net_device_ops ni52_netdev_ops = {
4432c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger	.ndo_open		= ni52_open,
4442c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger	.ndo_stop		= ni52_close,
4452c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger	.ndo_get_stats		= ni52_get_stats,
4462c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger	.ndo_tx_timeout 	= ni52_timeout,
4472c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger	.ndo_start_xmit 	= ni52_send_packet,
448afc4b13df143122f99a0eb10bfefb216c2806de0Jiri Pirko	.ndo_set_rx_mode	= set_multicast_list,
4492c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger	.ndo_change_mtu		= eth_change_mtu,
4502c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger	.ndo_set_mac_address 	= eth_mac_addr,
4512c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger	.ndo_validate_addr	= eth_validate_addr,
4522c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger};
4532c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger
454a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstatic int __init ni52_probe1(struct net_device *dev, int ioaddr)
4551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
4561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int i, size, retval;
4574cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *priv = netdev_priv(dev);
4581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	dev->base_addr = ioaddr;
4601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	dev->irq = irq;
4611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	dev->mem_start = memstart;
4621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	dev->mem_end = memend;
4631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4647f8cfd560875fd643024c02ea25d4f3b8f1fd31cAl Viro	spin_lock_init(&priv->spinlock);
4657f8cfd560875fd643024c02ea25d4f3b8f1fd31cAl Viro
4661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME))
4671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return -EBUSY;
4681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
469a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
4701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	    !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) {
4711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		retval = -ENODEV;
4721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto out;
4731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
4741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
475a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < ETH_ALEN; i++)
4761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		dev->dev_addr[i] = inb(dev->base_addr+i);
4771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4788e95a2026f3b43f7c3d676adaccd2de9532e8dccJoe Perches	if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1 ||
4798e95a2026f3b43f7c3d676adaccd2de9532e8dccJoe Perches	    dev->dev_addr[2] != NI52_ADDR2) {
4801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		retval = -ENODEV;
4811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto out;
4821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
4831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
484a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	printk(KERN_INFO "%s: NI5210 found at %#3lx, ",
485a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name, dev->base_addr);
4861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
4881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * check (or search) IO-Memory, 8K and 16K
4891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
4901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef MODULE
4911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	size = dev->mem_end - dev->mem_start;
492a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (size != 0x2000 && size != 0x4000) {
493a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk("\n");
494a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev->name, size);
4951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		retval = -ENODEV;
4961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto out;
4971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
498de5971462fe27885290d8c95d9446a8b6d012448Al Viro	if (!check586(dev, size)) {
499a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "?memcheck, Can't find memory at 0x%lx with size %d!\n", dev->mem_start, size);
5001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		retval = -ENODEV;
5011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto out;
5021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
5031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
504a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (dev->mem_start != 0) {
505a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		/* no auto-mem-probe */
5061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		size = 0x4000; /* check for 16K mem */
507de5971462fe27885290d8c95d9446a8b6d012448Al Viro		if (!check586(dev, size)) {
5081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			size = 0x2000; /* check for 8K mem */
509de5971462fe27885290d8c95d9446a8b6d012448Al Viro			if (!check586(dev, size)) {
510a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start);
5111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				retval = -ENODEV;
5121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				goto out;
5131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			}
5141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
515a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	} else {
516a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		static const unsigned long memaddrs[] = {
517a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000,
518a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0
519a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		};
520a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		for (i = 0;; i++) {
521a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			if (!memaddrs[i]) {
522a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				printk(KERN_ERR "?memprobe, Can't find io-memory!\n");
5231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				retval = -ENODEV;
5241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				goto out;
5251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			}
5261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			dev->mem_start = memaddrs[i];
5271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			size = 0x2000; /* check for 8K mem */
528de5971462fe27885290d8c95d9446a8b6d012448Al Viro			if (check586(dev, size))
529a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				/* 8K-check */
5301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				break;
5311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			size = 0x4000; /* check for 16K mem */
532de5971462fe27885290d8c95d9446a8b6d012448Al Viro			if (check586(dev, size))
533a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				/* 16K-check */
5341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				break;
5351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
5361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
537a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* set mem_end showed by 'ifconfig' */
538a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	dev->mem_end = dev->mem_start + size;
5391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
5401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	alloc586(dev);
5421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* set number of receive-buffs according to memsize */
544a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (size == 0x2000)
545e06ee2bb03f936c57265e447bc05e8324db61207Al Viro		priv->num_recv_buffs = NUM_RECV_BUFFS_8;
5461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	else
547e06ee2bb03f936c57265e447bc05e8324db61207Al Viro		priv->num_recv_buffs = NUM_RECV_BUFFS_16;
5481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
549a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ",
550a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->mem_start, size);
5511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
552a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (dev->irq < 2) {
5531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		unsigned long irq_mask;
5541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		irq_mask = probe_irq_on();
5561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni_reset586();
5571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni_attn586();
5581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		mdelay(20);
5601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		dev->irq = probe_irq_off(irq_mask);
561a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (!dev->irq) {
5621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			printk("?autoirq, Failed to detect IRQ line!\n");
5631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			retval = -EAGAIN;
564176f65f3efb55723518d018c8020867f44d05147Al Viro			iounmap(priv->mapped);
5651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			goto out;
5661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
567a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk("IRQ %d (autodetected).\n", dev->irq);
568a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	} else {
569a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (dev->irq == 2)
5701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			dev->irq = 9;
571a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk("IRQ %d (assigned and not checked!).\n", dev->irq);
5721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
5731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5742c7669e3a9f748dd35743f06cbdaf4340263c3bfStephen Hemminger	dev->netdev_ops		= &ni52_netdev_ops;
5751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	dev->watchdog_timeo	= HZ/20;
5761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return 0;
5781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsout:
5791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	release_region(ioaddr, NI52_TOTAL_SIZE);
5801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return retval;
5811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
5821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**********************************************
5841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * init the chip (ni52-interrupt should be disabled?!)
5851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * needs a correct 'allocated' memory
5861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
5871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
5881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int init586(struct net_device *dev)
5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
5902d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	void __iomem *ptr;
591a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int i, result = 0;
5924cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
5932d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct configure_cmd_struct __iomem *cfg_cmd;
5942d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct iasetup_cmd_struct __iomem *ias_cmd;
5952d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct tdr_cmd_struct __iomem *tdr_cmd;
5962d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct mcsetup_cmd_struct __iomem *mc_cmd;
59722bedad3ce112d5ca1eaf043d4990fa2ed698c87Jiri Pirko	struct netdev_hw_addr *ha;
5984cd24eaf0c6ee7f0242e34ee77ec899f255e66b5Jiri Pirko	int num_addrs = netdev_mc_count(dev);
5991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
6002d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	ptr = p->scb + 1;
6011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
6022d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	cfg_cmd = ptr; /* configure-command */
603a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &cfg_cmd->cmd_status);
604a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd);
605a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0xFFFF, &cfg_cmd->cmd_link);
606a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox
607a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* number of cfg bytes */
608a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(0x0a, &cfg_cmd->byte_cnt);
609a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* fifo-limit (8=tx:32/rx:64) */
610a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(fifo, &cfg_cmd->fifo);
611a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* hold or discard bad recv frames (bit 7) */
612a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(0x40, &cfg_cmd->sav_bf);
613a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* addr_len |!src_insert |pre-len |loopback */
614a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(0x2e, &cfg_cmd->adr_len);
615a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(0x00, &cfg_cmd->priority);
616a419aef8b858a2bdb98df60336063d28df4b272fJoe Perches	writeb(0x60, &cfg_cmd->ifs);
617a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(0x00, &cfg_cmd->time_low);
618a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(0xf2, &cfg_cmd->time_high);
619a419aef8b858a2bdb98df60336063d28df4b272fJoe Perches	writeb(0x00, &cfg_cmd->promisc);
620a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (dev->flags & IFF_ALLMULTI) {
6212d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		int len = ((char __iomem *)p->iscp - (char __iomem *)ptr - 8) / 6;
622a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (num_addrs > len) {
623a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: switching to promisc. mode\n",
624a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
625c16d118537cadb21d186e35aebad90a13cd78846Wang Chen			writeb(0x01, &cfg_cmd->promisc);
6261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
6271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
628a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (dev->flags & IFF_PROMISC)
629a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(0x01, &cfg_cmd->promisc);
630a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(0x00, &cfg_cmd->carr_coll);
631a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(cfg_cmd), &p->scb->cbl_offset);
63205bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro	writeb(0, &p->scb->cmd_ruc);
6331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
634a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
6351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_attn586();
6361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
637a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_stat_compl(cfg_cmd);
6381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
639a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
640a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox							(STAT_COMPL|STAT_OK)) {
641a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: configure command failed: %x\n",
642a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name, readw(&cfg_cmd->cmd_status));
6431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return 1;
6441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
6451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
6461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
6471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * individual address setup
6481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
6491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
6502d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	ias_cmd = ptr;
6511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
652a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &ias_cmd->cmd_status);
653a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd);
654a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0xffff, &ias_cmd->cmd_link);
6551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
6562d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	memcpy_toio(&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN);
6571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
658a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(ias_cmd), &p->scb->cbl_offset);
6591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
660a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
6611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_attn586();
6621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
663a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_stat_compl(ias_cmd);
6641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
665a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
666a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox							(STAT_OK|STAT_COMPL)) {
667a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s (ni52): individual address setup command failed: %04x\n", dev->name, readw(&ias_cmd->cmd_status));
6681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return 1;
6691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
6701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
6711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
6721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * TDR, wire check .. e.g. no resistor e.t.c
6731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
6746aa20a2235535605db6d6d2bd850298b2fe7f31eJeff Garzik
6752d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	tdr_cmd = ptr;
6761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
677a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &tdr_cmd->cmd_status);
678a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd);
679a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0xffff, &tdr_cmd->cmd_link);
680a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &tdr_cmd->status);
6811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
682a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(tdr_cmd), &p->scb->cbl_offset);
683a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
6841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_attn586();
6851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
686a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_stat_compl(tdr_cmd);
6871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
688a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (!(readw(&tdr_cmd->cmd_status) & STAT_COMPL))
689a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: Problems while running the TDR.\n",
690a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
691a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	else {
692a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		udelay(16);
693a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		result = readw(&tdr_cmd->status);
694a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
6951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni_attn586(); /* ack the interrupts */
6961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
697a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (result & TDR_LNK_OK)
6981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			;
699a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		else if (result & TDR_XCVR_PRB)
700a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n",
701a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
702a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		else if (result & TDR_ET_OPN)
703a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n",
704a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name, result & TDR_TIMEMASK);
705a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		else if (result & TDR_ET_SRT) {
706a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			/* time == 0 -> strange :-) */
707a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			if (result & TDR_TIMEMASK)
708a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n",
709a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					dev->name, result & TDR_TIMEMASK);
710a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		} else
711a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: TDR: Unknown status %04x\n",
712a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox						dev->name, result);
7131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
7141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
7161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Multicast setup
7171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
718a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (num_addrs && !(dev->flags & IFF_PROMISC)) {
7192d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		mc_cmd = ptr;
720a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(0, &mc_cmd->cmd_status);
721a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd);
722a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(0xffff, &mc_cmd->cmd_link);
723a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(num_addrs * 6, &mc_cmd->mc_cnt);
7241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
725f9dcbcc9e338d08c0f7de7eba4eaafbbb7f81249Jiri Pirko		i = 0;
72622bedad3ce112d5ca1eaf043d4990fa2ed698c87Jiri Pirko		netdev_for_each_mc_addr(ha, dev)
72722bedad3ce112d5ca1eaf043d4990fa2ed698c87Jiri Pirko			memcpy_toio(mc_cmd->mc_list[i++], ha->addr, 6);
7281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
729a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(make16(mc_cmd), &p->scb->cbl_offset);
730a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(CUC_START, &p->scb->cmd_cuc);
7311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni_attn586();
7321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
733a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		wait_for_stat_compl(mc_cmd);
7341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
735a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK))
736a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox						 != (STAT_COMPL|STAT_OK))
737a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: Can't apply multicast-address-list.\n", dev->name);
7381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
7391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
7411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * alloc nop/xmit-cmds
7421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
7431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if (NUM_XMIT_BUFFS == 1)
744a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < 2; i++) {
7452d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		p->nop_cmds[i] = ptr;
746a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
747a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(0, &p->nop_cmds[i]->cmd_status);
748a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
7492d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		ptr = ptr + sizeof(struct nop_cmd_struct);
7501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
7511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
752a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < NUM_XMIT_BUFFS; i++) {
7532d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		p->nop_cmds[i] = ptr;
754a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
755a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(0, &p->nop_cmds[i]->cmd_status);
756a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
7572d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		ptr = ptr + sizeof(struct nop_cmd_struct);
7581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
7591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
7601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7612d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	ptr = alloc_rfa(dev, ptr); /* init receive-frame-area */
7621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
7641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * alloc xmit-buffs / init xmit_cmds
7651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
766a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < NUM_XMIT_BUFFS; i++) {
767a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		/* Transmit cmd/buff 0 */
7682d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		p->xmit_cmds[i] = ptr;
7692d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		ptr = ptr + sizeof(struct transmit_cmd_struct);
7702d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		p->xmit_cbuffs[i] = ptr; /* char-buffs */
7712d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		ptr = ptr + XMIT_BUFF_SIZE;
7722d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		p->xmit_buffs[i] = ptr; /* TBD */
7732d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		ptr = ptr + sizeof(struct tbd_struct);
7742d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		if ((void __iomem *)ptr > (void __iomem *)p->iscp) {
775a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n",
776a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
7771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return 1;
7781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
7792d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		memset_io(p->xmit_cmds[i], 0,
780a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					sizeof(struct transmit_cmd_struct));
7812d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		memset_io(p->xmit_buffs[i], 0,
782a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					sizeof(struct tbd_struct));
783a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]),
784a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					&p->xmit_cmds[i]->cmd_link);
785a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status);
786a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(CMD_XMIT|CMD_INT, &p->xmit_cmds[i]->cmd_cmd);
787a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(make16(p->xmit_buffs[i]), &p->xmit_cmds[i]->tbd_offset);
788a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(0xffff, &p->xmit_buffs[i]->next);
789a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writel(make24(p->xmit_cbuffs[i]), &p->xmit_buffs[i]->buffer);
7901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
7911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	p->xmit_count = 0;
7931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	p->xmit_last	= 0;
7941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef NO_NOPCOMMANDS
7951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	p->nop_point	= 0;
7961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
7971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 /*
7991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		* 'start transmitter'
8001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		*/
8011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef NO_NOPCOMMANDS
802a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset);
803a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(CUC_START, &p->scb->cmd_cuc);
8041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_attn586();
805a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_scb_cmd(dev);
8061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
807a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link);
808a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(CMD_XMIT | CMD_SUSPEND | CMD_INT, &p->xmit_cmds[0]->cmd_cmd);
8091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
8101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
8121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * ack. interrupts
8131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
814a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
8151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_attn586();
816a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	udelay(16);
8171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_enaint();
8191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return 0;
8211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
8221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/******************************************************
8241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This is a helper routine for ni52_rnr_int() and init586().
8251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * It sets up the Receive Frame Area (RFA).
8261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
8271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8282d76c267e90aafef72df1318b49cb8f43a59ac94Al Virostatic void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr)
8291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
8302d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct rfd_struct __iomem *rfd = ptr;
8312d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct rbd_struct __iomem *rbd;
8321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int i;
8334cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
8341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8352d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	memset_io(rfd, 0,
836a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd));
8371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	p->rfd_first = rfd;
8381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
839a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) {
840a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)),
841a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			&rfd[i].next);
842a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(0xffff, &rfd[i].rbd_offset);
8431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
844a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* RU suspend */
845a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last);
8461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8472d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	ptr = rfd + (p->num_recv_buffs + rfdadd);
8481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8492d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	rbd = ptr;
8502d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	ptr = rbd + p->num_recv_buffs;
8511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 /* clr descriptors */
8532d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	memset_io(rbd, 0, sizeof(struct rbd_struct) * (p->num_recv_buffs));
8541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
855a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < p->num_recv_buffs; i++) {
856a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next);
857a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(RECV_BUFF_SIZE, &rbd[i].size);
858a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writel(make24(ptr), &rbd[i].buffer);
8592d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro		ptr = ptr + RECV_BUFF_SIZE;
8601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
8611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	p->rfd_top	= p->rfd_first;
8621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
8631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
864a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->rfd_first), &p->scb->rfa_offset);
865a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(rbd), &p->rfd_first->rbd_offset);
8661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return ptr;
8681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
8691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**************************************************
8721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Interrupt Handler ...
8731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
8741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
875a197f6938db43b5ef464242f707233d3bd8842ebAlan Coxstatic irqreturn_t ni52_interrupt(int irq, void *dev_id)
8761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
8771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct net_device *dev = dev_id;
878a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	unsigned int stat;
879a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int cnt = 0;
8801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct priv *p;
8811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8824cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	p = netdev_priv(dev);
8831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
884a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (debuglevel > 1)
8851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		printk("I");
8861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
887a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	spin_lock(&p->spinlock);
8881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
889a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_scb_cmd(dev); /* wait for last command	*/
890a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox
891a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	while ((stat = readb(&p->scb->cus) & STAT_MASK)) {
892a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(stat, &p->scb->cmd_cuc);
8931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni_attn586();
8941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
895a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (stat & STAT_FR)	 /* received a frame */
8961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			ni52_rcv_int(dev);
8971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
898a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (stat & STAT_RNR) { /* RU went 'not ready' */
8991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			printk("(R)");
900a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			if (readb(&p->scb->rus) & RU_SUSPEND) {
901a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				/* special case: RU_SUSPEND */
902a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				wait_for_scb_cmd(dev);
90305bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro				writeb(RUC_RESUME, &p->scb->cmd_ruc);
9041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				ni_attn586();
905a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				wait_for_scb_cmd_ruc(dev);
906a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			} else {
907a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",
908a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					dev->name, stat, readb(&p->scb->rus));
9091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				ni52_rnr_int(dev);
9101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			}
9111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
9121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
913a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		/* Command with I-bit set complete */
914a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (stat & STAT_CX)
9151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 ni52_xmt_int(dev);
9161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef NO_NOPCOMMANDS
918a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (stat & STAT_CNA) {	/* CU went 'not ready' */
919a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			if (netif_running(dev))
920a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n",
921a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					dev->name, stat, readb(&p->scb->cus));
9221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
9231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
9241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
925a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (debuglevel > 1)
926a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk("%d", cnt++);
9271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
928a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		/* Wait for ack. (ni52_xmt_int can be faster than ack!!) */
929a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		wait_for_scb_cmd(dev);
93005bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro		if (readb(&p->scb->cmd_cuc)) {	 /* timed out? */
931a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: Acknowledge timed out.\n",
932a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
9331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			ni_disint();
9341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			break;
9351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
9361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
937a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	spin_unlock(&p->spinlock);
9381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
939a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (debuglevel > 1)
9401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		printk("i");
9411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return IRQ_HANDLED;
9421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
9431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*******************************************************
9451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * receive-interrupt
9461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
9471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void ni52_rcv_int(struct net_device *dev)
9491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
950a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int status, cnt = 0;
9511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned short totlen;
9521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct sk_buff *skb;
9532d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	struct rbd_struct __iomem *rbd;
9544cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
9551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
956a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (debuglevel > 0)
9571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		printk("R");
9581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
959a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) {
96005bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro		rbd = make32(readw(&p->rfd_top->rbd_offset));
961a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (status & RFD_OK) { /* frame received without error? */
962a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			totlen = readw(&rbd->status);
963a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			if (totlen & RBD_LAST) {
964a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				/* the first and the last buffer? */
965a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				totlen &= RBD_MASK; /* length of this frame */
966a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				writew(0x00, &rbd->status);
967c056b734e54e12f38f34a2583a4824e6cecc16c1Pradeep A Dalvi				skb = netdev_alloc_skb(dev, totlen + 2);
968a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				if (skb != NULL) {
969a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					skb_reserve(skb, 2);
970a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					skb_put(skb, totlen);
97105bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro					memcpy_fromio(skb->data, p->base + readl(&rbd->buffer), totlen);
972a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					skb->protocol = eth_type_trans(skb, dev);
973a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					netif_rx(skb);
9744265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy					dev->stats.rx_packets++;
9754265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy					dev->stats.rx_bytes += totlen;
976a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				} else
9774265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy					dev->stats.rx_dropped++;
978a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			} else {
979a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				int rstat;
980a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				 /* free all RBD's until RBD_LAST is set */
981a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				totlen = 0;
982a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				while (!((rstat = readw(&rbd->status)) & RBD_LAST)) {
983a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					totlen += rstat & RBD_MASK;
984a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					if (!rstat) {
985a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox						printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name);
986a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox						break;
9871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds					}
988a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					writew(0, &rbd->status);
98905bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro					rbd = make32(readw(&rbd->next));
9901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				}
991a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				totlen += rstat & RBD_MASK;
992a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				writew(0, &rbd->status);
993a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				printk(KERN_ERR "%s: received oversized frame! length: %d\n",
994a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox					dev->name, totlen);
9954265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy				dev->stats.rx_dropped++;
9961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 }
997a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		} else {/* frame !(ok), only with 'save-bad-frames' */
998a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n",
999a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name, status);
10004265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy			dev->stats.rx_errors++;
10011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1002a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(0, &p->rfd_top->stat_high);
1003a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */
1004a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(0xffff, &p->rfd_top->rbd_offset);
1005a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(0, &p->rfd_last->last);	/* delete RFD_SUSP	*/
10061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		p->rfd_last = p->rfd_top;
100705bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro		p->rfd_top = make32(readw(&p->rfd_top->next)); /* step to next RFD */
1008a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(make16(p->rfd_top), &p->scb->rfa_offset);
10091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1010a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (debuglevel > 0)
1011a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk("%d", cnt++);
10121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
10131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1014a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (automatic_resume) {
1015a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		wait_for_scb_cmd(dev);
1016a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(RUC_RESUME, &p->scb->cmd_ruc);
10171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni_attn586();
1018a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		wait_for_scb_cmd_ruc(dev);
10191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
10201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef WAIT_4_BUSY
10221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	{
10231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		int i;
1024a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		for (i = 0; i < 1024; i++) {
1025a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			if (p->rfd_top->status)
10261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				break;
1027a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			udelay(16);
1028a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			if (i == 1023)
1029a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name);
10301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
10311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
10321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
1033a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (debuglevel > 0)
10341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		printk("r");
10351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
10361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**********************************************************
10381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * handle 'Receiver went not ready'.
10391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
10401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void ni52_rnr_int(struct net_device *dev)
10421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
10434cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
10441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10454265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy	dev->stats.rx_errors++;
10461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1047a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_scb_cmd(dev);		/* wait for the last cmd, WAIT_4_FULLSTAT?? */
1048a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(RUC_ABORT, &p->scb->cmd_ruc); /* usually the RU is in the 'no resource'-state .. abort it now. */
10491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_attn586();
1050a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_scb_cmd_ruc(dev);		/* wait for accept cmd. */
10511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10522d76c267e90aafef72df1318b49cb8f43a59ac94Al Viro	alloc_rfa(dev, p->rfd_first);
1053a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* maybe add a check here, before restarting the RU */
10541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	startrecv586(dev); /* restart RU */
10551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
105605bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro	printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n",
105705bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro		dev->name, readb(&p->scb->rus));
10581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
10601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**********************************************************
10621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * handle xmit - interrupt
10631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
10641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void ni52_xmt_int(struct net_device *dev)
10661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
10671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int status;
10684cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
10691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1070a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (debuglevel > 0)
10711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		printk("X");
10721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1073a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status);
1074a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (!(status & STAT_COMPL))
1075a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
10761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1077a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (status & STAT_OK) {
10784265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy		dev->stats.tx_packets++;
10794265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy		dev->stats.collisions += (status & TCMD_MAXCOLLMASK);
1080a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	} else {
10814265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy		dev->stats.tx_errors++;
1082a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (status & TCMD_LATECOLL) {
1083a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: late collision detected.\n",
1084a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
10854265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy			dev->stats.collisions++;
1086a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		} else if (status & TCMD_NOCARRIER) {
10874265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy			dev->stats.tx_carrier_errors++;
1088a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: no carrier detected.\n",
1089a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
1090a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		} else if (status & TCMD_LOSTCTS)
1091a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: loss of CTS detected.\n",
1092a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
1093a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		else if (status & TCMD_UNDERRUN) {
10944265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy			dev->stats.tx_fifo_errors++;
1095a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: DMA underrun detected.\n",
1096a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
1097a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		} else if (status & TCMD_MAXCOLL) {
1098a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_ERR "%s: Max. collisions exceeded.\n",
1099a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
11004265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy			dev->stats.collisions += 16;
11011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
11021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
11031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if (NUM_XMIT_BUFFS > 1)
1104a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if ((++p->xmit_last) == NUM_XMIT_BUFFS)
11051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		p->xmit_last = 0;
11061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
11071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	netif_wake_queue(dev);
11081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
11091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/***********************************************************
11111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (re)start the receiver
11121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
11131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void startrecv586(struct net_device *dev)
11151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
11164cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
11171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1118a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_scb_cmd(dev);
1119a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_scb_cmd_ruc(dev);
1120a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->rfd_first), &p->scb->rfa_offset);
1121a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writeb(RUC_START, &p->scb->cmd_ruc);
11221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_attn586();		/* start cmd. */
1123a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	wait_for_scb_cmd_ruc(dev);
1124a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* wait for accept cmd. (no timeout!!) */
11251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
11261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void ni52_timeout(struct net_device *dev)
11281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
11294cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
11301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef NO_NOPCOMMANDS
1131a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */
11321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		netif_wake_queue(dev);
11331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef DEBUG
1134a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n",
1135a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			dev->name);
1136a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: X0: %04x N0: %04x N1: %04x %d\n",
1137a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			dev->name, (int)p->xmit_cmds[0]->cmd_status,
1138a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			readw(&p->nop_cmds[0]->cmd_status),
1139a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			readw(&p->nop_cmds[1]->cmd_status),
1140a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			p->nop_point);
11411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
1142a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(CUC_ABORT, &p->scb->cmd_cuc);
11431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni_attn586();
1144a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		wait_for_scb_cmd(dev);
1145a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset);
1146a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writeb(CUC_START, &p->scb->cmd_cuc);
11471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni_attn586();
1148a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		wait_for_scb_cmd(dev);
11491ae5dc342ac78d7a42965fd1f323815f6f5ef2c1Eric Dumazet		dev->trans_start = jiffies; /* prevent tx timeout */
11501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return 0;
11511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
11521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
11531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	{
11541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef DEBUG
1155a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n",
1156a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name, readb(&p->scb->cus));
1157a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: command-stats: %04x %04x\n",
1158a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name,
1159a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				readw(&p->xmit_cmds[0]->cmd_status),
1160a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				readw(&p->xmit_cmds[1]->cmd_status));
1161a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: check, whether you set the right interrupt number!\n",
1162a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name);
11631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
11641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni52_close(dev);
11651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ni52_open(dev);
11661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
11671ae5dc342ac78d7a42965fd1f323815f6f5ef2c1Eric Dumazet	dev->trans_start = jiffies; /* prevent tx timeout */
11681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
11691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/******************************************************
11711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * send frame
11721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
11731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
117461357325f377889a1daffa14962d705dc814dd0eStephen Hemmingerstatic netdev_tx_t ni52_send_packet(struct sk_buff *skb,
117561357325f377889a1daffa14962d705dc814dd0eStephen Hemminger				    struct net_device *dev)
11761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1177a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	int len, i;
11781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef NO_NOPCOMMANDS
11791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int next_nop;
11801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
11814cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
11821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1183a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (skb->len > XMIT_BUFF_SIZE) {
1184a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n", dev->name, XMIT_BUFF_SIZE, skb->len);
1185ec634fe328182a1a098585bfc7b69e5042bdb08dPatrick McHardy		return NETDEV_TX_OK;
11861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
11871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	netif_stop_queue(dev);
11891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
119005bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro	memcpy_toio(p->xmit_cbuffs[p->xmit_count], skb->data, skb->len);
1191a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	len = skb->len;
1192a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (len < ETH_ZLEN) {
1193a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		len = ETH_ZLEN;
119405bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro		memset_io(p->xmit_cbuffs[p->xmit_count]+skb->len, 0,
1195a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox							len - skb->len);
11961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
11971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if (NUM_XMIT_BUFFS == 1)
11991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#	ifdef NO_NOPCOMMANDS
12001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
12011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef DEBUG
120205bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro	if (readb(&p->scb->cus) & CU_ACTIVE) {
1203a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name);
1204a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "%s: stat: %04x %04x\n",
1205a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				dev->name, readb(&p->scb->cus),
1206a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				readw(&p->xmit_cmds[0]->cmd_status));
1207a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	}
12081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
120905bd831fcdf4ce08ae5b832cfe03a303245fb135Al Viro	writew(TBD_LAST | len, &p->xmit_buffs[0]->size);
1210a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	for (i = 0; i < 16; i++) {
1211a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		writew(0, &p->xmit_cmds[0]->cmd_status);
1212a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		wait_for_scb_cmd(dev);
1213a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND)
1214a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			writeb(CUC_RESUME, &p->scb->cmd_cuc);
1215a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		else {
1216a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset);
1217a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			writeb(CUC_START, &p->scb->cmd_cuc);
12181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1219a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		ni_attn586();
1220a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (!i)
1221a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			dev_kfree_skb(skb);
1222a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		wait_for_scb_cmd(dev);
1223a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		/* test it, because CU sometimes doesn't start immediately */
1224a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (readb(&p->scb->cus) & CU_ACTIVE)
1225a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			break;
1226a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (readw(&p->xmit_cmds[0]->cmd_status))
1227a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			break;
1228a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (i == 15)
1229a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
1230a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	}
1231a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox#	else
1232a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	next_nop = (p->nop_point + 1) & 0x1;
1233a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(TBD_LAST | len, &p->xmit_buffs[0]->size);
1234a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link);
1235a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->nop_cmds[next_nop]),
1236a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				&p->nop_cmds[next_nop]->cmd_link);
1237a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &p->xmit_cmds[0]->cmd_status);
1238a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &p->nop_cmds[next_nop]->cmd_status);
1239a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox
1240a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link);
1241a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	p->nop_point = next_nop;
1242a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	dev_kfree_skb(skb);
12431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#	endif
12441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
1245a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size);
1246a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	next_nop = p->xmit_count + 1
1247a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (next_nop == NUM_XMIT_BUFFS)
1248a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		next_nop = 0;
1249a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status);
1250a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* linkpointer of xmit-command already points to next nop cmd */
1251a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->nop_cmds[next_nop]),
1252a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				&p->nop_cmds[next_nop]->cmd_link);
1253a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &p->nop_cmds[next_nop]->cmd_status);
1254a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(make16(p->xmit_cmds[p->xmit_count]),
1255a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox				&p->nop_cmds[p->xmit_count]->cmd_link);
1256a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	p->xmit_count = next_nop;
1257a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	{
1258a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		unsigned long flags;
1259a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		spin_lock_irqsave(&p->spinlock);
1260a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		if (p->xmit_count != p->xmit_last)
1261a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox			netif_wake_queue(dev);
1262a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		spin_unlock_irqrestore(&p->spinlock);
12631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1264a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	dev_kfree_skb(skb);
1265a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox#endif
1266ec634fe328182a1a098585bfc7b69e5042bdb08dPatrick McHardy	return NETDEV_TX_OK;
12671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
12681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
12691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*******************************************
12701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Someone wanna have the statistics
12711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
12721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
12731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct net_device_stats *ni52_get_stats(struct net_device *dev)
12741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
12754cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev);
1276a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	unsigned short crc, aln, rsc, ovrn;
1277a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox
1278a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	/* Get error-statistics from the ni82586 */
1279a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	crc = readw(&p->scb->crc_errs);
1280a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &p->scb->crc_errs);
1281a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	aln = readw(&p->scb->aln_errs);
1282a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &p->scb->aln_errs);
1283a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	rsc = readw(&p->scb->rsc_errs);
1284a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &p->scb->rsc_errs);
1285a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	ovrn = readw(&p->scb->ovrn_errs);
1286a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	writew(0, &p->scb->ovrn_errs);
12871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
12884265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy	dev->stats.rx_crc_errors += crc;
12894265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy	dev->stats.rx_fifo_errors += ovrn;
12904265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy	dev->stats.rx_frame_errors += aln;
12914265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy	dev->stats.rx_dropped += rsc;
12921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
12934265e669ccafec0246f0bc45b7f461ff18da5acdKulikov Vasiliy	return &dev->stats;
12941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
12951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
12961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************
12971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Set MC list ..
12981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
12991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
13001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void set_multicast_list(struct net_device *dev)
13011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
13021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	netif_stop_queue(dev);
13031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_disint();
13041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	alloc586(dev);
13051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	init586(dev);
13061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	startrecv586(dev);
13071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ni_enaint();
13081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	netif_wake_queue(dev);
13091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
13101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
13111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef MODULE
13121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct net_device *dev_ni52;
13131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
13141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_param(io, int, 0);
13151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_param(irq, int, 0);
13161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_param(memstart, long, 0);
13171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_param(memend, long, 0);
13181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_PARM_DESC(io, "NI5210 I/O base address,required");
13191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_PARM_DESC(irq, "NI5210 IRQ number,required");
13201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_PARM_DESC(memstart, "NI5210 memory base address,required");
13211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_PARM_DESC(memend, "NI5210 memory end address,required");
13221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
132319a8664d8a05f75cab3cd4eb8022d22d3f0c53c3Andrew Mortonint __init init_module(void)
13241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1325a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox	if (io <= 0x0 || !memend || !memstart || irq < 2) {
1326a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n");
1327a197f6938db43b5ef464242f707233d3bd8842ebAlan Cox		printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
13281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return -ENODEV;
13291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
13301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	dev_ni52 = ni52_probe(-1);
13311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (IS_ERR(dev_ni52))
13321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return PTR_ERR(dev_ni52);
13331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return 0;
13341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
13351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1336afc8eb46c0ea2cab8bc28713b2e0614f015a7516Al Virovoid __exit cleanup_module(void)
13371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
13384cf1653aa90c6320dc8032443b5e322820aa28b1Wang Chen	struct priv *p = netdev_priv(dev_ni52);
13391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unregister_netdev(dev_ni52);
1340176f65f3efb55723518d018c8020867f44d05147Al Viro	iounmap(p->mapped);
13411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE);
13421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	free_netdev(dev_ni52);
13431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
13441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* MODULE */
13451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
13461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL");
1347