1 /* sun3lance.c: Ethernet driver for SUN3 Lance chip */
4 Sun3 Lance ethernet driver, by Sam Creasey (sammy@users.qual.net).
5 This driver is a part of the linux kernel, and is thus distributed
6 under the GNU Public License.
8 The values used in LANCE_OBIO and LANCE_IRQ seem to be empirically
9 true for the correct IRQ and address of the lance registers. They
10 have not been widely tested, however. What we probably need is a
11 "proper" way to search for a device in the sun3's prom, but, alas,
12 linux has no such thing.
14 This driver is largely based on atarilance.c, by Roman Hodek. Other
15 sources of inspiration were the NetBSD sun3 am7990 driver, and the
16 linux sparc lance driver (sunlance.c).
18 There are more assumptions made throughout this driver, it almost
19 certainly still needs work, but it does work at least for RARP/BOOTP and
20 mounting the root NFS filesystem.
24 static char *version
= "sun3lance.c: v1.0 12/12/96 Sam Creasey (sammy@users.qual.net)\n";
26 #include <linux/module.h>
28 #include <linux/stddef.h>
29 #include <linux/kernel.h>
30 #include <linux/sched.h>
31 #include <linux/string.h>
32 #include <linux/ptrace.h>
33 #include <linux/errno.h>
34 #include <linux/malloc.h>
35 #include <linux/interrupt.h>
36 #include <linux/init.h>
38 #include <asm/setup.h>
41 #include <asm/bitops.h>
43 #include <asm/idprom.h>
44 #include <asm/pgtable.h>
45 #include <asm/sun3mmu.h>
48 #include <linux/netdevice.h>
49 #include <linux/etherdevice.h>
50 #include <linux/skbuff.h>
52 /* sun3/60 addr/irq for the lance chip. If your sun is different,
54 #define LANCE_OBIO 0x120000
55 #define LANCE_IRQ IRQ3
58 * 0 = silent, print only serious errors
59 * 1 = normal, print error messages
60 * 2 = debug, print debug infos
61 * 3 = debug, print even more debug infos (packet data)
67 static int lance_debug
= LANCE_DEBUG
;
69 static int lance_debug
= 1;
71 MODULE_PARM(lance_debug
, "i");
73 #define DPRINTK(n,a) \
75 if (lance_debug >= n) \
80 /* we're only using 32k of memory, so we use 4 TX
81 buffers and 16 RX buffers. These values are expressed as log2. */
83 #define TX_LOG_RING_SIZE 3
84 #define RX_LOG_RING_SIZE 5
86 /* These are the derived values */
88 #define TX_RING_SIZE (1 << TX_LOG_RING_SIZE)
89 #define TX_RING_LEN_BITS (TX_LOG_RING_SIZE << 5)
90 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
92 #define RX_RING_SIZE (1 << RX_LOG_RING_SIZE)
93 #define RX_RING_LEN_BITS (RX_LOG_RING_SIZE << 5)
94 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
96 /* Definitions for packet buffer access: */
97 #define PKT_BUF_SZ 1544
99 /* Get the address of a packet buffer corresponding to a given buffer head */
100 #define PKTBUF_ADDR(head) (void *)((unsigned long)(MEM) | (head)->base)
103 /* The LANCE Rx and Tx ring descriptors. */
104 struct lance_rx_head
{
105 unsigned short base
; /* Low word of base addr */
106 volatile unsigned char flag
;
107 unsigned char base_hi
; /* High word of base addr (unused) */
108 short buf_length
; /* This length is 2s complement! */
109 volatile short msg_length
; /* This length is "normal". */
112 struct lance_tx_head
{
113 unsigned short base
; /* Low word of base addr */
114 volatile unsigned char flag
;
115 unsigned char base_hi
; /* High word of base addr (unused) */
116 short length
; /* Length is 2s complement! */
120 /* The LANCE initialization block, described in databook. */
121 struct lance_init_block
{
122 unsigned short mode
; /* Pre-set mode */
123 unsigned char hwaddr
[6]; /* Physical ethernet address */
124 unsigned int filter
[2]; /* Multicast filter (unused). */
125 /* Receive and transmit ring base, along with length bits. */
130 unsigned short pad
[4]; /* is thie needed? */
133 /* The whole layout of the Lance shared memory */
134 struct lance_memory
{
135 struct lance_init_block init
;
136 struct lance_tx_head tx_head
[TX_RING_SIZE
];
137 struct lance_rx_head rx_head
[RX_RING_SIZE
];
138 char rx_data
[RX_RING_SIZE
][PKT_BUF_SZ
];
139 char tx_data
[RX_RING_SIZE
][PKT_BUF_SZ
];
142 /* The driver's private device structure */
144 struct lance_private
{
145 volatile unsigned short *iobase
;
146 struct lance_memory
*mem
;
147 int new_rx
, new_tx
; /* The next free ring entry */
148 int old_tx
, old_rx
; /* ring entry to be processed */
149 struct net_device_stats stats
;
150 /* These two must be ints for set_bit() */
155 /* I/O register access macros */
158 #define DREG lp->iobase[0]
159 #define AREG lp->iobase[1]
160 #define REGA(a) ( AREG = (a), DREG )
162 /* Definitions for the Lance */
165 #define TMD1_ENP 0x01 /* end of packet */
166 #define TMD1_STP 0x02 /* start of packet */
167 #define TMD1_DEF 0x04 /* deferred */
168 #define TMD1_ONE 0x08 /* one retry needed */
169 #define TMD1_MORE 0x10 /* more than one retry needed */
170 #define TMD1_ERR 0x40 /* error summary */
171 #define TMD1_OWN 0x80 /* ownership (set: chip owns) */
173 #define TMD1_OWN_CHIP TMD1_OWN
174 #define TMD1_OWN_HOST 0
176 /* tx_head misc field */
177 #define TMD3_TDR 0x03FF /* Time Domain Reflectometry counter */
178 #define TMD3_RTRY 0x0400 /* failed after 16 retries */
179 #define TMD3_LCAR 0x0800 /* carrier lost */
180 #define TMD3_LCOL 0x1000 /* late collision */
181 #define TMD3_UFLO 0x4000 /* underflow (late memory) */
182 #define TMD3_BUFF 0x8000 /* buffering error (no ENP) */
185 #define RMD1_ENP 0x01 /* end of packet */
186 #define RMD1_STP 0x02 /* start of packet */
187 #define RMD1_BUFF 0x04 /* buffer error */
188 #define RMD1_CRC 0x08 /* CRC error */
189 #define RMD1_OFLO 0x10 /* overflow */
190 #define RMD1_FRAM 0x20 /* framing error */
191 #define RMD1_ERR 0x40 /* error summary */
192 #define RMD1_OWN 0x80 /* ownership (set: ship owns) */
194 #define RMD1_OWN_CHIP RMD1_OWN
195 #define RMD1_OWN_HOST 0
198 #define CSR0 0 /* mode/status */
199 #define CSR1 1 /* init block addr (low) */
200 #define CSR2 2 /* init block addr (high) */
201 #define CSR3 3 /* misc */
202 #define CSR8 8 /* address filter */
203 #define CSR15 15 /* promiscuous mode */
206 /* (R=readable, W=writeable, S=set on write, C=clear on write) */
207 #define CSR0_INIT 0x0001 /* initialize (RS) */
208 #define CSR0_STRT 0x0002 /* start (RS) */
209 #define CSR0_STOP 0x0004 /* stop (RS) */
210 #define CSR0_TDMD 0x0008 /* transmit demand (RS) */
211 #define CSR0_TXON 0x0010 /* transmitter on (R) */
212 #define CSR0_RXON 0x0020 /* receiver on (R) */
213 #define CSR0_INEA 0x0040 /* interrupt enable (RW) */
214 #define CSR0_INTR 0x0080 /* interrupt active (R) */
215 #define CSR0_IDON 0x0100 /* initialization done (RC) */
216 #define CSR0_TINT 0x0200 /* transmitter interrupt (RC) */
217 #define CSR0_RINT 0x0400 /* receiver interrupt (RC) */
218 #define CSR0_MERR 0x0800 /* memory error (RC) */
219 #define CSR0_MISS 0x1000 /* missed frame (RC) */
220 #define CSR0_CERR 0x2000 /* carrier error (no heartbeat :-) (RC) */
221 #define CSR0_BABL 0x4000 /* babble: tx-ed too many bits (RC) */
222 #define CSR0_ERR 0x8000 /* error (RC) */
225 #define CSR3_BCON 0x0001 /* byte control */
226 #define CSR3_ACON 0x0002 /* ALE control */
227 #define CSR3_BSWP 0x0004 /* byte swap (1=big endian) */
229 /***************************** Prototypes *****************************/
231 static int lance_probe( struct net_device
*dev
);
232 static int lance_open( struct net_device
*dev
);
233 static void lance_init_ring( struct net_device
*dev
);
234 static int lance_start_xmit( struct sk_buff
*skb
, struct net_device
*dev
);
235 static void lance_interrupt( int irq
, void *dev_id
, struct pt_regs
*fp
);
236 static int lance_rx( struct net_device
*dev
);
237 static int lance_close( struct net_device
*dev
);
238 static struct net_device_stats
*lance_get_stats( struct net_device
*dev
);
239 static void set_multicast_list( struct net_device
*dev
);
241 /************************* End of Prototypes **************************/
243 int __init
sun3lance_probe( struct net_device
*dev
)
245 static int found
= 0;
250 if (lance_probe(dev
)) {
258 static int __init
lance_probe( struct net_device
*dev
)
260 unsigned long ioaddr
, iopte
;
262 struct lance_private
*lp
;
264 static int did_version
= 0;
267 /* LANCE_OBIO can be found within the IO pmeg with some effort */
268 for(ioaddr
= 0xfe00000; ioaddr
< (0xfe00000 +
269 SUN3_PMEG_SIZE
); ioaddr
+= SUN3_PTE_SIZE
) {
271 iopte
= sun3_get_pte(ioaddr
);
272 if(!(iopte
& SUN3_PAGE_TYPE_IO
)) /* this an io page? */
275 if(((iopte
& SUN3_PAGE_PGNUM_MASK
) << PAGE_SHIFT
) ==
285 init_etherdev( dev
, sizeof(struct lance_private
) );
287 dev
->priv
= kmalloc( sizeof(struct lance_private
), GFP_KERNEL
);
288 lp
= (struct lance_private
*)dev
->priv
;
289 MEM
= (struct lance_memory
*)sun3_dvma_malloc(sizeof(struct
291 lp
->iobase
= (volatile unsigned short *)ioaddr
;
292 dev
->base_addr
= (unsigned long)ioaddr
; /* informational only */
294 REGA(CSR0
) = CSR0_STOP
;
296 request_irq(LANCE_IRQ
, lance_interrupt
, 0, "SUN3 Lance", dev
);
297 dev
->irq
= (unsigned short)LANCE_IRQ
;
300 printk("%s: SUN3 Lance at io %#lx, mem %#lx, irq %d, hwaddr ",
302 (unsigned long)ioaddr
,
306 /* copy in the ethernet address from the prom */
307 for(i
= 0; i
< 6 ; i
++)
308 dev
->dev_addr
[i
] = idprom
->id_ethaddr
[i
];
310 /* tell the card it's ether address, bytes swapped */
311 MEM
->init
.hwaddr
[0] = dev
->dev_addr
[1];
312 MEM
->init
.hwaddr
[1] = dev
->dev_addr
[0];
313 MEM
->init
.hwaddr
[2] = dev
->dev_addr
[3];
314 MEM
->init
.hwaddr
[3] = dev
->dev_addr
[2];
315 MEM
->init
.hwaddr
[4] = dev
->dev_addr
[5];
316 MEM
->init
.hwaddr
[5] = dev
->dev_addr
[4];
318 for( i
= 0; i
< 6; ++i
)
319 printk( "%02x%s", dev
->dev_addr
[i
], (i
< 5) ? ":" : "\n" );
321 MEM
->init
.mode
= 0x0000;
322 MEM
->init
.filter
[0] = 0x00000000;
323 MEM
->init
.filter
[1] = 0x00000000;
324 MEM
->init
.rdra
= sun3_dvma_vtop(MEM
->rx_head
);
325 MEM
->init
.rlen
= (RX_LOG_RING_SIZE
<< 13) |
326 (sun3_dvma_vtop(MEM
->rx_head
) >> 16);
327 MEM
->init
.tdra
= sun3_dvma_vtop(MEM
->tx_head
);
328 MEM
->init
.tlen
= (TX_LOG_RING_SIZE
<< 13) |
329 (sun3_dvma_vtop(MEM
->tx_head
) >> 16);
331 DPRINTK(2, ("initaddr: %08lx rx_ring: %08lx tx_ring: %08lx\n",
332 sun3_dvma_vtop(&(MEM
->init
)), sun3_dvma_vtop(MEM
->rx_head
),
333 (sun3_dvma_vtop(MEM
->tx_head
))));
336 if (did_version
++ == 0)
337 DPRINTK( 1, ( version
));
339 /* The LANCE-specific entries in the device structure. */
340 dev
->open
= &lance_open
;
341 dev
->hard_start_xmit
= &lance_start_xmit
;
342 dev
->stop
= &lance_close
;
343 dev
->get_stats
= &lance_get_stats
;
344 dev
->set_multicast_list
= &set_multicast_list
;
345 dev
->set_mac_address
= 0;
348 memset( &lp
->stats
, 0, sizeof(lp
->stats
) );
353 static int lance_open( struct net_device
*dev
)
355 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
;
358 DPRINTK( 2, ( "%s: lance_open()\n", dev
->name
));
360 REGA(CSR0
) = CSR0_STOP
;
362 /* tell the lance the address of its init block */
363 REGA(CSR1
) = sun3_dvma_vtop(&(MEM
->init
));
364 REGA(CSR2
) = sun3_dvma_vtop(&(MEM
->init
)) >> 16;
366 lance_init_ring(dev
);
368 /* Re-initialize the LANCE, and start it when done. */
370 REGA(CSR3
) = CSR3_BSWP
;
372 /* From now on, AREG is kept to point to CSR0 */
373 REGA(CSR0
) = CSR0_INIT
;
377 if (DREG
& CSR0_IDON
)
379 if (i
< 0 || (DREG
& CSR0_ERR
)) {
380 DPRINTK( 2, ( "lance_open(): opening %s failed, i=%d, csr0=%04x\n",
381 dev
->name
, i
, DREG
));
386 DREG
= CSR0_IDON
| CSR0_STRT
| CSR0_INEA
;
392 DPRINTK( 2, ( "%s: LANCE is open, csr0 %04x\n", dev
->name
, DREG
));
399 /* Initialize the LANCE Rx and Tx rings. */
401 static void lance_init_ring( struct net_device
*dev
)
403 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
;
408 lp
->new_rx
= lp
->new_tx
= 0;
409 lp
->old_rx
= lp
->old_tx
= 0;
411 for( i
= 0; i
< TX_RING_SIZE
; i
++ ) {
412 MEM
->tx_head
[i
].base
= sun3_dvma_vtop(MEM
->tx_data
[i
]);
413 MEM
->tx_head
[i
].flag
= 0;
414 MEM
->tx_head
[i
].base_hi
=
415 (sun3_dvma_vtop(MEM
->tx_data
[i
])) >>16;
416 MEM
->tx_head
[i
].length
= 0;
417 MEM
->tx_head
[i
].misc
= 0;
420 for( i
= 0; i
< RX_RING_SIZE
; i
++ ) {
421 MEM
->rx_head
[i
].base
= sun3_dvma_vtop(MEM
->rx_data
[i
]);
422 MEM
->rx_head
[i
].flag
= TMD1_OWN_CHIP
;
423 MEM
->rx_head
[i
].base_hi
=
424 (sun3_dvma_vtop(MEM
->rx_data
[i
])) >> 16;
425 MEM
->rx_head
[i
].buf_length
= -PKT_BUF_SZ
| 0xf000;
426 MEM
->rx_head
[i
].msg_length
= 0;
432 static int lance_start_xmit( struct sk_buff
*skb
, struct net_device
*dev
)
434 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
;
436 struct lance_tx_head
*head
;
439 /* Transmitter timeout, serious problems. */
441 int tickssofar
= jiffies
- dev
->trans_start
;
445 DPRINTK( 1, ( "%s: transmit timed out, status %04x, resetting.\n",
449 * Always set BSWP after a STOP as STOP puts it back into
450 * little endian mode.
452 REGA(CSR3
) = CSR3_BSWP
;
453 lp
->stats
.tx_errors
++;
455 if(lance_debug
>= 2) {
457 printk("Ring data: old_tx %d new_tx %d%s new_rx %d\n",
458 lp
->old_tx
, lp
->new_tx
,
459 lp
->tx_full
? " (full)" : "",
461 for( i
= 0 ; i
< RX_RING_SIZE
; i
++ )
462 printk( "rx #%d: base=%04x blen=%04x mlen=%04x\n",
463 i
, MEM
->rx_head
[i
].base
,
464 -MEM
->rx_head
[i
].buf_length
,
465 MEM
->rx_head
[i
].msg_length
);
466 for( i
= 0 ; i
< TX_RING_SIZE
; i
++ )
467 printk("tx #%d: base=%04x len=%04x misc=%04x\n",
468 i
, MEM
->tx_head
[i
].base
,
469 -MEM
->tx_head
[i
].length
,
470 MEM
->tx_head
[i
].misc
);
473 lance_init_ring(dev
);
474 REGA( CSR0
) = CSR0_INEA
| CSR0_INIT
| CSR0_STRT
;
477 dev
->trans_start
= jiffies
;
483 // DPRINTK( 2, ( "%s: lance_start_xmit() called, csr0 %4.4x.\n",
484 // dev->name, DREG ));
486 /* Block a timer-based transmit from overlapping. This could better be
487 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
488 if (test_and_set_bit( 0, (void*)&dev
->tbusy
) != 0) {
489 printk("%s: Transmitter access conflict.\n", dev
->name
);
493 if (test_and_set_bit( 0, (void*)&lp
->lock
) != 0) {
494 printk( "%s: tx queue lock!.\n", dev
->name
);
495 /* don't clear dev->tbusy flag. */
499 /* Fill in a Tx ring entry */
501 if (lance_debug
>= 3) {
504 printk( "%s: TX pkt %d type 0x%04x from ", dev
->name
,
505 lp
->new_tx
, ((u_short
*)skb
->data
)[6]);
506 for( p
= &((u_char
*)skb
->data
)[6], i
= 0; i
< 6; i
++ )
507 printk("%02x%s", *p
++, i
!= 5 ? ":" : "" );
509 for( p
= (u_char
*)skb
->data
, i
= 0; i
< 6; i
++ )
510 printk("%02x%s", *p
++, i
!= 5 ? ":" : "" );
511 printk(" data at 0x%08x len %d\n", (int)skb
->data
,
515 /* We're not prepared for the int until the last flags are set/reset.
516 * And the int may happen already after setting the OWN_CHIP... */
519 /* Mask to ring buffer boundary. */
521 head
= &(MEM
->tx_head
[entry
]);
523 /* Caution: the write order is important here, set the "ownership" bits
527 /* the sun3's lance needs it's buffer padded to the minimum
529 len
= (ETH_ZLEN
< skb
->len
) ? skb
->len
: ETH_ZLEN
;
531 // head->length = -len;
532 head
->length
= (-len
) | 0xf000;
535 memcpy( PKTBUF_ADDR(head
), (void *)skb
->data
, skb
->len
);
536 head
->flag
= TMD1_OWN_CHIP
| TMD1_ENP
| TMD1_STP
;
537 lp
->new_tx
= (lp
->new_tx
+ 1) & TX_RING_MOD_MASK
;
538 lp
->stats
.tx_bytes
+= skb
->len
;
540 /* Trigger an immediate send poll. */
541 REGA(CSR0
) = CSR0_INEA
| CSR0_TDMD
;
542 dev
->trans_start
= jiffies
;
543 dev_kfree_skb( skb
);
546 if ((MEM
->tx_head
[(entry
+1) & TX_RING_MOD_MASK
].flag
& TMD1_OWN
) ==
550 restore_flags(flags
);
555 /* The LANCE interrupt handler. */
557 static void lance_interrupt( int irq
, void *dev_id
, struct pt_regs
*fp
)
559 struct net_device
*dev
= dev_id
;
560 struct lance_private
*lp
= dev
->priv
;
564 DPRINTK( 1, ( "lance_interrupt(): invalid dev_id\n" ));
569 DPRINTK( 2, ( "%s: Re-entering the interrupt handler.\n", dev
->name
));
578 DREG
= csr0
& (CSR0_TINT
| CSR0_RINT
);
582 DREG
= CSR0_BABL
| CSR0_MERR
| CSR0_CERR
| CSR0_MISS
;
585 DPRINTK( 2, ( "%s: interrupt csr0=%04x new csr=%04x.\n",
586 dev
->name
, csr0
, DREG
));
588 if (csr0
& CSR0_TINT
) { /* Tx-done interrupt */
589 int old_tx
= lp
->old_tx
;
591 // if(lance_debug >= 3) {
594 // printk("%s: tx int\n", dev->name);
596 // for(i = 0; i < TX_RING_SIZE; i++)
597 // printk("ring %d flag=%04x\n", i,
598 // MEM->tx_head[i].flag);
601 while( old_tx
!= lp
->new_tx
) {
602 struct lance_tx_head
*head
= &(MEM
->tx_head
[old_tx
]);
604 DPRINTK(3, ("on tx_ring %d\n", old_tx
));
606 if (head
->flag
& TMD1_OWN_CHIP
)
607 break; /* It still hasn't been Txed */
609 if (head
->flag
& TMD1_ERR
) {
610 int status
= head
->misc
;
611 lp
->stats
.tx_errors
++;
612 if (status
& TMD3_RTRY
) lp
->stats
.tx_aborted_errors
++;
613 if (status
& TMD3_LCAR
) lp
->stats
.tx_carrier_errors
++;
614 if (status
& TMD3_LCOL
) lp
->stats
.tx_window_errors
++;
615 if (status
& (TMD3_UFLO
| TMD3_BUFF
)) {
616 lp
->stats
.tx_fifo_errors
++;
617 printk("%s: Tx FIFO error\n",
619 REGA(CSR0
) = CSR0_STOP
;
620 REGA(CSR3
) = CSR3_BSWP
;
621 lance_init_ring(dev
);
622 REGA(CSR0
) = CSR0_STRT
| CSR0_INEA
;
625 } else if(head
->flag
& (TMD1_ENP
| TMD1_STP
)) {
627 head
->flag
&= ~(TMD1_ENP
| TMD1_STP
);
628 if(head
->flag
& (TMD1_ONE
| TMD1_MORE
))
629 lp
->stats
.collisions
++;
631 lp
->stats
.tx_packets
++;
632 DPRINTK(3, ("cleared tx ring %d\n", old_tx
));
634 old_tx
= (old_tx
+1) & TX_RING_MOD_MASK
;
642 /* The ring is no longer full, clear tbusy. */
647 if (csr0
& CSR0_RINT
) /* Rx interrupt */
650 /* Log misc errors. */
651 if (csr0
& CSR0_BABL
) lp
->stats
.tx_errors
++; /* Tx babble. */
652 if (csr0
& CSR0_MISS
) lp
->stats
.rx_errors
++; /* Missed a Rx frame. */
653 if (csr0
& CSR0_MERR
) {
654 DPRINTK( 1, ( "%s: Bus master arbitration failure (?!?), "
655 "status %04x.\n", dev
->name
, csr0
));
656 /* Restart the chip. */
657 REGA(CSR0
) = CSR0_STOP
;
658 REGA(CSR3
) = CSR3_BSWP
;
659 lance_init_ring(dev
);
660 REGA(CSR0
) = CSR0_STRT
| CSR0_INEA
;
664 /* Clear any other interrupt, and set interrupt enable. */
665 // DREG = CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR |
666 // CSR0_IDON | CSR0_INEA;
668 REGA(CSR0
) = CSR0_INEA
;
670 if(DREG
& (CSR0_RINT
| CSR0_TINT
)) {
671 DPRINTK(2, ("restarting interrupt, csr0=%#04x\n", DREG
));
675 DPRINTK( 2, ( "%s: exiting interrupt, csr0=%#04x.\n",
681 /* get packet, toss into skbuff */
682 static int lance_rx( struct net_device
*dev
)
684 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
;
685 int entry
= lp
->new_rx
;
687 /* If we own the next entry, it's a new packet. Send it up. */
688 while( (MEM
->rx_head
[entry
].flag
& RMD1_OWN
) == RMD1_OWN_HOST
) {
689 struct lance_rx_head
*head
= &(MEM
->rx_head
[entry
]);
690 int status
= head
->flag
;
692 if (status
!= (RMD1_ENP
|RMD1_STP
)) { /* There was an error. */
693 /* There is a tricky error noted by John Murphy,
694 <murf@perftech.com> to Russ Nelson: Even with
695 full-sized buffers it's possible for a jabber packet to use two
696 buffers, with only the last correctly noting the error. */
697 if (status
& RMD1_ENP
) /* Only count a general error at the */
698 lp
->stats
.rx_errors
++; /* end of a packet.*/
699 if (status
& RMD1_FRAM
) lp
->stats
.rx_frame_errors
++;
700 if (status
& RMD1_OFLO
) lp
->stats
.rx_over_errors
++;
701 if (status
& RMD1_CRC
) lp
->stats
.rx_crc_errors
++;
702 if (status
& RMD1_BUFF
) lp
->stats
.rx_fifo_errors
++;
703 head
->flag
&= (RMD1_ENP
|RMD1_STP
);
705 /* Malloc up new buffer, compatible with net-3. */
706 // short pkt_len = head->msg_length;// & 0xfff;
707 short pkt_len
= (head
->msg_length
& 0xfff) - 4;
711 printk( "%s: Runt packet!\n", dev
->name
);
712 lp
->stats
.rx_errors
++;
715 skb
= dev_alloc_skb( pkt_len
+2 );
717 DPRINTK( 1, ( "%s: Memory squeeze, deferring packet.\n",
720 lp
->stats
.rx_dropped
++;
721 head
->msg_length
= 0;
722 head
->flag
|= RMD1_OWN_CHIP
;
723 lp
->new_rx
= (lp
->new_rx
+1) &
728 if (lance_debug
>= 3) {
729 u_char
*data
= PKTBUF_ADDR(head
), *p
;
730 printk( "%s: RX pkt %d type 0x%04x from ", dev
->name
, entry
, ((u_short
*)data
)[6]);
731 for( p
= &data
[6], i
= 0; i
< 6; i
++ )
732 printk("%02x%s", *p
++, i
!= 5 ? ":" : "" );
734 for( p
= data
, i
= 0; i
< 6; i
++ )
735 printk("%02x%s", *p
++, i
!= 5 ? ":" : "" );
736 printk(" data %02x %02x %02x %02x %02x %02x %02x %02x "
738 data
[15], data
[16], data
[17], data
[18],
739 data
[19], data
[20], data
[21], data
[22],
743 if (lance_debug
>= 3) {
744 u_char
*data
= PKTBUF_ADDR(head
);
745 printk( "%s: RX pkt %d type 0x%04x len %d\n ", dev
->name
, entry
, ((u_short
*)data
)[6], pkt_len
);
750 skb_reserve( skb
, 2 ); /* 16 byte align */
751 skb_put( skb
, pkt_len
); /* Make room */
752 // memcpy( skb->data, PKTBUF_ADDR(head), pkt_len );
753 eth_copy_and_sum(skb
,
757 skb
->protocol
= eth_type_trans( skb
, dev
);
759 lp
->stats
.rx_packets
++;
760 lp
->stats
.rx_bytes
+= skb
->len
;
764 // head->buf_length = -PKT_BUF_SZ | 0xf000;
765 head
->msg_length
= 0;
766 head
->flag
= RMD1_OWN_CHIP
;
768 entry
= lp
->new_rx
= (lp
->new_rx
+1) & RX_RING_MOD_MASK
;
771 /* From lance.c (Donald Becker): */
772 /* We should check that at least two ring entries are free.
773 If not, we should free one and mark stats->rx_dropped++. */
779 static int lance_close( struct net_device
*dev
)
781 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
;
788 DPRINTK( 2, ( "%s: Shutting down ethercard, status was %2.2x.\n",
791 /* We stop the LANCE here -- it occasionally polls
792 memory if we don't. */
800 static struct net_device_stats
*lance_get_stats( struct net_device
*dev
)
802 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
;
808 /* Set or clear the multicast filter for this adaptor.
809 num_addrs == -1 Promiscuous mode, receive all packets
810 num_addrs == 0 Normal mode, clear multicast list
811 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
812 best-effort filtering.
815 /* completely untested on a sun3 */
816 static void set_multicast_list( struct net_device
*dev
)
818 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
;
821 /* Only possible if board is already started */
824 /* We take the simple way out and always enable promiscuous mode. */
825 DREG
= CSR0_STOP
; /* Temporarily stop the lance. */
827 if (dev
->flags
& IFF_PROMISC
) {
828 /* Log any net taps. */
829 DPRINTK( 1, ( "%s: Promiscuous mode enabled.\n", dev
->name
));
830 REGA( CSR15
) = 0x8000; /* Set promiscuous mode */
832 short multicast_table
[4];
833 int num_addrs
= dev
->mc_count
;
835 /* We don't use the multicast table, but rely on upper-layer
837 memset( multicast_table
, (num_addrs
== 0) ? 0 : -1,
838 sizeof(multicast_table
) );
839 for( i
= 0; i
< 4; i
++ )
840 REGA( CSR8
+i
) = multicast_table
[i
];
841 REGA( CSR15
) = 0; /* Unset promiscuous mode */
845 * Always set BSWP after a STOP as STOP puts it back into
846 * little endian mode.
848 REGA( CSR3
) = CSR3_BSWP
;
850 /* Resume normal operation and reset AREG to CSR0 */
851 REGA( CSR0
) = CSR0_IDON
| CSR0_INEA
| CSR0_STRT
;
856 static char devicename
[9] = { 0, };
858 static struct net_device sun3lance_dev
=
860 devicename
, /* filled in by register_netdev() */
861 0, 0, 0, 0, /* memory */
862 0, 0, /* base, irq */
863 0, 0, 0, NULL
, sun3lance_probe
,
866 int init_module(void)
870 if ((err
= register_netdev( &sun3lance_dev
))) {
872 printk( "SUN3 Lance not detected. Module not loaded.\n");
879 void cleanup_module(void)
881 unregister_netdev( &sun3lance_dev
);