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 lancestr
[] = "LANCE";
74 #include <linux/config.h>
75 #include <linux/module.h>
76 #include <linux/kernel.h>
77 #include <linux/types.h>
78 #include <linux/fcntl.h>
79 #include <linux/interrupt.h>
80 #include <linux/ioport.h>
82 #include <linux/slab.h>
83 #include <linux/string.h>
84 #include <linux/delay.h>
85 #include <linux/init.h>
86 #include <linux/crc32.h>
87 #include <linux/errno.h>
88 #include <linux/socket.h> /* Used for the temporal inet entries and routing */
89 #include <linux/route.h>
90 #include <linux/netdevice.h>
91 #include <linux/etherdevice.h>
92 #include <linux/skbuff.h>
93 #include <linux/ethtool.h>
94 #include <linux/bitops.h>
96 #include <asm/system.h>
99 #include <asm/pgtable.h>
100 #include <asm/byteorder.h> /* Used by the checksum routines */
101 #include <asm/idprom.h>
102 #include <asm/sbus.h>
103 #include <asm/openprom.h>
104 #include <asm/oplib.h>
105 #include <asm/auxio.h> /* For tpe-link-test? setting */
108 #define DRV_NAME "sunlance"
109 #define DRV_VERSION "2.02"
110 #define DRV_RELDATE "8/24/03"
111 #define DRV_AUTHOR "Miguel de Icaza (miguel@nuclecu.unam.mx)"
113 static char version
[] =
114 DRV_NAME
".c:v" DRV_VERSION
" " DRV_RELDATE
" " DRV_AUTHOR
"\n";
116 MODULE_VERSION(DRV_VERSION
);
117 MODULE_AUTHOR(DRV_AUTHOR
);
118 MODULE_DESCRIPTION("Sun Lance ethernet driver");
119 MODULE_LICENSE("GPL");
121 /* Define: 2^4 Tx buffers and 2^4 Rx buffers */
122 #ifndef LANCE_LOG_TX_BUFFERS
123 #define LANCE_LOG_TX_BUFFERS 4
124 #define LANCE_LOG_RX_BUFFERS 4
132 #define LE_MO_PROM 0x8000 /* Enable promiscuous mode */
134 #define LE_C0_ERR 0x8000 /* Error: set if BAB, SQE, MISS or ME is set */
135 #define LE_C0_BABL 0x4000 /* BAB: Babble: tx timeout. */
136 #define LE_C0_CERR 0x2000 /* SQE: Signal quality error */
137 #define LE_C0_MISS 0x1000 /* MISS: Missed a packet */
138 #define LE_C0_MERR 0x0800 /* ME: Memory error */
139 #define LE_C0_RINT 0x0400 /* Received interrupt */
140 #define LE_C0_TINT 0x0200 /* Transmitter Interrupt */
141 #define LE_C0_IDON 0x0100 /* IFIN: Init finished. */
142 #define LE_C0_INTR 0x0080 /* Interrupt or error */
143 #define LE_C0_INEA 0x0040 /* Interrupt enable */
144 #define LE_C0_RXON 0x0020 /* Receiver on */
145 #define LE_C0_TXON 0x0010 /* Transmitter on */
146 #define LE_C0_TDMD 0x0008 /* Transmitter demand */
147 #define LE_C0_STOP 0x0004 /* Stop the card */
148 #define LE_C0_STRT 0x0002 /* Start the card */
149 #define LE_C0_INIT 0x0001 /* Init the card */
151 #define LE_C3_BSWP 0x4 /* SWAP */
152 #define LE_C3_ACON 0x2 /* ALE Control */
153 #define LE_C3_BCON 0x1 /* Byte control */
155 /* Receive message descriptor 1 */
156 #define LE_R1_OWN 0x80 /* Who owns the entry */
157 #define LE_R1_ERR 0x40 /* Error: if FRA, OFL, CRC or BUF is set */
158 #define LE_R1_FRA 0x20 /* FRA: Frame error */
159 #define LE_R1_OFL 0x10 /* OFL: Frame overflow */
160 #define LE_R1_CRC 0x08 /* CRC error */
161 #define LE_R1_BUF 0x04 /* BUF: Buffer error */
162 #define LE_R1_SOP 0x02 /* Start of packet */
163 #define LE_R1_EOP 0x01 /* End of packet */
164 #define LE_R1_POK 0x03 /* Packet is complete: SOP + EOP */
166 #define LE_T1_OWN 0x80 /* Lance owns the packet */
167 #define LE_T1_ERR 0x40 /* Error summary */
168 #define LE_T1_EMORE 0x10 /* Error: more than one retry needed */
169 #define LE_T1_EONE 0x08 /* Error: one retry needed */
170 #define LE_T1_EDEF 0x04 /* Error: deferred */
171 #define LE_T1_SOP 0x02 /* Start of packet */
172 #define LE_T1_EOP 0x01 /* End of packet */
173 #define LE_T1_POK 0x03 /* Packet is complete: SOP + EOP */
175 #define LE_T3_BUF 0x8000 /* Buffer error */
176 #define LE_T3_UFL 0x4000 /* Error underflow */
177 #define LE_T3_LCOL 0x1000 /* Error late collision */
178 #define LE_T3_CLOS 0x0800 /* Error carrier loss */
179 #define LE_T3_RTY 0x0400 /* Error retry */
180 #define LE_T3_TDR 0x03ff /* Time Domain Reflectometry counter */
182 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
183 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
184 #define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29)
185 #define TX_NEXT(__x) (((__x)+1) & TX_RING_MOD_MASK)
187 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
188 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
189 #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29)
190 #define RX_NEXT(__x) (((__x)+1) & RX_RING_MOD_MASK)
192 #define PKT_BUF_SZ 1544
193 #define RX_BUFF_SIZE PKT_BUF_SZ
194 #define TX_BUFF_SIZE PKT_BUF_SZ
196 struct lance_rx_desc
{
197 u16 rmd0
; /* low address of packet */
198 u8 rmd1_bits
; /* descriptor bits */
199 u8 rmd1_hadr
; /* high address of packet */
200 s16 length
; /* This length is 2s complement (negative)!
203 u16 mblength
; /* This is the actual number of bytes received */
206 struct lance_tx_desc
{
207 u16 tmd0
; /* low address of packet */
208 u8 tmd1_bits
; /* descriptor bits */
209 u8 tmd1_hadr
; /* high address of packet */
210 s16 length
; /* Length is 2s complement (negative)! */
214 /* The LANCE initialization block, described in databook. */
215 /* On the Sparc, this block should be on a DMA region */
216 struct lance_init_block
{
217 u16 mode
; /* Pre-set mode (reg. 15) */
218 u8 phys_addr
[6]; /* Physical ethernet address */
219 u32 filter
[2]; /* Multicast filter. */
221 /* Receive and transmit ring base, along with extra bits. */
222 u16 rx_ptr
; /* receive descriptor addr */
223 u16 rx_len
; /* receive len and high addr */
224 u16 tx_ptr
; /* transmit descriptor addr */
225 u16 tx_len
; /* transmit len and high addr */
227 /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
228 struct lance_rx_desc brx_ring
[RX_RING_SIZE
];
229 struct lance_tx_desc btx_ring
[TX_RING_SIZE
];
231 u8 tx_buf
[TX_RING_SIZE
][TX_BUFF_SIZE
];
232 u8 pad
[2]; /* align rx_buf for copy_and_sum(). */
233 u8 rx_buf
[RX_RING_SIZE
][RX_BUFF_SIZE
];
236 #define libdesc_offset(rt, elem) \
237 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem])))))
239 #define libbuff_offset(rt, elem) \
240 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem][0])))))
242 struct lance_private
{
243 void __iomem
*lregs
; /* Lance RAP/RDP regs. */
244 void __iomem
*dregs
; /* DMA controller regs. */
245 struct lance_init_block __iomem
*init_block_iomem
;
246 struct lance_init_block
*init_block_mem
;
253 struct net_device_stats stats
;
254 struct sbus_dma
*ledma
; /* If set this points to ledma */
255 char tpe
; /* cable-selection is TPE */
256 char auto_select
; /* cable-selection by carrier */
257 char burst_sizes
; /* ledma SBus burst sizes */
258 char pio_buffer
; /* init block in PIO space? */
260 unsigned short busmaster_regval
;
262 void (*init_ring
)(struct net_device
*);
263 void (*rx
)(struct net_device
*);
264 void (*tx
)(struct net_device
*);
267 dma_addr_t init_block_dvma
;
268 struct net_device
*dev
; /* Backpointer */
269 struct lance_private
*next_module
;
270 struct sbus_dev
*sdev
;
271 struct timer_list multicast_timer
;
274 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
275 lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\
276 lp->tx_old - lp->tx_new-1)
278 /* Lance registers. */
279 #define RDP 0x00UL /* register data port */
280 #define RAP 0x02UL /* register address port */
281 #define LANCE_REG_SIZE 0x04UL
283 #define STOP_LANCE(__lp) \
284 do { void __iomem *__base = (__lp)->lregs; \
285 sbus_writew(LE_CSR0, __base + RAP); \
286 sbus_writew(LE_C0_STOP, __base + RDP); \
289 int sparc_lance_debug
= 2;
291 /* The Lance uses 24 bit addresses */
292 /* On the Sun4c the DVMA will provide the remaining bytes for us */
293 /* On the Sun4m we have to instruct the ledma to provide them */
294 /* Even worse, on scsi/ether SBUS cards, the init block and the
295 * transmit/receive buffers are addresses as offsets from absolute
296 * zero on the lebuffer PIO area. -DaveM
299 #define LANCE_ADDR(x) ((long)(x) & ~0xff000000)
301 static struct lance_private
*root_lance_dev
;
303 /* Load the CSR registers */
304 static void load_csrs(struct lance_private
*lp
)
311 leptr
= LANCE_ADDR(lp
->init_block_dvma
);
313 sbus_writew(LE_CSR1
, lp
->lregs
+ RAP
);
314 sbus_writew(leptr
& 0xffff, lp
->lregs
+ RDP
);
315 sbus_writew(LE_CSR2
, lp
->lregs
+ RAP
);
316 sbus_writew(leptr
>> 16, lp
->lregs
+ RDP
);
317 sbus_writew(LE_CSR3
, lp
->lregs
+ RAP
);
318 sbus_writew(lp
->busmaster_regval
, lp
->lregs
+ RDP
);
320 /* Point back to csr0 */
321 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
324 /* Setup the Lance Rx and Tx rings */
325 static void lance_init_ring_dvma(struct net_device
*dev
)
327 struct lance_private
*lp
= netdev_priv(dev
);
328 struct lance_init_block
*ib
= lp
->init_block_mem
;
329 dma_addr_t aib
= lp
->init_block_dvma
;
333 /* Lock out other processes while setting up hardware */
334 netif_stop_queue(dev
);
335 lp
->rx_new
= lp
->tx_new
= 0;
336 lp
->rx_old
= lp
->tx_old
= 0;
338 /* Copy the ethernet address to the lance init block
339 * Note that on the sparc you need to swap the ethernet address.
341 ib
->phys_addr
[0] = dev
->dev_addr
[1];
342 ib
->phys_addr
[1] = dev
->dev_addr
[0];
343 ib
->phys_addr
[2] = dev
->dev_addr
[3];
344 ib
->phys_addr
[3] = dev
->dev_addr
[2];
345 ib
->phys_addr
[4] = dev
->dev_addr
[5];
346 ib
->phys_addr
[5] = dev
->dev_addr
[4];
348 /* Setup the Tx ring entries */
349 for (i
= 0; i
<= TX_RING_SIZE
; i
++) {
350 leptr
= LANCE_ADDR(aib
+ libbuff_offset(tx_buf
, i
));
351 ib
->btx_ring
[i
].tmd0
= leptr
;
352 ib
->btx_ring
[i
].tmd1_hadr
= leptr
>> 16;
353 ib
->btx_ring
[i
].tmd1_bits
= 0;
354 ib
->btx_ring
[i
].length
= 0xf000; /* The ones required by tmd2 */
355 ib
->btx_ring
[i
].misc
= 0;
358 /* Setup the Rx ring entries */
359 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
360 leptr
= LANCE_ADDR(aib
+ libbuff_offset(rx_buf
, i
));
362 ib
->brx_ring
[i
].rmd0
= leptr
;
363 ib
->brx_ring
[i
].rmd1_hadr
= leptr
>> 16;
364 ib
->brx_ring
[i
].rmd1_bits
= LE_R1_OWN
;
365 ib
->brx_ring
[i
].length
= -RX_BUFF_SIZE
| 0xf000;
366 ib
->brx_ring
[i
].mblength
= 0;
369 /* Setup the initialization block */
371 /* Setup rx descriptor pointer */
372 leptr
= LANCE_ADDR(aib
+ libdesc_offset(brx_ring
, 0));
373 ib
->rx_len
= (LANCE_LOG_RX_BUFFERS
<< 13) | (leptr
>> 16);
376 /* Setup tx descriptor pointer */
377 leptr
= LANCE_ADDR(aib
+ libdesc_offset(btx_ring
, 0));
378 ib
->tx_len
= (LANCE_LOG_TX_BUFFERS
<< 13) | (leptr
>> 16);
382 static void lance_init_ring_pio(struct net_device
*dev
)
384 struct lance_private
*lp
= netdev_priv(dev
);
385 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
389 /* Lock out other processes while setting up hardware */
390 netif_stop_queue(dev
);
391 lp
->rx_new
= lp
->tx_new
= 0;
392 lp
->rx_old
= lp
->tx_old
= 0;
394 /* Copy the ethernet address to the lance init block
395 * Note that on the sparc you need to swap the ethernet address.
397 sbus_writeb(dev
->dev_addr
[1], &ib
->phys_addr
[0]);
398 sbus_writeb(dev
->dev_addr
[0], &ib
->phys_addr
[1]);
399 sbus_writeb(dev
->dev_addr
[3], &ib
->phys_addr
[2]);
400 sbus_writeb(dev
->dev_addr
[2], &ib
->phys_addr
[3]);
401 sbus_writeb(dev
->dev_addr
[5], &ib
->phys_addr
[4]);
402 sbus_writeb(dev
->dev_addr
[4], &ib
->phys_addr
[5]);
404 /* Setup the Tx ring entries */
405 for (i
= 0; i
<= TX_RING_SIZE
; i
++) {
406 leptr
= libbuff_offset(tx_buf
, i
);
407 sbus_writew(leptr
, &ib
->btx_ring
[i
].tmd0
);
408 sbus_writeb(leptr
>> 16,&ib
->btx_ring
[i
].tmd1_hadr
);
409 sbus_writeb(0, &ib
->btx_ring
[i
].tmd1_bits
);
411 /* The ones required by tmd2 */
412 sbus_writew(0xf000, &ib
->btx_ring
[i
].length
);
413 sbus_writew(0, &ib
->btx_ring
[i
].misc
);
416 /* Setup the Rx ring entries */
417 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
418 leptr
= libbuff_offset(rx_buf
, i
);
420 sbus_writew(leptr
, &ib
->brx_ring
[i
].rmd0
);
421 sbus_writeb(leptr
>> 16,&ib
->brx_ring
[i
].rmd1_hadr
);
422 sbus_writeb(LE_R1_OWN
, &ib
->brx_ring
[i
].rmd1_bits
);
423 sbus_writew(-RX_BUFF_SIZE
|0xf000,
424 &ib
->brx_ring
[i
].length
);
425 sbus_writew(0, &ib
->brx_ring
[i
].mblength
);
428 /* Setup the initialization block */
430 /* Setup rx descriptor pointer */
431 leptr
= libdesc_offset(brx_ring
, 0);
432 sbus_writew((LANCE_LOG_RX_BUFFERS
<< 13) | (leptr
>> 16),
434 sbus_writew(leptr
, &ib
->rx_ptr
);
436 /* Setup tx descriptor pointer */
437 leptr
= libdesc_offset(btx_ring
, 0);
438 sbus_writew((LANCE_LOG_TX_BUFFERS
<< 13) | (leptr
>> 16),
440 sbus_writew(leptr
, &ib
->tx_ptr
);
443 static void init_restart_ledma(struct lance_private
*lp
)
445 u32 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
447 if (!(csr
& DMA_HNDL_ERROR
)) {
448 /* E-Cache draining */
449 while (sbus_readl(lp
->dregs
+ DMA_CSR
) & DMA_FIFO_ISDRAIN
)
453 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
454 csr
&= ~DMA_E_BURSTS
;
455 if (lp
->burst_sizes
& DMA_BURST32
)
456 csr
|= DMA_E_BURST32
;
458 csr
|= DMA_E_BURST16
;
460 csr
|= (DMA_DSBL_RD_DRN
| DMA_DSBL_WR_INV
| DMA_FIFO_INV
);
463 csr
|= DMA_EN_ENETAUI
;
465 csr
&= ~DMA_EN_ENETAUI
;
467 sbus_writel(csr
, lp
->dregs
+ DMA_CSR
);
471 static int init_restart_lance(struct lance_private
*lp
)
477 init_restart_ledma(lp
);
479 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
480 sbus_writew(LE_C0_INIT
, lp
->lregs
+ RDP
);
482 /* Wait for the lance to complete initialization */
483 for (i
= 0; i
< 100; i
++) {
484 regval
= sbus_readw(lp
->lregs
+ RDP
);
486 if (regval
& (LE_C0_ERR
| LE_C0_IDON
))
490 if (i
== 100 || (regval
& LE_C0_ERR
)) {
491 printk(KERN_ERR
"LANCE unopened after %d ticks, csr0=%4.4x.\n",
494 printk("dcsr=%8.8x\n", sbus_readl(lp
->dregs
+ DMA_CSR
));
498 /* Clear IDON by writing a "1", enable interrupts and start lance */
499 sbus_writew(LE_C0_IDON
, lp
->lregs
+ RDP
);
500 sbus_writew(LE_C0_INEA
| LE_C0_STRT
, lp
->lregs
+ RDP
);
503 u32 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
506 sbus_writel(csr
, lp
->dregs
+ DMA_CSR
);
512 static void lance_rx_dvma(struct net_device
*dev
)
514 struct lance_private
*lp
= netdev_priv(dev
);
515 struct lance_init_block
*ib
= lp
->init_block_mem
;
516 struct lance_rx_desc
*rd
;
518 int len
, entry
= lp
->rx_new
;
521 for (rd
= &ib
->brx_ring
[entry
];
522 !((bits
= rd
->rmd1_bits
) & LE_R1_OWN
);
523 rd
= &ib
->brx_ring
[entry
]) {
525 /* We got an incomplete frame? */
526 if ((bits
& LE_R1_POK
) != LE_R1_POK
) {
527 lp
->stats
.rx_over_errors
++;
528 lp
->stats
.rx_errors
++;
529 } else if (bits
& LE_R1_ERR
) {
530 /* Count only the end frame as a rx error,
533 if (bits
& LE_R1_BUF
) lp
->stats
.rx_fifo_errors
++;
534 if (bits
& LE_R1_CRC
) lp
->stats
.rx_crc_errors
++;
535 if (bits
& LE_R1_OFL
) lp
->stats
.rx_over_errors
++;
536 if (bits
& LE_R1_FRA
) lp
->stats
.rx_frame_errors
++;
537 if (bits
& LE_R1_EOP
) lp
->stats
.rx_errors
++;
539 len
= (rd
->mblength
& 0xfff) - 4;
540 skb
= dev_alloc_skb(len
+ 2);
543 printk(KERN_INFO
"%s: Memory squeeze, deferring packet.\n",
545 lp
->stats
.rx_dropped
++;
547 rd
->rmd1_bits
= LE_R1_OWN
;
548 lp
->rx_new
= RX_NEXT(entry
);
552 lp
->stats
.rx_bytes
+= len
;
555 skb_reserve(skb
, 2); /* 16 byte align */
556 skb_put(skb
, len
); /* make room */
557 eth_copy_and_sum(skb
,
558 (unsigned char *)&(ib
->rx_buf
[entry
][0]),
560 skb
->protocol
= eth_type_trans(skb
, dev
);
562 dev
->last_rx
= jiffies
;
563 lp
->stats
.rx_packets
++;
566 /* Return the packet to the pool */
568 rd
->rmd1_bits
= LE_R1_OWN
;
569 entry
= RX_NEXT(entry
);
575 static void lance_tx_dvma(struct net_device
*dev
)
577 struct lance_private
*lp
= netdev_priv(dev
);
578 struct lance_init_block
*ib
= lp
->init_block_mem
;
581 spin_lock(&lp
->lock
);
584 for (i
= j
; i
!= lp
->tx_new
; i
= j
) {
585 struct lance_tx_desc
*td
= &ib
->btx_ring
[i
];
586 u8 bits
= td
->tmd1_bits
;
588 /* If we hit a packet not owned by us, stop */
589 if (bits
& LE_T1_OWN
)
592 if (bits
& LE_T1_ERR
) {
593 u16 status
= td
->misc
;
595 lp
->stats
.tx_errors
++;
596 if (status
& LE_T3_RTY
) lp
->stats
.tx_aborted_errors
++;
597 if (status
& LE_T3_LCOL
) lp
->stats
.tx_window_errors
++;
599 if (status
& LE_T3_CLOS
) {
600 lp
->stats
.tx_carrier_errors
++;
601 if (lp
->auto_select
) {
602 lp
->tpe
= 1 - lp
->tpe
;
603 printk(KERN_NOTICE
"%s: Carrier Lost, trying %s\n",
604 dev
->name
, lp
->tpe
?"TPE":"AUI");
608 init_restart_lance(lp
);
613 /* Buffer errors and underflows turn off the
614 * transmitter, restart the adapter.
616 if (status
& (LE_T3_BUF
|LE_T3_UFL
)) {
617 lp
->stats
.tx_fifo_errors
++;
619 printk(KERN_ERR
"%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
624 init_restart_lance(lp
);
627 } else if ((bits
& LE_T1_POK
) == LE_T1_POK
) {
629 * So we don't count the packet more than once.
631 td
->tmd1_bits
= bits
& ~(LE_T1_POK
);
633 /* One collision before packet was sent. */
634 if (bits
& LE_T1_EONE
)
635 lp
->stats
.collisions
++;
637 /* More than one collision, be optimistic. */
638 if (bits
& LE_T1_EMORE
)
639 lp
->stats
.collisions
+= 2;
641 lp
->stats
.tx_packets
++;
648 if (netif_queue_stopped(dev
) &&
650 netif_wake_queue(dev
);
652 spin_unlock(&lp
->lock
);
655 static void lance_piocopy_to_skb(struct sk_buff
*skb
, void __iomem
*piobuf
, int len
)
657 u16
*p16
= (u16
*) skb
->data
;
660 void __iomem
*pbuf
= piobuf
;
662 /* We know here that both src and dest are on a 16bit boundary. */
663 *p16
++ = sbus_readw(pbuf
);
669 *p32
++ = sbus_readl(pbuf
);
676 *p16
++ = sbus_readw(pbuf
);
682 *p8
= sbus_readb(pbuf
);
685 static void lance_rx_pio(struct net_device
*dev
)
687 struct lance_private
*lp
= netdev_priv(dev
);
688 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
689 struct lance_rx_desc __iomem
*rd
;
695 for (rd
= &ib
->brx_ring
[entry
];
696 !((bits
= sbus_readb(&rd
->rmd1_bits
)) & LE_R1_OWN
);
697 rd
= &ib
->brx_ring
[entry
]) {
699 /* We got an incomplete frame? */
700 if ((bits
& LE_R1_POK
) != LE_R1_POK
) {
701 lp
->stats
.rx_over_errors
++;
702 lp
->stats
.rx_errors
++;
703 } else if (bits
& LE_R1_ERR
) {
704 /* Count only the end frame as a rx error,
707 if (bits
& LE_R1_BUF
) lp
->stats
.rx_fifo_errors
++;
708 if (bits
& LE_R1_CRC
) lp
->stats
.rx_crc_errors
++;
709 if (bits
& LE_R1_OFL
) lp
->stats
.rx_over_errors
++;
710 if (bits
& LE_R1_FRA
) lp
->stats
.rx_frame_errors
++;
711 if (bits
& LE_R1_EOP
) lp
->stats
.rx_errors
++;
713 len
= (sbus_readw(&rd
->mblength
) & 0xfff) - 4;
714 skb
= dev_alloc_skb(len
+ 2);
717 printk(KERN_INFO
"%s: Memory squeeze, deferring packet.\n",
719 lp
->stats
.rx_dropped
++;
720 sbus_writew(0, &rd
->mblength
);
721 sbus_writeb(LE_R1_OWN
, &rd
->rmd1_bits
);
722 lp
->rx_new
= RX_NEXT(entry
);
726 lp
->stats
.rx_bytes
+= len
;
729 skb_reserve (skb
, 2); /* 16 byte align */
730 skb_put(skb
, len
); /* make room */
731 lance_piocopy_to_skb(skb
, &(ib
->rx_buf
[entry
][0]), len
);
732 skb
->protocol
= eth_type_trans(skb
, dev
);
734 dev
->last_rx
= jiffies
;
735 lp
->stats
.rx_packets
++;
738 /* Return the packet to the pool */
739 sbus_writew(0, &rd
->mblength
);
740 sbus_writeb(LE_R1_OWN
, &rd
->rmd1_bits
);
741 entry
= RX_NEXT(entry
);
747 static void lance_tx_pio(struct net_device
*dev
)
749 struct lance_private
*lp
= netdev_priv(dev
);
750 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
753 spin_lock(&lp
->lock
);
756 for (i
= j
; i
!= lp
->tx_new
; i
= j
) {
757 struct lance_tx_desc __iomem
*td
= &ib
->btx_ring
[i
];
758 u8 bits
= sbus_readb(&td
->tmd1_bits
);
760 /* If we hit a packet not owned by us, stop */
761 if (bits
& LE_T1_OWN
)
764 if (bits
& LE_T1_ERR
) {
765 u16 status
= sbus_readw(&td
->misc
);
767 lp
->stats
.tx_errors
++;
768 if (status
& LE_T3_RTY
) lp
->stats
.tx_aborted_errors
++;
769 if (status
& LE_T3_LCOL
) lp
->stats
.tx_window_errors
++;
771 if (status
& LE_T3_CLOS
) {
772 lp
->stats
.tx_carrier_errors
++;
773 if (lp
->auto_select
) {
774 lp
->tpe
= 1 - lp
->tpe
;
775 printk(KERN_NOTICE
"%s: Carrier Lost, trying %s\n",
776 dev
->name
, lp
->tpe
?"TPE":"AUI");
780 init_restart_lance(lp
);
785 /* Buffer errors and underflows turn off the
786 * transmitter, restart the adapter.
788 if (status
& (LE_T3_BUF
|LE_T3_UFL
)) {
789 lp
->stats
.tx_fifo_errors
++;
791 printk(KERN_ERR
"%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
796 init_restart_lance(lp
);
799 } else if ((bits
& LE_T1_POK
) == LE_T1_POK
) {
801 * So we don't count the packet more than once.
803 sbus_writeb(bits
& ~(LE_T1_POK
), &td
->tmd1_bits
);
805 /* One collision before packet was sent. */
806 if (bits
& LE_T1_EONE
)
807 lp
->stats
.collisions
++;
809 /* More than one collision, be optimistic. */
810 if (bits
& LE_T1_EMORE
)
811 lp
->stats
.collisions
+= 2;
813 lp
->stats
.tx_packets
++;
820 if (netif_queue_stopped(dev
) &&
822 netif_wake_queue(dev
);
824 spin_unlock(&lp
->lock
);
827 static irqreturn_t
lance_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
829 struct net_device
*dev
= (struct net_device
*)dev_id
;
830 struct lance_private
*lp
= netdev_priv(dev
);
833 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
834 csr0
= sbus_readw(lp
->lregs
+ RDP
);
836 /* Acknowledge all the interrupt sources ASAP */
837 sbus_writew(csr0
& (LE_C0_INTR
| LE_C0_TINT
| LE_C0_RINT
),
840 if ((csr0
& LE_C0_ERR
) != 0) {
841 /* Clear the error condition */
842 sbus_writew((LE_C0_BABL
| LE_C0_ERR
| LE_C0_MISS
|
843 LE_C0_CERR
| LE_C0_MERR
),
847 if (csr0
& LE_C0_RINT
)
850 if (csr0
& LE_C0_TINT
)
853 if (csr0
& LE_C0_BABL
)
854 lp
->stats
.tx_errors
++;
856 if (csr0
& LE_C0_MISS
)
857 lp
->stats
.rx_errors
++;
859 if (csr0
& LE_C0_MERR
) {
861 u32 addr
= sbus_readl(lp
->dregs
+ DMA_ADDR
);
863 printk(KERN_ERR
"%s: Memory error, status %04x, addr %06x\n",
864 dev
->name
, csr0
, addr
& 0xffffff);
866 printk(KERN_ERR
"%s: Memory error, status %04x\n",
870 sbus_writew(LE_C0_STOP
, lp
->lregs
+ RDP
);
873 u32 dma_csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
875 dma_csr
|= DMA_FIFO_INV
;
876 sbus_writel(dma_csr
, lp
->dregs
+ DMA_CSR
);
881 init_restart_lance(lp
);
882 netif_wake_queue(dev
);
885 sbus_writew(LE_C0_INEA
, lp
->lregs
+ RDP
);
890 /* Build a fake network packet and send it to ourselves. */
891 static void build_fake_packet(struct lance_private
*lp
)
893 struct net_device
*dev
= lp
->dev
;
896 entry
= lp
->tx_new
& TX_RING_MOD_MASK
;
897 if (lp
->pio_buffer
) {
898 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
899 u16 __iomem
*packet
= (u16 __iomem
*) &(ib
->tx_buf
[entry
][0]);
900 struct ethhdr __iomem
*eth
= (struct ethhdr __iomem
*) packet
;
901 for (i
= 0; i
< (ETH_ZLEN
/ sizeof(u16
)); i
++)
902 sbus_writew(0, &packet
[i
]);
903 for (i
= 0; i
< 6; i
++) {
904 sbus_writeb(dev
->dev_addr
[i
], ð
->h_dest
[i
]);
905 sbus_writeb(dev
->dev_addr
[i
], ð
->h_source
[i
]);
907 sbus_writew((-ETH_ZLEN
) | 0xf000, &ib
->btx_ring
[entry
].length
);
908 sbus_writew(0, &ib
->btx_ring
[entry
].misc
);
909 sbus_writeb(LE_T1_POK
|LE_T1_OWN
, &ib
->btx_ring
[entry
].tmd1_bits
);
911 struct lance_init_block
*ib
= lp
->init_block_mem
;
912 u16
*packet
= (u16
*) &(ib
->tx_buf
[entry
][0]);
913 struct ethhdr
*eth
= (struct ethhdr
*) packet
;
914 memset(packet
, 0, ETH_ZLEN
);
915 for (i
= 0; i
< 6; i
++) {
916 eth
->h_dest
[i
] = dev
->dev_addr
[i
];
917 eth
->h_source
[i
] = dev
->dev_addr
[i
];
919 ib
->btx_ring
[entry
].length
= (-ETH_ZLEN
) | 0xf000;
920 ib
->btx_ring
[entry
].misc
= 0;
921 ib
->btx_ring
[entry
].tmd1_bits
= (LE_T1_POK
|LE_T1_OWN
);
923 lp
->tx_new
= TX_NEXT(entry
);
926 struct net_device
*last_dev
;
928 static int lance_open(struct net_device
*dev
)
930 struct lance_private
*lp
= netdev_priv(dev
);
937 if (request_irq(dev
->irq
, &lance_interrupt
, SA_SHIRQ
,
938 lancestr
, (void *) dev
)) {
939 printk(KERN_ERR
"Lance: Can't get irq %s\n", __irq_itoa(dev
->irq
));
943 /* On the 4m, setup the ledma to provide the upper bits for buffers */
945 u32 regval
= lp
->init_block_dvma
& 0xff000000;
947 sbus_writel(regval
, lp
->dregs
+ DMA_TEST
);
950 /* Set mode and clear multicast filter only at device open,
951 * so that lance_init_ring() called at any error will not
952 * forget multicast filters.
954 * BTW it is common bug in all lance drivers! --ANK
956 if (lp
->pio_buffer
) {
957 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
958 sbus_writew(0, &ib
->mode
);
959 sbus_writel(0, &ib
->filter
[0]);
960 sbus_writel(0, &ib
->filter
[1]);
962 struct lance_init_block
*ib
= lp
->init_block_mem
;
971 netif_start_queue(dev
);
973 status
= init_restart_lance(lp
);
974 if (!status
&& lp
->auto_select
) {
975 build_fake_packet(lp
);
976 sbus_writew(LE_C0_INEA
| LE_C0_TDMD
, lp
->lregs
+ RDP
);
982 static int lance_close(struct net_device
*dev
)
984 struct lance_private
*lp
= netdev_priv(dev
);
986 netif_stop_queue(dev
);
987 del_timer_sync(&lp
->multicast_timer
);
991 free_irq(dev
->irq
, (void *) dev
);
995 static int lance_reset(struct net_device
*dev
)
997 struct lance_private
*lp
= netdev_priv(dev
);
1002 /* On the 4m, reset the dma too */
1006 printk(KERN_ERR
"resetting ledma\n");
1007 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
1008 sbus_writel(csr
| DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1010 sbus_writel(csr
& ~DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1012 addr
= lp
->init_block_dvma
& 0xff000000;
1013 sbus_writel(addr
, lp
->dregs
+ DMA_TEST
);
1017 dev
->trans_start
= jiffies
;
1018 status
= init_restart_lance(lp
);
1022 static void lance_piocopy_from_skb(void __iomem
*dest
, unsigned char *src
, int len
)
1024 void __iomem
*piobuf
= dest
;
1029 switch ((unsigned long)src
& 0x3) {
1033 sbus_writel(*p32
, piobuf
);
1050 sbus_writel(val
, piobuf
);
1060 u32 val
= p16
[0]<<16 | p16
[1];
1061 sbus_writel(val
, piobuf
);
1070 u16 val
= src
[0] << 8 | src
[1];
1071 sbus_writew(val
, piobuf
);
1077 sbus_writeb(src
[0], piobuf
);
1080 static void lance_piozero(void __iomem
*dest
, int len
)
1082 void __iomem
*piobuf
= dest
;
1084 if ((unsigned long)piobuf
& 1) {
1085 sbus_writeb(0, piobuf
);
1092 sbus_writeb(0, piobuf
);
1095 if ((unsigned long)piobuf
& 2) {
1096 sbus_writew(0, piobuf
);
1103 sbus_writel(0, piobuf
);
1108 sbus_writew(0, piobuf
);
1113 sbus_writeb(0, piobuf
);
1116 static void lance_tx_timeout(struct net_device
*dev
)
1118 struct lance_private
*lp
= netdev_priv(dev
);
1120 printk(KERN_ERR
"%s: transmit timed out, status %04x, reset\n",
1121 dev
->name
, sbus_readw(lp
->lregs
+ RDP
));
1123 netif_wake_queue(dev
);
1126 static int lance_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1128 struct lance_private
*lp
= netdev_priv(dev
);
1129 int entry
, skblen
, len
;
1133 len
= (skblen
<= ETH_ZLEN
) ? ETH_ZLEN
: skblen
;
1135 spin_lock_irq(&lp
->lock
);
1137 lp
->stats
.tx_bytes
+= len
;
1139 entry
= lp
->tx_new
& TX_RING_MOD_MASK
;
1140 if (lp
->pio_buffer
) {
1141 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
1142 sbus_writew((-len
) | 0xf000, &ib
->btx_ring
[entry
].length
);
1143 sbus_writew(0, &ib
->btx_ring
[entry
].misc
);
1144 lance_piocopy_from_skb(&ib
->tx_buf
[entry
][0], skb
->data
, skblen
);
1146 lance_piozero(&ib
->tx_buf
[entry
][skblen
], len
- skblen
);
1147 sbus_writeb(LE_T1_POK
| LE_T1_OWN
, &ib
->btx_ring
[entry
].tmd1_bits
);
1149 struct lance_init_block
*ib
= lp
->init_block_mem
;
1150 ib
->btx_ring
[entry
].length
= (-len
) | 0xf000;
1151 ib
->btx_ring
[entry
].misc
= 0;
1152 memcpy((char *)&ib
->tx_buf
[entry
][0], skb
->data
, skblen
);
1154 memset((char *) &ib
->tx_buf
[entry
][skblen
], 0, len
- skblen
);
1155 ib
->btx_ring
[entry
].tmd1_bits
= (LE_T1_POK
| LE_T1_OWN
);
1158 lp
->tx_new
= TX_NEXT(entry
);
1160 if (TX_BUFFS_AVAIL
<= 0)
1161 netif_stop_queue(dev
);
1163 /* Kick the lance: transmit now */
1164 sbus_writew(LE_C0_INEA
| LE_C0_TDMD
, lp
->lregs
+ RDP
);
1166 /* Read back CSR to invalidate the E-Cache.
1167 * This is needed, because DMA_DSBL_WR_INV is set.
1170 sbus_readw(lp
->lregs
+ RDP
);
1172 spin_unlock_irq(&lp
->lock
);
1174 dev
->trans_start
= jiffies
;
1180 static struct net_device_stats
*lance_get_stats(struct net_device
*dev
)
1182 struct lance_private
*lp
= netdev_priv(dev
);
1187 /* taken from the depca driver */
1188 static void lance_load_multicast(struct net_device
*dev
)
1190 struct lance_private
*lp
= netdev_priv(dev
);
1191 struct dev_mc_list
*dmi
= dev
->mc_list
;
1197 /* set all multicast bits */
1198 if (dev
->flags
& IFF_ALLMULTI
)
1203 if (lp
->pio_buffer
) {
1204 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
1205 sbus_writel(val
, &ib
->filter
[0]);
1206 sbus_writel(val
, &ib
->filter
[1]);
1208 struct lance_init_block
*ib
= lp
->init_block_mem
;
1209 ib
->filter
[0] = val
;
1210 ib
->filter
[1] = val
;
1213 if (dev
->flags
& IFF_ALLMULTI
)
1217 for (i
= 0; i
< dev
->mc_count
; i
++) {
1218 addrs
= dmi
->dmi_addr
;
1221 /* multicast address? */
1224 crc
= ether_crc_le(6, addrs
);
1226 if (lp
->pio_buffer
) {
1227 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
1228 u16 __iomem
*mcast_table
= (u16 __iomem
*) &ib
->filter
;
1229 u16 tmp
= sbus_readw(&mcast_table
[crc
>>4]);
1230 tmp
|= 1 << (crc
& 0xf);
1231 sbus_writew(tmp
, &mcast_table
[crc
>>4]);
1233 struct lance_init_block
*ib
= lp
->init_block_mem
;
1234 u16
*mcast_table
= (u16
*) &ib
->filter
;
1235 mcast_table
[crc
>> 4] |= 1 << (crc
& 0xf);
1240 static void lance_set_multicast(struct net_device
*dev
)
1242 struct lance_private
*lp
= netdev_priv(dev
);
1243 struct lance_init_block
*ib_mem
= lp
->init_block_mem
;
1244 struct lance_init_block __iomem
*ib_iomem
= lp
->init_block_iomem
;
1247 if (!netif_running(dev
))
1250 if (lp
->tx_old
!= lp
->tx_new
) {
1251 mod_timer(&lp
->multicast_timer
, jiffies
+ 4);
1252 netif_wake_queue(dev
);
1256 netif_stop_queue(dev
);
1262 mode
= sbus_readw(&ib_iomem
->mode
);
1264 mode
= ib_mem
->mode
;
1265 if (dev
->flags
& IFF_PROMISC
) {
1268 sbus_writew(mode
, &ib_iomem
->mode
);
1270 ib_mem
->mode
= mode
;
1272 mode
&= ~LE_MO_PROM
;
1274 sbus_writew(mode
, &ib_iomem
->mode
);
1276 ib_mem
->mode
= mode
;
1277 lance_load_multicast(dev
);
1280 init_restart_lance(lp
);
1281 netif_wake_queue(dev
);
1284 static void lance_set_multicast_retry(unsigned long _opaque
)
1286 struct net_device
*dev
= (struct net_device
*) _opaque
;
1288 lance_set_multicast(dev
);
1291 static void lance_free_hwresources(struct lance_private
*lp
)
1294 sbus_iounmap(lp
->lregs
, LANCE_REG_SIZE
);
1295 if (lp
->init_block_iomem
) {
1296 sbus_iounmap(lp
->init_block_iomem
,
1297 sizeof(struct lance_init_block
));
1298 } else if (lp
->init_block_mem
) {
1299 sbus_free_consistent(lp
->sdev
,
1300 sizeof(struct lance_init_block
),
1302 lp
->init_block_dvma
);
1306 /* Ethtool support... */
1307 static void sparc_lance_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1309 struct lance_private
*lp
= netdev_priv(dev
);
1311 strcpy(info
->driver
, "sunlance");
1312 strcpy(info
->version
, "2.02");
1313 sprintf(info
->bus_info
, "SBUS:%d",
1317 static u32
sparc_lance_get_link(struct net_device
*dev
)
1319 /* We really do not keep track of this, but this
1320 * is better than not reporting anything at all.
1325 static struct ethtool_ops sparc_lance_ethtool_ops
= {
1326 .get_drvinfo
= sparc_lance_get_drvinfo
,
1327 .get_link
= sparc_lance_get_link
,
1330 static int __init
sparc_lance_init(struct sbus_dev
*sdev
,
1331 struct sbus_dma
*ledma
,
1332 struct sbus_dev
*lebuffer
)
1334 static unsigned version_printed
;
1335 struct net_device
*dev
;
1336 struct lance_private
*lp
;
1339 dev
= alloc_etherdev(sizeof(struct lance_private
) + 8);
1343 lp
= netdev_priv(dev
);
1344 memset(lp
, 0, sizeof(*lp
));
1346 if (sparc_lance_debug
&& version_printed
++ == 0)
1347 printk (KERN_INFO
"%s", version
);
1349 spin_lock_init(&lp
->lock
);
1351 /* Copy the IDPROM ethernet address to the device structure, later we
1352 * will copy the address in the device structure to the lance
1353 * initialization block.
1355 for (i
= 0; i
< 6; i
++)
1356 dev
->dev_addr
[i
] = idprom
->id_ethaddr
[i
];
1358 /* Get the IO region */
1359 lp
->lregs
= sbus_ioremap(&sdev
->resource
[0], 0,
1360 LANCE_REG_SIZE
, lancestr
);
1362 printk(KERN_ERR
"SunLance: Cannot map registers.\n");
1369 if (lebuffer
->resource
[0].start
& 7) {
1370 printk(KERN_ERR
"SunLance: ERROR: Rx and Tx rings not on even boundary.\n");
1373 lp
->init_block_iomem
=
1374 sbus_ioremap(&lebuffer
->resource
[0], 0,
1375 sizeof(struct lance_init_block
), "lebuffer");
1376 if (!lp
->init_block_iomem
) {
1377 printk(KERN_ERR
"SunLance: Cannot map PIO buffer.\n");
1380 lp
->init_block_dvma
= 0;
1382 lp
->init_ring
= lance_init_ring_pio
;
1383 lp
->rx
= lance_rx_pio
;
1384 lp
->tx
= lance_tx_pio
;
1386 lp
->init_block_mem
=
1387 sbus_alloc_consistent(sdev
, sizeof(struct lance_init_block
),
1388 &lp
->init_block_dvma
);
1389 if (!lp
->init_block_mem
|| lp
->init_block_dvma
== 0) {
1390 printk(KERN_ERR
"SunLance: Cannot allocate consistent DMA memory.\n");
1394 lp
->init_ring
= lance_init_ring_dvma
;
1395 lp
->rx
= lance_rx_dvma
;
1396 lp
->tx
= lance_tx_dvma
;
1398 lp
->busmaster_regval
= prom_getintdefault(sdev
->prom_node
,
1400 (LE_C3_BSWP
| LE_C3_ACON
|
1403 lp
->name
= lancestr
;
1406 lp
->burst_sizes
= 0;
1409 unsigned int sbmask
;
1412 /* Find burst-size property for ledma */
1413 lp
->burst_sizes
= prom_getintdefault(ledma
->sdev
->prom_node
,
1416 /* ledma may be capable of fast bursts, but sbus may not. */
1417 sbmask
= prom_getintdefault(ledma
->sdev
->bus
->prom_node
,
1418 "burst-sizes", DMA_BURSTBITS
);
1419 lp
->burst_sizes
&= sbmask
;
1421 /* Get the cable-selection property */
1422 memset(prop
, 0, sizeof(prop
));
1423 prom_getstring(ledma
->sdev
->prom_node
, "cable-selection",
1424 prop
, sizeof(prop
));
1428 printk(KERN_INFO
"SunLance: using auto-carrier-detection.\n");
1430 /* Is this found at /options .attributes in all
1431 * Prom versions? XXX
1433 topnd
= prom_getchild(prom_root_node
);
1435 nd
= prom_searchsiblings(topnd
, "options");
1439 if (!prom_node_has_property(nd
, "tpe-link-test?"))
1442 memset(prop
, 0, sizeof(prop
));
1443 prom_getstring(nd
, "tpe-link-test?", prop
,
1446 if (strcmp(prop
, "true")) {
1447 printk(KERN_NOTICE
"SunLance: warning: overriding option "
1448 "'tpe-link-test?'\n");
1449 printk(KERN_NOTICE
"SunLance: warning: mail any problems "
1450 "to ecd@skynet.be\n");
1451 auxio_set_lte(AUXIO_LTE_ON
);
1454 lp
->auto_select
= 1;
1456 } else if (!strcmp(prop
, "aui")) {
1457 lp
->auto_select
= 0;
1460 lp
->auto_select
= 0;
1464 lp
->dregs
= ledma
->regs
;
1467 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
1468 sbus_writel(csr
| DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1470 sbus_writel(csr
& ~DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1475 SET_MODULE_OWNER(dev
);
1476 dev
->open
= &lance_open
;
1477 dev
->stop
= &lance_close
;
1478 dev
->hard_start_xmit
= &lance_start_xmit
;
1479 dev
->tx_timeout
= &lance_tx_timeout
;
1480 dev
->watchdog_timeo
= 5*HZ
;
1481 dev
->get_stats
= &lance_get_stats
;
1482 dev
->set_multicast_list
= &lance_set_multicast
;
1483 dev
->ethtool_ops
= &sparc_lance_ethtool_ops
;
1485 dev
->irq
= sdev
->irqs
[0];
1489 /* We cannot sleep if the chip is busy during a
1490 * multicast list update event, because such events
1491 * can occur from interrupts (ex. IPv6). So we
1492 * use a timer to try again later when necessary. -DaveM
1494 init_timer(&lp
->multicast_timer
);
1495 lp
->multicast_timer
.data
= (unsigned long) dev
;
1496 lp
->multicast_timer
.function
= &lance_set_multicast_retry
;
1498 if (register_netdev(dev
)) {
1499 printk(KERN_ERR
"SunLance: Cannot register device.\n");
1503 lp
->next_module
= root_lance_dev
;
1504 root_lance_dev
= lp
;
1506 printk(KERN_INFO
"%s: LANCE ", dev
->name
);
1508 for (i
= 0; i
< 6; i
++)
1509 printk("%2.2x%c", dev
->dev_addr
[i
],
1516 lance_free_hwresources(lp
);
1521 /* On 4m, find the associated dma for the lance chip */
1522 static inline struct sbus_dma
*find_ledma(struct sbus_dev
*sdev
)
1527 if (p
->sdev
== sdev
)
1535 #include <asm/sun4paddr.h>
1536 #include <asm/machines.h>
1538 /* Find all the lance cards on the system and initialize them */
1539 static int __init
sparc_lance_probe(void)
1541 static struct sbus_dev sdev
;
1544 root_lance_dev
= NULL
;
1550 if ((idprom
->id_machtype
== (SM_SUN4
|SM_4_330
)) ||
1551 (idprom
->id_machtype
== (SM_SUN4
|SM_4_470
))) {
1552 memset(&sdev
, 0, sizeof(sdev
));
1553 sdev
.reg_addrs
[0].phys_addr
= sun4_eth_physaddr
;
1555 return sparc_lance_init(&sdev
, NULL
, NULL
);
1560 #else /* !CONFIG_SUN4 */
1562 /* Find all the lance cards on the system and initialize them */
1563 static int __init
sparc_lance_probe(void)
1565 struct sbus_bus
*bus
;
1566 struct sbus_dev
*sdev
= NULL
;
1567 struct sbus_dma
*ledma
= NULL
;
1571 root_lance_dev
= NULL
;
1577 for_each_sbus (bus
) {
1578 for_each_sbusdev (sdev
, bus
) {
1579 if (strcmp(sdev
->prom_name
, "le") == 0) {
1581 if ((v
= sparc_lance_init(sdev
, NULL
, NULL
)))
1585 if (strcmp(sdev
->prom_name
, "ledma") == 0) {
1587 ledma
= find_ledma(sdev
);
1588 if ((v
= sparc_lance_init(sdev
->child
,
1593 if (strcmp(sdev
->prom_name
, "lebuffer") == 0){
1595 if ((v
= sparc_lance_init(sdev
->child
,
1600 } /* for each sbusdev */
1601 } /* for each sbus */
1606 #endif /* !CONFIG_SUN4 */
1608 static void __exit
sparc_lance_cleanup(void)
1610 struct lance_private
*lp
;
1612 while (root_lance_dev
) {
1613 lp
= root_lance_dev
->next_module
;
1615 unregister_netdev(root_lance_dev
->dev
);
1616 lance_free_hwresources(root_lance_dev
);
1617 free_netdev(root_lance_dev
->dev
);
1618 root_lance_dev
= lp
;
1622 module_init(sparc_lance_probe
);
1623 module_exit(sparc_lance_cleanup
);