1 /* $Id: sunlance.c,v 1.112 2002/01/15 06:48:55 davem Exp $
2 * lance.c: Linux/Sparc/Lance driver
4 * Written 1995, 1996 by Miguel de Icaza
6 * The Linux depca driver
7 * The Linux lance driver.
8 * The Linux skeleton driver.
9 * The NetBSD Sparc/Lance driver.
10 * Theo de Raadt (deraadt@openbsd.org)
11 * NCR92C990 Lan Controller manual
14 * Added support to run with a ledma on the Sun4m
17 * Added multiple card detection.
19 * 4/17/96: Burst sizes and tpe selection on sun4m by Eddie C. Dost
22 * 5/15/96: auto carrier detection on sun4m by Eddie C. Dost
25 * 5/17/96: lebuffer on scsi/ether cards now work David S. Miller
26 * (davem@caip.rutgers.edu)
28 * 5/29/96: override option 'tpe-link-test?', if it is 'false', as
29 * this disables auto carrier detection on sun4m. Eddie C. Dost
33 * 6/26/96: Bug fix for multiple ledmas, miguel.
36 * Stole multicast code from depca.c, fixed lance_tx.
39 * 8/21/96: Fixed the multicast code (Pedro Roque)
41 * 8/28/96: Send fake packet in lance_open() if auto_select is true,
42 * so we can detect the carrier loss condition in time.
43 * Eddie C. Dost (ecd@skynet.be)
45 * 9/15/96: Align rx_buf so that eth_copy_and_sum() won't cause an
46 * MNA trap during chksum_partial_copy(). (ecd@skynet.be)
48 * 11/17/96: Handle LE_C0_MERR in lance_interrupt(). (ecd@skynet.be)
50 * 12/22/96: Don't loop forever in lance_rx() on incomplete packets.
51 * This was the sun4c killer. Shit, stupid bug.
55 * 1/26/97: Modularize driver. (ecd@skynet.be)
58 * 12/27/97: Added sun4d support. (jj@sunsite.mff.cuni.cz)
61 * 11/3/99: Fixed SMP race in lance_start_xmit found by davem.
62 * Anton Blanchard (anton@progsoc.uts.edu.au)
63 * 2.00: 11/9/99: Massive overhaul and port to new SBUS driver interfaces.
64 * David S. Miller (davem@redhat.com)
66 * 11/08/01: Use library crc32 functions (Matt_Domsch@dell.com)
72 static char version
[] =
73 "sunlance.c:v2.01 08/Nov/01 Miguel de Icaza (miguel@nuclecu.unam.mx)\n";
75 static char lancestr
[] = "LANCE";
77 #include <linux/config.h>
78 #include <linux/module.h>
79 #include <linux/kernel.h>
80 #include <linux/types.h>
81 #include <linux/fcntl.h>
82 #include <linux/interrupt.h>
83 #include <linux/ioport.h>
85 #include <linux/slab.h>
86 #include <linux/string.h>
87 #include <linux/delay.h>
88 #include <linux/init.h>
89 #include <linux/crc32.h>
90 #include <linux/errno.h>
91 #include <linux/socket.h> /* Used for the temporal inet entries and routing */
92 #include <linux/route.h>
93 #include <linux/netdevice.h>
94 #include <linux/etherdevice.h>
95 #include <linux/skbuff.h>
97 #include <asm/system.h>
98 #include <asm/bitops.h>
101 #include <asm/pgtable.h>
102 #include <asm/byteorder.h> /* Used by the checksum routines */
103 #include <asm/idprom.h>
104 #include <asm/sbus.h>
105 #include <asm/openprom.h>
106 #include <asm/oplib.h>
107 #include <asm/auxio.h> /* For tpe-link-test? setting */
110 /* Define: 2^4 Tx buffers and 2^4 Rx buffers */
111 #ifndef LANCE_LOG_TX_BUFFERS
112 #define LANCE_LOG_TX_BUFFERS 4
113 #define LANCE_LOG_RX_BUFFERS 4
121 #define LE_MO_PROM 0x8000 /* Enable promiscuous mode */
123 #define LE_C0_ERR 0x8000 /* Error: set if BAB, SQE, MISS or ME is set */
124 #define LE_C0_BABL 0x4000 /* BAB: Babble: tx timeout. */
125 #define LE_C0_CERR 0x2000 /* SQE: Signal quality error */
126 #define LE_C0_MISS 0x1000 /* MISS: Missed a packet */
127 #define LE_C0_MERR 0x0800 /* ME: Memory error */
128 #define LE_C0_RINT 0x0400 /* Received interrupt */
129 #define LE_C0_TINT 0x0200 /* Transmitter Interrupt */
130 #define LE_C0_IDON 0x0100 /* IFIN: Init finished. */
131 #define LE_C0_INTR 0x0080 /* Interrupt or error */
132 #define LE_C0_INEA 0x0040 /* Interrupt enable */
133 #define LE_C0_RXON 0x0020 /* Receiver on */
134 #define LE_C0_TXON 0x0010 /* Transmitter on */
135 #define LE_C0_TDMD 0x0008 /* Transmitter demand */
136 #define LE_C0_STOP 0x0004 /* Stop the card */
137 #define LE_C0_STRT 0x0002 /* Start the card */
138 #define LE_C0_INIT 0x0001 /* Init the card */
140 #define LE_C3_BSWP 0x4 /* SWAP */
141 #define LE_C3_ACON 0x2 /* ALE Control */
142 #define LE_C3_BCON 0x1 /* Byte control */
144 /* Receive message descriptor 1 */
145 #define LE_R1_OWN 0x80 /* Who owns the entry */
146 #define LE_R1_ERR 0x40 /* Error: if FRA, OFL, CRC or BUF is set */
147 #define LE_R1_FRA 0x20 /* FRA: Frame error */
148 #define LE_R1_OFL 0x10 /* OFL: Frame overflow */
149 #define LE_R1_CRC 0x08 /* CRC error */
150 #define LE_R1_BUF 0x04 /* BUF: Buffer error */
151 #define LE_R1_SOP 0x02 /* Start of packet */
152 #define LE_R1_EOP 0x01 /* End of packet */
153 #define LE_R1_POK 0x03 /* Packet is complete: SOP + EOP */
155 #define LE_T1_OWN 0x80 /* Lance owns the packet */
156 #define LE_T1_ERR 0x40 /* Error summary */
157 #define LE_T1_EMORE 0x10 /* Error: more than one retry needed */
158 #define LE_T1_EONE 0x08 /* Error: one retry needed */
159 #define LE_T1_EDEF 0x04 /* Error: deferred */
160 #define LE_T1_SOP 0x02 /* Start of packet */
161 #define LE_T1_EOP 0x01 /* End of packet */
162 #define LE_T1_POK 0x03 /* Packet is complete: SOP + EOP */
164 #define LE_T3_BUF 0x8000 /* Buffer error */
165 #define LE_T3_UFL 0x4000 /* Error underflow */
166 #define LE_T3_LCOL 0x1000 /* Error late collision */
167 #define LE_T3_CLOS 0x0800 /* Error carrier loss */
168 #define LE_T3_RTY 0x0400 /* Error retry */
169 #define LE_T3_TDR 0x03ff /* Time Domain Reflectometry counter */
171 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
172 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
173 #define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29)
174 #define TX_NEXT(__x) (((__x)+1) & TX_RING_MOD_MASK)
176 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
177 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
178 #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29)
179 #define RX_NEXT(__x) (((__x)+1) & RX_RING_MOD_MASK)
181 #define PKT_BUF_SZ 1544
182 #define RX_BUFF_SIZE PKT_BUF_SZ
183 #define TX_BUFF_SIZE PKT_BUF_SZ
185 struct lance_rx_desc
{
186 u16 rmd0
; /* low address of packet */
187 u8 rmd1_bits
; /* descriptor bits */
188 u8 rmd1_hadr
; /* high address of packet */
189 s16 length
; /* This length is 2s complement (negative)!
192 u16 mblength
; /* This is the actual number of bytes received */
195 struct lance_tx_desc
{
196 u16 tmd0
; /* low address of packet */
197 u8 tmd1_bits
; /* descriptor bits */
198 u8 tmd1_hadr
; /* high address of packet */
199 s16 length
; /* Length is 2s complement (negative)! */
203 /* The LANCE initialization block, described in databook. */
204 /* On the Sparc, this block should be on a DMA region */
205 struct lance_init_block
{
206 u16 mode
; /* Pre-set mode (reg. 15) */
207 u8 phys_addr
[6]; /* Physical ethernet address */
208 u32 filter
[2]; /* Multicast filter. */
210 /* Receive and transmit ring base, along with extra bits. */
211 u16 rx_ptr
; /* receive descriptor addr */
212 u16 rx_len
; /* receive len and high addr */
213 u16 tx_ptr
; /* transmit descriptor addr */
214 u16 tx_len
; /* transmit len and high addr */
216 /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
217 struct lance_rx_desc brx_ring
[RX_RING_SIZE
];
218 struct lance_tx_desc btx_ring
[TX_RING_SIZE
];
220 u8 tx_buf
[TX_RING_SIZE
][TX_BUFF_SIZE
];
221 u8 pad
[2]; /* align rx_buf for copy_and_sum(). */
222 u8 rx_buf
[RX_RING_SIZE
][RX_BUFF_SIZE
];
225 #define libdesc_offset(rt, elem) \
226 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem])))))
228 #define libbuff_offset(rt, elem) \
229 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem][0])))))
231 struct lance_private
{
232 unsigned long lregs
; /* Lance RAP/RDP regs. */
233 unsigned long dregs
; /* DMA controller regs. */
234 volatile struct lance_init_block
*init_block
;
241 struct net_device_stats stats
;
242 struct sbus_dma
*ledma
; /* If set this points to ledma */
243 char tpe
; /* cable-selection is TPE */
244 char auto_select
; /* cable-selection by carrier */
245 char burst_sizes
; /* ledma SBus burst sizes */
246 char pio_buffer
; /* init block in PIO space? */
248 unsigned short busmaster_regval
;
250 void (*init_ring
)(struct net_device
*);
251 void (*rx
)(struct net_device
*);
252 void (*tx
)(struct net_device
*);
255 dma_addr_t init_block_dvma
;
256 struct net_device
*dev
; /* Backpointer */
257 struct lance_private
*next_module
;
258 struct sbus_dev
*sdev
;
259 struct timer_list multicast_timer
;
262 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
263 lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\
264 lp->tx_old - lp->tx_new-1)
266 /* Lance registers. */
267 #define RDP 0x00UL /* register data port */
268 #define RAP 0x02UL /* register address port */
269 #define LANCE_REG_SIZE 0x04UL
271 #define STOP_LANCE(__lp) \
272 do { unsigned long __base = (__lp)->lregs; \
273 sbus_writew(LE_CSR0, __base + RAP); \
274 sbus_writew(LE_C0_STOP, __base + RDP); \
277 int sparc_lance_debug
= 2;
279 /* The Lance uses 24 bit addresses */
280 /* On the Sun4c the DVMA will provide the remaining bytes for us */
281 /* On the Sun4m we have to instruct the ledma to provide them */
282 /* Even worse, on scsi/ether SBUS cards, the init block and the
283 * transmit/receive buffers are addresses as offsets from absolute
284 * zero on the lebuffer PIO area. -DaveM
287 #define LANCE_ADDR(x) ((long)(x) & ~0xff000000)
289 static struct lance_private
*root_lance_dev
;
291 /* Load the CSR registers */
292 static void load_csrs(struct lance_private
*lp
)
299 leptr
= LANCE_ADDR(lp
->init_block_dvma
);
301 sbus_writew(LE_CSR1
, lp
->lregs
+ RAP
);
302 sbus_writew(leptr
& 0xffff, lp
->lregs
+ RDP
);
303 sbus_writew(LE_CSR2
, lp
->lregs
+ RAP
);
304 sbus_writew(leptr
>> 16, lp
->lregs
+ RDP
);
305 sbus_writew(LE_CSR3
, lp
->lregs
+ RAP
);
306 sbus_writew(lp
->busmaster_regval
, lp
->lregs
+ RDP
);
308 /* Point back to csr0 */
309 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
312 /* Setup the Lance Rx and Tx rings */
313 static void lance_init_ring_dvma(struct net_device
*dev
)
315 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
316 volatile struct lance_init_block
*ib
= lp
->init_block
;
317 dma_addr_t aib
= lp
->init_block_dvma
;
321 /* Lock out other processes while setting up hardware */
322 netif_stop_queue(dev
);
323 lp
->rx_new
= lp
->tx_new
= 0;
324 lp
->rx_old
= lp
->tx_old
= 0;
326 /* Copy the ethernet address to the lance init block
327 * Note that on the sparc you need to swap the ethernet address.
329 ib
->phys_addr
[0] = dev
->dev_addr
[1];
330 ib
->phys_addr
[1] = dev
->dev_addr
[0];
331 ib
->phys_addr
[2] = dev
->dev_addr
[3];
332 ib
->phys_addr
[3] = dev
->dev_addr
[2];
333 ib
->phys_addr
[4] = dev
->dev_addr
[5];
334 ib
->phys_addr
[5] = dev
->dev_addr
[4];
336 /* Setup the Tx ring entries */
337 for (i
= 0; i
<= TX_RING_SIZE
; i
++) {
338 leptr
= LANCE_ADDR(aib
+ libbuff_offset(tx_buf
, i
));
339 ib
->btx_ring
[i
].tmd0
= leptr
;
340 ib
->btx_ring
[i
].tmd1_hadr
= leptr
>> 16;
341 ib
->btx_ring
[i
].tmd1_bits
= 0;
342 ib
->btx_ring
[i
].length
= 0xf000; /* The ones required by tmd2 */
343 ib
->btx_ring
[i
].misc
= 0;
346 /* Setup the Rx ring entries */
347 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
348 leptr
= LANCE_ADDR(aib
+ libbuff_offset(rx_buf
, i
));
350 ib
->brx_ring
[i
].rmd0
= leptr
;
351 ib
->brx_ring
[i
].rmd1_hadr
= leptr
>> 16;
352 ib
->brx_ring
[i
].rmd1_bits
= LE_R1_OWN
;
353 ib
->brx_ring
[i
].length
= -RX_BUFF_SIZE
| 0xf000;
354 ib
->brx_ring
[i
].mblength
= 0;
357 /* Setup the initialization block */
359 /* Setup rx descriptor pointer */
360 leptr
= LANCE_ADDR(aib
+ libdesc_offset(brx_ring
, 0));
361 ib
->rx_len
= (LANCE_LOG_RX_BUFFERS
<< 13) | (leptr
>> 16);
364 /* Setup tx descriptor pointer */
365 leptr
= LANCE_ADDR(aib
+ libdesc_offset(btx_ring
, 0));
366 ib
->tx_len
= (LANCE_LOG_TX_BUFFERS
<< 13) | (leptr
>> 16);
370 static void lance_init_ring_pio(struct net_device
*dev
)
372 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
373 volatile struct lance_init_block
*ib
= lp
->init_block
;
377 /* Lock out other processes while setting up hardware */
378 netif_stop_queue(dev
);
379 lp
->rx_new
= lp
->tx_new
= 0;
380 lp
->rx_old
= lp
->tx_old
= 0;
382 /* Copy the ethernet address to the lance init block
383 * Note that on the sparc you need to swap the ethernet address.
385 sbus_writeb(dev
->dev_addr
[1], &ib
->phys_addr
[0]);
386 sbus_writeb(dev
->dev_addr
[0], &ib
->phys_addr
[1]);
387 sbus_writeb(dev
->dev_addr
[3], &ib
->phys_addr
[2]);
388 sbus_writeb(dev
->dev_addr
[2], &ib
->phys_addr
[3]);
389 sbus_writeb(dev
->dev_addr
[5], &ib
->phys_addr
[4]);
390 sbus_writeb(dev
->dev_addr
[4], &ib
->phys_addr
[5]);
392 /* Setup the Tx ring entries */
393 for (i
= 0; i
<= TX_RING_SIZE
; i
++) {
394 leptr
= libbuff_offset(tx_buf
, i
);
395 sbus_writew(leptr
, &ib
->btx_ring
[i
].tmd0
);
396 sbus_writeb(leptr
>> 16,&ib
->btx_ring
[i
].tmd1_hadr
);
397 sbus_writeb(0, &ib
->btx_ring
[i
].tmd1_bits
);
399 /* The ones required by tmd2 */
400 sbus_writew(0xf000, &ib
->btx_ring
[i
].length
);
401 sbus_writew(0, &ib
->btx_ring
[i
].misc
);
404 /* Setup the Rx ring entries */
405 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
406 leptr
= libbuff_offset(rx_buf
, i
);
408 sbus_writew(leptr
, &ib
->brx_ring
[i
].rmd0
);
409 sbus_writeb(leptr
>> 16,&ib
->brx_ring
[i
].rmd1_hadr
);
410 sbus_writeb(LE_R1_OWN
, &ib
->brx_ring
[i
].rmd1_bits
);
411 sbus_writew(-RX_BUFF_SIZE
|0xf000,
412 &ib
->brx_ring
[i
].length
);
413 sbus_writew(0, &ib
->brx_ring
[i
].mblength
);
416 /* Setup the initialization block */
418 /* Setup rx descriptor pointer */
419 leptr
= libdesc_offset(brx_ring
, 0);
420 sbus_writew((LANCE_LOG_RX_BUFFERS
<< 13) | (leptr
>> 16),
422 sbus_writew(leptr
, &ib
->rx_ptr
);
424 /* Setup tx descriptor pointer */
425 leptr
= libdesc_offset(btx_ring
, 0);
426 sbus_writew((LANCE_LOG_TX_BUFFERS
<< 13) | (leptr
>> 16),
428 sbus_writew(leptr
, &ib
->tx_ptr
);
431 static void init_restart_ledma(struct lance_private
*lp
)
433 u32 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
435 if (!(csr
& DMA_HNDL_ERROR
)) {
436 /* E-Cache draining */
437 while (sbus_readl(lp
->dregs
+ DMA_CSR
) & DMA_FIFO_ISDRAIN
)
441 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
442 csr
&= ~DMA_E_BURSTS
;
443 if (lp
->burst_sizes
& DMA_BURST32
)
444 csr
|= DMA_E_BURST32
;
446 csr
|= DMA_E_BURST16
;
448 csr
|= (DMA_DSBL_RD_DRN
| DMA_DSBL_WR_INV
| DMA_FIFO_INV
);
451 csr
|= DMA_EN_ENETAUI
;
453 csr
&= ~DMA_EN_ENETAUI
;
455 sbus_writel(csr
, lp
->dregs
+ DMA_CSR
);
459 static int init_restart_lance(struct lance_private
*lp
)
465 init_restart_ledma(lp
);
467 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
468 sbus_writew(LE_C0_INIT
, lp
->lregs
+ RDP
);
470 /* Wait for the lance to complete initialization */
471 for (i
= 0; i
< 100; i
++) {
472 regval
= sbus_readw(lp
->lregs
+ RDP
);
474 if (regval
& (LE_C0_ERR
| LE_C0_IDON
))
478 if (i
== 100 || (regval
& LE_C0_ERR
)) {
479 printk(KERN_ERR
"LANCE unopened after %d ticks, csr0=%4.4x.\n",
482 printk("dcsr=%8.8x\n", sbus_readl(lp
->dregs
+ DMA_CSR
));
486 /* Clear IDON by writing a "1", enable interrupts and start lance */
487 sbus_writew(LE_C0_IDON
, lp
->lregs
+ RDP
);
488 sbus_writew(LE_C0_INEA
| LE_C0_STRT
, lp
->lregs
+ RDP
);
491 u32 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
494 sbus_writel(csr
, lp
->dregs
+ DMA_CSR
);
500 static void lance_rx_dvma(struct net_device
*dev
)
502 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
503 volatile struct lance_init_block
*ib
= lp
->init_block
;
504 volatile struct lance_rx_desc
*rd
;
506 int len
, entry
= lp
->rx_new
;
509 for (rd
= &ib
->brx_ring
[entry
];
510 !((bits
= rd
->rmd1_bits
) & LE_R1_OWN
);
511 rd
= &ib
->brx_ring
[entry
]) {
513 /* We got an incomplete frame? */
514 if ((bits
& LE_R1_POK
) != LE_R1_POK
) {
515 lp
->stats
.rx_over_errors
++;
516 lp
->stats
.rx_errors
++;
517 } else if (bits
& LE_R1_ERR
) {
518 /* Count only the end frame as a rx error,
521 if (bits
& LE_R1_BUF
) lp
->stats
.rx_fifo_errors
++;
522 if (bits
& LE_R1_CRC
) lp
->stats
.rx_crc_errors
++;
523 if (bits
& LE_R1_OFL
) lp
->stats
.rx_over_errors
++;
524 if (bits
& LE_R1_FRA
) lp
->stats
.rx_frame_errors
++;
525 if (bits
& LE_R1_EOP
) lp
->stats
.rx_errors
++;
527 len
= (rd
->mblength
& 0xfff) - 4;
528 skb
= dev_alloc_skb(len
+ 2);
531 printk(KERN_INFO
"%s: Memory squeeze, deferring packet.\n",
533 lp
->stats
.rx_dropped
++;
535 rd
->rmd1_bits
= LE_R1_OWN
;
536 lp
->rx_new
= RX_NEXT(entry
);
540 lp
->stats
.rx_bytes
+= len
;
543 skb_reserve(skb
, 2); /* 16 byte align */
544 skb_put(skb
, len
); /* make room */
545 eth_copy_and_sum(skb
,
546 (unsigned char *)&(ib
->rx_buf
[entry
][0]),
548 skb
->protocol
= eth_type_trans(skb
, dev
);
550 dev
->last_rx
= jiffies
;
551 lp
->stats
.rx_packets
++;
554 /* Return the packet to the pool */
556 rd
->rmd1_bits
= LE_R1_OWN
;
557 entry
= RX_NEXT(entry
);
563 static void lance_tx_dvma(struct net_device
*dev
)
565 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
566 volatile struct lance_init_block
*ib
= lp
->init_block
;
569 spin_lock(&lp
->lock
);
572 for (i
= j
; i
!= lp
->tx_new
; i
= j
) {
573 volatile struct lance_tx_desc
*td
= &ib
->btx_ring
[i
];
574 u8 bits
= td
->tmd1_bits
;
576 /* If we hit a packet not owned by us, stop */
577 if (bits
& LE_T1_OWN
)
580 if (bits
& LE_T1_ERR
) {
581 u16 status
= td
->misc
;
583 lp
->stats
.tx_errors
++;
584 if (status
& LE_T3_RTY
) lp
->stats
.tx_aborted_errors
++;
585 if (status
& LE_T3_LCOL
) lp
->stats
.tx_window_errors
++;
587 if (status
& LE_T3_CLOS
) {
588 lp
->stats
.tx_carrier_errors
++;
589 if (lp
->auto_select
) {
590 lp
->tpe
= 1 - lp
->tpe
;
591 printk(KERN_NOTICE
"%s: Carrier Lost, trying %s\n",
592 dev
->name
, lp
->tpe
?"TPE":"AUI");
596 init_restart_lance(lp
);
601 /* Buffer errors and underflows turn off the
602 * transmitter, restart the adapter.
604 if (status
& (LE_T3_BUF
|LE_T3_UFL
)) {
605 lp
->stats
.tx_fifo_errors
++;
607 printk(KERN_ERR
"%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
612 init_restart_lance(lp
);
615 } else if ((bits
& LE_T1_POK
) == LE_T1_POK
) {
617 * So we don't count the packet more than once.
619 td
->tmd1_bits
= bits
& ~(LE_T1_POK
);
621 /* One collision before packet was sent. */
622 if (bits
& LE_T1_EONE
)
623 lp
->stats
.collisions
++;
625 /* More than one collision, be optimistic. */
626 if (bits
& LE_T1_EMORE
)
627 lp
->stats
.collisions
+= 2;
629 lp
->stats
.tx_packets
++;
636 if (netif_queue_stopped(dev
) &&
638 netif_wake_queue(dev
);
640 spin_unlock(&lp
->lock
);
643 static void lance_piocopy_to_skb(struct sk_buff
*skb
, volatile void *piobuf
, int len
)
645 u16
*p16
= (u16
*) skb
->data
;
648 unsigned long pbuf
= (unsigned long) piobuf
;
650 /* We know here that both src and dest are on a 16bit boundary. */
651 *p16
++ = sbus_readw(pbuf
);
657 *p32
++ = sbus_readl(pbuf
);
664 *p16
++ = sbus_readw(pbuf
);
670 *p8
= sbus_readb(pbuf
);
673 static void lance_rx_pio(struct net_device
*dev
)
675 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
676 volatile struct lance_init_block
*ib
= lp
->init_block
;
677 volatile struct lance_rx_desc
*rd
;
683 for (rd
= &ib
->brx_ring
[entry
];
684 !((bits
= sbus_readb(&rd
->rmd1_bits
)) & LE_R1_OWN
);
685 rd
= &ib
->brx_ring
[entry
]) {
687 /* We got an incomplete frame? */
688 if ((bits
& LE_R1_POK
) != LE_R1_POK
) {
689 lp
->stats
.rx_over_errors
++;
690 lp
->stats
.rx_errors
++;
691 } else if (bits
& LE_R1_ERR
) {
692 /* Count only the end frame as a rx error,
695 if (bits
& LE_R1_BUF
) lp
->stats
.rx_fifo_errors
++;
696 if (bits
& LE_R1_CRC
) lp
->stats
.rx_crc_errors
++;
697 if (bits
& LE_R1_OFL
) lp
->stats
.rx_over_errors
++;
698 if (bits
& LE_R1_FRA
) lp
->stats
.rx_frame_errors
++;
699 if (bits
& LE_R1_EOP
) lp
->stats
.rx_errors
++;
701 len
= (sbus_readw(&rd
->mblength
) & 0xfff) - 4;
702 skb
= dev_alloc_skb(len
+ 2);
705 printk(KERN_INFO
"%s: Memory squeeze, deferring packet.\n",
707 lp
->stats
.rx_dropped
++;
708 sbus_writew(0, &rd
->mblength
);
709 sbus_writeb(LE_R1_OWN
, &rd
->rmd1_bits
);
710 lp
->rx_new
= RX_NEXT(entry
);
714 lp
->stats
.rx_bytes
+= len
;
717 skb_reserve (skb
, 2); /* 16 byte align */
718 skb_put(skb
, len
); /* make room */
719 lance_piocopy_to_skb(skb
, &(ib
->rx_buf
[entry
][0]), len
);
720 skb
->protocol
= eth_type_trans(skb
, dev
);
722 dev
->last_rx
= jiffies
;
723 lp
->stats
.rx_packets
++;
726 /* Return the packet to the pool */
727 sbus_writew(0, &rd
->mblength
);
728 sbus_writeb(LE_R1_OWN
, &rd
->rmd1_bits
);
729 entry
= RX_NEXT(entry
);
735 static void lance_tx_pio(struct net_device
*dev
)
737 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
738 volatile struct lance_init_block
*ib
= lp
->init_block
;
741 spin_lock(&lp
->lock
);
744 for (i
= j
; i
!= lp
->tx_new
; i
= j
) {
745 volatile struct lance_tx_desc
*td
= &ib
->btx_ring
[i
];
746 u8 bits
= sbus_readb(&td
->tmd1_bits
);
748 /* If we hit a packet not owned by us, stop */
749 if (bits
& LE_T1_OWN
)
752 if (bits
& LE_T1_ERR
) {
753 u16 status
= sbus_readw(&td
->misc
);
755 lp
->stats
.tx_errors
++;
756 if (status
& LE_T3_RTY
) lp
->stats
.tx_aborted_errors
++;
757 if (status
& LE_T3_LCOL
) lp
->stats
.tx_window_errors
++;
759 if (status
& LE_T3_CLOS
) {
760 lp
->stats
.tx_carrier_errors
++;
761 if (lp
->auto_select
) {
762 lp
->tpe
= 1 - lp
->tpe
;
763 printk(KERN_NOTICE
"%s: Carrier Lost, trying %s\n",
764 dev
->name
, lp
->tpe
?"TPE":"AUI");
768 init_restart_lance(lp
);
773 /* Buffer errors and underflows turn off the
774 * transmitter, restart the adapter.
776 if (status
& (LE_T3_BUF
|LE_T3_UFL
)) {
777 lp
->stats
.tx_fifo_errors
++;
779 printk(KERN_ERR
"%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
784 init_restart_lance(lp
);
787 } else if ((bits
& LE_T1_POK
) == LE_T1_POK
) {
789 * So we don't count the packet more than once.
791 sbus_writeb(bits
& ~(LE_T1_POK
), &td
->tmd1_bits
);
793 /* One collision before packet was sent. */
794 if (bits
& LE_T1_EONE
)
795 lp
->stats
.collisions
++;
797 /* More than one collision, be optimistic. */
798 if (bits
& LE_T1_EMORE
)
799 lp
->stats
.collisions
+= 2;
801 lp
->stats
.tx_packets
++;
808 if (netif_queue_stopped(dev
) &&
810 netif_wake_queue(dev
);
812 spin_unlock(&lp
->lock
);
815 static irqreturn_t
lance_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
817 struct net_device
*dev
= (struct net_device
*)dev_id
;
818 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
;
821 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
822 csr0
= sbus_readw(lp
->lregs
+ RDP
);
824 /* Acknowledge all the interrupt sources ASAP */
825 sbus_writew(csr0
& (LE_C0_INTR
| LE_C0_TINT
| LE_C0_RINT
),
828 if ((csr0
& LE_C0_ERR
) != 0) {
829 /* Clear the error condition */
830 sbus_writew((LE_C0_BABL
| LE_C0_ERR
| LE_C0_MISS
|
831 LE_C0_CERR
| LE_C0_MERR
),
835 if (csr0
& LE_C0_RINT
)
838 if (csr0
& LE_C0_TINT
)
841 if (csr0
& LE_C0_BABL
)
842 lp
->stats
.tx_errors
++;
844 if (csr0
& LE_C0_MISS
)
845 lp
->stats
.rx_errors
++;
847 if (csr0
& LE_C0_MERR
) {
849 u32 addr
= sbus_readl(lp
->dregs
+ DMA_ADDR
);
851 printk(KERN_ERR
"%s: Memory error, status %04x, addr %06x\n",
852 dev
->name
, csr0
, addr
& 0xffffff);
854 printk(KERN_ERR
"%s: Memory error, status %04x\n",
858 sbus_writew(LE_C0_STOP
, lp
->lregs
+ RDP
);
861 u32 dma_csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
863 dma_csr
|= DMA_FIFO_INV
;
864 sbus_writel(dma_csr
, lp
->dregs
+ DMA_CSR
);
869 init_restart_lance(lp
);
870 netif_wake_queue(dev
);
873 sbus_writew(LE_C0_INEA
, lp
->lregs
+ RDP
);
878 /* Build a fake network packet and send it to ourselves. */
879 static void build_fake_packet(struct lance_private
*lp
)
881 struct net_device
*dev
= lp
->dev
;
882 volatile struct lance_init_block
*ib
= lp
->init_block
;
887 entry
= lp
->tx_new
& TX_RING_MOD_MASK
;
888 packet
= (u16
*) &(ib
->tx_buf
[entry
][0]);
889 eth
= (struct ethhdr
*) packet
;
890 if (lp
->pio_buffer
) {
891 for (i
= 0; i
< (ETH_ZLEN
/ sizeof(u16
)); i
++)
892 sbus_writew(0, &packet
[i
]);
893 for (i
= 0; i
< 6; i
++) {
894 sbus_writeb(dev
->dev_addr
[i
], ð
->h_dest
[i
]);
895 sbus_writeb(dev
->dev_addr
[i
], ð
->h_source
[i
]);
897 sbus_writew((-ETH_ZLEN
) | 0xf000, &ib
->btx_ring
[entry
].length
);
898 sbus_writew(0, &ib
->btx_ring
[entry
].misc
);
899 sbus_writeb(LE_T1_POK
|LE_T1_OWN
, &ib
->btx_ring
[entry
].tmd1_bits
);
901 memset(packet
, 0, ETH_ZLEN
);
902 for (i
= 0; i
< 6; i
++) {
903 eth
->h_dest
[i
] = dev
->dev_addr
[i
];
904 eth
->h_source
[i
] = dev
->dev_addr
[i
];
906 ib
->btx_ring
[entry
].length
= (-ETH_ZLEN
) | 0xf000;
907 ib
->btx_ring
[entry
].misc
= 0;
908 ib
->btx_ring
[entry
].tmd1_bits
= (LE_T1_POK
|LE_T1_OWN
);
910 lp
->tx_new
= TX_NEXT(entry
);
913 struct net_device
*last_dev
= 0;
915 static int lance_open(struct net_device
*dev
)
917 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
;
918 volatile struct lance_init_block
*ib
= lp
->init_block
;
925 if (request_irq(dev
->irq
, &lance_interrupt
, SA_SHIRQ
,
926 lancestr
, (void *) dev
)) {
927 printk(KERN_ERR
"Lance: Can't get irq %s\n", __irq_itoa(dev
->irq
));
931 /* On the 4m, setup the ledma to provide the upper bits for buffers */
933 u32 regval
= lp
->init_block_dvma
& 0xff000000;
935 sbus_writel(regval
, lp
->dregs
+ DMA_TEST
);
938 /* Set mode and clear multicast filter only at device open,
939 * so that lance_init_ring() called at any error will not
940 * forget multicast filters.
942 * BTW it is common bug in all lance drivers! --ANK
944 if (lp
->pio_buffer
) {
945 sbus_writew(0, &ib
->mode
);
946 sbus_writel(0, &ib
->filter
[0]);
947 sbus_writel(0, &ib
->filter
[1]);
957 netif_start_queue(dev
);
959 status
= init_restart_lance(lp
);
960 if (!status
&& lp
->auto_select
) {
961 build_fake_packet(lp
);
962 sbus_writew(LE_C0_INEA
| LE_C0_TDMD
, lp
->lregs
+ RDP
);
968 static int lance_close(struct net_device
*dev
)
970 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
972 netif_stop_queue(dev
);
973 del_timer_sync(&lp
->multicast_timer
);
977 free_irq(dev
->irq
, (void *) dev
);
981 static int lance_reset(struct net_device
*dev
)
983 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
988 /* On the 4m, reset the dma too */
992 printk(KERN_ERR
"resetting ledma\n");
993 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
994 sbus_writel(csr
| DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
996 sbus_writel(csr
& ~DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
998 addr
= lp
->init_block_dvma
& 0xff000000;
999 sbus_writel(addr
, lp
->dregs
+ DMA_TEST
);
1003 dev
->trans_start
= jiffies
;
1004 status
= init_restart_lance(lp
);
1008 static void lance_piocopy_from_skb(volatile void *dest
, unsigned char *src
, int len
)
1010 unsigned long piobuf
= (unsigned long) dest
;
1015 switch ((unsigned long)src
& 0x3) {
1019 sbus_writel(*p32
, piobuf
);
1036 sbus_writel(val
, piobuf
);
1046 u32 val
= p16
[0]<<16 | p16
[1];
1047 sbus_writel(val
, piobuf
);
1056 u16 val
= src
[0] << 8 | src
[1];
1057 sbus_writew(val
, piobuf
);
1063 sbus_writeb(src
[0], piobuf
);
1066 static void lance_piozero(volatile void *dest
, int len
)
1068 unsigned long piobuf
= (unsigned long) dest
;
1071 sbus_writeb(0, piobuf
);
1078 sbus_writeb(0, piobuf
);
1082 sbus_writew(0, piobuf
);
1089 sbus_writel(0, piobuf
);
1094 sbus_writew(0, piobuf
);
1099 sbus_writeb(0, piobuf
);
1102 static void lance_tx_timeout(struct net_device
*dev
)
1104 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
1106 printk(KERN_ERR
"%s: transmit timed out, status %04x, reset\n",
1107 dev
->name
, sbus_readw(lp
->lregs
+ RDP
));
1109 netif_wake_queue(dev
);
1112 static int lance_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1114 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
1115 volatile struct lance_init_block
*ib
= lp
->init_block
;
1116 int entry
, skblen
, len
;
1120 len
= (skblen
<= ETH_ZLEN
) ? ETH_ZLEN
: skblen
;
1122 spin_lock_irq(&lp
->lock
);
1124 lp
->stats
.tx_bytes
+= len
;
1126 entry
= lp
->tx_new
& TX_RING_MOD_MASK
;
1127 if (lp
->pio_buffer
) {
1128 sbus_writew((-len
) | 0xf000, &ib
->btx_ring
[entry
].length
);
1129 sbus_writew(0, &ib
->btx_ring
[entry
].misc
);
1130 lance_piocopy_from_skb(&ib
->tx_buf
[entry
][0], skb
->data
, skblen
);
1132 lance_piozero(&ib
->tx_buf
[entry
][skblen
], len
- skblen
);
1133 sbus_writeb(LE_T1_POK
| LE_T1_OWN
, &ib
->btx_ring
[entry
].tmd1_bits
);
1135 ib
->btx_ring
[entry
].length
= (-len
) | 0xf000;
1136 ib
->btx_ring
[entry
].misc
= 0;
1137 memcpy((char *)&ib
->tx_buf
[entry
][0], skb
->data
, skblen
);
1139 memset((char *) &ib
->tx_buf
[entry
][skblen
], 0, len
- skblen
);
1140 ib
->btx_ring
[entry
].tmd1_bits
= (LE_T1_POK
| LE_T1_OWN
);
1143 lp
->tx_new
= TX_NEXT(entry
);
1145 if (TX_BUFFS_AVAIL
<= 0)
1146 netif_stop_queue(dev
);
1148 /* Kick the lance: transmit now */
1149 sbus_writew(LE_C0_INEA
| LE_C0_TDMD
, lp
->lregs
+ RDP
);
1151 /* Read back CSR to invalidate the E-Cache.
1152 * This is needed, because DMA_DSBL_WR_INV is set.
1155 sbus_readw(lp
->lregs
+ RDP
);
1157 spin_unlock_irq(&lp
->lock
);
1159 dev
->trans_start
= jiffies
;
1165 static struct net_device_stats
*lance_get_stats(struct net_device
*dev
)
1167 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
1172 /* taken from the depca driver */
1173 static void lance_load_multicast(struct net_device
*dev
)
1175 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
1176 volatile struct lance_init_block
*ib
= lp
->init_block
;
1177 volatile u16
*mcast_table
= (u16
*) &ib
->filter
;
1178 struct dev_mc_list
*dmi
= dev
->mc_list
;
1183 /* set all multicast bits */
1184 if (dev
->flags
& IFF_ALLMULTI
) {
1185 if (lp
->pio_buffer
) {
1186 sbus_writel(0xffffffff, &ib
->filter
[0]);
1187 sbus_writel(0xffffffff, &ib
->filter
[1]);
1189 ib
->filter
[0] = 0xffffffff;
1190 ib
->filter
[1] = 0xffffffff;
1194 /* clear the multicast filter */
1195 if (lp
->pio_buffer
) {
1196 sbus_writel(0, &ib
->filter
[0]);
1197 sbus_writel(0, &ib
->filter
[1]);
1204 for (i
= 0; i
< dev
->mc_count
; i
++) {
1205 addrs
= dmi
->dmi_addr
;
1208 /* multicast address? */
1211 crc
= ether_crc_le(6, addrs
);
1213 if (lp
->pio_buffer
) {
1214 u16 tmp
= sbus_readw(&mcast_table
[crc
>>4]);
1215 tmp
|= 1 << (crc
& 0xf);
1216 sbus_writew(tmp
, &mcast_table
[crc
>>4]);
1218 mcast_table
[crc
>> 4] |= 1 << (crc
& 0xf);
1223 static void lance_set_multicast(struct net_device
*dev
)
1225 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
;
1226 volatile struct lance_init_block
*ib
= lp
->init_block
;
1229 if (!netif_running(dev
))
1232 if (lp
->tx_old
!= lp
->tx_new
) {
1233 mod_timer(&lp
->multicast_timer
, jiffies
+ 4);
1234 netif_wake_queue(dev
);
1238 netif_stop_queue(dev
);
1244 mode
= sbus_readw(&ib
->mode
);
1247 if (dev
->flags
& IFF_PROMISC
) {
1250 sbus_writew(mode
, &ib
->mode
);
1254 mode
&= ~LE_MO_PROM
;
1256 sbus_writew(mode
, &ib
->mode
);
1259 lance_load_multicast(dev
);
1262 init_restart_lance(lp
);
1263 netif_wake_queue(dev
);
1266 static void lance_set_multicast_retry(unsigned long _opaque
)
1268 struct net_device
*dev
= (struct net_device
*) _opaque
;
1270 lance_set_multicast(dev
);
1273 static void lance_free_hwresources(struct lance_private
*lp
)
1276 sbus_iounmap(lp
->lregs
, LANCE_REG_SIZE
);
1277 if (lp
->init_block
!= NULL
) {
1278 if (lp
->pio_buffer
) {
1279 sbus_iounmap((unsigned long)lp
->init_block
,
1280 sizeof(struct lance_init_block
));
1282 sbus_free_consistent(lp
->sdev
,
1283 sizeof(struct lance_init_block
),
1284 (void *)lp
->init_block
,
1285 lp
->init_block_dvma
);
1290 static int __init
sparc_lance_init(struct net_device
*dev
,
1291 struct sbus_dev
*sdev
,
1292 struct sbus_dma
*ledma
,
1293 struct sbus_dev
*lebuffer
)
1295 static unsigned version_printed
;
1296 struct lance_private
*lp
= NULL
;
1300 dev
= init_etherdev (0, sizeof (struct lance_private
) + 8);
1302 dev
->priv
= kmalloc(sizeof (struct lance_private
) + 8,
1304 if (dev
->priv
== NULL
)
1306 memset(dev
->priv
, 0, sizeof (struct lance_private
) + 8);
1308 if (sparc_lance_debug
&& version_printed
++ == 0)
1309 printk (KERN_INFO
"%s", version
);
1311 printk(KERN_INFO
"%s: LANCE ", dev
->name
);
1313 /* Make certain the data structures used by the LANCE are aligned. */
1314 dev
->priv
= (void *)(((unsigned long)dev
->priv
+ 7) & ~7);
1315 lp
= (struct lance_private
*) dev
->priv
;
1316 spin_lock_init(&lp
->lock
);
1318 /* Copy the IDPROM ethernet address to the device structure, later we
1319 * will copy the address in the device structure to the lance
1320 * initialization block.
1322 for (i
= 0; i
< 6; i
++)
1323 printk("%2.2x%c", dev
->dev_addr
[i
] = idprom
->id_ethaddr
[i
],
1327 /* Get the IO region */
1328 lp
->lregs
= sbus_ioremap(&sdev
->resource
[0], 0,
1329 LANCE_REG_SIZE
, lancestr
);
1330 if (lp
->lregs
== 0UL) {
1331 printk(KERN_ERR
"%s: Cannot map SunLance registers.\n",
1338 lp
->init_block
= (volatile struct lance_init_block
*)
1339 sbus_ioremap(&lebuffer
->resource
[0], 0,
1340 sizeof(struct lance_init_block
), "lebuffer");
1341 if (lp
->init_block
== NULL
) {
1342 printk(KERN_ERR
"%s: Cannot map SunLance PIO buffer.\n",
1346 lp
->init_block_dvma
= 0;
1348 lp
->init_ring
= lance_init_ring_pio
;
1349 lp
->rx
= lance_rx_pio
;
1350 lp
->tx
= lance_tx_pio
;
1352 lp
->init_block
= (volatile struct lance_init_block
*)
1353 sbus_alloc_consistent(sdev
, sizeof(struct lance_init_block
),
1354 &lp
->init_block_dvma
);
1355 if (lp
->init_block
== NULL
||
1356 lp
->init_block_dvma
== 0) {
1357 printk(KERN_ERR
"%s: Cannot allocate consistent DMA memory.\n",
1362 lp
->init_ring
= lance_init_ring_dvma
;
1363 lp
->rx
= lance_rx_dvma
;
1364 lp
->tx
= lance_tx_dvma
;
1366 lp
->busmaster_regval
= prom_getintdefault(sdev
->prom_node
,
1368 (LE_C3_BSWP
| LE_C3_ACON
|
1371 lp
->name
= lancestr
;
1374 lp
->burst_sizes
= 0;
1377 unsigned int sbmask
;
1380 /* Find burst-size property for ledma */
1381 lp
->burst_sizes
= prom_getintdefault(ledma
->sdev
->prom_node
,
1384 /* ledma may be capable of fast bursts, but sbus may not. */
1385 sbmask
= prom_getintdefault(ledma
->sdev
->bus
->prom_node
,
1386 "burst-sizes", DMA_BURSTBITS
);
1387 lp
->burst_sizes
&= sbmask
;
1389 /* Get the cable-selection property */
1390 memset(prop
, 0, sizeof(prop
));
1391 prom_getstring(ledma
->sdev
->prom_node
, "cable-selection",
1392 prop
, sizeof(prop
));
1396 printk(KERN_INFO
"%s: using auto-carrier-detection.\n",
1399 /* Is this found at /options .attributes in all
1400 * Prom versions? XXX
1402 topnd
= prom_getchild(prom_root_node
);
1404 nd
= prom_searchsiblings(topnd
, "options");
1408 if (!prom_node_has_property(nd
, "tpe-link-test?"))
1411 memset(prop
, 0, sizeof(prop
));
1412 prom_getstring(nd
, "tpe-link-test?", prop
,
1415 if (strcmp(prop
, "true")) {
1416 printk(KERN_NOTICE
"%s: warning: overriding option "
1417 "'tpe-link-test?'\n", dev
->name
);
1418 printk(KERN_NOTICE
"%s: warning: mail any problems "
1419 "to ecd@skynet.be\n", dev
->name
);
1420 auxio_set_lte(AUXIO_LTE_ON
);
1423 lp
->auto_select
= 1;
1425 } else if (!strcmp(prop
, "aui")) {
1426 lp
->auto_select
= 0;
1429 lp
->auto_select
= 0;
1433 lp
->dregs
= ledma
->regs
;
1436 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
1437 sbus_writel(csr
| DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1439 sbus_writel(csr
& ~DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1443 /* This should never happen. */
1444 if ((unsigned long)(lp
->init_block
->brx_ring
) & 0x07) {
1445 printk(KERN_ERR
"%s: ERROR: Rx and Tx rings not on even boundary.\n",
1451 SET_MODULE_OWNER(dev
);
1452 dev
->open
= &lance_open
;
1453 dev
->stop
= &lance_close
;
1454 dev
->hard_start_xmit
= &lance_start_xmit
;
1455 dev
->tx_timeout
= &lance_tx_timeout
;
1456 dev
->watchdog_timeo
= 5*HZ
;
1457 dev
->get_stats
= &lance_get_stats
;
1458 dev
->set_multicast_list
= &lance_set_multicast
;
1460 dev
->irq
= sdev
->irqs
[0];
1465 /* We cannot sleep if the chip is busy during a
1466 * multicast list update event, because such events
1467 * can occur from interrupts (ex. IPv6). So we
1468 * use a timer to try again later when necessary. -DaveM
1470 init_timer(&lp
->multicast_timer
);
1471 lp
->multicast_timer
.data
= (unsigned long) dev
;
1472 lp
->multicast_timer
.function
= &lance_set_multicast_retry
;
1474 dev
->ifindex
= dev_new_index();
1475 lp
->next_module
= root_lance_dev
;
1476 root_lance_dev
= lp
;
1482 lance_free_hwresources(lp
);
1486 /* On 4m, find the associated dma for the lance chip */
1487 static inline struct sbus_dma
*find_ledma(struct sbus_dev
*sdev
)
1492 if (p
->sdev
== sdev
)
1500 #include <asm/sun4paddr.h>
1501 #include <asm/machines.h>
1503 /* Find all the lance cards on the system and initialize them */
1504 static int __init
sparc_lance_probe(void)
1506 static struct sbus_dev sdev
;
1509 root_lance_dev
= NULL
;
1515 if ((idprom
->id_machtype
== (SM_SUN4
|SM_4_330
)) ||
1516 (idprom
->id_machtype
== (SM_SUN4
|SM_4_470
))) {
1517 memset(&sdev
, 0, sizeof(sdev
));
1518 sdev
.reg_addrs
[0].phys_addr
= sun4_eth_physaddr
;
1520 return sparc_lance_init(NULL
, &sdev
, 0, 0);
1525 #else /* !CONFIG_SUN4 */
1527 /* Find all the lance cards on the system and initialize them */
1528 static int __init
sparc_lance_probe(void)
1530 struct sbus_bus
*bus
;
1531 struct sbus_dev
*sdev
= 0;
1532 struct net_device
*dev
= NULL
;
1533 struct sbus_dma
*ledma
= 0;
1537 root_lance_dev
= NULL
;
1543 for_each_sbus (bus
) {
1544 for_each_sbusdev (sdev
, bus
) {
1547 if (strcmp(sdev
->prom_name
, "le") == 0) {
1549 if ((v
= sparc_lance_init(dev
, sdev
, 0, 0)))
1553 if (strcmp(sdev
->prom_name
, "ledma") == 0) {
1555 ledma
= find_ledma(sdev
);
1556 if ((v
= sparc_lance_init(dev
, sdev
->child
,
1561 if (strcmp(sdev
->prom_name
, "lebuffer") == 0){
1563 if ((v
= sparc_lance_init(dev
, sdev
->child
,
1568 } /* for each sbusdev */
1569 } /* for each sbus */
1574 #endif /* !CONFIG_SUN4 */
1576 static void __exit
sparc_lance_cleanup(void)
1578 struct lance_private
*lp
;
1580 while (root_lance_dev
) {
1581 lp
= root_lance_dev
->next_module
;
1583 unregister_netdev(root_lance_dev
->dev
);
1584 lance_free_hwresources(root_lance_dev
);
1585 kfree(root_lance_dev
->dev
);
1586 root_lance_dev
= lp
;
1590 module_init(sparc_lance_probe
);
1591 module_exit(sparc_lance_cleanup
);
1592 MODULE_LICENSE("GPL");