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

Subversion Repositories or1k

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

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

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 * Amiga Linux/68k A2065 Ethernet Driver
3
 *
4
 * (C) Copyright 1995 by Geert Uytterhoeven
5
 *                      (Geert.Uytterhoeven@cs.kuleuven.ac.be)
6
 *
7
 * Fixes and tips by:
8
 *      - Janos Farkas (CHEXUM@sparta.banki.hu)
9
 *      - Jes Degn Soerensen (jds@kom.auc.dk)
10
 *
11
 * ----------------------------------------------------------------------------
12
 *
13
 * This program is based on
14
 *
15
 *      ariadne.?:      Amiga Linux/68k Ariadne Ethernet Driver
16
 *                      (C) Copyright 1995 by Geert Uytterhoeven,
17
 *                                            Peter De Schrijver
18
 *
19
 *      lance.c:        An AMD LANCE ethernet driver for linux.
20
 *                      Written 1993-94 by Donald Becker.
21
 *
22
 *      Am79C960:       PCnet(tm)-ISA Single-Chip Ethernet Controller
23
 *                      Advanced Micro Devices
24
 *                      Publication #16907, Rev. B, Amendment/0, May 1994
25
 *
26
 * ----------------------------------------------------------------------------
27
 *
28
 * This file is subject to the terms and conditions of the GNU General Public
29
 * License.  See the file COPYING in the main directory of the Linux
30
 * distribution for more details.
31
 *
32
 * ----------------------------------------------------------------------------
33
 *
34
 * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains:
35
 *
36
 *      - an Am7990 Local Area Network Controller for Ethernet (LANCE) with
37
 *        both 10BASE-2 (thin coax) and AUI (DB-15) connectors
38
 */
39
 
40
#include <linux/module.h>
41
#include <linux/stddef.h>
42
#include <linux/kernel.h>
43
#include <linux/sched.h>
44
#include <linux/string.h>
45
#include <linux/ptrace.h>
46
#include <linux/errno.h>
47
#include <linux/ioport.h>
48
#include <linux/malloc.h>
49
#include <linux/interrupt.h>
50
#include <linux/netdevice.h>
51
#include <linux/etherdevice.h>
52
#include <linux/skbuff.h>
53
 
54
#include <asm/bitops.h>
55
#include <asm/io.h>
56
#include <asm/irq.h>
57
 
58
#include <asm/bootinfo.h>
59
#include <asm/amigaints.h>
60
#include <asm/amigahw.h>
61
#include <asm/zorro.h>
62
 
63
#include "a2065.h"
64
 
65
#ifdef A2065_DEBUG
66
int a2065_debug = A2065_DEBUG;
67
#else
68
int a2065_debug = 1;
69
#endif
70
 
71
 
72
        /*
73
         *              Transmit/Receive Ring Definitions
74
         */
75
 
76
#define LANCE_LOG_TX_BUFFERS    (2)
77
#define LANCE_LOG_RX_BUFFERS    (4)
78
 
79
#define TX_RING_SIZE            (1<<LANCE_LOG_TX_BUFFERS)
80
#define RX_RING_SIZE            (1<<LANCE_LOG_RX_BUFFERS)
81
 
82
#define TX_RING_MOD_MASK        (TX_RING_SIZE-1)
83
#define RX_RING_MOD_MASK        (RX_RING_SIZE-1)
84
 
85
#define PKT_BUF_SIZE            (1520)
86
 
87
 
88
        /*
89
         *              Private Device Data
90
         */
91
 
92
struct a2065_private {
93
        struct A2065Board *board;
94
        struct TDRE *tx_ring[TX_RING_SIZE];
95
        struct RDRE *rx_ring[RX_RING_SIZE];
96
        u_char *tx_buff[TX_RING_SIZE];
97
        u_char *rx_buff[RX_RING_SIZE];
98
        int cur_tx, cur_rx;             /* The next free ring entry */
99
        int dirty_tx;                   /* The ring entries to be free()ed. */
100
        struct enet_statistics stats;
101
        char tx_full;
102
        unsigned long lock;
103
        int key;
104
};
105
 
106
 
107
        /*
108
         *              Structure Created in the A2065's RAM Buffer
109
         */
110
 
111
struct lancedata {
112
        struct InitBlock init;
113
        struct TDRE tx_ring[TX_RING_SIZE];
114
        struct RDRE rx_ring[RX_RING_SIZE];
115
        u_char tx_buff[TX_RING_SIZE][PKT_BUF_SIZE];
116
        u_char rx_buff[RX_RING_SIZE][PKT_BUF_SIZE];
117
};
118
 
119
 
120
static int a2065_open(struct device *dev);
121
static void a2065_init_ring(struct device *dev);
122
static int a2065_start_xmit(struct sk_buff *skb, struct device *dev);
123
static int a2065_rx(struct device *dev);
124
static void a2065_interrupt(int irq, struct pt_regs *fp, void *data);
125
static int a2065_close(struct device *dev);
126
static struct enet_statistics *a2065_get_stats(struct device *dev);
127
static void set_multicast_list(struct device *dev);
128
 
129
 
130
int a2065_probe(struct device *dev)
131
{
132
        int key1, key2;
133
        struct ConfigDev *cd;
134
        u_long board;
135
        u_long sn;
136
        struct a2065_private *priv;
137
 
138
        if ((key1 = zorro_find(MANUF_COMMODORE, PROD_A2065, 0, 0)) ||
139
            (key2 = zorro_find(MANUF_AMERISTAR, PROD_AMERISTAR2065, 0, 0))) {
140
                cd = zorro_get_board(key1 ? key1 : key2);
141
                if ((board = (u_long)cd->cd_BoardAddr)) {
142
                        sn = cd->cd_Rom.er_SerialNumber;
143
                        if (key1) {                     /* Commodore */
144
                                dev->dev_addr[0] = 0x00;
145
                                dev->dev_addr[1] = 0x80;
146
                                dev->dev_addr[2] = 0x10;
147
                        } else {                        /* Ameristar */
148
                                dev->dev_addr[0] = 0x00;
149
                                dev->dev_addr[1] = 0x00;
150
                                dev->dev_addr[2] = 0x9f;
151
                        }
152
                        dev->dev_addr[3] = (sn>>16) & 0xff;
153
                        dev->dev_addr[4] = (sn>>8) & 0xff;
154
                        dev->dev_addr[5] = sn & 0xff;
155
                        printk("%s: A2065 at 0x%08lx, Ethernet Address %02x:%02x:%02x:%02x:%02x:%02x\n",
156
                               dev->name, board, dev->dev_addr[0],
157
                               dev->dev_addr[1], dev->dev_addr[2],
158
                               dev->dev_addr[3], dev->dev_addr[4],
159
                               dev->dev_addr[5]);
160
 
161
                        init_etherdev(dev, 0);
162
 
163
                        dev->priv = kmalloc(sizeof(struct
164
                                                   a2065_private),
165
                                            GFP_KERNEL);
166
                        priv = (struct a2065_private *)dev->priv;
167
                        memset(priv, 0, sizeof(struct a2065_private));
168
 
169
                        priv->board = (struct A2065Board *)ZTWO_VADDR(board);
170
                        priv->key = key1 ? key1 : key2;
171
 
172
                        dev->open = &a2065_open;
173
                        dev->stop = &a2065_close;
174
                        dev->hard_start_xmit = &a2065_start_xmit;
175
                        dev->get_stats = &a2065_get_stats;
176
                        dev->set_multicast_list = &set_multicast_list;
177
 
178
                        zorro_config_board(key1 ? key1 : key2, 0);
179
                        return(0);
180
                }
181
        }
182
        return(ENODEV);
183
}
184
 
185
 
186
static int a2065_open(struct device *dev)
187
{
188
        struct a2065_private *priv = (struct a2065_private *)dev->priv;
189
        struct A2065Board *board = priv->board;
190
        struct lancedata *lancedata;            /* LANCE point of view */
191
        struct lancedata *alancedata;           /* Amiga point of view */
192
 
193
        lancedata = (struct lancedata *)offsetof(struct A2065Board, RAM);
194
        alancedata = (struct lancedata *)board->RAM;
195
 
196
        /* Stop the LANCE */
197
        board->Lance.RAP = CSR0;                /* LANCE Controller Status */
198
        board->Lance.RDP = STOP;
199
 
200
        /* Enable big endian byte ordering */
201
        board->Lance.RAP = CSR3;                /* CSR3 */
202
        board->Lance.RDP = BSWP;
203
 
204
        /* Set the Init Block Pointer */
205
        board->Lance.RAP = CSR1;                /* IADR[15:0] */
206
        board->Lance.RDP = (u_long)&lancedata->init;
207
        board->Lance.RAP = CSR2;                /* IADR[23:16] */
208
        board->Lance.RDP = 0x0000;
209
 
210
        /* Set the Mode */
211
        alancedata->init.Mode = 0;
212
 
213
        /* Set the Ethernet Hardware Address */
214
                            /* Physical Address Register */
215
        alancedata->init.PADR[0] = dev->dev_addr[1];
216
        alancedata->init.PADR[1] = dev->dev_addr[0];
217
        alancedata->init.PADR[2] = dev->dev_addr[3];
218
        alancedata->init.PADR[3] = dev->dev_addr[2];
219
        alancedata->init.PADR[4] = dev->dev_addr[5];
220
        alancedata->init.PADR[5] = dev->dev_addr[4];
221
 
222
        /* Set the Multicast Table */
223
                            /* Logical Address Filter, LADRF[31:0] */
224
        alancedata->init.LADRF[0] = 0x00000000;
225
                            /* Logical Address Filter, LADRF[63:32] */
226
        alancedata->init.LADRF[1] = 0x00000000;
227
 
228
        /* Set the Receive and Transmit Descriptor Ring Pointers */
229
        alancedata->init.RDRA = (u_long)&lancedata->rx_ring;
230
        alancedata->init.RLEN = LANCE_LOG_RX_BUFFERS << 13;
231
        alancedata->init.TDRA = (u_long)&lancedata->tx_ring;
232
        alancedata->init.TLEN = LANCE_LOG_TX_BUFFERS << 13;
233
 
234
        /* Initialise the Rings */
235
        a2065_init_ring(dev);
236
 
237
 
238
        /* Install the Interrupt handler */
239
        if (!add_isr(IRQ_AMIGA_PORTS, a2065_interrupt, 0, dev, "a2065 Ethernet"))
240
                return(-EAGAIN);
241
 
242
        /* Make the LANCE read the Init Block */
243
        board->Lance.RAP = CSR0;                /* LANCE Controller Status */
244
        board->Lance.RDP = INEA|INIT;
245
 
246
        dev->tbusy = 0;
247
        dev->interrupt = 0;
248
        dev->start = 1;
249
 
250
        MOD_INC_USE_COUNT;
251
 
252
        return(0);
253
}
254
 
255
 
256
static void a2065_init_ring(struct device *dev)
257
{
258
        struct a2065_private *priv = (struct a2065_private *)dev->priv;
259
        struct A2065Board *board = priv->board;
260
        struct lancedata *lancedata;            /* LANCE point of view */
261
        struct lancedata *alancedata;           /* Amiga point of view */
262
        int i;
263
 
264
        priv->lock = 0, priv->tx_full = 0;
265
        priv->cur_rx = priv->cur_tx = 0;
266
        priv->dirty_tx = 0;
267
 
268
        lancedata = (struct lancedata *)offsetof(struct A2065Board, RAM);
269
        alancedata = (struct lancedata *)board->RAM;
270
 
271
        /* Set up TX Ring */
272
        for (i = 0; i < TX_RING_SIZE; i++) {
273
                alancedata->tx_ring[i].TMD0 = (u_long)lancedata->tx_buff[i];
274
                alancedata->tx_ring[i].TMD1 = TF_STP|TF_ENP;
275
                alancedata->tx_ring[i].TMD2 = -PKT_BUF_SIZE;
276
                alancedata->tx_ring[i].TMD3 = 0x0000;
277
                priv->tx_ring[i] = &alancedata->tx_ring[i];
278
                priv->tx_buff[i] = alancedata->tx_buff[i];
279
#if 0
280
                printk("TX Entry %2d @ 0x%08x (LANCE 0x%08x), Buf @ 0x%08x (LANCE 0x%08x)\n", i,
281
                       (int)&alancedata->tx_ring[i],
282
                       (int)&lancedata->tx_ring[i],
283
                       (int)alancedata->tx_buff[i],
284
                       (int)lancedata->tx_buff[i]);
285
#endif
286
        }
287
 
288
        /* Set up RX Ring */
289
        for (i = 0; i < RX_RING_SIZE; i++) {
290
                alancedata->rx_ring[i].RMD0 = (u_long)lancedata->rx_buff[i];
291
                alancedata->rx_ring[i].RMD1 = RF_OWN;
292
                alancedata->rx_ring[i].RMD2 = -PKT_BUF_SIZE;
293
                alancedata->rx_ring[i].RMD3 = 0x0000;
294
                priv->rx_ring[i] = &alancedata->rx_ring[i];
295
                priv->rx_buff[i] = alancedata->rx_buff[i];
296
#if 0
297
                printk("RX Entry %2d @ 0x%08x (LANCE 0x%08x), Buf @ 0x%08x (LANCE 0x%08x)\n", i,
298
                       (int)&alancedata->rx_ring[i],
299
                       (int)&lancedata->rx_ring[i],
300
                       (int)alancedata->rx_buff[i],
301
                       (int)lancedata->rx_buff[i]);
302
#endif
303
        }
304
}
305
 
306
 
307
static int a2065_close(struct device *dev)
308
{
309
        struct a2065_private *priv = (struct a2065_private *)dev->priv;
310
        struct A2065Board *board = priv->board;
311
 
312
        dev->start = 0;
313
        dev->tbusy = 1;
314
 
315
        board->Lance.RAP = CSR0;                /* LANCE Controller Status */
316
 
317
        if (a2065_debug > 1) {
318
          printk("%s: Shutting down ethercard, status was %2.2x.\n",
319
                 dev->name, board->Lance.RDP);
320
          printk("%s: %d packets missed\n", dev->name,
321
                 priv->stats.rx_missed_errors);
322
        }
323
 
324
        /* We stop the LANCE here - it occasionally polls memory if we don't */
325
        board->Lance.RDP = STOP;
326
 
327
        remove_isr(IRQ_AMIGA_PORTS, a2065_interrupt, dev);
328
 
329
        MOD_DEC_USE_COUNT;
330
 
331
        return(0);
332
}
333
 
334
 
335
static void a2065_interrupt(int irq, struct pt_regs *fp, void *data)
336
{
337
        struct device *dev = (struct device *)data;
338
        struct a2065_private *priv;
339
        struct A2065Board *board;
340
        int csr0, boguscnt = 10;
341
 
342
        if (dev == NULL) {
343
                printk("a2065_interrupt(): irq for unknown device.\n");
344
                return;
345
        }
346
 
347
        priv = (struct a2065_private *)dev->priv;
348
        board = priv->board;
349
 
350
        board->Lance.RAP = CSR0;        /* LANCE Controller Status */
351
 
352
        if (!(board->Lance.RDP & INTR)) /* Check if any interrupt has
353
                                           been generated by the board. */
354
                return;
355
 
356
        if (dev->interrupt)
357
                printk("%s: Re-entering the interrupt handler.\n", dev->name);
358
 
359
        dev->interrupt = 1;
360
 
361
        while ((csr0 = board->Lance.RDP) & (ERR|RINT|TINT) && --boguscnt >= 0){
362
                /* Acknowledge all of the current interrupt sources ASAP. */
363
                board->Lance.RDP = csr0 & ~(INEA|TDMD|STOP|STRT|INIT);
364
 
365
#if 0
366
                if (a2065_debug > 5) {
367
                  printk("%s: interrupt  csr0=%#2.2x new csr=%#2.2x.",
368
                         dev->name, csr0, board->Lance.RDP);
369
                  printk("[");
370
                  if (csr0 & INTR)
371
                    printk(" INTR");
372
                  if (csr0 & INEA)
373
                    printk(" INEA");
374
                  if (csr0 & RXON)
375
                    printk(" RXON");
376
                  if (csr0 & TXON)
377
                    printk(" TXON");
378
                  if (csr0 & TDMD)
379
                    printk(" TDMD");
380
                  if (csr0 & STOP)
381
                    printk(" STOP");
382
                  if (csr0 & STRT)
383
                    printk(" STRT");
384
                  if (csr0 & INIT)
385
                    printk(" INIT");
386
                  if (csr0 & ERR)
387
                    printk(" ERR");
388
                  if (csr0 & BABL)
389
                    printk(" BABL");
390
                  if (csr0 & CERR)
391
                    printk(" CERR");
392
                  if (csr0 & MISS)
393
                    printk(" MISS");
394
                  if (csr0 & MERR)
395
                    printk(" MERR");
396
                  if (csr0 & RINT)
397
                    printk(" RINT");
398
                  if (csr0 & TINT)
399
                    printk(" TINT");
400
                  if (csr0 & IDON)
401
                    printk(" IDON");
402
                  printk(" ]\n");
403
                }
404
#endif
405
 
406
                if (csr0 & RINT)                        /* Rx interrupt */
407
                        a2065_rx(dev);
408
 
409
                if (csr0 & TINT) {                      /* Tx-done interrupt */
410
                        int dirty_tx = priv->dirty_tx;
411
 
412
                        while (dirty_tx < priv->cur_tx) {
413
                                int entry = dirty_tx % TX_RING_SIZE;
414
                                int status =
415
                                  priv->tx_ring[entry]->TMD1 & 0xff00;
416
 
417
                                if (status & TF_OWN)
418
                                        break;  /* It still hasn't been Txed */
419
 
420
                                priv->tx_ring[entry]->TMD1 &= 0x00ff;
421
 
422
                                if (status & TF_ERR) {
423
                                        /* There was an major error, log it. */
424
                                        int err_status =
425
                                          priv->tx_ring[entry]->TMD3;
426
                                        priv->stats.tx_errors++;
427
                                        if (err_status & EF_RTRY)
428
                                          priv->stats.tx_aborted_errors++;
429
                                        if (err_status & EF_LCAR)
430
                                          priv->stats.tx_carrier_errors++;
431
                                        if (err_status & EF_LCOL)
432
                                          priv->stats.tx_window_errors++;
433
                                        if (err_status & EF_UFLO) {
434
                         /* Ackk!  On FIFO errors the Tx unit is turned off! */
435
                                          priv->stats.tx_fifo_errors++;
436
                                          /* Remove this verbosity later! */
437
                                          printk("%s: Tx FIFO error! Status %4.4x.\n", dev->name, csr0);
438
                                          /* Restart the chip. */
439
                                          board->Lance.RDP = STRT;
440
                                        }
441
                                } else {
442
                                        if (status & (TF_MORE|TF_ONE))
443
                                          priv->stats.collisions++;
444
                                        priv->stats.tx_packets++;
445
                                }
446
                                dirty_tx++;
447
                        }
448
 
449
#ifndef final_version
450
                        if (priv->cur_tx - dirty_tx >= TX_RING_SIZE) {
451
                                printk("out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
452
                                       dirty_tx, priv->cur_tx, priv->tx_full);
453
                                dirty_tx += TX_RING_SIZE;
454
                        }
455
#endif
456
 
457
                        if (priv->tx_full && dev->tbusy && dirty_tx >
458
                            priv->cur_tx - TX_RING_SIZE + 2) {
459
                                /* The ring is no longer full, clear tbusy. */
460
                                priv->tx_full = 0;
461
                                dev->tbusy = 0;
462
                                mark_bh(NET_BH);
463
                        }
464
 
465
                        priv->dirty_tx = dirty_tx;
466
                }
467
 
468
                /* Log misc errors. */
469
                if (csr0 & BABL)
470
                        priv->stats.tx_errors++;       /* Tx babble. */
471
                if (csr0 & MISS)
472
                        priv->stats.rx_errors++;       /* Missed a Rx frame. */
473
                if (csr0 & MERR) {
474
                        printk("%s: Bus master arbitration failure, status %4.4x.\n", dev->name, csr0);
475
                        /* Restart the chip. */
476
                        board->Lance.RDP = STRT;
477
                }
478
        }
479
 
480
        /* Clear any other interrupt, and set interrupt enable. */
481
        board->Lance.RAP = CSR0;                /* LANCE Controller Status */
482
        board->Lance.RDP = INEA|BABL|CERR|MISS|MERR|IDON;
483
 
484
#if 0
485
        if (a2065_debug > 4)
486
                printk("%s: exiting interrupt, csr%d=%#4.4x.\n",
487
                       dev->name, board->Lance.RAP, board->Lance.RDP);
488
#endif
489
 
490
        dev->interrupt = 0;
491
        return;
492
}
493
 
494
 
495
static int a2065_start_xmit(struct sk_buff *skb, struct device *dev)
496
{
497
        struct a2065_private *priv = (struct a2065_private *)dev->priv;
498
        struct A2065Board *board = priv->board;
499
        int entry;
500
 
501
        /* Transmitter timeout, serious problems. */
502
        if (dev->tbusy) {
503
                int tickssofar = jiffies - dev->trans_start;
504
                if (tickssofar < 20)
505
                        return(1);
506
                board->Lance.RAP = CSR0;        /* LANCE Controller Status */
507
                printk("%s: transmit timed out, status %4.4x, resetting.\n", dev->name, board->Lance.RDP);
508
                board->Lance.RDP = STOP;
509
 
510
                /* Enable big endian byte ordering */
511
                board->Lance.RAP = CSR3;                        /* CSR3 */
512
                board->Lance.RDP = BSWP;
513
 
514
                priv->stats.tx_errors++;
515
#ifndef final_version
516
                {
517
                  int i;
518
                  printk(" Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.",
519
                         priv->dirty_tx, priv->cur_tx, priv->tx_full ?
520
                         " (full)" : "", priv->cur_rx);
521
                  for (i = 0 ; i < RX_RING_SIZE; i++)
522
                    printk("%s %08x %04x %04x", i & 0x3 ? "" : "\n ",
523
                           ((priv->rx_ring[i]->RMD1)<<16) |
524
                           priv->rx_ring[i]->RMD0,
525
                           -priv->rx_ring[i]->RMD2, priv->rx_ring[i]->RMD3);
526
                  for (i = 0 ; i < TX_RING_SIZE; i++)
527
                    printk("%s %08x %04x %04x", i & 0x3 ? "" : "\n ",
528
                           ((priv->tx_ring[i]->TMD1)<<16) |
529
                           priv->tx_ring[i]->TMD0,
530
                           -priv->tx_ring[i]->TMD2, priv->tx_ring[i]->TMD3);
531
                        printk("\n");
532
                }
533
#endif
534
                a2065_init_ring(dev);
535
                board->Lance.RDP = INEA|INIT;
536
 
537
                dev->tbusy = 0;
538
                dev->trans_start = jiffies;
539
                dev_kfree_skb(skb, FREE_WRITE);
540
                return(0);
541
        }
542
 
543
        if (skb == NULL) {
544
                dev_tint(dev);
545
                return(0);
546
        }
547
 
548
        if (skb->len <= 0)
549
                return(0);
550
 
551
#if 0
552
        if (a2065_debug > 3) {
553
                board->Lance.RAP = CSR0;        /* LANCE Controller Status */
554
                printk("%s: a2065_start_xmit() called, csr0 %4.4x.\n",
555
                       dev->name, board->Lance.RDP);
556
                board->Lance.RDP = 0x0000;
557
        }
558
#endif
559
 
560
        /*
561
         * Block a timer-based transmit from overlapping.  This could better be
562
         * done with atomic_swap(1, dev->tbusy), but set_bit() works as well.
563
         */
564
        if (set_bit(0, (void*)&dev->tbusy) != 0) {
565
                printk("%s: Transmitter access conflict.\n", dev->name);
566
                return(1);
567
        }
568
 
569
        if (set_bit(0, (void*)&priv->lock) != 0) {
570
                if (a2065_debug > 0)
571
                        printk("%s: tx queue lock!.\n", dev->name);
572
                /* don't clear dev->tbusy flag. */
573
                return(1);
574
        }
575
 
576
        /* Fill in a Tx ring entry */
577
 
578
#if 0
579
        printk("TX pkt type 0x%04x from ", ((u_short *)skb->data)[6]);
580
        {
581
                int i;
582
                u_char *ptr = &((u_char *)skb->data)[6];
583
                for (i = 0; i < 6; i++)
584
                        printk("%02x", ptr[i]);
585
        }
586
        printk(" to ");
587
        {
588
                int i;
589
                u_char *ptr = (u_char *)skb->data;
590
                for (i = 0; i < 6; i++)
591
                        printk("%02x", ptr[i]);
592
        }
593
        printk(" data 0x%08x len %d\n", (int)skb->data, (int)skb->len);
594
#endif
595
 
596
        entry = priv->cur_tx % TX_RING_SIZE;
597
 
598
        priv->tx_ring[entry]->TMD2 = -(ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN);
599
        priv->tx_ring[entry]->TMD3 = 0x0000;
600
        memcpy(priv->tx_buff[entry], skb->data, skb->len);
601
 
602
#if 0
603
        {
604
                int i, len;
605
 
606
                len = skb->len > 64 ? 64 : skb->len;
607
                for (i = 0; i < len; i += 8) {
608
                        int j;
609
                        printk("%02x:", i);
610
                        for (j = 0; (j < 16) && ((i+j) < len); j++) {
611
                                if (!(j & 1))
612
                                        printk(" ");
613
                                printk("%02x", priv->tx_buff[entry][i+j]);
614
                        }
615
                        printk("\n");
616
                }
617
        }
618
#endif
619
 
620
        priv->tx_ring[entry]->TMD1 = (priv->tx_ring[entry]->TMD1 &
621
                                      0x00ff)|TF_OWN|TF_STP|TF_ENP;
622
 
623
        dev_kfree_skb(skb, FREE_WRITE);
624
 
625
        priv->cur_tx++;
626
        if ((priv->cur_tx >= TX_RING_SIZE)&&(priv->dirty_tx >= TX_RING_SIZE)){
627
 
628
#if 0
629
          printk("*** Subtracting TX_RING_SIZE from cur_tx (%d) and dirty_tx (%d)\n",
630
                 priv->cur_tx, priv->dirty_tx);
631
#endif
632
 
633
                priv->cur_tx -= TX_RING_SIZE;
634
                priv->dirty_tx -= TX_RING_SIZE;
635
        }
636
 
637
        /* Trigger an immediate send poll. */
638
        board->Lance.RAP = CSR0;                /* LANCE Controller Status */
639
        board->Lance.RDP = INEA|TDMD;
640
 
641
        dev->trans_start = jiffies;
642
 
643
        cli();
644
        priv->lock = 0;
645
        if ((priv->tx_ring[(entry+1) % TX_RING_SIZE]->TMD1 & 0xff00) == 0)
646
                dev->tbusy = 0;
647
        else
648
                priv->tx_full = 1;
649
        sti();
650
 
651
        return(0);
652
}
653
 
654
 
655
static int a2065_rx(struct device *dev)
656
{
657
        struct a2065_private *priv = (struct a2065_private *)dev->priv;
658
        int entry = priv->cur_rx % RX_RING_SIZE;
659
        int i;
660
 
661
        /* If we own the next entry, it's a new packet. Send it up. */
662
        while (!(priv->rx_ring[entry]->RMD1 & RF_OWN)) {
663
                int status = priv->rx_ring[entry]->RMD1 & 0xff00;
664
 
665
                if (status != (RF_STP|RF_ENP)) {      /* There was an error. */
666
                  /* There is a tricky error noted by John Murphy,
667
                     <murf@perftech.com> to Russ Nelson: Even with full-sized
668
                     buffers it's possible for a jabber packet to use two
669
                     buffers, with only the last correctly noting the error. */
670
                        if (status & RF_ENP)
671
                          /* Only count a general error at the */
672
                                priv->stats.rx_errors++; /* end of a packet.*/
673
                        if (status & RF_FRAM)
674
                                priv->stats.rx_frame_errors++;
675
                        if (status & RF_OFLO)
676
                                priv->stats.rx_over_errors++;
677
                        if (status & RF_CRC)
678
                                priv->stats.rx_crc_errors++;
679
                        if (status & RF_BUFF)
680
                                priv->stats.rx_fifo_errors++;
681
                        priv->rx_ring[entry]->RMD1 &= 0x00ff|RF_STP|RF_ENP;
682
                } else {
683
                        /* Malloc up new buffer, compatible with net-3. */
684
                        short pkt_len = priv->rx_ring[entry]->RMD3;
685
                        struct sk_buff *skb;
686
 
687
                        if(pkt_len<60)
688
                        {
689
                                printk("%s: Runt packet!\n",dev->name);
690
                                priv->stats.rx_errors++;
691
                        }
692
                        else
693
                        {
694
                                skb = dev_alloc_skb(pkt_len+2);
695
                                if (skb == NULL) {
696
                                        printk("%s: Memory squeeze, deferring packet.\n", dev->name);
697
                                        for (i = 0; i < RX_RING_SIZE; i++)
698
                                                if (priv->rx_ring[(entry+i) % RX_RING_SIZE]->RMD1 & RF_OWN)
699
                                                        break;
700
 
701
                                        if (i > RX_RING_SIZE-2) {
702
                                                priv->stats.rx_dropped++;
703
                                                priv->rx_ring[entry]->RMD1 |= RF_OWN;
704
                                                priv->cur_rx++;
705
                                        }
706
                                        break;
707
                                }
708
                                skb->dev = dev;
709
                                skb_reserve(skb,2);     /* 16 byte align */
710
                                skb_put(skb,pkt_len);   /* Make room */
711
                                eth_copy_and_sum(skb,
712
                                                 priv->rx_buff[entry],
713
                                                 pkt_len,0);
714
                                skb->protocol=eth_type_trans(skb,dev);
715
#if 0
716
                                printk("RX pkt type 0x%04x from ",
717
                                       ((u_short *)skb->data)[6]);
718
                                {
719
                                  int i;
720
                                  u_char *ptr = &((u_char *)skb->data)[6];
721
                                  for (i = 0; i < 6; i++)
722
                                    printk("%02x", ptr[i]);
723
                                }
724
                                printk(" to ");
725
                                {
726
                                  int i;
727
                                  u_char *ptr = (u_char *)skb->data;
728
                                  for (i = 0; i < 6; i++)
729
                                    printk("%02x", ptr[i]);
730
                                }
731
                                printk(" data 0x%08x len %d\n",
732
                                       (int)skb->data, (int)skb->len);
733
#endif
734
 
735
                                netif_rx(skb);
736
                                priv->stats.rx_packets++;
737
                        }
738
                }
739
                priv->rx_ring[entry]->RMD1 |= RF_OWN;
740
                entry = (++priv->cur_rx) % RX_RING_SIZE;
741
        }
742
 
743
        priv->cur_rx = priv->cur_rx % RX_RING_SIZE;
744
 
745
        /* We should check that at least two ring entries are free.
746
           If not, we should free one and mark stats->rx_dropped++. */
747
 
748
        return(0);
749
}
750
 
751
 
752
static struct enet_statistics *a2065_get_stats(struct device *dev)
753
{
754
        struct a2065_private *priv = (struct a2065_private *)dev->priv;
755
 
756
        return(&priv->stats);
757
}
758
 
759
 
760
/* Set or clear the multicast filter for this adaptor.
761
 */
762
static void set_multicast_list(struct device *dev)
763
{
764
        struct a2065_private *priv = (struct a2065_private *)dev->priv;
765
        struct A2065Board *board = priv->board;
766
        struct lancedata *alancedata;         /* Amiga point of view */
767
        alancedata = (struct lancedata *)board->RAM;
768
 
769
        /* We take the simple way out and always enable promiscuous mode. */
770
        board->Lance.RAP = CSR0;              /* LANCE Controller Status */
771
        board->Lance.RDP = STOP;              /* Temporarily stop the lance. */
772
 
773
        /* Enable big endian byte ordering */
774
        board->Lance.RAP = CSR3;              /* CSR3 */
775
        board->Lance.RDP = BSWP;
776
 
777
        if (dev->flags&IFF_PROMISC) {
778
          /* Log any net taps. */
779
          printk("%s: Promiscuous mode enabled.\n", dev->name);
780
          alancedata->init.Mode = PROM;       /* Set promiscuous mode */
781
        } else {
782
          short multicast_table[4];
783
          int num_addrs=dev->mc_count;
784
          if(dev->flags&IFF_ALLMULTI)
785
                num_addrs=1;
786
          /*
787
           * We don't use the multicast table,
788
           * but rely on upper-layer filtering.
789
           */
790
          memset(multicast_table, (num_addrs == 0) ? 0 : -1,
791
                 sizeof(multicast_table));
792
          alancedata->init.LADRF[0] = multicast_table[0]<<16 |
793
            multicast_table[1];
794
          alancedata->init.LADRF[1] = multicast_table[2]<<16 |
795
            multicast_table[3];
796
          alancedata->init.Mode = 0x0000;
797
        }
798
 
799
        board->Lance.RAP = CSR0;                /* LANCE Controller Status */
800
        board->Lance.RDP = INEA|STRT|IDON|INIT; /* Resume normal operation. */
801
}
802
 
803
 
804
#ifdef MODULE
805
static char devicename[9] = { 0, };
806
 
807
static struct device a2065_dev =
808
{
809
        devicename,                     /* filled in by register_netdev() */
810
        0, 0, 0, 0,                 /* memory */
811
        0, 0,                             /* base, irq */
812
        0, 0, 0, NULL, a2065_probe,
813
};
814
 
815
int init_module(void)
816
{
817
        int err;
818
 
819
        if ((err = register_netdev(&a2065_dev))) {
820
                if (err == -EIO)
821
                        printk("No A2065 board found. Module not loaded.\n");
822
                return(err);
823
        }
824
        return(0);
825
}
826
 
827
void cleanup_module(void)
828
{
829
        struct a2065_private *priv = (struct a2065_private *)a2065_dev.priv;
830
 
831
        unregister_netdev(&a2065_dev);
832
        zorro_unconfig_board(priv->key, 0);
833
        kfree(priv);
834
}
835
 
836
#endif /* MODULE */

powered by: WebSVN 2.1.0

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