Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net-3-driver for the NI5210 card (i82586 Ethernet chip) |
| 3 | * |
| 4 | * This is an extension to the Linux operating system, and is covered by the |
| 5 | * same GNU General Public License that covers that work. |
| 6 | * |
| 7 | * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later) |
| 8 | * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de) |
| 9 | * [feel free to mail ....] |
| 10 | * |
| 11 | * when using as module: (no autoprobing!) |
| 12 | * compile with: |
| 13 | * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ -DMODULE -c ni52.c |
| 14 | * run with e.g: |
| 15 | * insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000 |
| 16 | * |
| 17 | * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!. |
| 18 | * |
| 19 | * If you find a bug, please report me: |
| 20 | * The kernel panic output and any kmsg from the ni52 driver |
| 21 | * the ni5210-driver-version and the linux-kernel version |
| 22 | * how many shared memory (memsize) on the netcard, |
| 23 | * bootprom: yes/no, base_addr, mem_start |
| 24 | * maybe the ni5210-card revision and the i82586 version |
| 25 | * |
| 26 | * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340 |
| 27 | * mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000, |
| 28 | * 0xd8000,0xcc000,0xce000,0xda000,0xdc000 |
| 29 | * |
| 30 | * sources: |
| 31 | * skeleton.c from Donald Becker |
| 32 | * |
| 33 | * I have also done a look in the following sources: (mail me if you need them) |
| 34 | * crynwr-packet-driver by Russ Nelson |
| 35 | * Garret A. Wollman's (fourth) i82586-driver for BSD |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 36 | * (before getting an i82596 (yes 596 not 586) manual, the existing drivers |
| 37 | * helped me a lot to understand this tricky chip.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | * |
| 39 | * Known Problems: |
| 40 | * The internal sysbus seems to be slow. So we often lose packets because of |
| 41 | * overruns while receiving from a fast remote host. |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 42 | * This can slow down TCP connections. Maybe the newer ni5210 cards are |
| 43 | * better. My experience is, that if a machine sends with more than about |
| 44 | * 500-600K/s the fifo/sysbus overflows. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | * |
| 46 | * IMPORTANT NOTE: |
| 47 | * On fast networks, it's a (very) good idea to have 16K shared memory. With |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 48 | * 8K, we can store only 4 receive frames, so it can (easily) happen that a |
| 49 | * remote machine 'overruns' our system. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | * |
| 51 | * Known i82586/card problems (I'm sure, there are many more!): |
| 52 | * Running the NOP-mode, the i82586 sometimes seems to forget to report |
| 53 | * every xmit-interrupt until we restart the CU. |
| 54 | * Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit |
| 55 | * in the RBD-Struct which indicates an end of the RBD queue. |
| 56 | * Instead, the RU fetches another (randomly selected and |
| 57 | * usually used) RBD and begins to fill it. (Maybe, this happens only if |
| 58 | * the last buffer from the previous RFD fits exact into the queue and |
| 59 | * the next RFD can't fetch an initial RBD. Anyone knows more? ) |
| 60 | * |
| 61 | * results from ftp performance tests with Linux 1.2.5 |
| 62 | * send and receive about 350-400 KByte/s (peak up to 460 kbytes/s) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 63 | * sending in NOP-mode: peak performance up to 530K/s (but better don't |
| 64 | * run this mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | */ |
| 66 | |
| 67 | /* |
| 68 | * 29.Sept.96: virt_to_bus changes for new memory scheme |
| 69 | * 19.Feb.96: more Mcast changes, module support (MH) |
| 70 | * |
| 71 | * 18.Nov.95: Mcast changes (AC). |
| 72 | * |
| 73 | * 23.April.95: fixed(?) receiving problems by configuring a RFD more |
| 74 | * than the number of RBD's. Can maybe cause other problems. |
| 75 | * 18.April.95: Added MODULE support (MH) |
| 76 | * 17.April.95: MC related changes in init586() and set_multicast_list(). |
| 77 | * removed use of 'jiffies' in init586() (MH) |
| 78 | * |
| 79 | * 19.Sep.94: Added Multicast support (not tested yet) (MH) |
| 80 | * |
| 81 | * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling. |
| 82 | * Now, every RFD has exact one RBD. (MH) |
| 83 | * |
| 84 | * 14.Sep.94: added promiscuous mode, a few cleanups (MH) |
| 85 | * |
| 86 | * 19.Aug.94: changed request_irq() parameter (MH) |
| 87 | * |
| 88 | * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH) |
| 89 | * |
| 90 | * 19.July.94: lotsa cleanups .. (MH) |
| 91 | * |
| 92 | * 17.July.94: some patches ... verified to run with 1.1.29 (MH) |
| 93 | * |
| 94 | * 4.July.94: patches for Linux 1.1.24 (MH) |
| 95 | * |
| 96 | * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH) |
| 97 | * |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 98 | * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff, |
| 99 | * too (MH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | * |
| 101 | * < 30.Sep.93: first versions |
| 102 | */ |
| 103 | |
| 104 | static int debuglevel; /* debug-printk 0: off 1: a few 2: more */ |
| 105 | static int automatic_resume; /* experimental .. better should be zero */ |
| 106 | static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 107 | static int fifo = 0x8; /* don't change */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | #include <linux/module.h> |
| 110 | #include <linux/kernel.h> |
| 111 | #include <linux/string.h> |
| 112 | #include <linux/errno.h> |
| 113 | #include <linux/ioport.h> |
| 114 | #include <linux/slab.h> |
| 115 | #include <linux/interrupt.h> |
| 116 | #include <linux/delay.h> |
| 117 | #include <linux/init.h> |
| 118 | #include <linux/bitops.h> |
| 119 | #include <asm/io.h> |
| 120 | |
| 121 | #include <linux/netdevice.h> |
| 122 | #include <linux/etherdevice.h> |
| 123 | #include <linux/skbuff.h> |
| 124 | |
| 125 | #include "ni52.h" |
| 126 | |
| 127 | #define DRV_NAME "ni52" |
| 128 | |
| 129 | #define DEBUG /* debug on */ |
| 130 | #define SYSBUSVAL 1 /* 8 Bit */ |
| 131 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 132 | #define ni_attn586() { outb(0, dev->base_addr + NI52_ATTENTION); } |
| 133 | #define ni_reset586() { outb(0, dev->base_addr + NI52_RESET); } |
| 134 | #define ni_disint() { outb(0, dev->base_addr + NI52_INTDIS); } |
| 135 | #define ni_enaint() { outb(0, dev->base_addr + NI52_INTENA); } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 137 | #define make32(ptr16) (p->memtop + (short) (ptr16)) |
| 138 | #define make24(ptr32) ((unsigned long)(ptr32)) - p->base |
| 139 | #define make16(ptr32) ((unsigned short) ((unsigned long)(ptr32)\ |
| 140 | - (unsigned long) p->memtop)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | /******************* how to calculate the buffers ***************************** |
| 143 | |
| 144 | * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works |
| 145 | * --------------- in a different (more stable?) mode. Only in this mode it's |
| 146 | * possible to configure the driver with 'NO_NOPCOMMANDS' |
| 147 | |
| 148 | sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8; |
| 149 | sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT |
| 150 | sizeof(rfd) = 24; sizeof(rbd) = 12; |
| 151 | sizeof(tbd) = 8; sizeof(transmit_cmd) = 16; |
| 152 | sizeof(nop_cmd) = 8; |
| 153 | |
| 154 | * if you don't know the driver, better do not change these values: */ |
| 155 | |
| 156 | #define RECV_BUFF_SIZE 1524 /* slightly oversized */ |
| 157 | #define XMIT_BUFF_SIZE 1524 /* slightly oversized */ |
| 158 | #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */ |
| 159 | #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */ |
| 160 | #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */ |
| 161 | #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */ |
| 162 | |
| 163 | /**************************************************************************/ |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | #define NI52_TOTAL_SIZE 16 |
| 167 | #define NI52_ADDR0 0x02 |
| 168 | #define NI52_ADDR1 0x07 |
| 169 | #define NI52_ADDR2 0x01 |
| 170 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 171 | static int ni52_probe1(struct net_device *dev, int ioaddr); |
| 172 | static irqreturn_t ni52_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | static int ni52_open(struct net_device *dev); |
| 174 | static int ni52_close(struct net_device *dev); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 175 | static int ni52_send_packet(struct sk_buff *, struct net_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | static struct net_device_stats *ni52_get_stats(struct net_device *dev); |
| 177 | static void set_multicast_list(struct net_device *dev); |
| 178 | static void ni52_timeout(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | /* helper-functions */ |
| 181 | static int init586(struct net_device *dev); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 182 | static int check586(struct net_device *dev, char *where, unsigned size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | static void alloc586(struct net_device *dev); |
| 184 | static void startrecv586(struct net_device *dev); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 185 | static void *alloc_rfa(struct net_device *dev, void *ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | static void ni52_rcv_int(struct net_device *dev); |
| 187 | static void ni52_xmt_int(struct net_device *dev); |
| 188 | static void ni52_rnr_int(struct net_device *dev); |
| 189 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 190 | struct priv { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | struct net_device_stats stats; |
| 192 | unsigned long base; |
| 193 | char *memtop; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 194 | spinlock_t spinlock; |
| 195 | int reset; |
| 196 | struct rfd_struct *rfd_last, *rfd_top, *rfd_first; |
| 197 | struct scp_struct *scp; |
| 198 | struct iscp_struct *iscp; |
| 199 | struct scb_struct *scb; |
| 200 | struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | #if (NUM_XMIT_BUFFS == 1) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 202 | struct transmit_cmd_struct *xmit_cmds[2]; |
| 203 | struct nop_cmd_struct *nop_cmds[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 205 | struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS]; |
| 206 | struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 208 | int nop_point, num_recv_buffs; |
| 209 | char *xmit_cbuffs[NUM_XMIT_BUFFS]; |
| 210 | int xmit_count, xmit_last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 213 | /* wait for command with timeout: */ |
| 214 | static void wait_for_scb_cmd(struct net_device *dev) |
| 215 | { |
| 216 | struct priv *p = dev->priv; |
| 217 | int i; |
| 218 | for (i = 0; i < 16384; i++) { |
| 219 | if (readb(&p->scb->cmd_cuc) == 0) |
| 220 | break; |
| 221 | udelay(4); |
| 222 | if (i == 16383) { |
| 223 | printk(KERN_ERR "%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n", |
| 224 | dev->name, readb(&p->scb->cmd_cuc), readb(&p->scb->cus)); |
| 225 | if (!p->reset) { |
| 226 | p->reset = 1; |
| 227 | ni_reset586(); |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | static void wait_for_scb_cmd_ruc(struct net_device *dev) |
| 234 | { |
| 235 | struct priv *p = dev->priv; |
| 236 | int i; |
| 237 | for (i = 0; i < 16384; i++) { |
| 238 | if (readb(&p->scb->cmd_ruc) == 0) |
| 239 | break; |
| 240 | udelay(4); |
| 241 | if (i == 16383) { |
| 242 | printk(KERN_ERR "%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n", |
| 243 | dev->name, p->scb->cmd_ruc, p->scb->rus); |
| 244 | if (!p->reset) { |
| 245 | p->reset = 1; |
| 246 | ni_reset586(); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | static void wait_for_stat_compl(void *p) |
| 253 | { |
| 254 | struct nop_cmd_struct *addr = p; |
| 255 | int i; |
| 256 | for (i = 0; i < 32767; i++) { |
| 257 | if (readw(&((addr)->cmd_status)) & STAT_COMPL) |
| 258 | break; |
| 259 | udelay(32); |
| 260 | } |
| 261 | } |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | /********************************************** |
| 264 | * close device |
| 265 | */ |
| 266 | static int ni52_close(struct net_device *dev) |
| 267 | { |
| 268 | free_irq(dev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | ni_reset586(); /* the hard way to stop the receiver */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | /********************************************** |
| 275 | * open device |
| 276 | */ |
| 277 | static int ni52_open(struct net_device *dev) |
| 278 | { |
| 279 | int ret; |
| 280 | |
| 281 | ni_disint(); |
| 282 | alloc586(dev); |
| 283 | init586(dev); |
| 284 | startrecv586(dev); |
| 285 | ni_enaint(); |
| 286 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 287 | ret = request_irq(dev->irq, &ni52_interrupt, 0, dev->name, dev); |
| 288 | if (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | ni_reset586(); |
| 290 | return ret; |
| 291 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | netif_start_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | return 0; /* most done by init */ |
| 294 | } |
| 295 | |
| 296 | /********************************************** |
| 297 | * Check to see if there's an 82586 out there. |
| 298 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 299 | static int check586(struct net_device *dev, char *where, unsigned size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
| 301 | struct priv pb; |
| 302 | struct priv *p = /* (struct priv *) dev->priv*/ &pb; |
| 303 | char *iscp_addrs[2]; |
| 304 | int i; |
| 305 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 306 | p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) |
| 307 | + size - 0x01000000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | p->memtop = isa_bus_to_virt((unsigned long)where) + size; |
| 309 | p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 310 | memset_io((char *)p->scp, 0, sizeof(struct scp_struct)); |
| 311 | for (i = 0; i < sizeof(struct scp_struct); i++) |
| 312 | /* memory was writeable? */ |
| 313 | if (readb((char *)p->scp + i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | return 0; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 315 | writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */ |
| 316 | if (readb(&p->scp->sysbus) != SYSBUSVAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return 0; |
| 318 | |
| 319 | iscp_addrs[0] = isa_bus_to_virt((unsigned long)where); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 320 | iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 322 | for (i = 0; i < 2; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | p->iscp = (struct iscp_struct *) iscp_addrs[i]; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 324 | memset_io((char *)p->iscp, 0, sizeof(struct iscp_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 326 | writel(make24(p->iscp), &p->scp->iscp); |
| 327 | writeb(1, &p->iscp->busy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | ni_reset586(); |
| 330 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 331 | mdelay(32); /* wait a while... */ |
| 332 | /* i82586 clears 'busy' after successful init */ |
| 333 | if (readb(&p->iscp->busy)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | return 1; |
| 337 | } |
| 338 | |
| 339 | /****************************************************************** |
| 340 | * set iscp at the right place, called by ni52_probe1 and open586. |
| 341 | */ |
| 342 | static void alloc586(struct net_device *dev) |
| 343 | { |
| 344 | struct priv *p = (struct priv *) dev->priv; |
| 345 | |
| 346 | ni_reset586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 347 | mdelay(32); |
| 348 | |
| 349 | spin_lock_init(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS); |
| 352 | p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 353 | p->iscp = (struct iscp_struct *) |
| 354 | ((char *)p->scp - sizeof(struct iscp_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 356 | memset_io(p->iscp, 0, sizeof(struct iscp_struct)); |
| 357 | memset_io(p->scp , 0, sizeof(struct scp_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 359 | writel(make24(p->iscp), &p->scp->iscp); |
| 360 | writeb(SYSBUSVAL, &p->scp->sysbus); |
| 361 | writew(make16(p->scb), &p->iscp->scb_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 363 | writeb(1, &p->iscp->busy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | ni_reset586(); |
| 365 | ni_attn586(); |
| 366 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 367 | mdelay(32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 369 | if (readb(&p->iscp->busy)) |
| 370 | printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 372 | p->reset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 374 | memset_io((char *)p->scb, 0, sizeof(struct scb_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /* set: io,irq,memstart,memend or set it when calling insmod */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 378 | static int irq = 9; |
| 379 | static int io = 0x300; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | static long memstart; /* e.g 0xd0000 */ |
| 381 | static long memend; /* e.g 0xd4000 */ |
| 382 | |
| 383 | /********************************************** |
| 384 | * probe the ni5210-card |
| 385 | */ |
| 386 | struct net_device * __init ni52_probe(int unit) |
| 387 | { |
| 388 | struct net_device *dev = alloc_etherdev(sizeof(struct priv)); |
| 389 | static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0}; |
| 390 | int *port; |
| 391 | int err = 0; |
| 392 | |
| 393 | if (!dev) |
| 394 | return ERR_PTR(-ENOMEM); |
| 395 | |
| 396 | if (unit >= 0) { |
| 397 | sprintf(dev->name, "eth%d", unit); |
| 398 | netdev_boot_setup_check(dev); |
| 399 | io = dev->base_addr; |
| 400 | irq = dev->irq; |
| 401 | memstart = dev->mem_start; |
| 402 | memend = dev->mem_end; |
| 403 | } |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | if (io > 0x1ff) { /* Check a single specified location. */ |
| 406 | err = ni52_probe1(dev, io); |
| 407 | } else if (io > 0) { /* Don't probe at all. */ |
| 408 | err = -ENXIO; |
| 409 | } else { |
| 410 | for (port = ports; *port && ni52_probe1(dev, *port) ; port++) |
| 411 | ; |
| 412 | if (*port) |
| 413 | goto got_it; |
| 414 | #ifdef FULL_IO_PROBE |
| 415 | for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8) |
| 416 | ; |
| 417 | if (io < 0x400) |
| 418 | goto got_it; |
| 419 | #endif |
| 420 | err = -ENODEV; |
| 421 | } |
| 422 | if (err) |
| 423 | goto out; |
| 424 | got_it: |
| 425 | err = register_netdev(dev); |
| 426 | if (err) |
| 427 | goto out1; |
| 428 | return dev; |
| 429 | out1: |
| 430 | release_region(dev->base_addr, NI52_TOTAL_SIZE); |
| 431 | out: |
| 432 | free_netdev(dev); |
| 433 | return ERR_PTR(err); |
| 434 | } |
| 435 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 436 | static int __init ni52_probe1(struct net_device *dev, int ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | { |
| 438 | int i, size, retval; |
| 439 | |
| 440 | dev->base_addr = ioaddr; |
| 441 | dev->irq = irq; |
| 442 | dev->mem_start = memstart; |
| 443 | dev->mem_end = memend; |
| 444 | |
| 445 | if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME)) |
| 446 | return -EBUSY; |
| 447 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 448 | if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) { |
| 450 | retval = -ENODEV; |
| 451 | goto out; |
| 452 | } |
| 453 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 454 | for (i = 0; i < ETH_ALEN; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | dev->dev_addr[i] = inb(dev->base_addr+i); |
| 456 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 457 | if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | || dev->dev_addr[2] != NI52_ADDR2) { |
| 459 | retval = -ENODEV; |
| 460 | goto out; |
| 461 | } |
| 462 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 463 | printk(KERN_INFO "%s: NI5210 found at %#3lx, ", |
| 464 | dev->name, dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | /* |
| 467 | * check (or search) IO-Memory, 8K and 16K |
| 468 | */ |
| 469 | #ifdef MODULE |
| 470 | size = dev->mem_end - dev->mem_start; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 471 | if (size != 0x2000 && size != 0x4000) { |
| 472 | printk("\n"); |
| 473 | printk(KERN_ERR "%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev->name, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | retval = -ENODEV; |
| 475 | goto out; |
| 476 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 477 | if (!check586(dev, (char *)dev->mem_start, size)) { |
| 478 | printk(KERN_ERR "?memcheck, Can't find memory at 0x%lx with size %d!\n", dev->mem_start, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | retval = -ENODEV; |
| 480 | goto out; |
| 481 | } |
| 482 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 483 | if (dev->mem_start != 0) { |
| 484 | /* no auto-mem-probe */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | size = 0x4000; /* check for 16K mem */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 486 | if (!check586(dev, (char *) dev->mem_start, size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | size = 0x2000; /* check for 8K mem */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 488 | if (!check586(dev, (char *)dev->mem_start, size)) { |
| 489 | printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | retval = -ENODEV; |
| 491 | goto out; |
| 492 | } |
| 493 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 494 | } else { |
| 495 | static const unsigned long memaddrs[] = { |
| 496 | 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000, |
| 497 | 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0 |
| 498 | }; |
| 499 | for (i = 0;; i++) { |
| 500 | if (!memaddrs[i]) { |
| 501 | printk(KERN_ERR "?memprobe, Can't find io-memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | retval = -ENODEV; |
| 503 | goto out; |
| 504 | } |
| 505 | dev->mem_start = memaddrs[i]; |
| 506 | size = 0x2000; /* check for 8K mem */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 507 | if (check586(dev, (char *)dev->mem_start, size)) |
| 508 | /* 8K-check */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | break; |
| 510 | size = 0x4000; /* check for 16K mem */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 511 | if (check586(dev, (char *)dev->mem_start, size)) |
| 512 | /* 16K-check */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | break; |
| 514 | } |
| 515 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 516 | /* set mem_end showed by 'ifconfig' */ |
| 517 | dev->mem_end = dev->mem_start + size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | #endif |
| 519 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 520 | memset((char *)dev->priv, 0, sizeof(struct priv)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 522 | ((struct priv *)(dev->priv))->memtop = |
| 523 | isa_bus_to_virt(dev->mem_start) + size; |
| 524 | ((struct priv *)(dev->priv))->base = (unsigned long) |
| 525 | isa_bus_to_virt(dev->mem_start) + size - 0x01000000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | alloc586(dev); |
| 527 | |
| 528 | /* set number of receive-buffs according to memsize */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 529 | if (size == 0x2000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8; |
| 531 | else |
| 532 | ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16; |
| 533 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 534 | printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ", |
| 535 | dev->mem_start, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 537 | if (dev->irq < 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | unsigned long irq_mask; |
| 539 | |
| 540 | irq_mask = probe_irq_on(); |
| 541 | ni_reset586(); |
| 542 | ni_attn586(); |
| 543 | |
| 544 | mdelay(20); |
| 545 | dev->irq = probe_irq_off(irq_mask); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 546 | if (!dev->irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | printk("?autoirq, Failed to detect IRQ line!\n"); |
| 548 | retval = -EAGAIN; |
| 549 | goto out; |
| 550 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 551 | printk("IRQ %d (autodetected).\n", dev->irq); |
| 552 | } else { |
| 553 | if (dev->irq == 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | dev->irq = 9; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 555 | printk("IRQ %d (assigned and not checked!).\n", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | dev->open = ni52_open; |
| 559 | dev->stop = ni52_close; |
| 560 | dev->get_stats = ni52_get_stats; |
| 561 | dev->tx_timeout = ni52_timeout; |
| 562 | dev->watchdog_timeo = HZ/20; |
| 563 | dev->hard_start_xmit = ni52_send_packet; |
| 564 | dev->set_multicast_list = set_multicast_list; |
| 565 | |
| 566 | dev->if_port = 0; |
| 567 | |
| 568 | return 0; |
| 569 | out: |
| 570 | release_region(ioaddr, NI52_TOTAL_SIZE); |
| 571 | return retval; |
| 572 | } |
| 573 | |
| 574 | /********************************************** |
| 575 | * init the chip (ni52-interrupt should be disabled?!) |
| 576 | * needs a correct 'allocated' memory |
| 577 | */ |
| 578 | |
| 579 | static int init586(struct net_device *dev) |
| 580 | { |
| 581 | void *ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 582 | int i, result = 0; |
| 583 | struct priv *p = (struct priv *)dev->priv; |
| 584 | struct configure_cmd_struct *cfg_cmd; |
| 585 | struct iasetup_cmd_struct *ias_cmd; |
| 586 | struct tdr_cmd_struct *tdr_cmd; |
| 587 | struct mcsetup_cmd_struct *mc_cmd; |
| 588 | struct dev_mc_list *dmi = dev->mc_list; |
| 589 | int num_addrs = dev->mc_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
| 591 | ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct)); |
| 592 | |
| 593 | cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 594 | writew(0, &cfg_cmd->cmd_status); |
| 595 | writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd); |
| 596 | writew(0xFFFF, &cfg_cmd->cmd_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 598 | /* number of cfg bytes */ |
| 599 | writeb(0x0a, &cfg_cmd->byte_cnt); |
| 600 | /* fifo-limit (8=tx:32/rx:64) */ |
| 601 | writeb(fifo, &cfg_cmd->fifo); |
| 602 | /* hold or discard bad recv frames (bit 7) */ |
| 603 | writeb(0x40, &cfg_cmd->sav_bf); |
| 604 | /* addr_len |!src_insert |pre-len |loopback */ |
| 605 | writeb(0x2e, &cfg_cmd->adr_len); |
| 606 | writeb(0x00, &cfg_cmd->priority); |
| 607 | writeb(0x60, &cfg_cmd->ifs);; |
| 608 | writeb(0x00, &cfg_cmd->time_low); |
| 609 | writeb(0xf2, &cfg_cmd->time_high); |
| 610 | writeb(0x00, &cfg_cmd->promisc);; |
| 611 | if (dev->flags & IFF_ALLMULTI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | int len = ((char *) p->iscp - (char *) ptr - 8) / 6; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 613 | if (num_addrs > len) { |
| 614 | printk(KERN_ERR "%s: switching to promisc. mode\n", |
| 615 | dev->name); |
| 616 | dev->flags |= IFF_PROMISC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 619 | if (dev->flags & IFF_PROMISC) |
| 620 | writeb(0x01, &cfg_cmd->promisc); |
| 621 | writeb(0x00, &cfg_cmd->carr_coll); |
| 622 | writew(make16(cfg_cmd), &p->scb->cbl_offset); |
| 623 | writew(0, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 625 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | ni_attn586(); |
| 627 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 628 | wait_for_stat_compl(cfg_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 630 | if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != |
| 631 | (STAT_COMPL|STAT_OK)) { |
| 632 | printk(KERN_ERR "%s: configure command failed: %x\n", |
| 633 | dev->name, readw(&cfg_cmd->cmd_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | return 1; |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * individual address setup |
| 639 | */ |
| 640 | |
| 641 | ias_cmd = (struct iasetup_cmd_struct *)ptr; |
| 642 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 643 | writew(0, &ias_cmd->cmd_status); |
| 644 | writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd); |
| 645 | writew(0xffff, &ias_cmd->cmd_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 647 | memcpy_toio((char *)&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 649 | writew(make16(ias_cmd), &p->scb->cbl_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 651 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | ni_attn586(); |
| 653 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 654 | wait_for_stat_compl(ias_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 656 | if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != |
| 657 | (STAT_OK|STAT_COMPL)) { |
| 658 | printk(KERN_ERR "%s (ni52): individual address setup command failed: %04x\n", dev->name, readw(&ias_cmd->cmd_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | return 1; |
| 660 | } |
| 661 | |
| 662 | /* |
| 663 | * TDR, wire check .. e.g. no resistor e.t.c |
| 664 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | tdr_cmd = (struct tdr_cmd_struct *)ptr; |
| 667 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 668 | writew(0, &tdr_cmd->cmd_status); |
| 669 | writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd); |
| 670 | writew(0xffff, &tdr_cmd->cmd_link); |
| 671 | writew(0, &tdr_cmd->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 673 | writew(make16(tdr_cmd), &p->scb->cbl_offset); |
| 674 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | ni_attn586(); |
| 676 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 677 | wait_for_stat_compl(tdr_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 679 | if (!(readw(&tdr_cmd->cmd_status) & STAT_COMPL)) |
| 680 | printk(KERN_ERR "%s: Problems while running the TDR.\n", |
| 681 | dev->name); |
| 682 | else { |
| 683 | udelay(16); |
| 684 | result = readw(&tdr_cmd->status); |
| 685 | writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | ni_attn586(); /* ack the interrupts */ |
| 687 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 688 | if (result & TDR_LNK_OK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | ; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 690 | else if (result & TDR_XCVR_PRB) |
| 691 | printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n", |
| 692 | dev->name); |
| 693 | else if (result & TDR_ET_OPN) |
| 694 | printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n", |
| 695 | dev->name, result & TDR_TIMEMASK); |
| 696 | else if (result & TDR_ET_SRT) { |
| 697 | /* time == 0 -> strange :-) */ |
| 698 | if (result & TDR_TIMEMASK) |
| 699 | printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n", |
| 700 | dev->name, result & TDR_TIMEMASK); |
| 701 | } else |
| 702 | printk(KERN_ERR "%s: TDR: Unknown status %04x\n", |
| 703 | dev->name, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /* |
| 707 | * Multicast setup |
| 708 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 709 | if (num_addrs && !(dev->flags & IFF_PROMISC)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | mc_cmd = (struct mcsetup_cmd_struct *) ptr; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 711 | writew(0, &mc_cmd->cmd_status); |
| 712 | writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd); |
| 713 | writew(0xffff, &mc_cmd->cmd_link); |
| 714 | writew(num_addrs * 6, &mc_cmd->mc_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 716 | for (i = 0; i < num_addrs; i++, dmi = dmi->next) |
| 717 | memcpy_toio((char *) mc_cmd->mc_list[i], |
| 718 | dmi->dmi_addr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 720 | writew(make16(mc_cmd), &p->scb->cbl_offset); |
| 721 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | ni_attn586(); |
| 723 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 724 | wait_for_stat_compl(mc_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 726 | if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK)) |
| 727 | != (STAT_COMPL|STAT_OK)) |
| 728 | printk(KERN_ERR "%s: Can't apply multicast-address-list.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /* |
| 732 | * alloc nop/xmit-cmds |
| 733 | */ |
| 734 | #if (NUM_XMIT_BUFFS == 1) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 735 | for (i = 0; i < 2; i++) { |
| 736 | p->nop_cmds[i] = (struct nop_cmd_struct *)ptr; |
| 737 | writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd); |
| 738 | writew(0, &p->nop_cmds[i]->cmd_status); |
| 739 | writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | ptr = (char *) ptr + sizeof(struct nop_cmd_struct); |
| 741 | } |
| 742 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 743 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
| 744 | p->nop_cmds[i] = (struct nop_cmd_struct *)ptr; |
| 745 | writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd); |
| 746 | writew(0, &p->nop_cmds[i]->cmd_status); |
| 747 | writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | ptr = (char *) ptr + sizeof(struct nop_cmd_struct); |
| 749 | } |
| 750 | #endif |
| 751 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 752 | ptr = alloc_rfa(dev, (void *)ptr); /* init receive-frame-area */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | /* |
| 755 | * alloc xmit-buffs / init xmit_cmds |
| 756 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 757 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
| 758 | /* Transmit cmd/buff 0 */ |
| 759 | p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | ptr = (char *) ptr + sizeof(struct transmit_cmd_struct); |
| 761 | p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */ |
| 762 | ptr = (char *) ptr + XMIT_BUFF_SIZE; |
| 763 | p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */ |
| 764 | ptr = (char *) ptr + sizeof(struct tbd_struct); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 765 | if ((void *)ptr > (void *)p->iscp) { |
| 766 | printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", |
| 767 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | return 1; |
| 769 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 770 | memset_io((char *)(p->xmit_cmds[i]), 0, |
| 771 | sizeof(struct transmit_cmd_struct)); |
| 772 | memset_io((char *)(p->xmit_buffs[i]), 0, |
| 773 | sizeof(struct tbd_struct)); |
| 774 | writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]), |
| 775 | &p->xmit_cmds[i]->cmd_link); |
| 776 | writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status); |
| 777 | writew(CMD_XMIT|CMD_INT, &p->xmit_cmds[i]->cmd_cmd); |
| 778 | writew(make16(p->xmit_buffs[i]), &p->xmit_cmds[i]->tbd_offset); |
| 779 | writew(0xffff, &p->xmit_buffs[i]->next); |
| 780 | writel(make24(p->xmit_cbuffs[i]), &p->xmit_buffs[i]->buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | p->xmit_count = 0; |
| 784 | p->xmit_last = 0; |
| 785 | #ifndef NO_NOPCOMMANDS |
| 786 | p->nop_point = 0; |
| 787 | #endif |
| 788 | |
| 789 | /* |
| 790 | * 'start transmitter' |
| 791 | */ |
| 792 | #ifndef NO_NOPCOMMANDS |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 793 | writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset); |
| 794 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 796 | wait_for_scb_cmd(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 798 | writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link); |
| 799 | writew(CMD_XMIT | CMD_SUSPEND | CMD_INT, &p->xmit_cmds[0]->cmd_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | #endif |
| 801 | |
| 802 | /* |
| 803 | * ack. interrupts |
| 804 | */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 805 | writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 807 | udelay(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
| 809 | ni_enaint(); |
| 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | /****************************************************** |
| 815 | * This is a helper routine for ni52_rnr_int() and init586(). |
| 816 | * It sets up the Receive Frame Area (RFA). |
| 817 | */ |
| 818 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 819 | static void *alloc_rfa(struct net_device *dev, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 821 | struct rfd_struct *rfd = (struct rfd_struct *)ptr; |
| 822 | struct rbd_struct *rbd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | int i; |
| 824 | struct priv *p = (struct priv *) dev->priv; |
| 825 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 826 | memset_io((char *) rfd, 0, |
| 827 | sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | p->rfd_first = rfd; |
| 829 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 830 | for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) { |
| 831 | writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)), |
| 832 | &rfd[i].next); |
| 833 | writew(0xffff, &rfd[i].rbd_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 835 | /* RU suspend */ |
| 836 | writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 838 | ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
| 840 | rbd = (struct rbd_struct *) ptr; |
| 841 | ptr = (void *) (rbd + p->num_recv_buffs); |
| 842 | |
| 843 | /* clr descriptors */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 844 | memset_io((char *)rbd, 0, |
| 845 | sizeof(struct rbd_struct) * (p->num_recv_buffs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 847 | for (i = 0; i < p->num_recv_buffs; i++) { |
| 848 | writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next); |
| 849 | writew(RECV_BUFF_SIZE, &rbd[i].size); |
| 850 | writel(make24(ptr), &rbd[i].buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | ptr = (char *) ptr + RECV_BUFF_SIZE; |
| 852 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | p->rfd_top = p->rfd_first; |
| 854 | p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd); |
| 855 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 856 | writew(make16(p->rfd_first), &p->scb->rfa_offset); |
| 857 | writew(make16(rbd), &p->rfd_first->rbd_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
| 859 | return ptr; |
| 860 | } |
| 861 | |
| 862 | |
| 863 | /************************************************** |
| 864 | * Interrupt Handler ... |
| 865 | */ |
| 866 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 867 | static irqreturn_t ni52_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | { |
| 869 | struct net_device *dev = dev_id; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 870 | unsigned int stat; |
| 871 | int cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | struct priv *p; |
| 873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | p = (struct priv *) dev->priv; |
| 875 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 876 | if (debuglevel > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | printk("I"); |
| 878 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 879 | spin_lock(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 881 | wait_for_scb_cmd(dev); /* wait for last command */ |
| 882 | |
| 883 | while ((stat = readb(&p->scb->cus) & STAT_MASK)) { |
| 884 | writeb(stat, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | ni_attn586(); |
| 886 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 887 | if (stat & STAT_FR) /* received a frame */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | ni52_rcv_int(dev); |
| 889 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 890 | if (stat & STAT_RNR) { /* RU went 'not ready' */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | printk("(R)"); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 892 | if (readb(&p->scb->rus) & RU_SUSPEND) { |
| 893 | /* special case: RU_SUSPEND */ |
| 894 | wait_for_scb_cmd(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | p->scb->cmd_ruc = RUC_RESUME; |
| 896 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 897 | wait_for_scb_cmd_ruc(dev); |
| 898 | } else { |
| 899 | printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n", |
| 900 | dev->name, stat, readb(&p->scb->rus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | ni52_rnr_int(dev); |
| 902 | } |
| 903 | } |
| 904 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 905 | /* Command with I-bit set complete */ |
| 906 | if (stat & STAT_CX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | ni52_xmt_int(dev); |
| 908 | |
| 909 | #ifndef NO_NOPCOMMANDS |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 910 | if (stat & STAT_CNA) { /* CU went 'not ready' */ |
| 911 | if (netif_running(dev)) |
| 912 | printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n", |
| 913 | dev->name, stat, readb(&p->scb->cus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | } |
| 915 | #endif |
| 916 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 917 | if (debuglevel > 1) |
| 918 | printk("%d", cnt++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 920 | /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */ |
| 921 | wait_for_scb_cmd(dev); |
| 922 | if (p->scb->cmd_cuc) { /* timed out? */ |
| 923 | printk(KERN_ERR "%s: Acknowledge timed out.\n", |
| 924 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | ni_disint(); |
| 926 | break; |
| 927 | } |
| 928 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 929 | spin_unlock(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 931 | if (debuglevel > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | printk("i"); |
| 933 | return IRQ_HANDLED; |
| 934 | } |
| 935 | |
| 936 | /******************************************************* |
| 937 | * receive-interrupt |
| 938 | */ |
| 939 | |
| 940 | static void ni52_rcv_int(struct net_device *dev) |
| 941 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 942 | int status, cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | unsigned short totlen; |
| 944 | struct sk_buff *skb; |
| 945 | struct rbd_struct *rbd; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 946 | struct priv *p = (struct priv *)dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 948 | if (debuglevel > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | printk("R"); |
| 950 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 951 | for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) { |
| 952 | rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset); |
| 953 | if (status & RFD_OK) { /* frame received without error? */ |
| 954 | totlen = readw(&rbd->status); |
| 955 | if (totlen & RBD_LAST) { |
| 956 | /* the first and the last buffer? */ |
| 957 | totlen &= RBD_MASK; /* length of this frame */ |
| 958 | writew(0x00, &rbd->status); |
| 959 | skb = (struct sk_buff *)dev_alloc_skb(totlen+2); |
| 960 | if (skb != NULL) { |
| 961 | skb_reserve(skb, 2); |
| 962 | skb_put(skb, totlen); |
| 963 | skb_copy_to_linear_data(skb, (char *)p->base + (unsigned long) rbd->buffer, totlen); |
| 964 | skb->protocol = eth_type_trans(skb, dev); |
| 965 | netif_rx(skb); |
| 966 | dev->last_rx = jiffies; |
| 967 | p->stats.rx_packets++; |
| 968 | p->stats.rx_bytes += totlen; |
| 969 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | p->stats.rx_dropped++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 971 | } else { |
| 972 | int rstat; |
| 973 | /* free all RBD's until RBD_LAST is set */ |
| 974 | totlen = 0; |
| 975 | while (!((rstat = readw(&rbd->status)) & RBD_LAST)) { |
| 976 | totlen += rstat & RBD_MASK; |
| 977 | if (!rstat) { |
| 978 | printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name); |
| 979 | break; |
| 980 | } |
| 981 | writew(0, &rbd->status); |
| 982 | rbd = (struct rbd_struct *) make32(readl(&rbd->next)); |
| 983 | } |
| 984 | totlen += rstat & RBD_MASK; |
| 985 | writew(0, &rbd->status); |
| 986 | printk(KERN_ERR "%s: received oversized frame! length: %d\n", |
| 987 | dev->name, totlen); |
| 988 | p->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 990 | } else {/* frame !(ok), only with 'save-bad-frames' */ |
| 991 | printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n", |
| 992 | dev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | p->stats.rx_errors++; |
| 994 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 995 | writeb(0, &p->rfd_top->stat_high); |
| 996 | writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */ |
| 997 | writew(0xffff, &p->rfd_top->rbd_offset); |
| 998 | writeb(0, &p->rfd_last->last); /* delete RFD_SUSP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | p->rfd_last = p->rfd_top; |
| 1000 | p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1001 | writew(make16(p->rfd_top), &p->scb->rfa_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1003 | if (debuglevel > 0) |
| 1004 | printk("%d", cnt++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1007 | if (automatic_resume) { |
| 1008 | wait_for_scb_cmd(dev); |
| 1009 | writeb(RUC_RESUME, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1011 | wait_for_scb_cmd_ruc(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | #ifdef WAIT_4_BUSY |
| 1015 | { |
| 1016 | int i; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1017 | for (i = 0; i < 1024; i++) { |
| 1018 | if (p->rfd_top->status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | break; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1020 | udelay(16); |
| 1021 | if (i == 1023) |
| 1022 | printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1026 | if (debuglevel > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | printk("r"); |
| 1028 | } |
| 1029 | |
| 1030 | /********************************************************** |
| 1031 | * handle 'Receiver went not ready'. |
| 1032 | */ |
| 1033 | |
| 1034 | static void ni52_rnr_int(struct net_device *dev) |
| 1035 | { |
| 1036 | struct priv *p = (struct priv *) dev->priv; |
| 1037 | |
| 1038 | p->stats.rx_errors++; |
| 1039 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1040 | wait_for_scb_cmd(dev); /* wait for the last cmd, WAIT_4_FULLSTAT?? */ |
| 1041 | writeb(RUC_ABORT, &p->scb->cmd_ruc); /* usually the RU is in the 'no resource'-state .. abort it now. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1043 | wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1045 | alloc_rfa(dev, (char *)p->rfd_first); |
| 1046 | /* maybe add a check here, before restarting the RU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | startrecv586(dev); /* restart RU */ |
| 1048 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1049 | printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->rus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
| 1051 | } |
| 1052 | |
| 1053 | /********************************************************** |
| 1054 | * handle xmit - interrupt |
| 1055 | */ |
| 1056 | |
| 1057 | static void ni52_xmt_int(struct net_device *dev) |
| 1058 | { |
| 1059 | int status; |
| 1060 | struct priv *p = (struct priv *) dev->priv; |
| 1061 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1062 | if (debuglevel > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | printk("X"); |
| 1064 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1065 | status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status); |
| 1066 | if (!(status & STAT_COMPL)) |
| 1067 | printk(KERN_ERR "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1069 | if (status & STAT_OK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | p->stats.tx_packets++; |
| 1071 | p->stats.collisions += (status & TCMD_MAXCOLLMASK); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1072 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | p->stats.tx_errors++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1074 | if (status & TCMD_LATECOLL) { |
| 1075 | printk(KERN_ERR "%s: late collision detected.\n", |
| 1076 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | p->stats.collisions++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1078 | } else if (status & TCMD_NOCARRIER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | p->stats.tx_carrier_errors++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1080 | printk(KERN_ERR "%s: no carrier detected.\n", |
| 1081 | dev->name); |
| 1082 | } else if (status & TCMD_LOSTCTS) |
| 1083 | printk(KERN_ERR "%s: loss of CTS detected.\n", |
| 1084 | dev->name); |
| 1085 | else if (status & TCMD_UNDERRUN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | p->stats.tx_fifo_errors++; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1087 | printk(KERN_ERR "%s: DMA underrun detected.\n", |
| 1088 | dev->name); |
| 1089 | } else if (status & TCMD_MAXCOLL) { |
| 1090 | printk(KERN_ERR "%s: Max. collisions exceeded.\n", |
| 1091 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | p->stats.collisions += 16; |
| 1093 | } |
| 1094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | #if (NUM_XMIT_BUFFS > 1) |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1096 | if ((++p->xmit_last) == NUM_XMIT_BUFFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | p->xmit_last = 0; |
| 1098 | #endif |
| 1099 | netif_wake_queue(dev); |
| 1100 | } |
| 1101 | |
| 1102 | /*********************************************************** |
| 1103 | * (re)start the receiver |
| 1104 | */ |
| 1105 | |
| 1106 | static void startrecv586(struct net_device *dev) |
| 1107 | { |
| 1108 | struct priv *p = (struct priv *) dev->priv; |
| 1109 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1110 | wait_for_scb_cmd(dev); |
| 1111 | wait_for_scb_cmd_ruc(dev); |
| 1112 | writew(make16(p->rfd_first), &p->scb->rfa_offset); |
| 1113 | writeb(RUC_START, &p->scb->cmd_ruc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | ni_attn586(); /* start cmd. */ |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1115 | wait_for_scb_cmd_ruc(dev); |
| 1116 | /* wait for accept cmd. (no timeout!!) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | static void ni52_timeout(struct net_device *dev) |
| 1120 | { |
| 1121 | struct priv *p = (struct priv *) dev->priv; |
| 1122 | #ifndef NO_NOPCOMMANDS |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1123 | if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | netif_wake_queue(dev); |
| 1125 | #ifdef DEBUG |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1126 | printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n", |
| 1127 | dev->name); |
| 1128 | printk(KERN_ERR "%s: X0: %04x N0: %04x N1: %04x %d\n", |
| 1129 | dev->name, (int)p->xmit_cmds[0]->cmd_status, |
| 1130 | readw(&p->nop_cmds[0]->cmd_status), |
| 1131 | readw(&p->nop_cmds[1]->cmd_status), |
| 1132 | p->nop_point); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1134 | writeb(CUC_ABORT, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1136 | wait_for_scb_cmd(dev); |
| 1137 | writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset); |
| 1138 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | ni_attn586(); |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1140 | wait_for_scb_cmd(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | dev->trans_start = jiffies; |
| 1142 | return 0; |
| 1143 | } |
| 1144 | #endif |
| 1145 | { |
| 1146 | #ifdef DEBUG |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1147 | printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n", |
| 1148 | dev->name, readb(&p->scb->cus)); |
| 1149 | printk(KERN_ERR "%s: command-stats: %04x %04x\n", |
| 1150 | dev->name, |
| 1151 | readw(&p->xmit_cmds[0]->cmd_status), |
| 1152 | readw(&p->xmit_cmds[1]->cmd_status)); |
| 1153 | printk(KERN_ERR "%s: check, whether you set the right interrupt number!\n", |
| 1154 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | #endif |
| 1156 | ni52_close(dev); |
| 1157 | ni52_open(dev); |
| 1158 | } |
| 1159 | dev->trans_start = jiffies; |
| 1160 | } |
| 1161 | |
| 1162 | /****************************************************** |
| 1163 | * send frame |
| 1164 | */ |
| 1165 | |
| 1166 | static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev) |
| 1167 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1168 | int len, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | #ifndef NO_NOPCOMMANDS |
| 1170 | int next_nop; |
| 1171 | #endif |
| 1172 | struct priv *p = (struct priv *) dev->priv; |
| 1173 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1174 | if (skb->len > XMIT_BUFF_SIZE) { |
| 1175 | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | netif_stop_queue(dev); |
| 1180 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1181 | skb_copy_from_linear_data(skb, (char *)p->xmit_cbuffs[p->xmit_count], |
| 1182 | skb->len); |
| 1183 | len = skb->len; |
| 1184 | if (len < ETH_ZLEN) { |
| 1185 | len = ETH_ZLEN; |
| 1186 | memset((char *)p->xmit_cbuffs[p->xmit_count]+skb->len, 0, |
| 1187 | len - skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
| 1190 | #if (NUM_XMIT_BUFFS == 1) |
| 1191 | # ifdef NO_NOPCOMMANDS |
| 1192 | |
| 1193 | #ifdef DEBUG |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1194 | if (p->scb->cus & CU_ACTIVE) { |
| 1195 | printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name); |
| 1196 | printk(KERN_ERR "%s: stat: %04x %04x\n", |
| 1197 | dev->name, readb(&p->scb->cus), |
| 1198 | readw(&p->xmit_cmds[0]->cmd_status)); |
| 1199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | #endif |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1201 | writew(TBD_LAST | len, &p->xmit_buffs[0]->size);; |
| 1202 | for (i = 0; i < 16; i++) { |
| 1203 | writew(0, &p->xmit_cmds[0]->cmd_status); |
| 1204 | wait_for_scb_cmd(dev); |
| 1205 | if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND) |
| 1206 | writeb(CUC_RESUME, &p->scb->cmd_cuc); |
| 1207 | else { |
| 1208 | writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset); |
| 1209 | writeb(CUC_START, &p->scb->cmd_cuc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1211 | ni_attn586(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | dev->trans_start = jiffies; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1213 | if (!i) |
| 1214 | dev_kfree_skb(skb); |
| 1215 | wait_for_scb_cmd(dev); |
| 1216 | /* test it, because CU sometimes doesn't start immediately */ |
| 1217 | if (readb(&p->scb->cus) & CU_ACTIVE) |
| 1218 | break; |
| 1219 | if (readw(&p->xmit_cmds[0]->cmd_status)) |
| 1220 | break; |
| 1221 | if (i == 15) |
| 1222 | printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name); |
| 1223 | } |
| 1224 | # else |
| 1225 | next_nop = (p->nop_point + 1) & 0x1; |
| 1226 | writew(TBD_LAST | len, &p->xmit_buffs[0]->size); |
| 1227 | writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link); |
| 1228 | writew(make16(p->nop_cmds[next_nop]), |
| 1229 | &p->nop_cmds[next_nop]->cmd_link); |
| 1230 | writew(0, &p->xmit_cmds[0]->cmd_status); |
| 1231 | writew(0, &p->nop_cmds[next_nop]->cmd_status); |
| 1232 | |
| 1233 | writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link); |
| 1234 | dev->trans_start = jiffies; |
| 1235 | p->nop_point = next_nop; |
| 1236 | dev_kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | # endif |
| 1238 | #else |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1239 | writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size); |
| 1240 | next_nop = p->xmit_count + 1 |
| 1241 | if (next_nop == NUM_XMIT_BUFFS) |
| 1242 | next_nop = 0; |
| 1243 | writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status); |
| 1244 | /* linkpointer of xmit-command already points to next nop cmd */ |
| 1245 | writew(make16(p->nop_cmds[next_nop]), |
| 1246 | &p->nop_cmds[next_nop]->cmd_link); |
| 1247 | writew(0, &p->nop_cmds[next_nop]->cmd_status); |
| 1248 | writew(make16(p->xmit_cmds[p->xmit_count]), |
| 1249 | &p->nop_cmds[p->xmit_count]->cmd_link); |
| 1250 | dev->trans_start = jiffies; |
| 1251 | p->xmit_count = next_nop; |
| 1252 | { |
| 1253 | unsigned long flags; |
| 1254 | spin_lock_irqsave(&p->spinlock); |
| 1255 | if (p->xmit_count != p->xmit_last) |
| 1256 | netif_wake_queue(dev); |
| 1257 | spin_unlock_irqrestore(&p->spinlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | } |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1259 | dev_kfree_skb(skb); |
| 1260 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | return 0; |
| 1262 | } |
| 1263 | |
| 1264 | /******************************************* |
| 1265 | * Someone wanna have the statistics |
| 1266 | */ |
| 1267 | |
| 1268 | static struct net_device_stats *ni52_get_stats(struct net_device *dev) |
| 1269 | { |
| 1270 | struct priv *p = (struct priv *) dev->priv; |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1271 | unsigned short crc, aln, rsc, ovrn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1273 | /* Get error-statistics from the ni82586 */ |
| 1274 | crc = readw(&p->scb->crc_errs); |
| 1275 | writew(0, &p->scb->crc_errs); |
| 1276 | aln = readw(&p->scb->aln_errs); |
| 1277 | writew(0, &p->scb->aln_errs); |
| 1278 | rsc = readw(&p->scb->rsc_errs); |
| 1279 | writew(0, &p->scb->rsc_errs); |
| 1280 | ovrn = readw(&p->scb->ovrn_errs); |
| 1281 | writew(0, &p->scb->ovrn_errs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | |
| 1283 | p->stats.rx_crc_errors += crc; |
| 1284 | p->stats.rx_fifo_errors += ovrn; |
| 1285 | p->stats.rx_frame_errors += aln; |
| 1286 | p->stats.rx_dropped += rsc; |
| 1287 | |
| 1288 | return &p->stats; |
| 1289 | } |
| 1290 | |
| 1291 | /******************************************************** |
| 1292 | * Set MC list .. |
| 1293 | */ |
| 1294 | |
| 1295 | static void set_multicast_list(struct net_device *dev) |
| 1296 | { |
| 1297 | netif_stop_queue(dev); |
| 1298 | ni_disint(); |
| 1299 | alloc586(dev); |
| 1300 | init586(dev); |
| 1301 | startrecv586(dev); |
| 1302 | ni_enaint(); |
| 1303 | netif_wake_queue(dev); |
| 1304 | } |
| 1305 | |
| 1306 | #ifdef MODULE |
| 1307 | static struct net_device *dev_ni52; |
| 1308 | |
| 1309 | module_param(io, int, 0); |
| 1310 | module_param(irq, int, 0); |
| 1311 | module_param(memstart, long, 0); |
| 1312 | module_param(memend, long, 0); |
| 1313 | MODULE_PARM_DESC(io, "NI5210 I/O base address,required"); |
| 1314 | MODULE_PARM_DESC(irq, "NI5210 IRQ number,required"); |
| 1315 | MODULE_PARM_DESC(memstart, "NI5210 memory base address,required"); |
| 1316 | MODULE_PARM_DESC(memend, "NI5210 memory end address,required"); |
| 1317 | |
Andrew Morton | 19a8664 | 2006-08-14 23:00:05 -0700 | [diff] [blame] | 1318 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | { |
Alan Cox | a197f69 | 2008-02-08 15:27:38 +0000 | [diff] [blame] | 1320 | if (io <= 0x0 || !memend || !memstart || irq < 2) { |
| 1321 | printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n"); |
| 1322 | printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | return -ENODEV; |
| 1324 | } |
| 1325 | dev_ni52 = ni52_probe(-1); |
| 1326 | if (IS_ERR(dev_ni52)) |
| 1327 | return PTR_ERR(dev_ni52); |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 1331 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | { |
| 1333 | unregister_netdev(dev_ni52); |
| 1334 | release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE); |
| 1335 | free_netdev(dev_ni52); |
| 1336 | } |
| 1337 | #endif /* MODULE */ |
| 1338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | MODULE_LICENSE("GPL"); |
| 1340 | |
| 1341 | /* |
| 1342 | * END: linux/drivers/net/ni52.c |
| 1343 | */ |