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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/* mcen302.c: A Linux network driver for Mototrola 68EN302 MCU
2
 *
3
 *      Copyright (C) 1999 Aplio S.A.
4
 *  Written by Vadim Lebedev
5
 *
6
 *  based on the skeleton.c by Donald Becker
7
 *      This software may be used and distributed according to the terms
8
 *      of the GNU Public License, incorporated herein by reference.
9
 *
10
 */
11
 
12
static const char *version =
13
        "$Version$\n";
14
 
15
/*
16
 *  Sources:
17
 *      List your sources of programming information to document that
18
 *      the driver is your own creation, and give due credit to others
19
 *      that contributed to the work. Remember that GNU project code
20
 *      cannot use proprietary or trade secret information. Interface
21
 *      definitions are generally considered non-copyrightable to the
22
 *      extent that the same names and structures must be used to be
23
 *      compatible.
24
 *
25
 *      Finally, keep in mind that the Linux kernel is has an API, not
26
 *      ABI. Proprietary object-code-only distributions are not permitted
27
 *      under the GPL.
28
 */
29
 
30
#include <linux/module.h>
31
 
32
#include <linux/kernel.h>
33
#include <linux/sched.h>
34
#include <linux/types.h>
35
#include <linux/fcntl.h>
36
#include <linux/interrupt.h>
37
#include <linux/ptrace.h>
38
#include <linux/ioport.h>
39
#include <linux/in.h>
40
#include <linux/malloc.h>
41
#include <linux/string.h>
42
#include <asm/system.h>
43
#include <asm/bitops.h>
44
#include <asm/io.h>
45
#include <asm/dma.h>
46
#include <linux/errno.h>
47
 
48
#include <linux/netdevice.h>
49
#include <linux/etherdevice.h>
50
#include <linux/skbuff.h>
51
#include <asm/m68en302.h>
52
#include <asm/irq.h>
53
 
54
/*
55
 * The name of the card. Is used for messages and in the requests for
56
 * io regions, irqs and dma channels
57
 */
58
static const char* cardname = "en302";
59
 
60
/* First, a few definitions that the brave might change. */
61
 
62
/* A zero-terminated list of I/O addresses to be probed. */
63
static unsigned int netcard_portlist[] =
64
   { ECNTRL0 };
65
 
66
#define NETCARD_IO_EXTENT sizeof(struct _68EN302_ETHR_BLOCK)
67
 
68
 
69
 
70
/* use 0 for production, 1 for verification, >2 for debug */
71
#ifndef NET_DEBUG
72
#define NET_DEBUG 2
73
#endif
74
static unsigned int net_debug = NET_DEBUG;
75
 
76
 
77
#define MAX_FRAME_SIZE 0x600
78
#define RX_QUEUE_SIZE 8
79
#define TX_QUEUE_SIZE 8
80
#define TX_QUEUE_MASK 7
81
#define RX_QUEUE_MASK 7
82
#define HW_MAX_ADDRS (_68EN302_MAX_CET-1)
83
 
84
#define TX_BD_START 0
85
#define RX_BD_START 64
86
 
87
/* Information that need to be kept for each board. */
88
struct net_local {
89
        struct enet_statistics stats;
90
        long open_time;                 /* Useless example local info. */
91
        struct sk_buff* rx_skb[RX_QUEUE_SIZE];
92
        struct sk_buff* tx_skb[TX_QUEUE_SIZE];
93
        struct _68EN302_ETHR_BLOCK* eblk;
94
        int             tx_running;
95
        int             tx_next;
96
        int             tx_next_done;
97
        int             tx_count;
98
        int             rx_next;                /* check this RX descriptor on the next interrupt */
99
};
100
 
101
/* The station (ethernet) address prefix, used for IDing the board. */
102
#if 0
103
#define SA_ADDR0 0x00
104
#define SA_ADDR1 0x42
105
#define SA_ADDR2 0x65
106
#endif
107
 
108
/* Index to functions, as function prototypes. */
109
 
110
extern int netcard_probe(struct device *dev);
111
 
112
static int netcard_probe1(struct device *dev, int ioaddr);
113
static int net_open(struct device *dev);
114
static int      net_send_packet(struct sk_buff *skb, struct device *dev);
115
static void net_interrupt(int irq, void *dev_id, struct pt_regs *regs);
116
static void net_rx(struct device *dev);
117
static void net_tx(struct device* dev);
118
static int net_close(struct device *dev);
119
static struct enet_statistics *net_get_stats(struct device *dev);
120
static void set_multicast_list(struct device *dev);
121
 
122
 
123
 
124
#define tx_done(dev) 1
125
 
126
 
127
 
128
static void en302_set_filter(struct net_local* lp, struct dev_mc_list* list)
129
{
130
        int i = 1;
131
        struct _68EN302_ETHR_BLOCK* eblk = lp->eblk;
132
 
133
        while(list)
134
        {
135
                memcpy(eblk->CET[i], list->dmi_addr, ETH_ALEN);
136
                list = list->next;
137
                i++;
138
        }
139
 
140
        for(;  i < _68EN302_MAX_CET; i++)
141
                memset(eblk->CET[i], 0, ETH_ALEN);
142
}
143
 
144
static void en302_stop(volatile struct net_local *lp)
145
{
146
 
147
        lp->eblk->info.ECNTRL.GTS = 1;
148
 
149
        while(lp->tx_running)
150
                ;
151
 
152
        lp->eblk->info.ECNTRL.ETHER_EN = 0;
153
        lp->rx_next = lp->tx_next = lp->tx_next_done = 0;
154
 
155
}
156
 
157
 
158
static void en302_send_packet(struct _68EN302_ETHR_BLOCK* eblk, void* buf, unsigned short length, int index)
159
{
160
        struct _68EN302_ETHR_TXBD* bd;
161
 
162
        bd = &eblk->BD[TX_BD_START+index].tx;
163
        bd->length = length;
164
        bd->address = (unsigned long) buf;
165
        bd->flags.w |=  0x9C00; /* R=1, I=1, L=1 TC=1 */
166
#if 0
167
        bd->flags.s.L = 1;
168
        bd->flags.s.I = 1;
169
        bd->flags.s.TC = 1;
170
        bd->flags.s.R = 1;
171
#endif
172
}
173
 
174
 
175
static void en302_flush_tx_ring(struct net_local* lp)
176
{
177
        int i;
178
 
179
        for(i = 0; i < TX_QUEUE_SIZE; i++)
180
        {
181
                if (lp->tx_skb[i])
182
                        dev_kfree_skb (lp->tx_skb[i], FREE_WRITE);
183
                lp->tx_skb[i] = 0;
184
        }
185
 
186
        lp->tx_count = 0;
187
}
188
 
189
static void en302_flush_rx_ring(struct net_local* lp)
190
{
191
        int i;
192
 
193
        for(i = 0; i < RX_QUEUE_SIZE; i++)
194
        {
195
                if (lp->rx_skb[i])
196
                        dev_kfree_skb (lp->rx_skb[i], FREE_READ);
197
                lp->rx_skb[i] = 0;
198
        }
199
 
200
}
201
 
202
static void en302_load_rx_ring(struct net_local *lp)
203
{
204
        struct _68EN302_ETHR_BLOCK* eblk = lp->eblk;
205
        int i;
206
 
207
 
208
        for(i = 0; i < RX_QUEUE_SIZE; i++)
209
        {
210
                struct sk_buff *skb;
211
 
212
                if (!lp->rx_skb[i])
213
                {
214
                        struct  _68EN302_ETHR_RXBD* bd;
215
                        skb = dev_alloc_skb(MAX_FRAME_SIZE);
216
 
217
                        if (skb == NULL)
218
                                break;
219
 
220
                        lp->rx_skb[i] = skb;
221
                        bd = &eblk->BD[RX_BD_START+i].rx;
222
                        bd->length = MAX_FRAME_SIZE;
223
                        bd->address.l = (unsigned long) skb->tail;
224
                        bd->flags.s.I = 1;
225
                        bd->flags.s.E = 1;
226
                }
227
        }
228
}
229
 
230
 
231
 
232
 
233
static void en302_init(struct net_local* lp, int flag)
234
{
235
        struct _68EN302_ETHR_BLOCK* eblk = lp->eblk;
236
 
237
        eblk->BD[TX_BD_START+TX_QUEUE_SIZE-1].tx.flags.s.W = 1;
238
        eblk->BD[RX_BD_START+RX_QUEUE_SIZE-1].rx.flags.s.W = 1;
239
 
240
        lp->rx_next = 0;
241
        lp->tx_next = 0;
242
        lp->tx_next_done = 0;
243
        lp->tx_count = 0;
244
 
245
        en302_load_rx_ring(lp);
246
        eblk->info.ECNTRL.GTS = 0;
247
        eblk->info.ECNTRL.ETHER_EN = 1;
248
 
249
 
250
 
251
}
252
 
253
 
254
 
255
 
256
 
257
 
258
 
259
/*
260
 * Check for a network adaptor of this type, and return '0' iff one exists.
261
 * If dev->base_addr == 0, probe all likely locations.
262
 * If dev->base_addr == 1, always return failure.
263
 * If dev->base_addr == 2, allocate space for the device and return success
264
 * (detachable devices only).
265
 */
266
#ifdef HAVE_DEVLIST
267
/*
268
 * Support for a alternate probe manager,
269
 * which will eliminate the boilerplate below.
270
 */
271
struct netdev_entry netcard_drv =
272
{cardname, netcard_probe1, NETCARD_IO_EXTENT, netcard_portlist};
273
#else
274
int
275
en302_probe(struct device *dev)
276
{
277
        int i;
278
        int base_addr = dev ? dev->base_addr : 0;
279
 
280
        if (base_addr > 0x1ff)    /* Check a single specified location. */
281
                return netcard_probe1(dev, base_addr);
282
        else if (base_addr != 0)  /* Don't probe at all. */
283
                return -ENXIO;
284
 
285
        for (i = 0; netcard_portlist[i]; i++) {
286
                int ioaddr = netcard_portlist[i];
287
                if (check_region(ioaddr, NETCARD_IO_EXTENT))
288
                        continue;
289
                if (netcard_probe1(dev, ioaddr) == 0)
290
                        return 0;
291
        }
292
 
293
        return -ENODEV;
294
}
295
#endif
296
 
297
/*
298
 * This is the real probe routine. Linux has a history of friendly device
299
 * probes on the ISA bus. A good device probes avoids doing writes, and
300
 * verifies that the correct device exists and functions.
301
 */
302
static int netcard_probe1(struct device *dev, int ioaddr)
303
{
304
        static unsigned version_printed = 0;
305
        /* address of the INTERRUPT EXTENSION REGISTER */
306
        unsigned long ier = 2 + (((unsigned long) (REG16(MOBARREG) & ~0xf000)) << 12);
307
 
308
 
309
        /* Allocate a new 'dev' if needed. */
310
        if (dev == NULL) {
311
                /*
312
                 * Don't allocate the private data here, it is done later
313
                 * This makes it easier to free the memory when this driver
314
                 * is used as a module.
315
                 */
316
                dev = init_etherdev(0, 0);
317
                if (dev == NULL)
318
                        return -ENOMEM;
319
        }
320
 
321
        if (net_debug  &&  version_printed++ == 0)
322
                printk(KERN_DEBUG "%s", version);
323
 
324
        printk(KERN_INFO "%s: %s found at %#3x, ", dev->name, cardname, ioaddr);
325
 
326
        /* Fill in the 'dev' fields. */
327
        dev->base_addr = ioaddr;
328
        if (REG16(ier) & 0x0800) /* MIL bit is set */
329
        {
330
                dev->irq = IRQ3;
331
        }
332
        else
333
        {
334
                dev->irq = IRQ5;
335
        }
336
 
337
 
338
        /* Initialize the device structure. */
339
        if (dev->priv == NULL) {
340
                dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
341
                if (dev->priv == NULL)
342
                        return -ENOMEM;
343
        }
344
 
345
        memset(dev->priv, 0, sizeof(struct net_local));
346
 
347
        /* Grab the region so that no one else tries to probe our ioports. */
348
        request_region(ioaddr, NETCARD_IO_EXTENT, cardname);
349
 
350
        dev->open               = net_open;
351
        dev->stop               = net_close;
352
        dev->hard_start_xmit = net_send_packet;
353
        dev->get_stats  = net_get_stats;
354
        dev->set_multicast_list = &set_multicast_list;
355
 
356
        /* Fill in the fields of the device structure with ethernet values. */
357
        ether_setup(dev);
358
 
359
        return 0;
360
}
361
 
362
/*
363
 * Open/initialize the board. This is called (in the current kernel)
364
 * sometime after booting when the 'ifconfig' program is run.
365
 *
366
 * This routine should set everything up anew at each open, even
367
 * registers that "should" only need to be set once at boot, so that
368
 * there is non-reboot way to recover if something goes wrong.
369
 */
370
static int
371
net_open(struct device *dev)
372
{
373
        struct net_local *lp = (struct net_local *)dev->priv;
374
        struct _68EN302_ETHR_BLOCK *eblk = (struct _68EN302_ETHR_BLOCK*) dev->base_addr;
375
        unsigned short vecBase = REG16(GIMR) & 0xE0;   /* interrupt vector base  */
376
 
377
        /*
378
         * This is used if the interrupt line can turned off (shared).
379
         * See 3c503.c for an example of selecting the IRQ at config-time.
380
         */
381
        if (request_irq(dev->irq, &net_interrupt, 0, cardname, NULL)) {
382
                return -EAGAIN;
383
        }
384
 
385
 
386
        irq2dev_map[dev->irq] = dev;
387
 
388
 
389
        lp->eblk = eblk;
390
 
391
        eblk->info.ECNTRL.RESET = 1;
392
        eblk->info.EDMA.MBZ = 0;
393
        eblk->info.EDMA.BLIM = 3;
394
        eblk->info.EDMA.WMRK = 1;
395
        eblk->info.EDMA.BDSIZE = 3;
396
 
397
 
398
        eblk->info.EMRBRL = MAX_FRAME_SIZE;
399
        eblk->info.INTR_VEC.VG = 0;
400
        eblk->info.INTR_VEC.INV = vecBase + dev->irq;
401
        eblk->info.INTR_VEC.MBZ = 0;
402
 
403
        eblk->info.INTR_MASK = 0x07BC;
404
        eblk->info.ECNFIG = ETHR_FDEN;
405
 
406
        eblk->info.AR_CNTRL.MBZ = 0;
407
        eblk->info.AR_CNTRL.MULT = 0;
408
        eblk->info.AR_CNTRL.PROM = 0;
409
        eblk->info.AR_CNTRL.PA_REJ = 0;
410
 
411
 
412
 
413
        memset(eblk->BD,  0, sizeof(eblk->BD));
414
        en302_set_filter(lp, NULL);
415
        memcpy(eblk->CET[0], dev->dev_addr, ETH_ALEN);
416
 
417
        lp->open_time = jiffies;
418
 
419
        dev->tbusy = 0;
420
        dev->interrupt = 0;
421
        dev->start = 1;
422
        lp->tx_running = 1;
423
        en302_init(lp, 1);
424
        MOD_INC_USE_COUNT;
425
 
426
        return 0;
427
}
428
 
429
static int
430
net_send_packet(struct sk_buff *skb, struct device *dev)
431
{
432
        struct net_local *lp = (struct net_local *)dev->priv;
433
 
434
        if (dev->tbusy) {
435
                /*
436
                 * If we get here, some higher level has decided we are broken.
437
                 * There should really be a "kick me" function call instead.
438
                 */
439
                int tickssofar = jiffies - dev->trans_start;
440
                if (tickssofar < 5)
441
                        return 1;
442
                printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
443
                           tx_done(dev) ? "IRQ conflict" : "network cable problem");
444
                /* Try to restart the adaptor. */
445
                en302_stop(lp);
446
                en302_flush_rx_ring(lp);
447
                en302_flush_tx_ring(lp);
448
                en302_init(lp, 1);
449
 
450
                dev->tbusy=0;
451
                dev->trans_start = 0;
452
        }
453
        /*
454
         * If some higher layer thinks we've missed an tx-done interrupt
455
         * we are passed NULL. Caution: dev_tint() handles the cli()/sti()
456
         * itself.
457
         */
458
        if (skb == NULL) {
459
                dev_tint(dev);
460
                return 0;
461
        }
462
 
463
 
464
        {
465
                short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
466
                unsigned char *buf = skb->data;
467
                unsigned long flags;
468
 
469
                save_flags(flags); cli();
470
                if (lp->tx_count < TX_QUEUE_SIZE)
471
                {
472
                        lp->tx_skb[lp->tx_next] = skb;
473
                        en302_send_packet(lp->eblk, buf, length, lp->tx_next);
474
                        lp->tx_next = (lp->tx_next+1) & TX_QUEUE_MASK;
475
                        if (++lp->tx_count == TX_QUEUE_SIZE)
476
                        {
477
                                set_bit(0, (void*)&dev->tbusy);
478
                                dev->trans_start = jiffies;
479
                        }
480
 
481
                }
482
 
483
                restore_flags(flags);
484
 
485
        }
486
 
487
        return 0;
488
}
489
 
490
/*
491
 * The typical workload of the driver:
492
 *   Handle the network interface interrupts.
493
 */
494
static void
495
net_interrupt(int irq, void *dev_id, struct pt_regs * regs)
496
{
497
        struct device *dev = (struct device *)(irq2dev_map[irq]);
498
        struct net_local *lp;
499
        int  status;
500
        struct _68EN302_ETHR_BLOCK* eblk;
501
 
502
        if (dev == NULL) {
503
                printk(KERN_WARNING "%s: irq %d for unknown device.\n", cardname, irq);
504
                return;
505
        }
506
        dev->interrupt = 1;
507
 
508
        lp = (struct net_local *)dev->priv;
509
        eblk = lp->eblk;
510
 
511
        status = eblk->info.INTR_EVENT;
512
 
513
        while(status)
514
        {
515
                eblk->info.INTR_EVENT |= status;
516
 
517
                if (status & ETHR_RFINT) {
518
                        /* Got a packet(s). */
519
                        net_rx(dev);
520
                }
521
                if (status & ETHR_TFINT) {
522
                        net_tx(dev);
523
                        dev->tbusy = 0;
524
                        mark_bh(NET_BH);        /* Inform upper layers. */
525
                }
526
 
527
                if (status & ETHR_BSY)
528
                {
529
                        if (!(status & ETHR_RFINT))
530
                        {
531
                                net_rx(dev);
532
                        }
533
                        else
534
                        {
535
                                en302_load_rx_ring(lp);
536
                        }
537
                }
538
 
539
 
540
 
541
                if (status & ETHR_HBERR)
542
                {
543
                }
544
 
545
                if (status & ETHR_BABR)
546
                {
547
                }
548
 
549
                if (status & ETHR_BABT)
550
                {
551
                }
552
 
553
                if (status & ETHR_GRA)
554
                {
555
                        eblk->info.ECNTRL.GTS = 0;
556
                        lp->tx_running = 0;
557
                }
558
 
559
                if (status & ETHR_EBERR)
560
                {
561
 
562
                        printk(KERN_WARNING "Ethernet buss error: BD %d\n", eblk->info.EDMA.BDERR);
563
                }
564
 
565
 
566
                status = eblk->info.INTR_EVENT;
567
 
568
 
569
        }
570
 
571
        dev->interrupt = 0;
572
        return;
573
}
574
 
575
static void dummy_call()
576
{
577
}
578
 
579
 
580
 
581
/* We have a good packet(s), get it/them out of the buffers. */
582
static void
583
net_rx(struct device *dev)
584
{
585
        struct net_local *lp = (struct net_local *)dev->priv;
586
        struct _68EN302_ETHR_BLOCK* eblk = lp->eblk;
587
        int rxbd = 0;
588
        struct sk_buff *skb;
589
        int count = 0;
590
 
591
        for(rxbd = lp->rx_next;  count < RX_QUEUE_SIZE; rxbd = (rxbd + 1) & RX_QUEUE_MASK, count++)
592
        {
593
                struct  _68EN302_ETHR_RXBD* bd = &eblk->BD[RX_BD_START+rxbd].rx;
594
                union  _68EN302_ETHR_RXBD_FLAGS  flags;
595
                int bad = 0;
596
 
597
 
598
                skb = lp->rx_skb[rxbd];
599
 
600
                if (!skb)
601
                {
602
                        skb = dev_alloc_skb(MAX_FRAME_SIZE);
603
 
604
                        if (skb != NULL)
605
                        {
606
                                bd->length = MAX_FRAME_SIZE;
607
                                bd->address.l = (unsigned long) skb->tail;
608
                                bd->flags.s.I = 1;
609
                                bd->flags.s.E = 1;
610
                        }
611
 
612
                        continue;
613
 
614
                }
615
 
616
 
617
                flags.w = bd->flags.w;
618
 
619
                if (flags.s.E)
620
                {
621
                        break;
622
                }
623
 
624
                if (flags.s.SH)
625
                {
626
                        bad = 1;
627
                        lp->stats.rx_length_errors++;
628
                }
629
 
630
                if (flags.s.L)
631
                {
632
                        if (flags.s.LG)
633
                        {
634
                                bad = 1;
635
                                lp->stats.rx_length_errors++;
636
                        }
637
 
638
                        if (flags.s.NO)
639
                        {
640
                                bad = 1;
641
                                lp->stats.rx_frame_errors++;
642
                        }
643
 
644
                        if (flags.s.CR)
645
                        {
646
                                bad = 1;
647
                                lp->stats.rx_crc_errors++;
648
                        }
649
 
650
                        if (flags.s.OV)
651
                        {
652
                                bad = 1;
653
                                lp->stats.rx_fifo_errors++;
654
                        }
655
 
656
                }
657
 
658
                if (flags.s.CL)
659
                {
660
                        bad = 1;
661
                }
662
 
663
 
664
 
665
                if (bad)
666
                {
667
                        lp->stats.rx_errors++;
668
                        bd->length = MAX_FRAME_SIZE;
669
                        bd->address.l = (unsigned long) lp->rx_skb[rxbd]->tail;
670
                        bd->flags.s.I = 1;
671
                        bd->flags.s.E = 1;
672
 
673
                        continue;
674
                }
675
 
676
                if (bd->length < 128) // small packet
677
                {
678
                        struct sk_buff *nskb = dev_alloc_skb(bd->length);
679
                        if (nskb)
680
                        {
681
                                memcpy(skb_put(nskb, bd->length), bd->address.l, bd->length);
682
                                dummy_call();
683
                                nskb->dev = dev;
684
                                nskb->protocol = eth_type_trans(nskb,dev);
685
                                netif_rx(nskb);
686
                                lp->stats.rx_packets++;
687
                        }
688
                        else
689
                        {
690
                                lp->stats.rx_dropped++;
691
                        }
692
                }
693
                else
694
                {
695
                        skb->dev = dev;
696
                        skb_put(skb, bd->length);
697
                        dummy_call();
698
                        skb->protocol = eth_type_trans(skb,dev);
699
                        netif_rx(skb);
700
                        lp->stats.rx_packets++;
701
 
702
                        skb = dev_alloc_skb(MAX_FRAME_SIZE);
703
                }
704
 
705
                if (skb != NULL)
706
                {
707
                        bd->length = MAX_FRAME_SIZE;
708
                        bd->address.l = (unsigned long) skb->tail;
709
                        bd->flags.s.I = 1;
710
                        bd->flags.s.E = 1;
711
                }
712
                else
713
                {
714
                        printk(KERN_WARNING "en302: can't get input packet buffer\n");
715
                }
716
 
717
                lp->rx_skb[rxbd] = skb;
718
 
719
 
720
        }
721
 
722
        lp->rx_next = rxbd;
723
 
724
 
725
 
726
 
727
}
728
 
729
 
730
static void
731
net_tx(struct device *dev)
732
{
733
        struct net_local *lp = (struct net_local *)dev->priv;
734
        struct _68EN302_ETHR_BLOCK* eblk = lp->eblk;
735
        int txbd;
736
        int bad = 0;
737
        int count = 0;
738
 
739
        for(txbd = lp->tx_next_done;  count < TX_QUEUE_SIZE; txbd = (txbd + 1) & TX_QUEUE_MASK, count++)
740
        {
741
                struct  _68EN302_ETHR_TXBD* bd = &eblk->BD[TX_BD_START+txbd].tx;
742
                register union  _68EN302_ETHR_TXBD_FLAGS  flags;
743
 
744
                flags.w = bd->flags.w;
745
 
746
                if (!lp->tx_skb[txbd])
747
                        break;
748
 
749
                if (flags.s.R)
750
                        break;
751
 
752
                dev_kfree_skb (lp->tx_skb[txbd], FREE_WRITE);
753
                lp->tx_skb[txbd] = 0;
754
                lp->tx_count--;
755
 
756
                if (flags.s.CSL)
757
                {
758
                        bad = 1;
759
                        lp->stats.tx_carrier_errors++;
760
                }
761
 
762
                if (flags.s.UN)
763
                {
764
                        bad = 1;
765
                        lp->stats.tx_fifo_errors++;
766
                }
767
 
768
                if (flags.s.RL)
769
                {
770
                        bad = 1;
771
                        lp->stats.tx_aborted_errors++;
772
                }
773
 
774
                if (flags.s.HB)
775
                {
776
                        bad = 1;
777
                        lp->stats.tx_heartbeat_errors++;
778
                }
779
 
780
                if (flags.s.LC)
781
                {
782
                        bad = 1;
783
                        lp->stats.tx_window_errors++;
784
                }
785
 
786
                if (flags.w & 0x1C0)
787
                {
788
                        bad = 1;
789
                        lp->stats.tx_dropped++;
790
                }
791
 
792
                if (!bad)
793
                        lp->stats.tx_packets++;
794
        }
795
 
796
        lp->tx_next_done = txbd;
797
 
798
}
799
 
800
/* The inverse routine to net_open(). */
801
static int
802
net_close(struct device *dev)
803
{
804
        struct net_local *lp = (struct net_local *)dev->priv;
805
 
806
 
807
        lp->open_time = 0;
808
 
809
        dev->tbusy = 1;
810
        dev->start = 0;
811
 
812
        en302_stop(lp);
813
        en302_flush_rx_ring(lp);
814
        en302_flush_tx_ring(lp);
815
 
816
 
817
        /* Update the statistics here. */
818
 
819
        MOD_DEC_USE_COUNT;
820
 
821
        return 0;
822
 
823
}
824
 
825
/*
826
 * Get the current statistics.
827
 * This may be called with the card open or closed.
828
 */
829
static struct enet_statistics *
830
net_get_stats(struct device *dev)
831
{
832
        struct net_local *lp = (struct net_local *)dev->priv;
833
        return &lp->stats;
834
}
835
 
836
 
837
 
838
 
839
/*
840
 * Set or clear the multicast filter for this adaptor.
841
 * num_addrs == -1      Promiscuous mode, receive all packets
842
 * num_addrs == 0       Normal mode, clear multicast list
843
 * num_addrs > 0        Multicast mode, receive normal and MC packets,
844
 *                      and do best-effort filtering.
845
 */
846
static void
847
set_multicast_list(struct device *dev)
848
{
849
        struct net_local* lp = (struct net_local*) dev->priv;
850
        struct _68EN302_ETHR_BLOCK* eblk = lp->eblk;
851
 
852
        en302_stop(lp);
853
        en302_flush_tx_ring(lp);
854
        en302_flush_rx_ring(lp);
855
 
856
        memcpy(eblk->CET[0], dev->dev_addr, ETH_ALEN);
857
 
858
        if (dev->flags&IFF_PROMISC)
859
        {
860
                /* Enable promiscuous mode */
861
                eblk->info.AR_CNTRL.PROM = 1;
862
        }
863
        else if((dev->flags&IFF_ALLMULTI) || dev->mc_count > HW_MAX_ADDRS)
864
        {
865
 
866
                /* Disable promiscuous mode, use normal mode. */
867
                eblk->info.AR_CNTRL.PROM = 0;
868
                eblk->info.AR_CNTRL.MULT = 2;
869
                en302_set_filter(lp, NULL);
870
 
871
        }
872
        else if(dev->mc_count)
873
        {
874
                /* Walk the address list, and load the filter */
875
                en302_set_filter(lp, dev->mc_list);
876
        }
877
        else
878
        {
879
                eblk->info.AR_CNTRL.MULT = 0;
880
                en302_set_filter(lp, NULL);
881
        }
882
 
883
        en302_init(lp, 1);
884
}
885
 
886
#ifdef MODULE
887
 
888
static char devicename[9] = { 0, };
889
static struct device this_device = {
890
        devicename, /* will be inserted by linux/drivers/net/net_init.c */
891
        0, 0, 0, 0,
892
        0, 0,  /* I/O address, IRQ */
893
        0, 0, 0, NULL, netcard_probe };
894
 
895
static int io = ECTRL0;
896
static int irq = 0;
897
static int dma = 0;
898
static int mem = 0;
899
 
900
int init_module(void)
901
{
902
        int result;
903
 
904
        if (io == 0)
905
                printk(KERN_WARNING "%s: You shouldn't use auto-probing with insmod!\n",
906
                           cardname);
907
 
908
        /* Copy the parameters from insmod into the device structure. */
909
        this_device.base_addr = io;
910
        this_device.irq       = irq;
911
        this_device.dma       = dma;
912
        this_device.mem_start = mem;
913
 
914
        if ((result = register_netdev(&this_device)) != 0)
915
                return result;
916
 
917
        return 0;
918
}
919
 
920
void
921
cleanup_module(void)
922
{
923
        /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
924
        unregister_netdev(&this_device);
925
        /*
926
         * If we don't do this, we can't re-insmod it later.
927
         * Release irq/dma here, when you have jumpered versions and
928
         * allocate them in net_probe1().
929
         */
930
        /*
931
           free_irq(this_device.irq, NULL);
932
           free_dma(this_device.dma);
933
        */
934
        release_region(this_device.base_addr, NETCARD_IO_EXTENT);
935
 
936
        if (this_device.priv)
937
                kfree_s(this_device.priv, sizeof(struct net_local));
938
}
939
 
940
#endif /* MODULE */
941
 
942
/*
943
 * Local variables:
944
 *  compile-command:
945
 *      gcc -D__KERNEL__ -Wall -Wstrict-prototypes -Wwrite-strings
946
 *      -Wredundant-decls -O2 -m486 -c skeleton.c
947
 *  version-control: t
948
 *  kept-new-versions: 5
949
 *  tab-width: 4
950
 *  c-indent-level: 4
951
 * End:
952
 */

powered by: WebSVN 2.1.0

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