OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [net/] [ni52.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.