aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ni52.c
diff options
context:
space:
mode:
authorAlan Cox <alan@lxorguk.ukuu.org.uk>2008-02-08 10:27:38 -0500
committerJeff Garzik <jeff@garzik.org>2008-02-11 10:28:33 -0500
commita197f6938db43b5ef464242f707233d3bd8842eb (patch)
treead6052d0da4fe9ab3bed5a214d367035d873f28b /drivers/net/ni52.c
parentb3028cdc1859adf371f9457862e466f0e67f0b10 (diff)
ni52: Remove 278 scripts/checkpatch errors
To kill the volatiles also switch it to stop poking ISA memory directly without going through readb and friends. Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/net/ni52.c')
-rw-r--r--drivers/net/ni52.c1142
1 files changed, 552 insertions, 590 deletions
diff --git a/drivers/net/ni52.c b/drivers/net/ni52.c
index 6b3384a24f07..26aa8fe1fb2d 100644
--- a/drivers/net/ni52.c
+++ b/drivers/net/ni52.c
@@ -33,20 +33,20 @@
33 * I have also done a look in the following sources: (mail me if you need them) 33 * I have also done a look in the following sources: (mail me if you need them)
34 * crynwr-packet-driver by Russ Nelson 34 * crynwr-packet-driver by Russ Nelson
35 * Garret A. Wollman's (fourth) i82586-driver for BSD 35 * Garret A. Wollman's (fourth) i82586-driver for BSD
36 * (before getting an i82596 (yes 596 not 586) manual, the existing drivers helped 36 * (before getting an i82596 (yes 596 not 586) manual, the existing drivers
37 * me a lot to understand this tricky chip.) 37 * helped me a lot to understand this tricky chip.)
38 * 38 *
39 * Known Problems: 39 * Known Problems:
40 * The internal sysbus seems to be slow. So we often lose packets because of 40 * The internal sysbus seems to be slow. So we often lose packets because of
41 * overruns while receiving from a fast remote host. 41 * overruns while receiving from a fast remote host.
42 * This can slow down TCP connections. Maybe the newer ni5210 cards are better. 42 * This can slow down TCP connections. Maybe the newer ni5210 cards are
43 * my experience is, that if a machine sends with more than about 500-600K/s 43 * better. My experience is, that if a machine sends with more than about
44 * the fifo/sysbus overflows. 44 * 500-600K/s the fifo/sysbus overflows.
45 * 45 *
46 * IMPORTANT NOTE: 46 * IMPORTANT NOTE:
47 * On fast networks, it's a (very) good idea to have 16K shared memory. With 47 * On fast networks, it's a (very) good idea to have 16K shared memory. With
48 * 8K, we can store only 4 receive frames, so it can (easily) happen that a remote 48 * 8K, we can store only 4 receive frames, so it can (easily) happen that a
49 * machine 'overruns' our system. 49 * remote machine 'overruns' our system.
50 * 50 *
51 * Known i82586/card problems (I'm sure, there are many more!): 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 52 * Running the NOP-mode, the i82586 sometimes seems to forget to report
@@ -60,7 +60,8 @@
60 * 60 *
61 * results from ftp performance tests with Linux 1.2.5 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) 62 * send and receive about 350-400 KByte/s (peak up to 460 kbytes/s)
63 * sending in NOP-mode: peak performance up to 530K/s (but better don't run this mode) 63 * sending in NOP-mode: peak performance up to 530K/s (but better don't
64 * run this mode)
64 */ 65 */
65 66
66/* 67/*
@@ -94,7 +95,8 @@
94 * 95 *
95 * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH) 96 * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH)
96 * 97 *
97 * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff, too (MH) 98 * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff,
99 * too (MH)
98 * 100 *
99 * < 30.Sep.93: first versions 101 * < 30.Sep.93: first versions
100 */ 102 */
@@ -102,7 +104,7 @@
102static int debuglevel; /* debug-printk 0: off 1: a few 2: more */ 104static int debuglevel; /* debug-printk 0: off 1: a few 2: more */
103static int automatic_resume; /* experimental .. better should be zero */ 105static int automatic_resume; /* experimental .. better should be zero */
104static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */ 106static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */
105static int fifo=0x8; /* don't change */ 107static int fifo = 0x8; /* don't change */
106 108
107#include <linux/module.h> 109#include <linux/module.h>
108#include <linux/kernel.h> 110#include <linux/kernel.h>
@@ -127,14 +129,15 @@ static int fifo=0x8; /* don't change */
127#define DEBUG /* debug on */ 129#define DEBUG /* debug on */
128#define SYSBUSVAL 1 /* 8 Bit */ 130#define SYSBUSVAL 1 /* 8 Bit */
129 131
130#define ni_attn586() {outb(0,dev->base_addr+NI52_ATTENTION);} 132#define ni_attn586() { outb(0, dev->base_addr + NI52_ATTENTION); }
131#define ni_reset586() {outb(0,dev->base_addr+NI52_RESET);} 133#define ni_reset586() { outb(0, dev->base_addr + NI52_RESET); }
132#define ni_disint() {outb(0,dev->base_addr+NI52_INTDIS);} 134#define ni_disint() { outb(0, dev->base_addr + NI52_INTDIS); }
133#define ni_enaint() {outb(0,dev->base_addr+NI52_INTENA);} 135#define ni_enaint() { outb(0, dev->base_addr + NI52_INTENA); }
134 136
135#define make32(ptr16) (p->memtop + (short) (ptr16) ) 137#define make32(ptr16) (p->memtop + (short) (ptr16))
136#define make24(ptr32) ( ((char *) (ptr32)) - p->base) 138#define make24(ptr32) ((unsigned long)(ptr32)) - p->base
137#define make16(ptr32) ((unsigned short) ((unsigned long)(ptr32) - (unsigned long) p->memtop )) 139#define make16(ptr32) ((unsigned short) ((unsigned long)(ptr32)\
140 - (unsigned long) p->memtop))
138 141
139/******************* how to calculate the buffers ***************************** 142/******************* how to calculate the buffers *****************************
140 143
@@ -159,96 +162,112 @@ sizeof(nop_cmd) = 8;
159 162
160/**************************************************************************/ 163/**************************************************************************/
161 164
162/* different DELAYs */
163#define DELAY(x) mdelay(32 * x);
164#define DELAY_16(); { udelay(16); }
165#define DELAY_18(); { udelay(4); }
166
167/* wait for command with timeout: */
168#define WAIT_4_SCB_CMD() \
169{ int i; \
170 for(i=0;i<16384;i++) { \
171 if(!p->scb->cmd_cuc) break; \
172 DELAY_18(); \
173 if(i == 16383) { \
174 printk("%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_cuc,p->scb->cus); \
175 if(!p->reseted) { p->reseted = 1; ni_reset586(); } } } }
176
177#define WAIT_4_SCB_CMD_RUC() { int i; \
178 for(i=0;i<16384;i++) { \
179 if(!p->scb->cmd_ruc) break; \
180 DELAY_18(); \
181 if(i == 16383) { \
182 printk("%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_ruc,p->scb->rus); \
183 if(!p->reseted) { p->reseted = 1; ni_reset586(); } } } }
184
185#define WAIT_4_STAT_COMPL(addr) { int i; \
186 for(i=0;i<32767;i++) { \
187 if((addr)->cmd_status & STAT_COMPL) break; \
188 DELAY_16(); DELAY_16(); } }
189 165
190#define NI52_TOTAL_SIZE 16 166#define NI52_TOTAL_SIZE 16
191#define NI52_ADDR0 0x02 167#define NI52_ADDR0 0x02
192#define NI52_ADDR1 0x07 168#define NI52_ADDR1 0x07
193#define NI52_ADDR2 0x01 169#define NI52_ADDR2 0x01
194 170
195static int ni52_probe1(struct net_device *dev,int ioaddr); 171static int ni52_probe1(struct net_device *dev, int ioaddr);
196static irqreturn_t ni52_interrupt(int irq,void *dev_id); 172static irqreturn_t ni52_interrupt(int irq, void *dev_id);
197static int ni52_open(struct net_device *dev); 173static int ni52_open(struct net_device *dev);
198static int ni52_close(struct net_device *dev); 174static int ni52_close(struct net_device *dev);
199static int ni52_send_packet(struct sk_buff *,struct net_device *); 175static int ni52_send_packet(struct sk_buff *, struct net_device *);
200static struct net_device_stats *ni52_get_stats(struct net_device *dev); 176static struct net_device_stats *ni52_get_stats(struct net_device *dev);
201static void set_multicast_list(struct net_device *dev); 177static void set_multicast_list(struct net_device *dev);
202static void ni52_timeout(struct net_device *dev); 178static void ni52_timeout(struct net_device *dev);
203#if 0
204static void ni52_dump(struct net_device *,void *);
205#endif
206 179
207/* helper-functions */ 180/* helper-functions */
208static int init586(struct net_device *dev); 181static int init586(struct net_device *dev);
209static int check586(struct net_device *dev,char *where,unsigned size); 182static int check586(struct net_device *dev, char *where, unsigned size);
210static void alloc586(struct net_device *dev); 183static void alloc586(struct net_device *dev);
211static void startrecv586(struct net_device *dev); 184static void startrecv586(struct net_device *dev);
212static void *alloc_rfa(struct net_device *dev,void *ptr); 185static void *alloc_rfa(struct net_device *dev, void *ptr);
213static void ni52_rcv_int(struct net_device *dev); 186static void ni52_rcv_int(struct net_device *dev);
214static void ni52_xmt_int(struct net_device *dev); 187static void ni52_xmt_int(struct net_device *dev);
215static void ni52_rnr_int(struct net_device *dev); 188static void ni52_rnr_int(struct net_device *dev);
216 189
217struct priv 190struct priv {
218{
219 struct net_device_stats stats; 191 struct net_device_stats stats;
220 unsigned long base; 192 unsigned long base;
221 char *memtop; 193 char *memtop;
222 long int lock; 194 spinlock_t spinlock;
223 int reseted; 195 int reset;
224 volatile struct rfd_struct *rfd_last,*rfd_top,*rfd_first; 196 struct rfd_struct *rfd_last, *rfd_top, *rfd_first;
225 volatile struct scp_struct *scp; /* volatile is important */ 197 struct scp_struct *scp;
226 volatile struct iscp_struct *iscp; /* volatile is important */ 198 struct iscp_struct *iscp;
227 volatile struct scb_struct *scb; /* volatile is important */ 199 struct scb_struct *scb;
228 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS]; 200 struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
229#if (NUM_XMIT_BUFFS == 1) 201#if (NUM_XMIT_BUFFS == 1)
230 volatile struct transmit_cmd_struct *xmit_cmds[2]; 202 struct transmit_cmd_struct *xmit_cmds[2];
231 volatile struct nop_cmd_struct *nop_cmds[2]; 203 struct nop_cmd_struct *nop_cmds[2];
232#else 204#else
233 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS]; 205 struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
234 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS]; 206 struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
235#endif 207#endif
236 volatile int nop_point,num_recv_buffs; 208 int nop_point, num_recv_buffs;
237 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS]; 209 char *xmit_cbuffs[NUM_XMIT_BUFFS];
238 volatile int xmit_count,xmit_last; 210 int xmit_count, xmit_last;
239}; 211};
240 212
213/* wait for command with timeout: */
214static 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
233static 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
252static 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
241/********************************************** 263/**********************************************
242 * close device 264 * close device
243 */ 265 */
244static int ni52_close(struct net_device *dev) 266static int ni52_close(struct net_device *dev)
245{ 267{
246 free_irq(dev->irq, dev); 268 free_irq(dev->irq, dev);
247
248 ni_reset586(); /* the hard way to stop the receiver */ 269 ni_reset586(); /* the hard way to stop the receiver */
249
250 netif_stop_queue(dev); 270 netif_stop_queue(dev);
251
252 return 0; 271 return 0;
253} 272}
254 273
@@ -265,55 +284,53 @@ static int ni52_open(struct net_device *dev)
265 startrecv586(dev); 284 startrecv586(dev);
266 ni_enaint(); 285 ni_enaint();
267 286
268 ret = request_irq(dev->irq, &ni52_interrupt,0,dev->name,dev); 287 ret = request_irq(dev->irq, &ni52_interrupt, 0, dev->name, dev);
269 if (ret) 288 if (ret) {
270 {
271 ni_reset586(); 289 ni_reset586();
272 return ret; 290 return ret;
273 } 291 }
274
275 netif_start_queue(dev); 292 netif_start_queue(dev);
276
277 return 0; /* most done by init */ 293 return 0; /* most done by init */
278} 294}
279 295
280/********************************************** 296/**********************************************
281 * Check to see if there's an 82586 out there. 297 * Check to see if there's an 82586 out there.
282 */ 298 */
283static int check586(struct net_device *dev,char *where,unsigned size) 299static int check586(struct net_device *dev, char *where, unsigned size)
284{ 300{
285 struct priv pb; 301 struct priv pb;
286 struct priv *p = /* (struct priv *) dev->priv*/ &pb; 302 struct priv *p = /* (struct priv *) dev->priv*/ &pb;
287 char *iscp_addrs[2]; 303 char *iscp_addrs[2];
288 int i; 304 int i;
289 305
290 p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000; 306 p->base = (unsigned long) isa_bus_to_virt((unsigned long)where)
307 + size - 0x01000000;
291 p->memtop = isa_bus_to_virt((unsigned long)where) + size; 308 p->memtop = isa_bus_to_virt((unsigned long)where) + size;
292 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS); 309 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
293 memset((char *)p->scp,0, sizeof(struct scp_struct)); 310 memset_io((char *)p->scp, 0, sizeof(struct scp_struct));
294 for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */ 311 for (i = 0; i < sizeof(struct scp_struct); i++)
295 if(((char *)p->scp)[i]) 312 /* memory was writeable? */
313 if (readb((char *)p->scp + i))
296 return 0; 314 return 0;
297 p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */ 315 writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */
298 if(p->scp->sysbus != SYSBUSVAL) 316 if (readb(&p->scp->sysbus) != SYSBUSVAL)
299 return 0; 317 return 0;
300 318
301 iscp_addrs[0] = isa_bus_to_virt((unsigned long)where); 319 iscp_addrs[0] = isa_bus_to_virt((unsigned long)where);
302 iscp_addrs[1]= (char *) p->scp - sizeof(struct iscp_struct); 320 iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct);
303 321
304 for(i=0;i<2;i++) 322 for (i = 0; i < 2; i++) {
305 {
306 p->iscp = (struct iscp_struct *) iscp_addrs[i]; 323 p->iscp = (struct iscp_struct *) iscp_addrs[i];
307 memset((char *)p->iscp,0, sizeof(struct iscp_struct)); 324 memset_io((char *)p->iscp, 0, sizeof(struct iscp_struct));
308 325
309 p->scp->iscp = make24(p->iscp); 326 writel(make24(p->iscp), &p->scp->iscp);
310 p->iscp->busy = 1; 327 writeb(1, &p->iscp->busy);
311 328
312 ni_reset586(); 329 ni_reset586();
313 ni_attn586(); 330 ni_attn586();
314 DELAY(1); /* wait a while... */ 331 mdelay(32); /* wait a while... */
315 332 /* i82586 clears 'busy' after successful init */
316 if(p->iscp->busy) /* i82586 clears 'busy' after successful init */ 333 if (readb(&p->iscp->busy))
317 return 0; 334 return 0;
318 } 335 }
319 return 1; 336 return 1;
@@ -327,36 +344,39 @@ static void alloc586(struct net_device *dev)
327 struct priv *p = (struct priv *) dev->priv; 344 struct priv *p = (struct priv *) dev->priv;
328 345
329 ni_reset586(); 346 ni_reset586();
330 DELAY(1); 347 mdelay(32);
348
349 spin_lock_init(&p->spinlock);
331 350
332 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS); 351 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
333 p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start); 352 p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start);
334 p->iscp = (struct iscp_struct *) ((char *)p->scp - sizeof(struct iscp_struct)); 353 p->iscp = (struct iscp_struct *)
354 ((char *)p->scp - sizeof(struct iscp_struct));
335 355
336 memset((char *) p->iscp,0,sizeof(struct iscp_struct)); 356 memset_io(p->iscp, 0, sizeof(struct iscp_struct));
337 memset((char *) p->scp ,0,sizeof(struct scp_struct)); 357 memset_io(p->scp , 0, sizeof(struct scp_struct));
338 358
339 p->scp->iscp = make24(p->iscp); 359 writel(make24(p->iscp), &p->scp->iscp);
340 p->scp->sysbus = SYSBUSVAL; 360 writeb(SYSBUSVAL, &p->scp->sysbus);
341 p->iscp->scb_offset = make16(p->scb); 361 writew(make16(p->scb), &p->iscp->scb_offset);
342 362
343 p->iscp->busy = 1; 363 writeb(1, &p->iscp->busy);
344 ni_reset586(); 364 ni_reset586();
345 ni_attn586(); 365 ni_attn586();
346 366
347 DELAY(1); 367 mdelay(32);
348 368
349 if(p->iscp->busy) 369 if (readb(&p->iscp->busy))
350 printk("%s: Init-Problems (alloc).\n",dev->name); 370 printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
351 371
352 p->reseted = 0; 372 p->reset = 0;
353 373
354 memset((char *)p->scb,0,sizeof(struct scb_struct)); 374 memset_io((char *)p->scb, 0, sizeof(struct scb_struct));
355} 375}
356 376
357/* set: io,irq,memstart,memend or set it when calling insmod */ 377/* set: io,irq,memstart,memend or set it when calling insmod */
358static int irq=9; 378static int irq = 9;
359static int io=0x300; 379static int io = 0x300;
360static long memstart; /* e.g 0xd0000 */ 380static long memstart; /* e.g 0xd0000 */
361static long memend; /* e.g 0xd4000 */ 381static long memend; /* e.g 0xd4000 */
362 382
@@ -413,7 +433,7 @@ out:
413 return ERR_PTR(err); 433 return ERR_PTR(err);
414} 434}
415 435
416static int __init ni52_probe1(struct net_device *dev,int ioaddr) 436static int __init ni52_probe1(struct net_device *dev, int ioaddr)
417{ 437{
418 int i, size, retval; 438 int i, size, retval;
419 439
@@ -425,90 +445,96 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr)
425 if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME)) 445 if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME))
426 return -EBUSY; 446 return -EBUSY;
427 447
428 if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) || 448 if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
429 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) { 449 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) {
430 retval = -ENODEV; 450 retval = -ENODEV;
431 goto out; 451 goto out;
432 } 452 }
433 453
434 for(i=0;i<ETH_ALEN;i++) 454 for (i = 0; i < ETH_ALEN; i++)
435 dev->dev_addr[i] = inb(dev->base_addr+i); 455 dev->dev_addr[i] = inb(dev->base_addr+i);
436 456
437 if(dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1 457 if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
438 || dev->dev_addr[2] != NI52_ADDR2) { 458 || dev->dev_addr[2] != NI52_ADDR2) {
439 retval = -ENODEV; 459 retval = -ENODEV;
440 goto out; 460 goto out;
441 } 461 }
442 462
443 printk(KERN_INFO "%s: NI5210 found at %#3lx, ",dev->name,dev->base_addr); 463 printk(KERN_INFO "%s: NI5210 found at %#3lx, ",
464 dev->name, dev->base_addr);
444 465
445 /* 466 /*
446 * check (or search) IO-Memory, 8K and 16K 467 * check (or search) IO-Memory, 8K and 16K
447 */ 468 */
448#ifdef MODULE 469#ifdef MODULE
449 size = dev->mem_end - dev->mem_start; 470 size = dev->mem_end - dev->mem_start;
450 if(size != 0x2000 && size != 0x4000) { 471 if (size != 0x2000 && size != 0x4000) {
451 printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n",dev->name,size); 472 printk("\n");
473 printk(KERN_ERR "%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev->name, size);
452 retval = -ENODEV; 474 retval = -ENODEV;
453 goto out; 475 goto out;
454 } 476 }
455 if(!check586(dev,(char *) dev->mem_start,size)) { 477 if (!check586(dev, (char *)dev->mem_start, size)) {
456 printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size); 478 printk(KERN_ERR "?memcheck, Can't find memory at 0x%lx with size %d!\n", dev->mem_start, size);
457 retval = -ENODEV; 479 retval = -ENODEV;
458 goto out; 480 goto out;
459 } 481 }
460#else 482#else
461 if(dev->mem_start != 0) /* no auto-mem-probe */ 483 if (dev->mem_start != 0) {
462 { 484 /* no auto-mem-probe */
463 size = 0x4000; /* check for 16K mem */ 485 size = 0x4000; /* check for 16K mem */
464 if(!check586(dev,(char *) dev->mem_start,size)) { 486 if (!check586(dev, (char *) dev->mem_start, size)) {
465 size = 0x2000; /* check for 8K mem */ 487 size = 0x2000; /* check for 8K mem */
466 if(!check586(dev,(char *) dev->mem_start,size)) { 488 if (!check586(dev, (char *)dev->mem_start, size)) {
467 printk("?memprobe, Can't find memory at 0x%lx!\n",dev->mem_start); 489 printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start);
468 retval = -ENODEV; 490 retval = -ENODEV;
469 goto out; 491 goto out;
470 } 492 }
471 } 493 }
472 } 494 } else {
473 else 495 static const unsigned long memaddrs[] = {
474 { 496 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000,
475 static long memaddrs[] = { 0xc8000,0xca000,0xcc000,0xce000,0xd0000,0xd2000, 497 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0
476 0xd4000,0xd6000,0xd8000,0xda000,0xdc000, 0 }; 498 };
477 for(i=0;;i++) 499 for (i = 0;; i++) {
478 { 500 if (!memaddrs[i]) {
479 if(!memaddrs[i]) { 501 printk(KERN_ERR "?memprobe, Can't find io-memory!\n");
480 printk("?memprobe, Can't find io-memory!\n");
481 retval = -ENODEV; 502 retval = -ENODEV;
482 goto out; 503 goto out;
483 } 504 }
484 dev->mem_start = memaddrs[i]; 505 dev->mem_start = memaddrs[i];
485 size = 0x2000; /* check for 8K mem */ 506 size = 0x2000; /* check for 8K mem */
486 if(check586(dev,(char *)dev->mem_start,size)) /* 8K-check */ 507 if (check586(dev, (char *)dev->mem_start, size))
508 /* 8K-check */
487 break; 509 break;
488 size = 0x4000; /* check for 16K mem */ 510 size = 0x4000; /* check for 16K mem */
489 if(check586(dev,(char *)dev->mem_start,size)) /* 16K-check */ 511 if (check586(dev, (char *)dev->mem_start, size))
512 /* 16K-check */
490 break; 513 break;
491 } 514 }
492 } 515 }
493 dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */ 516 /* set mem_end showed by 'ifconfig' */
517 dev->mem_end = dev->mem_start + size;
494#endif 518#endif
495 519
496 memset((char *) dev->priv,0,sizeof(struct priv)); 520 memset((char *)dev->priv, 0, sizeof(struct priv));
497 521
498 ((struct priv *) (dev->priv))->memtop = isa_bus_to_virt(dev->mem_start) + size; 522 ((struct priv *)(dev->priv))->memtop =
499 ((struct priv *) (dev->priv))->base = (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000; 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;
500 alloc586(dev); 526 alloc586(dev);
501 527
502 /* set number of receive-buffs according to memsize */ 528 /* set number of receive-buffs according to memsize */
503 if(size == 0x2000) 529 if (size == 0x2000)
504 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8; 530 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8;
505 else 531 else
506 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16; 532 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16;
507 533
508 printk("Memaddr: 0x%lx, Memsize: %d, ",dev->mem_start,size); 534 printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ",
535 dev->mem_start, size);
509 536
510 if(dev->irq < 2) 537 if (dev->irq < 2) {
511 {
512 unsigned long irq_mask; 538 unsigned long irq_mask;
513 539
514 irq_mask = probe_irq_on(); 540 irq_mask = probe_irq_on();
@@ -517,18 +543,16 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr)
517 543
518 mdelay(20); 544 mdelay(20);
519 dev->irq = probe_irq_off(irq_mask); 545 dev->irq = probe_irq_off(irq_mask);
520 if(!dev->irq) 546 if (!dev->irq) {
521 {
522 printk("?autoirq, Failed to detect IRQ line!\n"); 547 printk("?autoirq, Failed to detect IRQ line!\n");
523 retval = -EAGAIN; 548 retval = -EAGAIN;
524 goto out; 549 goto out;
525 } 550 }
526 printk("IRQ %d (autodetected).\n",dev->irq); 551 printk("IRQ %d (autodetected).\n", dev->irq);
527 } 552 } else {
528 else { 553 if (dev->irq == 2)
529 if(dev->irq == 2)
530 dev->irq = 9; 554 dev->irq = 9;
531 printk("IRQ %d (assigned and not checked!).\n",dev->irq); 555 printk("IRQ %d (assigned and not checked!).\n", dev->irq);
532 } 556 }
533 557
534 dev->open = ni52_open; 558 dev->open = ni52_open;
@@ -555,56 +579,58 @@ out:
555static int init586(struct net_device *dev) 579static int init586(struct net_device *dev)
556{ 580{
557 void *ptr; 581 void *ptr;
558 int i,result=0; 582 int i, result = 0;
559 struct priv *p = (struct priv *) dev->priv; 583 struct priv *p = (struct priv *)dev->priv;
560 volatile struct configure_cmd_struct *cfg_cmd; 584 struct configure_cmd_struct *cfg_cmd;
561 volatile struct iasetup_cmd_struct *ias_cmd; 585 struct iasetup_cmd_struct *ias_cmd;
562 volatile struct tdr_cmd_struct *tdr_cmd; 586 struct tdr_cmd_struct *tdr_cmd;
563 volatile struct mcsetup_cmd_struct *mc_cmd; 587 struct mcsetup_cmd_struct *mc_cmd;
564 struct dev_mc_list *dmi=dev->mc_list; 588 struct dev_mc_list *dmi = dev->mc_list;
565 int num_addrs=dev->mc_count; 589 int num_addrs = dev->mc_count;
566 590
567 ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct)); 591 ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct));
568 592
569 cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */ 593 cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */
570 cfg_cmd->cmd_status = 0; 594 writew(0, &cfg_cmd->cmd_status);
571 cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST; 595 writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd);
572 cfg_cmd->cmd_link = 0xffff; 596 writew(0xFFFF, &cfg_cmd->cmd_link);
573 597
574 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */ 598 /* number of cfg bytes */
575 cfg_cmd->fifo = fifo; /* fifo-limit (8=tx:32/rx:64) */ 599 writeb(0x0a, &cfg_cmd->byte_cnt);
576 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */ 600 /* fifo-limit (8=tx:32/rx:64) */
577 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */ 601 writeb(fifo, &cfg_cmd->fifo);
578 cfg_cmd->priority = 0x00; 602 /* hold or discard bad recv frames (bit 7) */
579 cfg_cmd->ifs = 0x60; 603 writeb(0x40, &cfg_cmd->sav_bf);
580 cfg_cmd->time_low = 0x00; 604 /* addr_len |!src_insert |pre-len |loopback */
581 cfg_cmd->time_high = 0xf2; 605 writeb(0x2e, &cfg_cmd->adr_len);
582 cfg_cmd->promisc = 0; 606 writeb(0x00, &cfg_cmd->priority);
583 if(dev->flags & IFF_ALLMULTI) { 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) {
584 int len = ((char *) p->iscp - (char *) ptr - 8) / 6; 612 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
585 if(num_addrs > len) { 613 if (num_addrs > len) {
586 printk("%s: switching to promisc. mode\n",dev->name); 614 printk(KERN_ERR "%s: switching to promisc. mode\n",
587 dev->flags|=IFF_PROMISC; 615 dev->name);
616 dev->flags |= IFF_PROMISC;
588 } 617 }
589 } 618 }
590 if(dev->flags&IFF_PROMISC) 619 if (dev->flags & IFF_PROMISC)
591 { 620 writeb(0x01, &cfg_cmd->promisc);
592 cfg_cmd->promisc=1; 621 writeb(0x00, &cfg_cmd->carr_coll);
593 dev->flags|=IFF_PROMISC; 622 writew(make16(cfg_cmd), &p->scb->cbl_offset);
594 } 623 writew(0, &p->scb->cmd_ruc);
595 cfg_cmd->carr_coll = 0x00;
596 624
597 p->scb->cbl_offset = make16(cfg_cmd); 625 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
598 p->scb->cmd_ruc = 0;
599
600 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
601 ni_attn586(); 626 ni_attn586();
602 627
603 WAIT_4_STAT_COMPL(cfg_cmd); 628 wait_for_stat_compl(cfg_cmd);
604 629
605 if((cfg_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK)) 630 if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
606 { 631 (STAT_COMPL|STAT_OK)) {
607 printk("%s: configure command failed: %x\n",dev->name,cfg_cmd->cmd_status); 632 printk(KERN_ERR "%s: configure command failed: %x\n",
633 dev->name, readw(&cfg_cmd->cmd_status));
608 return 1; 634 return 1;
609 } 635 }
610 636
@@ -614,21 +640,22 @@ static int init586(struct net_device *dev)
614 640
615 ias_cmd = (struct iasetup_cmd_struct *)ptr; 641 ias_cmd = (struct iasetup_cmd_struct *)ptr;
616 642
617 ias_cmd->cmd_status = 0; 643 writew(0, &ias_cmd->cmd_status);
618 ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST; 644 writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd);
619 ias_cmd->cmd_link = 0xffff; 645 writew(0xffff, &ias_cmd->cmd_link);
620 646
621 memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN); 647 memcpy_toio((char *)&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN);
622 648
623 p->scb->cbl_offset = make16(ias_cmd); 649 writew(make16(ias_cmd), &p->scb->cbl_offset);
624 650
625 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */ 651 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
626 ni_attn586(); 652 ni_attn586();
627 653
628 WAIT_4_STAT_COMPL(ias_cmd); 654 wait_for_stat_compl(ias_cmd);
629 655
630 if((ias_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) { 656 if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
631 printk("%s (ni52): individual address setup command failed: %04x\n",dev->name,ias_cmd->cmd_status); 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));
632 return 1; 659 return 1;
633 } 660 }
634 661
@@ -638,117 +665,119 @@ static int init586(struct net_device *dev)
638 665
639 tdr_cmd = (struct tdr_cmd_struct *)ptr; 666 tdr_cmd = (struct tdr_cmd_struct *)ptr;
640 667
641 tdr_cmd->cmd_status = 0; 668 writew(0, &tdr_cmd->cmd_status);
642 tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST; 669 writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd);
643 tdr_cmd->cmd_link = 0xffff; 670 writew(0xffff, &tdr_cmd->cmd_link);
644 tdr_cmd->status = 0; 671 writew(0, &tdr_cmd->status);
645 672
646 p->scb->cbl_offset = make16(tdr_cmd); 673 writew(make16(tdr_cmd), &p->scb->cbl_offset);
647 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */ 674 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
648 ni_attn586(); 675 ni_attn586();
649 676
650 WAIT_4_STAT_COMPL(tdr_cmd); 677 wait_for_stat_compl(tdr_cmd);
651
652 if(!(tdr_cmd->cmd_status & STAT_COMPL))
653 {
654 printk("%s: Problems while running the TDR.\n",dev->name);
655 }
656 else
657 {
658 DELAY_16(); /* wait for result */
659 result = tdr_cmd->status;
660 678
661 p->scb->cmd_cuc = p->scb->cus & STAT_MASK; 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);
662 ni_attn586(); /* ack the interrupts */ 686 ni_attn586(); /* ack the interrupts */
663 687
664 if(result & TDR_LNK_OK) 688 if (result & TDR_LNK_OK)
665 ; 689 ;
666 else if(result & TDR_XCVR_PRB) 690 else if (result & TDR_XCVR_PRB)
667 printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name); 691 printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n",
668 else if(result & TDR_ET_OPN) 692 dev->name);
669 printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK); 693 else if (result & TDR_ET_OPN)
670 else if(result & TDR_ET_SRT) 694 printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n",
671 { 695 dev->name, result & TDR_TIMEMASK);
672 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */ 696 else if (result & TDR_ET_SRT) {
673 printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK); 697 /* time == 0 -> strange :-) */
674 } 698 if (result & TDR_TIMEMASK)
675 else 699 printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n",
676 printk("%s: TDR: Unknown status %04x\n",dev->name,result); 700 dev->name, result & TDR_TIMEMASK);
701 } else
702 printk(KERN_ERR "%s: TDR: Unknown status %04x\n",
703 dev->name, result);
677 } 704 }
678 705
679 /* 706 /*
680 * Multicast setup 707 * Multicast setup
681 */ 708 */
682 if(num_addrs && !(dev->flags & IFF_PROMISC) ) 709 if (num_addrs && !(dev->flags & IFF_PROMISC)) {
683 {
684 mc_cmd = (struct mcsetup_cmd_struct *) ptr; 710 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
685 mc_cmd->cmd_status = 0; 711 writew(0, &mc_cmd->cmd_status);
686 mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST; 712 writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd);
687 mc_cmd->cmd_link = 0xffff; 713 writew(0xffff, &mc_cmd->cmd_link);
688 mc_cmd->mc_cnt = num_addrs * 6; 714 writew(num_addrs * 6, &mc_cmd->mc_cnt);
689 715
690 for(i=0;i<num_addrs;i++,dmi=dmi->next) 716 for (i = 0; i < num_addrs; i++, dmi = dmi->next)
691 memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr,6); 717 memcpy_toio((char *) mc_cmd->mc_list[i],
718 dmi->dmi_addr, 6);
692 719
693 p->scb->cbl_offset = make16(mc_cmd); 720 writew(make16(mc_cmd), &p->scb->cbl_offset);
694 p->scb->cmd_cuc = CUC_START; 721 writeb(CUC_START, &p->scb->cmd_cuc);
695 ni_attn586(); 722 ni_attn586();
696 723
697 WAIT_4_STAT_COMPL(mc_cmd); 724 wait_for_stat_compl(mc_cmd);
698 725
699 if( (mc_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) ) 726 if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK))
700 printk("%s: Can't apply multicast-address-list.\n",dev->name); 727 != (STAT_COMPL|STAT_OK))
728 printk(KERN_ERR "%s: Can't apply multicast-address-list.\n", dev->name);
701 } 729 }
702 730
703 /* 731 /*
704 * alloc nop/xmit-cmds 732 * alloc nop/xmit-cmds
705 */ 733 */
706#if (NUM_XMIT_BUFFS == 1) 734#if (NUM_XMIT_BUFFS == 1)
707 for(i=0;i<2;i++) 735 for (i = 0; i < 2; i++) {
708 { 736 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
709 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr; 737 writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
710 p->nop_cmds[i]->cmd_cmd = CMD_NOP; 738 writew(0, &p->nop_cmds[i]->cmd_status);
711 p->nop_cmds[i]->cmd_status = 0; 739 writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
712 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
713 ptr = (char *) ptr + sizeof(struct nop_cmd_struct); 740 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
714 } 741 }
715#else 742#else
716 for(i=0;i<NUM_XMIT_BUFFS;i++) 743 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
717 { 744 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
718 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr; 745 writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
719 p->nop_cmds[i]->cmd_cmd = CMD_NOP; 746 writew(0, &p->nop_cmds[i]->cmd_status);
720 p->nop_cmds[i]->cmd_status = 0; 747 writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
721 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
722 ptr = (char *) ptr + sizeof(struct nop_cmd_struct); 748 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
723 } 749 }
724#endif 750#endif
725 751
726 ptr = alloc_rfa(dev,(void *)ptr); /* init receive-frame-area */ 752 ptr = alloc_rfa(dev, (void *)ptr); /* init receive-frame-area */
727 753
728 /* 754 /*
729 * alloc xmit-buffs / init xmit_cmds 755 * alloc xmit-buffs / init xmit_cmds
730 */ 756 */
731 for(i=0;i<NUM_XMIT_BUFFS;i++) 757 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
732 { 758 /* Transmit cmd/buff 0 */
733 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/ 759 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr;
734 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct); 760 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
735 p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */ 761 p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */
736 ptr = (char *) ptr + XMIT_BUFF_SIZE; 762 ptr = (char *) ptr + XMIT_BUFF_SIZE;
737 p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */ 763 p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */
738 ptr = (char *) ptr + sizeof(struct tbd_struct); 764 ptr = (char *) ptr + sizeof(struct tbd_struct);
739 if((void *)ptr > (void *)p->iscp) 765 if ((void *)ptr > (void *)p->iscp) {
740 { 766 printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n",
741 printk("%s: not enough shared-mem for your configuration!\n",dev->name); 767 dev->name);
742 return 1; 768 return 1;
743 } 769 }
744 memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct)); 770 memset_io((char *)(p->xmit_cmds[i]), 0,
745 memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct)); 771 sizeof(struct transmit_cmd_struct));
746 p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]); 772 memset_io((char *)(p->xmit_buffs[i]), 0,
747 p->xmit_cmds[i]->cmd_status = STAT_COMPL; 773 sizeof(struct tbd_struct));
748 p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT; 774 writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]),
749 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i])); 775 &p->xmit_cmds[i]->cmd_link);
750 p->xmit_buffs[i]->next = 0xffff; 776 writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status);
751 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i])); 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);
752 } 781 }
753 782
754 p->xmit_count = 0; 783 p->xmit_count = 0;
@@ -761,21 +790,21 @@ static int init586(struct net_device *dev)
761 * 'start transmitter' 790 * 'start transmitter'
762 */ 791 */
763#ifndef NO_NOPCOMMANDS 792#ifndef NO_NOPCOMMANDS
764 p->scb->cbl_offset = make16(p->nop_cmds[0]); 793 writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset);
765 p->scb->cmd_cuc = CUC_START; 794 writeb(CUC_START, &p->scb->cmd_cuc);
766 ni_attn586(); 795 ni_attn586();
767 WAIT_4_SCB_CMD(); 796 wait_for_scb_cmd(dev);
768#else 797#else
769 p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]); 798 writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link);
770 p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_SUSPEND | CMD_INT; 799 writew(CMD_XMIT | CMD_SUSPEND | CMD_INT, &p->xmit_cmds[0]->cmd_cmd);
771#endif 800#endif
772 801
773 /* 802 /*
774 * ack. interrupts 803 * ack. interrupts
775 */ 804 */
776 p->scb->cmd_cuc = p->scb->cus & STAT_MASK; 805 writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
777 ni_attn586(); 806 ni_attn586();
778 DELAY_16(); 807 udelay(16);
779 808
780 ni_enaint(); 809 ni_enaint();
781 810
@@ -787,43 +816,45 @@ static int init586(struct net_device *dev)
787 * It sets up the Receive Frame Area (RFA). 816 * It sets up the Receive Frame Area (RFA).
788 */ 817 */
789 818
790static void *alloc_rfa(struct net_device *dev,void *ptr) 819static void *alloc_rfa(struct net_device *dev, void *ptr)
791{ 820{
792 volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr; 821 struct rfd_struct *rfd = (struct rfd_struct *)ptr;
793 volatile struct rbd_struct *rbd; 822 struct rbd_struct *rbd;
794 int i; 823 int i;
795 struct priv *p = (struct priv *) dev->priv; 824 struct priv *p = (struct priv *) dev->priv;
796 825
797 memset((char *) rfd,0,sizeof(struct rfd_struct)*(p->num_recv_buffs+rfdadd)); 826 memset_io((char *) rfd, 0,
827 sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd));
798 p->rfd_first = rfd; 828 p->rfd_first = rfd;
799 829
800 for(i = 0; i < (p->num_recv_buffs+rfdadd); i++) { 830 for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) {
801 rfd[i].next = make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd) ); 831 writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)),
802 rfd[i].rbd_offset = 0xffff; 832 &rfd[i].next);
833 writew(0xffff, &rfd[i].rbd_offset);
803 } 834 }
804 rfd[p->num_recv_buffs-1+rfdadd].last = RFD_SUSP; /* RU suspend */ 835 /* RU suspend */
836 writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last);
805 837
806 ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd) ); 838 ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd));
807 839
808 rbd = (struct rbd_struct *) ptr; 840 rbd = (struct rbd_struct *) ptr;
809 ptr = (void *) (rbd + p->num_recv_buffs); 841 ptr = (void *) (rbd + p->num_recv_buffs);
810 842
811 /* clr descriptors */ 843 /* clr descriptors */
812 memset((char *) rbd,0,sizeof(struct rbd_struct)*(p->num_recv_buffs)); 844 memset_io((char *)rbd, 0,
845 sizeof(struct rbd_struct) * (p->num_recv_buffs));
813 846
814 for(i=0;i<p->num_recv_buffs;i++) 847 for (i = 0; i < p->num_recv_buffs; i++) {
815 { 848 writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next);
816 rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs)); 849 writew(RECV_BUFF_SIZE, &rbd[i].size);
817 rbd[i].size = RECV_BUFF_SIZE; 850 writel(make24(ptr), &rbd[i].buffer);
818 rbd[i].buffer = make24(ptr);
819 ptr = (char *) ptr + RECV_BUFF_SIZE; 851 ptr = (char *) ptr + RECV_BUFF_SIZE;
820 } 852 }
821
822 p->rfd_top = p->rfd_first; 853 p->rfd_top = p->rfd_first;
823 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd); 854 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
824 855
825 p->scb->rfa_offset = make16(p->rfd_first); 856 writew(make16(p->rfd_first), &p->scb->rfa_offset);
826 p->rfd_first->rbd_offset = make16(rbd); 857 writew(make16(rbd), &p->rfd_first->rbd_offset);
827 858
828 return ptr; 859 return ptr;
829} 860}
@@ -833,73 +864,71 @@ static void *alloc_rfa(struct net_device *dev,void *ptr)
833 * Interrupt Handler ... 864 * Interrupt Handler ...
834 */ 865 */
835 866
836static irqreturn_t ni52_interrupt(int irq,void *dev_id) 867static irqreturn_t ni52_interrupt(int irq, void *dev_id)
837{ 868{
838 struct net_device *dev = dev_id; 869 struct net_device *dev = dev_id;
839 unsigned short stat; 870 unsigned int stat;
840 int cnt=0; 871 int cnt = 0;
841 struct priv *p; 872 struct priv *p;
842 873
843 if (!dev) {
844 printk ("ni5210-interrupt: irq %d for unknown device.\n",irq);
845 return IRQ_NONE;
846 }
847 p = (struct priv *) dev->priv; 874 p = (struct priv *) dev->priv;
848 875
849 if(debuglevel > 1) 876 if (debuglevel > 1)
850 printk("I"); 877 printk("I");
851 878
852 WAIT_4_SCB_CMD(); /* wait for last command */ 879 spin_lock(&p->spinlock);
853 880
854 while((stat=p->scb->cus & STAT_MASK)) 881 wait_for_scb_cmd(dev); /* wait for last command */
855 { 882
856 p->scb->cmd_cuc = stat; 883 while ((stat = readb(&p->scb->cus) & STAT_MASK)) {
884 writeb(stat, &p->scb->cmd_cuc);
857 ni_attn586(); 885 ni_attn586();
858 886
859 if(stat & STAT_FR) /* received a frame */ 887 if (stat & STAT_FR) /* received a frame */
860 ni52_rcv_int(dev); 888 ni52_rcv_int(dev);
861 889
862 if(stat & STAT_RNR) /* RU went 'not ready' */ 890 if (stat & STAT_RNR) { /* RU went 'not ready' */
863 {
864 printk("(R)"); 891 printk("(R)");
865 if(p->scb->rus & RU_SUSPEND) /* special case: RU_SUSPEND */ 892 if (readb(&p->scb->rus) & RU_SUSPEND) {
866 { 893 /* special case: RU_SUSPEND */
867 WAIT_4_SCB_CMD(); 894 wait_for_scb_cmd(dev);
868 p->scb->cmd_ruc = RUC_RESUME; 895 p->scb->cmd_ruc = RUC_RESUME;
869 ni_attn586(); 896 ni_attn586();
870 WAIT_4_SCB_CMD_RUC(); 897 wait_for_scb_cmd_ruc(dev);
871 } 898 } else {
872 else 899 printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",
873 { 900 dev->name, stat, readb(&p->scb->rus));
874 printk("%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->rus);
875 ni52_rnr_int(dev); 901 ni52_rnr_int(dev);
876 } 902 }
877 } 903 }
878 904
879 if(stat & STAT_CX) /* command with I-bit set complete */ 905 /* Command with I-bit set complete */
906 if (stat & STAT_CX)
880 ni52_xmt_int(dev); 907 ni52_xmt_int(dev);
881 908
882#ifndef NO_NOPCOMMANDS 909#ifndef NO_NOPCOMMANDS
883 if(stat & STAT_CNA) /* CU went 'not ready' */ 910 if (stat & STAT_CNA) { /* CU went 'not ready' */
884 { 911 if (netif_running(dev))
885 if(netif_running(dev)) 912 printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n",
886 printk("%s: oops! CU has left active state. stat: %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->cus); 913 dev->name, stat, readb(&p->scb->cus));
887 } 914 }
888#endif 915#endif
889 916
890 if(debuglevel > 1) 917 if (debuglevel > 1)
891 printk("%d",cnt++); 918 printk("%d", cnt++);
892 919
893 WAIT_4_SCB_CMD(); /* wait for ack. (ni52_xmt_int can be faster than ack!!) */ 920 /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */
894 if(p->scb->cmd_cuc) /* timed out? */ 921 wait_for_scb_cmd(dev);
895 { 922 if (p->scb->cmd_cuc) { /* timed out? */
896 printk("%s: Acknowledge timed out.\n",dev->name); 923 printk(KERN_ERR "%s: Acknowledge timed out.\n",
924 dev->name);
897 ni_disint(); 925 ni_disint();
898 break; 926 break;
899 } 927 }
900 } 928 }
929 spin_unlock(&p->spinlock);
901 930
902 if(debuglevel > 1) 931 if (debuglevel > 1)
903 printk("i"); 932 printk("i");
904 return IRQ_HANDLED; 933 return IRQ_HANDLED;
905} 934}
@@ -910,121 +939,91 @@ static irqreturn_t ni52_interrupt(int irq,void *dev_id)
910 939
911static void ni52_rcv_int(struct net_device *dev) 940static void ni52_rcv_int(struct net_device *dev)
912{ 941{
913 int status,cnt=0; 942 int status, cnt = 0;
914 unsigned short totlen; 943 unsigned short totlen;
915 struct sk_buff *skb; 944 struct sk_buff *skb;
916 struct rbd_struct *rbd; 945 struct rbd_struct *rbd;
917 struct priv *p = (struct priv *) dev->priv; 946 struct priv *p = (struct priv *)dev->priv;
918 947
919 if(debuglevel > 0) 948 if (debuglevel > 0)
920 printk("R"); 949 printk("R");
921 950
922 for(;(status = p->rfd_top->stat_high) & RFD_COMPL;) 951 for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) {
923 { 952 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
924 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset); 953 if (status & RFD_OK) { /* frame received without error? */
925 954 totlen = readw(&rbd->status);
926 if(status & RFD_OK) /* frame received without error? */ 955 if (totlen & RBD_LAST) {
927 { 956 /* the first and the last buffer? */
928 if( (totlen = rbd->status) & RBD_LAST) /* the first and the last buffer? */ 957 totlen &= RBD_MASK; /* length of this frame */
929 { 958 writew(0x00, &rbd->status);
930 totlen &= RBD_MASK; /* length of this frame */ 959 skb = (struct sk_buff *)dev_alloc_skb(totlen+2);
931 rbd->status = 0; 960 if (skb != NULL) {
932 skb = (struct sk_buff *) dev_alloc_skb(totlen+2); 961 skb_reserve(skb, 2);
933 if(skb != NULL) 962 skb_put(skb, totlen);
934 { 963 skb_copy_to_linear_data(skb, (char *)p->base + (unsigned long) rbd->buffer, totlen);
935 skb_reserve(skb,2); 964 skb->protocol = eth_type_trans(skb, dev);
936 skb_put(skb,totlen); 965 netif_rx(skb);
937 skb_copy_to_linear_data(skb,(char *) p->base+(unsigned long) rbd->buffer,totlen); 966 dev->last_rx = jiffies;
938 skb->protocol=eth_type_trans(skb,dev); 967 p->stats.rx_packets++;
939 netif_rx(skb); 968 p->stats.rx_bytes += totlen;
940 dev->last_rx = jiffies; 969 } else
941 p->stats.rx_packets++; 970 p->stats.rx_dropped++;
942 p->stats.rx_bytes += totlen; 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;
943 } 980 }
944 else 981 writew(0, &rbd->status);
945 p->stats.rx_dropped++; 982 rbd = (struct rbd_struct *) make32(readl(&rbd->next));
946 } 983 }
947 else 984 totlen += rstat & RBD_MASK;
948 { 985 writew(0, &rbd->status);
949 int rstat; 986 printk(KERN_ERR "%s: received oversized frame! length: %d\n",
950 /* free all RBD's until RBD_LAST is set */ 987 dev->name, totlen);
951 totlen = 0; 988 p->stats.rx_dropped++;
952 while(!((rstat=rbd->status) & RBD_LAST))
953 {
954 totlen += rstat & RBD_MASK;
955 if(!rstat)
956 {
957 printk("%s: Whoops .. no end mark in RBD list\n",dev->name);
958 break;
959 }
960 rbd->status = 0;
961 rbd = (struct rbd_struct *) make32(rbd->next);
962 }
963 totlen += rstat & RBD_MASK;
964 rbd->status = 0;
965 printk("%s: received oversized frame! length: %d\n",dev->name,totlen);
966 p->stats.rx_dropped++;
967 } 989 }
968 } 990 } else {/* frame !(ok), only with 'save-bad-frames' */
969 else /* frame !(ok), only with 'save-bad-frames' */ 991 printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n",
970 { 992 dev->name, status);
971 printk("%s: oops! rfd-error-status: %04x\n",dev->name,status);
972 p->stats.rx_errors++; 993 p->stats.rx_errors++;
973 } 994 }
974 p->rfd_top->stat_high = 0; 995 writeb(0, &p->rfd_top->stat_high);
975 p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */ 996 writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */
976 p->rfd_top->rbd_offset = 0xffff; 997 writew(0xffff, &p->rfd_top->rbd_offset);
977 p->rfd_last->last = 0; /* delete RFD_SUSP */ 998 writeb(0, &p->rfd_last->last); /* delete RFD_SUSP */
978 p->rfd_last = p->rfd_top; 999 p->rfd_last = p->rfd_top;
979 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */ 1000 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
980 p->scb->rfa_offset = make16(p->rfd_top); 1001 writew(make16(p->rfd_top), &p->scb->rfa_offset);
981 1002
982 if(debuglevel > 0) 1003 if (debuglevel > 0)
983 printk("%d",cnt++); 1004 printk("%d", cnt++);
984 } 1005 }
985 1006
986 if(automatic_resume) 1007 if (automatic_resume) {
987 { 1008 wait_for_scb_cmd(dev);
988 WAIT_4_SCB_CMD(); 1009 writeb(RUC_RESUME, &p->scb->cmd_ruc);
989 p->scb->cmd_ruc = RUC_RESUME;
990 ni_attn586(); 1010 ni_attn586();
991 WAIT_4_SCB_CMD_RUC(); 1011 wait_for_scb_cmd_ruc(dev);
992 } 1012 }
993 1013
994#ifdef WAIT_4_BUSY 1014#ifdef WAIT_4_BUSY
995 { 1015 {
996 int i; 1016 int i;
997 for(i=0;i<1024;i++) 1017 for (i = 0; i < 1024; i++) {
998 { 1018 if (p->rfd_top->status)
999 if(p->rfd_top->status)
1000 break; 1019 break;
1001 DELAY_16(); 1020 udelay(16);
1002 if(i == 1023) 1021 if (i == 1023)
1003 printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name); 1022 printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name);
1004 } 1023 }
1005 } 1024 }
1006#endif 1025#endif
1007 1026 if (debuglevel > 0)
1008#if 0
1009 if(!at_least_one)
1010 {
1011 int i;
1012 volatile struct rfd_struct *rfds=p->rfd_top;
1013 volatile struct rbd_struct *rbds;
1014 printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least);
1015 for(i=0;i< (p->num_recv_buffs+4);i++)
1016 {
1017 rbds = (struct rbd_struct *) make32(rfds->rbd_offset);
1018 printk("%04x:%04x ",rfds->status,rbds->status);
1019 rfds = (struct rfd_struct *) make32(rfds->next);
1020 }
1021 printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status);
1022 printk("\nerrs: %04x %04x rus: %02x, cus: %02x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->rus,(int)p->scb->cus);
1023 }
1024 old_at_least = at_least_one;
1025#endif
1026
1027 if(debuglevel > 0)
1028 printk("r"); 1027 printk("r");
1029} 1028}
1030 1029
@@ -1038,16 +1037,16 @@ static void ni52_rnr_int(struct net_device *dev)
1038 1037
1039 p->stats.rx_errors++; 1038 p->stats.rx_errors++;
1040 1039
1041 WAIT_4_SCB_CMD(); /* wait for the last cmd, WAIT_4_FULLSTAT?? */ 1040 wait_for_scb_cmd(dev); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1042 p->scb->cmd_ruc = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */ 1041 writeb(RUC_ABORT, &p->scb->cmd_ruc); /* usually the RU is in the 'no resource'-state .. abort it now. */
1043 ni_attn586(); 1042 ni_attn586();
1044 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. */ 1043 wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */
1045 1044
1046 alloc_rfa(dev,(char *)p->rfd_first); 1045 alloc_rfa(dev, (char *)p->rfd_first);
1047/* maybe add a check here, before restarting the RU */ 1046 /* maybe add a check here, before restarting the RU */
1048 startrecv586(dev); /* restart RU */ 1047 startrecv586(dev); /* restart RU */
1049 1048
1050 printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->rus); 1049 printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->rus);
1051 1050
1052} 1051}
1053 1052
@@ -1060,43 +1059,41 @@ static void ni52_xmt_int(struct net_device *dev)
1060 int status; 1059 int status;
1061 struct priv *p = (struct priv *) dev->priv; 1060 struct priv *p = (struct priv *) dev->priv;
1062 1061
1063 if(debuglevel > 0) 1062 if (debuglevel > 0)
1064 printk("X"); 1063 printk("X");
1065 1064
1066 status = p->xmit_cmds[p->xmit_last]->cmd_status; 1065 status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status);
1067 if(!(status & STAT_COMPL)) 1066 if (!(status & STAT_COMPL))
1068 printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name); 1067 printk(KERN_ERR "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
1069 1068
1070 if(status & STAT_OK) 1069 if (status & STAT_OK) {
1071 {
1072 p->stats.tx_packets++; 1070 p->stats.tx_packets++;
1073 p->stats.collisions += (status & TCMD_MAXCOLLMASK); 1071 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
1074 } 1072 } else {
1075 else
1076 {
1077 p->stats.tx_errors++; 1073 p->stats.tx_errors++;
1078 if(status & TCMD_LATECOLL) { 1074 if (status & TCMD_LATECOLL) {
1079 printk("%s: late collision detected.\n",dev->name); 1075 printk(KERN_ERR "%s: late collision detected.\n",
1076 dev->name);
1080 p->stats.collisions++; 1077 p->stats.collisions++;
1081 } 1078 } else if (status & TCMD_NOCARRIER) {
1082 else if(status & TCMD_NOCARRIER) {
1083 p->stats.tx_carrier_errors++; 1079 p->stats.tx_carrier_errors++;
1084 printk("%s: no carrier detected.\n",dev->name); 1080 printk(KERN_ERR "%s: no carrier detected.\n",
1085 } 1081 dev->name);
1086 else if(status & TCMD_LOSTCTS) 1082 } else if (status & TCMD_LOSTCTS)
1087 printk("%s: loss of CTS detected.\n",dev->name); 1083 printk(KERN_ERR "%s: loss of CTS detected.\n",
1088 else if(status & TCMD_UNDERRUN) { 1084 dev->name);
1085 else if (status & TCMD_UNDERRUN) {
1089 p->stats.tx_fifo_errors++; 1086 p->stats.tx_fifo_errors++;
1090 printk("%s: DMA underrun detected.\n",dev->name); 1087 printk(KERN_ERR "%s: DMA underrun detected.\n",
1091 } 1088 dev->name);
1092 else if(status & TCMD_MAXCOLL) { 1089 } else if (status & TCMD_MAXCOLL) {
1093 printk("%s: Max. collisions exceeded.\n",dev->name); 1090 printk(KERN_ERR "%s: Max. collisions exceeded.\n",
1091 dev->name);
1094 p->stats.collisions += 16; 1092 p->stats.collisions += 16;
1095 } 1093 }
1096 } 1094 }
1097
1098#if (NUM_XMIT_BUFFS > 1) 1095#if (NUM_XMIT_BUFFS > 1)
1099 if( (++p->xmit_last) == NUM_XMIT_BUFFS) 1096 if ((++p->xmit_last) == NUM_XMIT_BUFFS)
1100 p->xmit_last = 0; 1097 p->xmit_last = 0;
1101#endif 1098#endif
1102 netif_wake_queue(dev); 1099 netif_wake_queue(dev);
@@ -1110,41 +1107,51 @@ static void startrecv586(struct net_device *dev)
1110{ 1107{
1111 struct priv *p = (struct priv *) dev->priv; 1108 struct priv *p = (struct priv *) dev->priv;
1112 1109
1113 WAIT_4_SCB_CMD(); 1110 wait_for_scb_cmd(dev);
1114 WAIT_4_SCB_CMD_RUC(); 1111 wait_for_scb_cmd_ruc(dev);
1115 p->scb->rfa_offset = make16(p->rfd_first); 1112 writew(make16(p->rfd_first), &p->scb->rfa_offset);
1116 p->scb->cmd_ruc = RUC_START; 1113 writeb(RUC_START, &p->scb->cmd_ruc);
1117 ni_attn586(); /* start cmd. */ 1114 ni_attn586(); /* start cmd. */
1118 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. (no timeout!!) */ 1115 wait_for_scb_cmd_ruc(dev);
1116 /* wait for accept cmd. (no timeout!!) */
1119} 1117}
1120 1118
1121static void ni52_timeout(struct net_device *dev) 1119static void ni52_timeout(struct net_device *dev)
1122{ 1120{
1123 struct priv *p = (struct priv *) dev->priv; 1121 struct priv *p = (struct priv *) dev->priv;
1124#ifndef NO_NOPCOMMANDS 1122#ifndef NO_NOPCOMMANDS
1125 if(p->scb->cus & CU_ACTIVE) /* COMMAND-UNIT active? */ 1123 if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */
1126 {
1127 netif_wake_queue(dev); 1124 netif_wake_queue(dev);
1128#ifdef DEBUG 1125#ifdef DEBUG
1129 printk("%s: strange ... timeout with CU active?!?\n",dev->name); 1126 printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n",
1130 printk("%s: X0: %04x N0: %04x N1: %04x %d\n",dev->name,(int)p->xmit_cmds[0]->cmd_status,(int)p->nop_cmds[0]->cmd_status,(int)p->nop_cmds[1]->cmd_status,(int)p->nop_point); 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);
1131#endif 1133#endif
1132 p->scb->cmd_cuc = CUC_ABORT; 1134 writeb(CUC_ABORT, &p->scb->cmd_cuc);
1133 ni_attn586(); 1135 ni_attn586();
1134 WAIT_4_SCB_CMD(); 1136 wait_for_scb_cmd(dev);
1135 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]); 1137 writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset);
1136 p->scb->cmd_cuc = CUC_START; 1138 writeb(CUC_START, &p->scb->cmd_cuc);
1137 ni_attn586(); 1139 ni_attn586();
1138 WAIT_4_SCB_CMD(); 1140 wait_for_scb_cmd(dev);
1139 dev->trans_start = jiffies; 1141 dev->trans_start = jiffies;
1140 return 0; 1142 return 0;
1141 } 1143 }
1142#endif 1144#endif
1143 { 1145 {
1144#ifdef DEBUG 1146#ifdef DEBUG
1145 printk("%s: xmitter timed out, try to restart! stat: %02x\n",dev->name,p->scb->cus); 1147 printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n",
1146 printk("%s: command-stats: %04x %04x\n",dev->name,p->xmit_cmds[0]->cmd_status,p->xmit_cmds[1]->cmd_status); 1148 dev->name, readb(&p->scb->cus));
1147 printk("%s: check, whether you set the right interrupt number!\n",dev->name); 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);
1148#endif 1155#endif
1149 ni52_close(dev); 1156 ni52_close(dev);
1150 ni52_open(dev); 1157 ni52_open(dev);
@@ -1158,110 +1165,99 @@ static void ni52_timeout(struct net_device *dev)
1158 1165
1159static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev) 1166static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
1160{ 1167{
1161 int len,i; 1168 int len, i;
1162#ifndef NO_NOPCOMMANDS 1169#ifndef NO_NOPCOMMANDS
1163 int next_nop; 1170 int next_nop;
1164#endif 1171#endif
1165 struct priv *p = (struct priv *) dev->priv; 1172 struct priv *p = (struct priv *) dev->priv;
1166 1173
1167 if(skb->len > XMIT_BUFF_SIZE) 1174 if (skb->len > XMIT_BUFF_SIZE) {
1168 { 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);
1169 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len);
1170 return 0; 1176 return 0;
1171 } 1177 }
1172 1178
1173 netif_stop_queue(dev); 1179 netif_stop_queue(dev);
1174 1180
1175#if(NUM_XMIT_BUFFS > 1) 1181 skb_copy_from_linear_data(skb, (char *)p->xmit_cbuffs[p->xmit_count],
1176 if(test_and_set_bit(0,(void *) &p->lock)) { 1182 skb->len);
1177 printk("%s: Queue was locked\n",dev->name); 1183 len = skb->len;
1178 return 1; 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);
1179 } 1188 }
1180 else
1181#endif
1182 {
1183 skb_copy_from_linear_data(skb, (char *) p->xmit_cbuffs[p->xmit_count], skb->len);
1184 len = skb->len;
1185 if (len < ETH_ZLEN) {
1186 len = ETH_ZLEN;
1187 memset((char *)p->xmit_cbuffs[p->xmit_count]+skb->len, 0, len - skb->len);
1188 }
1189 1189
1190#if (NUM_XMIT_BUFFS == 1) 1190#if (NUM_XMIT_BUFFS == 1)
1191# ifdef NO_NOPCOMMANDS 1191# ifdef NO_NOPCOMMANDS
1192 1192
1193#ifdef DEBUG 1193#ifdef DEBUG
1194 if(p->scb->cus & CU_ACTIVE) 1194 if (p->scb->cus & CU_ACTIVE) {
1195 { 1195 printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name);
1196 printk("%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 printk("%s: stat: %04x %04x\n",dev->name,p->scb->cus,p->xmit_cmds[0]->cmd_status); 1197 dev->name, readb(&p->scb->cus),
1198 } 1198 readw(&p->xmit_cmds[0]->cmd_status));
1199 }
1199#endif 1200#endif
1200 1201 writew(TBD_LAST | len, &p->xmit_buffs[0]->size);;
1201 p->xmit_buffs[0]->size = TBD_LAST | len; 1202 for (i = 0; i < 16; i++) {
1202 for(i=0;i<16;i++) 1203 writew(0, &p->xmit_cmds[0]->cmd_status);
1203 { 1204 wait_for_scb_cmd(dev);
1204 p->xmit_cmds[0]->cmd_status = 0; 1205 if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND)
1205 WAIT_4_SCB_CMD(); 1206 writeb(CUC_RESUME, &p->scb->cmd_cuc);
1206 if( (p->scb->cus & CU_STATUS) == CU_SUSPEND) 1207 else {
1207 p->scb->cmd_cuc = CUC_RESUME; 1208 writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset);
1208 else 1209 writeb(CUC_START, &p->scb->cmd_cuc);
1209 {
1210 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1211 p->scb->cmd_cuc = CUC_START;
1212 }
1213
1214 ni_attn586();
1215 dev->trans_start = jiffies;
1216 if(!i)
1217 dev_kfree_skb(skb);
1218 WAIT_4_SCB_CMD();
1219 if( (p->scb->cus & CU_ACTIVE)) /* test it, because CU sometimes doesn't start immediately */
1220 break;
1221 if(p->xmit_cmds[0]->cmd_status)
1222 break;
1223 if(i==15)
1224 printk("%s: Can't start transmit-command.\n",dev->name);
1225 } 1210 }
1226# else 1211 ni_attn586();
1227 next_nop = (p->nop_point + 1) & 0x1;
1228 p->xmit_buffs[0]->size = TBD_LAST | len;
1229
1230 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1231 = make16((p->nop_cmds[next_nop]));
1232 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1233
1234 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
1235 dev->trans_start = jiffies; 1212 dev->trans_start = jiffies;
1236 p->nop_point = next_nop; 1213 if (!i)
1237 dev_kfree_skb(skb); 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);
1238# endif 1237# endif
1239#else 1238#else
1240 p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len; 1239 writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size);
1241 if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS ) 1240 next_nop = p->xmit_count + 1
1242 next_nop = 0; 1241 if (next_nop == NUM_XMIT_BUFFS)
1243 1242 next_nop = 0;
1244 p->xmit_cmds[p->xmit_count]->cmd_status = 0; 1243 writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status);
1245 /* linkpointer of xmit-command already points to next nop cmd */ 1244 /* linkpointer of xmit-command already points to next nop cmd */
1246 p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop])); 1245 writew(make16(p->nop_cmds[next_nop]),
1247 p->nop_cmds[next_nop]->cmd_status = 0; 1246 &p->nop_cmds[next_nop]->cmd_link);
1248 1247 writew(0, &p->nop_cmds[next_nop]->cmd_status);
1249 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count])); 1248 writew(make16(p->xmit_cmds[p->xmit_count]),
1250 dev->trans_start = jiffies; 1249 &p->nop_cmds[p->xmit_count]->cmd_link);
1251 p->xmit_count = next_nop; 1250 dev->trans_start = jiffies;
1252 1251 p->xmit_count = next_nop;
1253 { 1252 {
1254 unsigned long flags; 1253 unsigned long flags;
1255 save_flags(flags); 1254 spin_lock_irqsave(&p->spinlock);
1256 cli(); 1255 if (p->xmit_count != p->xmit_last)
1257 if(p->xmit_count != p->xmit_last) 1256 netif_wake_queue(dev);
1258 netif_wake_queue(dev); 1257 spin_unlock_irqrestore(&p->spinlock);
1259 p->lock = 0;
1260 restore_flags(flags);
1261 }
1262 dev_kfree_skb(skb);
1263#endif
1264 } 1258 }
1259 dev_kfree_skb(skb);
1260#endif
1265 return 0; 1261 return 0;
1266} 1262}
1267 1263
@@ -1272,16 +1268,17 @@ static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
1272static struct net_device_stats *ni52_get_stats(struct net_device *dev) 1268static struct net_device_stats *ni52_get_stats(struct net_device *dev)
1273{ 1269{
1274 struct priv *p = (struct priv *) dev->priv; 1270 struct priv *p = (struct priv *) dev->priv;
1275 unsigned short crc,aln,rsc,ovrn; 1271 unsigned short crc, aln, rsc, ovrn;
1276 1272
1277 crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */ 1273 /* Get error-statistics from the ni82586 */
1278 p->scb->crc_errs = 0; 1274 crc = readw(&p->scb->crc_errs);
1279 aln = p->scb->aln_errs; 1275 writew(0, &p->scb->crc_errs);
1280 p->scb->aln_errs = 0; 1276 aln = readw(&p->scb->aln_errs);
1281 rsc = p->scb->rsc_errs; 1277 writew(0, &p->scb->aln_errs);
1282 p->scb->rsc_errs = 0; 1278 rsc = readw(&p->scb->rsc_errs);
1283 ovrn = p->scb->ovrn_errs; 1279 writew(0, &p->scb->rsc_errs);
1284 p->scb->ovrn_errs = 0; 1280 ovrn = readw(&p->scb->ovrn_errs);
1281 writew(0, &p->scb->ovrn_errs);
1285 1282
1286 p->stats.rx_crc_errors += crc; 1283 p->stats.rx_crc_errors += crc;
1287 p->stats.rx_fifo_errors += ovrn; 1284 p->stats.rx_fifo_errors += ovrn;
@@ -1320,8 +1317,9 @@ MODULE_PARM_DESC(memend, "NI5210 memory end address,required");
1320 1317
1321int __init init_module(void) 1318int __init init_module(void)
1322{ 1319{
1323 if(io <= 0x0 || !memend || !memstart || irq < 2) { 1320 if (io <= 0x0 || !memend || !memstart || irq < 2) {
1324 printk("ni52: Autoprobing not allowed for modules.\nni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n"); 1321 printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n");
1322 printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
1325 return -ENODEV; 1323 return -ENODEV;
1326 } 1324 }
1327 dev_ni52 = ni52_probe(-1); 1325 dev_ni52 = ni52_probe(-1);
@@ -1338,42 +1336,6 @@ void __exit cleanup_module(void)
1338} 1336}
1339#endif /* MODULE */ 1337#endif /* MODULE */
1340 1338
1341#if 0
1342/*
1343 * DUMP .. we expect a not running CMD unit and enough space
1344 */
1345void ni52_dump(struct net_device *dev,void *ptr)
1346{
1347 struct priv *p = (struct priv *) dev->priv;
1348 struct dump_cmd_struct *dump_cmd = (struct dump_cmd_struct *) ptr;
1349 int i;
1350
1351 p->scb->cmd_cuc = CUC_ABORT;
1352 ni_attn586();
1353 WAIT_4_SCB_CMD();
1354 WAIT_4_SCB_CMD_RUC();
1355
1356 dump_cmd->cmd_status = 0;
1357 dump_cmd->cmd_cmd = CMD_DUMP | CMD_LAST;
1358 dump_cmd->dump_offset = make16((dump_cmd + 1));
1359 dump_cmd->cmd_link = 0xffff;
1360
1361 p->scb->cbl_offset = make16(dump_cmd);
1362 p->scb->cmd_cuc = CUC_START;
1363 ni_attn586();
1364 WAIT_4_STAT_COMPL(dump_cmd);
1365
1366 if( (dump_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
1367 printk("%s: Can't get dump information.\n",dev->name);
1368
1369 for(i=0;i<170;i++) {
1370 printk("%02x ",(int) ((unsigned char *) (dump_cmd + 1))[i]);
1371 if(i % 24 == 23)
1372 printk("\n");
1373 }
1374 printk("\n");
1375}
1376#endif
1377MODULE_LICENSE("GPL"); 1339MODULE_LICENSE("GPL");
1378 1340
1379/* 1341/*