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.02 24/Aug/03 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>
96 #include <linux/ethtool.h>
97 #include <linux/bitops.h>
99 #include <asm/system.h>
102 #include <asm/pgtable.h>
103 #include <asm/byteorder.h> /* Used by the checksum routines */
104 #include <asm/idprom.h>
105 #include <asm/sbus.h>
106 #include <asm/openprom.h>
107 #include <asm/oplib.h>
108 #include <asm/auxio.h> /* For tpe-link-test? setting */
111 /* Define: 2^4 Tx buffers and 2^4 Rx buffers */
112 #ifndef LANCE_LOG_TX_BUFFERS
113 #define LANCE_LOG_TX_BUFFERS 4
114 #define LANCE_LOG_RX_BUFFERS 4
122 #define LE_MO_PROM 0x8000 /* Enable promiscuous mode */
124 #define LE_C0_ERR 0x8000 /* Error: set if BAB, SQE, MISS or ME is set */
125 #define LE_C0_BABL 0x4000 /* BAB: Babble: tx timeout. */
126 #define LE_C0_CERR 0x2000 /* SQE: Signal quality error */
127 #define LE_C0_MISS 0x1000 /* MISS: Missed a packet */
128 #define LE_C0_MERR 0x0800 /* ME: Memory error */
129 #define LE_C0_RINT 0x0400 /* Received interrupt */
130 #define LE_C0_TINT 0x0200 /* Transmitter Interrupt */
131 #define LE_C0_IDON 0x0100 /* IFIN: Init finished. */
132 #define LE_C0_INTR 0x0080 /* Interrupt or error */
133 #define LE_C0_INEA 0x0040 /* Interrupt enable */
134 #define LE_C0_RXON 0x0020 /* Receiver on */
135 #define LE_C0_TXON 0x0010 /* Transmitter on */
136 #define LE_C0_TDMD 0x0008 /* Transmitter demand */
137 #define LE_C0_STOP 0x0004 /* Stop the card */
138 #define LE_C0_STRT 0x0002 /* Start the card */
139 #define LE_C0_INIT 0x0001 /* Init the card */
141 #define LE_C3_BSWP 0x4 /* SWAP */
142 #define LE_C3_ACON 0x2 /* ALE Control */
143 #define LE_C3_BCON 0x1 /* Byte control */
145 /* Receive message descriptor 1 */
146 #define LE_R1_OWN 0x80 /* Who owns the entry */
147 #define LE_R1_ERR 0x40 /* Error: if FRA, OFL, CRC or BUF is set */
148 #define LE_R1_FRA 0x20 /* FRA: Frame error */
149 #define LE_R1_OFL 0x10 /* OFL: Frame overflow */
150 #define LE_R1_CRC 0x08 /* CRC error */
151 #define LE_R1_BUF 0x04 /* BUF: Buffer error */
152 #define LE_R1_SOP 0x02 /* Start of packet */
153 #define LE_R1_EOP 0x01 /* End of packet */
154 #define LE_R1_POK 0x03 /* Packet is complete: SOP + EOP */
156 #define LE_T1_OWN 0x80 /* Lance owns the packet */
157 #define LE_T1_ERR 0x40 /* Error summary */
158 #define LE_T1_EMORE 0x10 /* Error: more than one retry needed */
159 #define LE_T1_EONE 0x08 /* Error: one retry needed */
160 #define LE_T1_EDEF 0x04 /* Error: deferred */
161 #define LE_T1_SOP 0x02 /* Start of packet */
162 #define LE_T1_EOP 0x01 /* End of packet */
163 #define LE_T1_POK 0x03 /* Packet is complete: SOP + EOP */
165 #define LE_T3_BUF 0x8000 /* Buffer error */
166 #define LE_T3_UFL 0x4000 /* Error underflow */
167 #define LE_T3_LCOL 0x1000 /* Error late collision */
168 #define LE_T3_CLOS 0x0800 /* Error carrier loss */
169 #define LE_T3_RTY 0x0400 /* Error retry */
170 #define LE_T3_TDR 0x03ff /* Time Domain Reflectometry counter */
172 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
173 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
174 #define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29)
175 #define TX_NEXT(__x) (((__x)+1) & TX_RING_MOD_MASK)
177 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
178 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
179 #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29)
180 #define RX_NEXT(__x) (((__x)+1) & RX_RING_MOD_MASK)
182 #define PKT_BUF_SZ 1544
183 #define RX_BUFF_SIZE PKT_BUF_SZ
184 #define TX_BUFF_SIZE PKT_BUF_SZ
186 struct lance_rx_desc
{
187 u16 rmd0
; /* low address of packet */
188 u8 rmd1_bits
; /* descriptor bits */
189 u8 rmd1_hadr
; /* high address of packet */
190 s16 length
; /* This length is 2s complement (negative)!
193 u16 mblength
; /* This is the actual number of bytes received */
196 struct lance_tx_desc
{
197 u16 tmd0
; /* low address of packet */
198 u8 tmd1_bits
; /* descriptor bits */
199 u8 tmd1_hadr
; /* high address of packet */
200 s16 length
; /* Length is 2s complement (negative)! */
204 /* The LANCE initialization block, described in databook. */
205 /* On the Sparc, this block should be on a DMA region */
206 struct lance_init_block
{
207 u16 mode
; /* Pre-set mode (reg. 15) */
208 u8 phys_addr
[6]; /* Physical ethernet address */
209 u32 filter
[2]; /* Multicast filter. */
211 /* Receive and transmit ring base, along with extra bits. */
212 u16 rx_ptr
; /* receive descriptor addr */
213 u16 rx_len
; /* receive len and high addr */
214 u16 tx_ptr
; /* transmit descriptor addr */
215 u16 tx_len
; /* transmit len and high addr */
217 /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
218 struct lance_rx_desc brx_ring
[RX_RING_SIZE
];
219 struct lance_tx_desc btx_ring
[TX_RING_SIZE
];
221 u8 tx_buf
[TX_RING_SIZE
][TX_BUFF_SIZE
];
222 u8 pad
[2]; /* align rx_buf for copy_and_sum(). */
223 u8 rx_buf
[RX_RING_SIZE
][RX_BUFF_SIZE
];
226 #define libdesc_offset(rt, elem) \
227 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem])))))
229 #define libbuff_offset(rt, elem) \
230 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem][0])))))
232 struct lance_private
{
233 void __iomem
*lregs
; /* Lance RAP/RDP regs. */
234 void __iomem
*dregs
; /* DMA controller regs. */
235 struct lance_init_block __iomem
*init_block_iomem
;
236 struct lance_init_block
*init_block_mem
;
243 struct net_device_stats stats
;
244 struct sbus_dma
*ledma
; /* If set this points to ledma */
245 char tpe
; /* cable-selection is TPE */
246 char auto_select
; /* cable-selection by carrier */
247 char burst_sizes
; /* ledma SBus burst sizes */
248 char pio_buffer
; /* init block in PIO space? */
250 unsigned short busmaster_regval
;
252 void (*init_ring
)(struct net_device
*);
253 void (*rx
)(struct net_device
*);
254 void (*tx
)(struct net_device
*);
257 dma_addr_t init_block_dvma
;
258 struct net_device
*dev
; /* Backpointer */
259 struct lance_private
*next_module
;
260 struct sbus_dev
*sdev
;
261 struct timer_list multicast_timer
;
264 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
265 lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\
266 lp->tx_old - lp->tx_new-1)
268 /* Lance registers. */
269 #define RDP 0x00UL /* register data port */
270 #define RAP 0x02UL /* register address port */
271 #define LANCE_REG_SIZE 0x04UL
273 #define STOP_LANCE(__lp) \
274 do { void __iomem *__base = (__lp)->lregs; \
275 sbus_writew(LE_CSR0, __base + RAP); \
276 sbus_writew(LE_C0_STOP, __base + RDP); \
279 int sparc_lance_debug
= 2;
281 /* The Lance uses 24 bit addresses */
282 /* On the Sun4c the DVMA will provide the remaining bytes for us */
283 /* On the Sun4m we have to instruct the ledma to provide them */
284 /* Even worse, on scsi/ether SBUS cards, the init block and the
285 * transmit/receive buffers are addresses as offsets from absolute
286 * zero on the lebuffer PIO area. -DaveM
289 #define LANCE_ADDR(x) ((long)(x) & ~0xff000000)
291 static struct lance_private
*root_lance_dev
;
293 /* Load the CSR registers */
294 static void load_csrs(struct lance_private
*lp
)
301 leptr
= LANCE_ADDR(lp
->init_block_dvma
);
303 sbus_writew(LE_CSR1
, lp
->lregs
+ RAP
);
304 sbus_writew(leptr
& 0xffff, lp
->lregs
+ RDP
);
305 sbus_writew(LE_CSR2
, lp
->lregs
+ RAP
);
306 sbus_writew(leptr
>> 16, lp
->lregs
+ RDP
);
307 sbus_writew(LE_CSR3
, lp
->lregs
+ RAP
);
308 sbus_writew(lp
->busmaster_regval
, lp
->lregs
+ RDP
);
310 /* Point back to csr0 */
311 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
314 /* Setup the Lance Rx and Tx rings */
315 static void lance_init_ring_dvma(struct net_device
*dev
)
317 struct lance_private
*lp
= netdev_priv(dev
);
318 struct lance_init_block
*ib
= lp
->init_block_mem
;
319 dma_addr_t aib
= lp
->init_block_dvma
;
323 /* Lock out other processes while setting up hardware */
324 netif_stop_queue(dev
);
325 lp
->rx_new
= lp
->tx_new
= 0;
326 lp
->rx_old
= lp
->tx_old
= 0;
328 /* Copy the ethernet address to the lance init block
329 * Note that on the sparc you need to swap the ethernet address.
331 ib
->phys_addr
[0] = dev
->dev_addr
[1];
332 ib
->phys_addr
[1] = dev
->dev_addr
[0];
333 ib
->phys_addr
[2] = dev
->dev_addr
[3];
334 ib
->phys_addr
[3] = dev
->dev_addr
[2];
335 ib
->phys_addr
[4] = dev
->dev_addr
[5];
336 ib
->phys_addr
[5] = dev
->dev_addr
[4];
338 /* Setup the Tx ring entries */
339 for (i
= 0; i
<= TX_RING_SIZE
; i
++) {
340 leptr
= LANCE_ADDR(aib
+ libbuff_offset(tx_buf
, i
));
341 ib
->btx_ring
[i
].tmd0
= leptr
;
342 ib
->btx_ring
[i
].tmd1_hadr
= leptr
>> 16;
343 ib
->btx_ring
[i
].tmd1_bits
= 0;
344 ib
->btx_ring
[i
].length
= 0xf000; /* The ones required by tmd2 */
345 ib
->btx_ring
[i
].misc
= 0;
348 /* Setup the Rx ring entries */
349 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
350 leptr
= LANCE_ADDR(aib
+ libbuff_offset(rx_buf
, i
));
352 ib
->brx_ring
[i
].rmd0
= leptr
;
353 ib
->brx_ring
[i
].rmd1_hadr
= leptr
>> 16;
354 ib
->brx_ring
[i
].rmd1_bits
= LE_R1_OWN
;
355 ib
->brx_ring
[i
].length
= -RX_BUFF_SIZE
| 0xf000;
356 ib
->brx_ring
[i
].mblength
= 0;
359 /* Setup the initialization block */
361 /* Setup rx descriptor pointer */
362 leptr
= LANCE_ADDR(aib
+ libdesc_offset(brx_ring
, 0));
363 ib
->rx_len
= (LANCE_LOG_RX_BUFFERS
<< 13) | (leptr
>> 16);
366 /* Setup tx descriptor pointer */
367 leptr
= LANCE_ADDR(aib
+ libdesc_offset(btx_ring
, 0));
368 ib
->tx_len
= (LANCE_LOG_TX_BUFFERS
<< 13) | (leptr
>> 16);
372 static void lance_init_ring_pio(struct net_device
*dev
)
374 struct lance_private
*lp
= netdev_priv(dev
);
375 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
379 /* Lock out other processes while setting up hardware */
380 netif_stop_queue(dev
);
381 lp
->rx_new
= lp
->tx_new
= 0;
382 lp
->rx_old
= lp
->tx_old
= 0;
384 /* Copy the ethernet address to the lance init block
385 * Note that on the sparc you need to swap the ethernet address.
387 sbus_writeb(dev
->dev_addr
[1], &ib
->phys_addr
[0]);
388 sbus_writeb(dev
->dev_addr
[0], &ib
->phys_addr
[1]);
389 sbus_writeb(dev
->dev_addr
[3], &ib
->phys_addr
[2]);
390 sbus_writeb(dev
->dev_addr
[2], &ib
->phys_addr
[3]);
391 sbus_writeb(dev
->dev_addr
[5], &ib
->phys_addr
[4]);
392 sbus_writeb(dev
->dev_addr
[4], &ib
->phys_addr
[5]);
394 /* Setup the Tx ring entries */
395 for (i
= 0; i
<= TX_RING_SIZE
; i
++) {
396 leptr
= libbuff_offset(tx_buf
, i
);
397 sbus_writew(leptr
, &ib
->btx_ring
[i
].tmd0
);
398 sbus_writeb(leptr
>> 16,&ib
->btx_ring
[i
].tmd1_hadr
);
399 sbus_writeb(0, &ib
->btx_ring
[i
].tmd1_bits
);
401 /* The ones required by tmd2 */
402 sbus_writew(0xf000, &ib
->btx_ring
[i
].length
);
403 sbus_writew(0, &ib
->btx_ring
[i
].misc
);
406 /* Setup the Rx ring entries */
407 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
408 leptr
= libbuff_offset(rx_buf
, i
);
410 sbus_writew(leptr
, &ib
->brx_ring
[i
].rmd0
);
411 sbus_writeb(leptr
>> 16,&ib
->brx_ring
[i
].rmd1_hadr
);
412 sbus_writeb(LE_R1_OWN
, &ib
->brx_ring
[i
].rmd1_bits
);
413 sbus_writew(-RX_BUFF_SIZE
|0xf000,
414 &ib
->brx_ring
[i
].length
);
415 sbus_writew(0, &ib
->brx_ring
[i
].mblength
);
418 /* Setup the initialization block */
420 /* Setup rx descriptor pointer */
421 leptr
= libdesc_offset(brx_ring
, 0);
422 sbus_writew((LANCE_LOG_RX_BUFFERS
<< 13) | (leptr
>> 16),
424 sbus_writew(leptr
, &ib
->rx_ptr
);
426 /* Setup tx descriptor pointer */
427 leptr
= libdesc_offset(btx_ring
, 0);
428 sbus_writew((LANCE_LOG_TX_BUFFERS
<< 13) | (leptr
>> 16),
430 sbus_writew(leptr
, &ib
->tx_ptr
);
433 static void init_restart_ledma(struct lance_private
*lp
)
435 u32 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
437 if (!(csr
& DMA_HNDL_ERROR
)) {
438 /* E-Cache draining */
439 while (sbus_readl(lp
->dregs
+ DMA_CSR
) & DMA_FIFO_ISDRAIN
)
443 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
444 csr
&= ~DMA_E_BURSTS
;
445 if (lp
->burst_sizes
& DMA_BURST32
)
446 csr
|= DMA_E_BURST32
;
448 csr
|= DMA_E_BURST16
;
450 csr
|= (DMA_DSBL_RD_DRN
| DMA_DSBL_WR_INV
| DMA_FIFO_INV
);
453 csr
|= DMA_EN_ENETAUI
;
455 csr
&= ~DMA_EN_ENETAUI
;
457 sbus_writel(csr
, lp
->dregs
+ DMA_CSR
);
461 static int init_restart_lance(struct lance_private
*lp
)
467 init_restart_ledma(lp
);
469 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
470 sbus_writew(LE_C0_INIT
, lp
->lregs
+ RDP
);
472 /* Wait for the lance to complete initialization */
473 for (i
= 0; i
< 100; i
++) {
474 regval
= sbus_readw(lp
->lregs
+ RDP
);
476 if (regval
& (LE_C0_ERR
| LE_C0_IDON
))
480 if (i
== 100 || (regval
& LE_C0_ERR
)) {
481 printk(KERN_ERR
"LANCE unopened after %d ticks, csr0=%4.4x.\n",
484 printk("dcsr=%8.8x\n", sbus_readl(lp
->dregs
+ DMA_CSR
));
488 /* Clear IDON by writing a "1", enable interrupts and start lance */
489 sbus_writew(LE_C0_IDON
, lp
->lregs
+ RDP
);
490 sbus_writew(LE_C0_INEA
| LE_C0_STRT
, lp
->lregs
+ RDP
);
493 u32 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
496 sbus_writel(csr
, lp
->dregs
+ DMA_CSR
);
502 static void lance_rx_dvma(struct net_device
*dev
)
504 struct lance_private
*lp
= netdev_priv(dev
);
505 struct lance_init_block
*ib
= lp
->init_block_mem
;
506 struct lance_rx_desc
*rd
;
508 int len
, entry
= lp
->rx_new
;
511 for (rd
= &ib
->brx_ring
[entry
];
512 !((bits
= rd
->rmd1_bits
) & LE_R1_OWN
);
513 rd
= &ib
->brx_ring
[entry
]) {
515 /* We got an incomplete frame? */
516 if ((bits
& LE_R1_POK
) != LE_R1_POK
) {
517 lp
->stats
.rx_over_errors
++;
518 lp
->stats
.rx_errors
++;
519 } else if (bits
& LE_R1_ERR
) {
520 /* Count only the end frame as a rx error,
523 if (bits
& LE_R1_BUF
) lp
->stats
.rx_fifo_errors
++;
524 if (bits
& LE_R1_CRC
) lp
->stats
.rx_crc_errors
++;
525 if (bits
& LE_R1_OFL
) lp
->stats
.rx_over_errors
++;
526 if (bits
& LE_R1_FRA
) lp
->stats
.rx_frame_errors
++;
527 if (bits
& LE_R1_EOP
) lp
->stats
.rx_errors
++;
529 len
= (rd
->mblength
& 0xfff) - 4;
530 skb
= dev_alloc_skb(len
+ 2);
533 printk(KERN_INFO
"%s: Memory squeeze, deferring packet.\n",
535 lp
->stats
.rx_dropped
++;
537 rd
->rmd1_bits
= LE_R1_OWN
;
538 lp
->rx_new
= RX_NEXT(entry
);
542 lp
->stats
.rx_bytes
+= len
;
545 skb_reserve(skb
, 2); /* 16 byte align */
546 skb_put(skb
, len
); /* make room */
547 eth_copy_and_sum(skb
,
548 (unsigned char *)&(ib
->rx_buf
[entry
][0]),
550 skb
->protocol
= eth_type_trans(skb
, dev
);
552 dev
->last_rx
= jiffies
;
553 lp
->stats
.rx_packets
++;
556 /* Return the packet to the pool */
558 rd
->rmd1_bits
= LE_R1_OWN
;
559 entry
= RX_NEXT(entry
);
565 static void lance_tx_dvma(struct net_device
*dev
)
567 struct lance_private
*lp
= netdev_priv(dev
);
568 struct lance_init_block
*ib
= lp
->init_block_mem
;
571 spin_lock(&lp
->lock
);
574 for (i
= j
; i
!= lp
->tx_new
; i
= j
) {
575 struct lance_tx_desc
*td
= &ib
->btx_ring
[i
];
576 u8 bits
= td
->tmd1_bits
;
578 /* If we hit a packet not owned by us, stop */
579 if (bits
& LE_T1_OWN
)
582 if (bits
& LE_T1_ERR
) {
583 u16 status
= td
->misc
;
585 lp
->stats
.tx_errors
++;
586 if (status
& LE_T3_RTY
) lp
->stats
.tx_aborted_errors
++;
587 if (status
& LE_T3_LCOL
) lp
->stats
.tx_window_errors
++;
589 if (status
& LE_T3_CLOS
) {
590 lp
->stats
.tx_carrier_errors
++;
591 if (lp
->auto_select
) {
592 lp
->tpe
= 1 - lp
->tpe
;
593 printk(KERN_NOTICE
"%s: Carrier Lost, trying %s\n",
594 dev
->name
, lp
->tpe
?"TPE":"AUI");
598 init_restart_lance(lp
);
603 /* Buffer errors and underflows turn off the
604 * transmitter, restart the adapter.
606 if (status
& (LE_T3_BUF
|LE_T3_UFL
)) {
607 lp
->stats
.tx_fifo_errors
++;
609 printk(KERN_ERR
"%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
614 init_restart_lance(lp
);
617 } else if ((bits
& LE_T1_POK
) == LE_T1_POK
) {
619 * So we don't count the packet more than once.
621 td
->tmd1_bits
= bits
& ~(LE_T1_POK
);
623 /* One collision before packet was sent. */
624 if (bits
& LE_T1_EONE
)
625 lp
->stats
.collisions
++;
627 /* More than one collision, be optimistic. */
628 if (bits
& LE_T1_EMORE
)
629 lp
->stats
.collisions
+= 2;
631 lp
->stats
.tx_packets
++;
638 if (netif_queue_stopped(dev
) &&
640 netif_wake_queue(dev
);
642 spin_unlock(&lp
->lock
);
645 static void lance_piocopy_to_skb(struct sk_buff
*skb
, void __iomem
*piobuf
, int len
)
647 u16
*p16
= (u16
*) skb
->data
;
650 void __iomem
*pbuf
= piobuf
;
652 /* We know here that both src and dest are on a 16bit boundary. */
653 *p16
++ = sbus_readw(pbuf
);
659 *p32
++ = sbus_readl(pbuf
);
666 *p16
++ = sbus_readw(pbuf
);
672 *p8
= sbus_readb(pbuf
);
675 static void lance_rx_pio(struct net_device
*dev
)
677 struct lance_private
*lp
= netdev_priv(dev
);
678 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
679 struct lance_rx_desc __iomem
*rd
;
685 for (rd
= &ib
->brx_ring
[entry
];
686 !((bits
= sbus_readb(&rd
->rmd1_bits
)) & LE_R1_OWN
);
687 rd
= &ib
->brx_ring
[entry
]) {
689 /* We got an incomplete frame? */
690 if ((bits
& LE_R1_POK
) != LE_R1_POK
) {
691 lp
->stats
.rx_over_errors
++;
692 lp
->stats
.rx_errors
++;
693 } else if (bits
& LE_R1_ERR
) {
694 /* Count only the end frame as a rx error,
697 if (bits
& LE_R1_BUF
) lp
->stats
.rx_fifo_errors
++;
698 if (bits
& LE_R1_CRC
) lp
->stats
.rx_crc_errors
++;
699 if (bits
& LE_R1_OFL
) lp
->stats
.rx_over_errors
++;
700 if (bits
& LE_R1_FRA
) lp
->stats
.rx_frame_errors
++;
701 if (bits
& LE_R1_EOP
) lp
->stats
.rx_errors
++;
703 len
= (sbus_readw(&rd
->mblength
) & 0xfff) - 4;
704 skb
= dev_alloc_skb(len
+ 2);
707 printk(KERN_INFO
"%s: Memory squeeze, deferring packet.\n",
709 lp
->stats
.rx_dropped
++;
710 sbus_writew(0, &rd
->mblength
);
711 sbus_writeb(LE_R1_OWN
, &rd
->rmd1_bits
);
712 lp
->rx_new
= RX_NEXT(entry
);
716 lp
->stats
.rx_bytes
+= len
;
719 skb_reserve (skb
, 2); /* 16 byte align */
720 skb_put(skb
, len
); /* make room */
721 lance_piocopy_to_skb(skb
, &(ib
->rx_buf
[entry
][0]), len
);
722 skb
->protocol
= eth_type_trans(skb
, dev
);
724 dev
->last_rx
= jiffies
;
725 lp
->stats
.rx_packets
++;
728 /* Return the packet to the pool */
729 sbus_writew(0, &rd
->mblength
);
730 sbus_writeb(LE_R1_OWN
, &rd
->rmd1_bits
);
731 entry
= RX_NEXT(entry
);
737 static void lance_tx_pio(struct net_device
*dev
)
739 struct lance_private
*lp
= netdev_priv(dev
);
740 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
743 spin_lock(&lp
->lock
);
746 for (i
= j
; i
!= lp
->tx_new
; i
= j
) {
747 struct lance_tx_desc __iomem
*td
= &ib
->btx_ring
[i
];
748 u8 bits
= sbus_readb(&td
->tmd1_bits
);
750 /* If we hit a packet not owned by us, stop */
751 if (bits
& LE_T1_OWN
)
754 if (bits
& LE_T1_ERR
) {
755 u16 status
= sbus_readw(&td
->misc
);
757 lp
->stats
.tx_errors
++;
758 if (status
& LE_T3_RTY
) lp
->stats
.tx_aborted_errors
++;
759 if (status
& LE_T3_LCOL
) lp
->stats
.tx_window_errors
++;
761 if (status
& LE_T3_CLOS
) {
762 lp
->stats
.tx_carrier_errors
++;
763 if (lp
->auto_select
) {
764 lp
->tpe
= 1 - lp
->tpe
;
765 printk(KERN_NOTICE
"%s: Carrier Lost, trying %s\n",
766 dev
->name
, lp
->tpe
?"TPE":"AUI");
770 init_restart_lance(lp
);
775 /* Buffer errors and underflows turn off the
776 * transmitter, restart the adapter.
778 if (status
& (LE_T3_BUF
|LE_T3_UFL
)) {
779 lp
->stats
.tx_fifo_errors
++;
781 printk(KERN_ERR
"%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
786 init_restart_lance(lp
);
789 } else if ((bits
& LE_T1_POK
) == LE_T1_POK
) {
791 * So we don't count the packet more than once.
793 sbus_writeb(bits
& ~(LE_T1_POK
), &td
->tmd1_bits
);
795 /* One collision before packet was sent. */
796 if (bits
& LE_T1_EONE
)
797 lp
->stats
.collisions
++;
799 /* More than one collision, be optimistic. */
800 if (bits
& LE_T1_EMORE
)
801 lp
->stats
.collisions
+= 2;
803 lp
->stats
.tx_packets
++;
810 if (netif_queue_stopped(dev
) &&
812 netif_wake_queue(dev
);
814 spin_unlock(&lp
->lock
);
817 static irqreturn_t
lance_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
819 struct net_device
*dev
= (struct net_device
*)dev_id
;
820 struct lance_private
*lp
= netdev_priv(dev
);
823 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
824 csr0
= sbus_readw(lp
->lregs
+ RDP
);
826 /* Acknowledge all the interrupt sources ASAP */
827 sbus_writew(csr0
& (LE_C0_INTR
| LE_C0_TINT
| LE_C0_RINT
),
830 if ((csr0
& LE_C0_ERR
) != 0) {
831 /* Clear the error condition */
832 sbus_writew((LE_C0_BABL
| LE_C0_ERR
| LE_C0_MISS
|
833 LE_C0_CERR
| LE_C0_MERR
),
837 if (csr0
& LE_C0_RINT
)
840 if (csr0
& LE_C0_TINT
)
843 if (csr0
& LE_C0_BABL
)
844 lp
->stats
.tx_errors
++;
846 if (csr0
& LE_C0_MISS
)
847 lp
->stats
.rx_errors
++;
849 if (csr0
& LE_C0_MERR
) {
851 u32 addr
= sbus_readl(lp
->dregs
+ DMA_ADDR
);
853 printk(KERN_ERR
"%s: Memory error, status %04x, addr %06x\n",
854 dev
->name
, csr0
, addr
& 0xffffff);
856 printk(KERN_ERR
"%s: Memory error, status %04x\n",
860 sbus_writew(LE_C0_STOP
, lp
->lregs
+ RDP
);
863 u32 dma_csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
865 dma_csr
|= DMA_FIFO_INV
;
866 sbus_writel(dma_csr
, lp
->dregs
+ DMA_CSR
);
871 init_restart_lance(lp
);
872 netif_wake_queue(dev
);
875 sbus_writew(LE_C0_INEA
, lp
->lregs
+ RDP
);
880 /* Build a fake network packet and send it to ourselves. */
881 static void build_fake_packet(struct lance_private
*lp
)
883 struct net_device
*dev
= lp
->dev
;
886 entry
= lp
->tx_new
& TX_RING_MOD_MASK
;
887 if (lp
->pio_buffer
) {
888 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
889 u16 __iomem
*packet
= (u16 __iomem
*) &(ib
->tx_buf
[entry
][0]);
890 struct ethhdr __iomem
*eth
= (struct ethhdr __iomem
*) packet
;
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 struct lance_init_block
*ib
= lp
->init_block_mem
;
902 u16
*packet
= (u16
*) &(ib
->tx_buf
[entry
][0]);
903 struct ethhdr
*eth
= (struct ethhdr
*) packet
;
904 memset(packet
, 0, ETH_ZLEN
);
905 for (i
= 0; i
< 6; i
++) {
906 eth
->h_dest
[i
] = dev
->dev_addr
[i
];
907 eth
->h_source
[i
] = dev
->dev_addr
[i
];
909 ib
->btx_ring
[entry
].length
= (-ETH_ZLEN
) | 0xf000;
910 ib
->btx_ring
[entry
].misc
= 0;
911 ib
->btx_ring
[entry
].tmd1_bits
= (LE_T1_POK
|LE_T1_OWN
);
913 lp
->tx_new
= TX_NEXT(entry
);
916 struct net_device
*last_dev
;
918 static int lance_open(struct net_device
*dev
)
920 struct lance_private
*lp
= netdev_priv(dev
);
927 if (request_irq(dev
->irq
, &lance_interrupt
, SA_SHIRQ
,
928 lancestr
, (void *) dev
)) {
929 printk(KERN_ERR
"Lance: Can't get irq %s\n", __irq_itoa(dev
->irq
));
933 /* On the 4m, setup the ledma to provide the upper bits for buffers */
935 u32 regval
= lp
->init_block_dvma
& 0xff000000;
937 sbus_writel(regval
, lp
->dregs
+ DMA_TEST
);
940 /* Set mode and clear multicast filter only at device open,
941 * so that lance_init_ring() called at any error will not
942 * forget multicast filters.
944 * BTW it is common bug in all lance drivers! --ANK
946 if (lp
->pio_buffer
) {
947 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
948 sbus_writew(0, &ib
->mode
);
949 sbus_writel(0, &ib
->filter
[0]);
950 sbus_writel(0, &ib
->filter
[1]);
952 struct lance_init_block
*ib
= lp
->init_block_mem
;
961 netif_start_queue(dev
);
963 status
= init_restart_lance(lp
);
964 if (!status
&& lp
->auto_select
) {
965 build_fake_packet(lp
);
966 sbus_writew(LE_C0_INEA
| LE_C0_TDMD
, lp
->lregs
+ RDP
);
972 static int lance_close(struct net_device
*dev
)
974 struct lance_private
*lp
= netdev_priv(dev
);
976 netif_stop_queue(dev
);
977 del_timer_sync(&lp
->multicast_timer
);
981 free_irq(dev
->irq
, (void *) dev
);
985 static int lance_reset(struct net_device
*dev
)
987 struct lance_private
*lp
= netdev_priv(dev
);
992 /* On the 4m, reset the dma too */
996 printk(KERN_ERR
"resetting ledma\n");
997 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
998 sbus_writel(csr
| DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1000 sbus_writel(csr
& ~DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1002 addr
= lp
->init_block_dvma
& 0xff000000;
1003 sbus_writel(addr
, lp
->dregs
+ DMA_TEST
);
1007 dev
->trans_start
= jiffies
;
1008 status
= init_restart_lance(lp
);
1012 static void lance_piocopy_from_skb(void __iomem
*dest
, unsigned char *src
, int len
)
1014 void __iomem
*piobuf
= dest
;
1019 switch ((unsigned long)src
& 0x3) {
1023 sbus_writel(*p32
, piobuf
);
1040 sbus_writel(val
, piobuf
);
1050 u32 val
= p16
[0]<<16 | p16
[1];
1051 sbus_writel(val
, piobuf
);
1060 u16 val
= src
[0] << 8 | src
[1];
1061 sbus_writew(val
, piobuf
);
1067 sbus_writeb(src
[0], piobuf
);
1070 static void lance_piozero(void __iomem
*dest
, int len
)
1072 void __iomem
*piobuf
= dest
;
1074 if ((unsigned long)piobuf
& 1) {
1075 sbus_writeb(0, piobuf
);
1082 sbus_writeb(0, piobuf
);
1085 if ((unsigned long)piobuf
& 2) {
1086 sbus_writew(0, piobuf
);
1093 sbus_writel(0, piobuf
);
1098 sbus_writew(0, piobuf
);
1103 sbus_writeb(0, piobuf
);
1106 static void lance_tx_timeout(struct net_device
*dev
)
1108 struct lance_private
*lp
= netdev_priv(dev
);
1110 printk(KERN_ERR
"%s: transmit timed out, status %04x, reset\n",
1111 dev
->name
, sbus_readw(lp
->lregs
+ RDP
));
1113 netif_wake_queue(dev
);
1116 static int lance_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1118 struct lance_private
*lp
= netdev_priv(dev
);
1119 int entry
, skblen
, len
;
1123 len
= (skblen
<= ETH_ZLEN
) ? ETH_ZLEN
: skblen
;
1125 spin_lock_irq(&lp
->lock
);
1127 lp
->stats
.tx_bytes
+= len
;
1129 entry
= lp
->tx_new
& TX_RING_MOD_MASK
;
1130 if (lp
->pio_buffer
) {
1131 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
1132 sbus_writew((-len
) | 0xf000, &ib
->btx_ring
[entry
].length
);
1133 sbus_writew(0, &ib
->btx_ring
[entry
].misc
);
1134 lance_piocopy_from_skb(&ib
->tx_buf
[entry
][0], skb
->data
, skblen
);
1136 lance_piozero(&ib
->tx_buf
[entry
][skblen
], len
- skblen
);
1137 sbus_writeb(LE_T1_POK
| LE_T1_OWN
, &ib
->btx_ring
[entry
].tmd1_bits
);
1139 struct lance_init_block
*ib
= lp
->init_block_mem
;
1140 ib
->btx_ring
[entry
].length
= (-len
) | 0xf000;
1141 ib
->btx_ring
[entry
].misc
= 0;
1142 memcpy((char *)&ib
->tx_buf
[entry
][0], skb
->data
, skblen
);
1144 memset((char *) &ib
->tx_buf
[entry
][skblen
], 0, len
- skblen
);
1145 ib
->btx_ring
[entry
].tmd1_bits
= (LE_T1_POK
| LE_T1_OWN
);
1148 lp
->tx_new
= TX_NEXT(entry
);
1150 if (TX_BUFFS_AVAIL
<= 0)
1151 netif_stop_queue(dev
);
1153 /* Kick the lance: transmit now */
1154 sbus_writew(LE_C0_INEA
| LE_C0_TDMD
, lp
->lregs
+ RDP
);
1156 /* Read back CSR to invalidate the E-Cache.
1157 * This is needed, because DMA_DSBL_WR_INV is set.
1160 sbus_readw(lp
->lregs
+ RDP
);
1162 spin_unlock_irq(&lp
->lock
);
1164 dev
->trans_start
= jiffies
;
1170 static struct net_device_stats
*lance_get_stats(struct net_device
*dev
)
1172 struct lance_private
*lp
= netdev_priv(dev
);
1177 /* taken from the depca driver */
1178 static void lance_load_multicast(struct net_device
*dev
)
1180 struct lance_private
*lp
= netdev_priv(dev
);
1181 struct dev_mc_list
*dmi
= dev
->mc_list
;
1187 /* set all multicast bits */
1188 if (dev
->flags
& IFF_ALLMULTI
)
1193 if (lp
->pio_buffer
) {
1194 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
1195 sbus_writel(val
, &ib
->filter
[0]);
1196 sbus_writel(val
, &ib
->filter
[1]);
1198 struct lance_init_block
*ib
= lp
->init_block_mem
;
1199 ib
->filter
[0] = val
;
1200 ib
->filter
[1] = val
;
1203 if (dev
->flags
& IFF_ALLMULTI
)
1207 for (i
= 0; i
< dev
->mc_count
; i
++) {
1208 addrs
= dmi
->dmi_addr
;
1211 /* multicast address? */
1214 crc
= ether_crc_le(6, addrs
);
1216 if (lp
->pio_buffer
) {
1217 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
1218 u16 __iomem
*mcast_table
= (u16 __iomem
*) &ib
->filter
;
1219 u16 tmp
= sbus_readw(&mcast_table
[crc
>>4]);
1220 tmp
|= 1 << (crc
& 0xf);
1221 sbus_writew(tmp
, &mcast_table
[crc
>>4]);
1223 struct lance_init_block
*ib
= lp
->init_block_mem
;
1224 u16
*mcast_table
= (u16
*) &ib
->filter
;
1225 mcast_table
[crc
>> 4] |= 1 << (crc
& 0xf);
1230 static void lance_set_multicast(struct net_device
*dev
)
1232 struct lance_private
*lp
= netdev_priv(dev
);
1233 struct lance_init_block
*ib_mem
= lp
->init_block_mem
;
1234 struct lance_init_block __iomem
*ib_iomem
= lp
->init_block_iomem
;
1237 if (!netif_running(dev
))
1240 if (lp
->tx_old
!= lp
->tx_new
) {
1241 mod_timer(&lp
->multicast_timer
, jiffies
+ 4);
1242 netif_wake_queue(dev
);
1246 netif_stop_queue(dev
);
1252 mode
= sbus_readw(&ib_iomem
->mode
);
1254 mode
= ib_mem
->mode
;
1255 if (dev
->flags
& IFF_PROMISC
) {
1258 sbus_writew(mode
, &ib_iomem
->mode
);
1260 ib_mem
->mode
= mode
;
1262 mode
&= ~LE_MO_PROM
;
1264 sbus_writew(mode
, &ib_iomem
->mode
);
1266 ib_mem
->mode
= mode
;
1267 lance_load_multicast(dev
);
1270 init_restart_lance(lp
);
1271 netif_wake_queue(dev
);
1274 static void lance_set_multicast_retry(unsigned long _opaque
)
1276 struct net_device
*dev
= (struct net_device
*) _opaque
;
1278 lance_set_multicast(dev
);
1281 static void lance_free_hwresources(struct lance_private
*lp
)
1284 sbus_iounmap(lp
->lregs
, LANCE_REG_SIZE
);
1285 if (lp
->init_block_iomem
) {
1286 sbus_iounmap(lp
->init_block_iomem
,
1287 sizeof(struct lance_init_block
));
1288 } else if (lp
->init_block_mem
) {
1289 sbus_free_consistent(lp
->sdev
,
1290 sizeof(struct lance_init_block
),
1292 lp
->init_block_dvma
);
1296 /* Ethtool support... */
1297 static void sparc_lance_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1299 struct lance_private
*lp
= netdev_priv(dev
);
1301 strcpy(info
->driver
, "sunlance");
1302 strcpy(info
->version
, "2.02");
1303 sprintf(info
->bus_info
, "SBUS:%d",
1307 static u32
sparc_lance_get_link(struct net_device
*dev
)
1309 /* We really do not keep track of this, but this
1310 * is better than not reporting anything at all.
1315 static struct ethtool_ops sparc_lance_ethtool_ops
= {
1316 .get_drvinfo
= sparc_lance_get_drvinfo
,
1317 .get_link
= sparc_lance_get_link
,
1320 static int __init
sparc_lance_init(struct sbus_dev
*sdev
,
1321 struct sbus_dma
*ledma
,
1322 struct sbus_dev
*lebuffer
)
1324 static unsigned version_printed
;
1325 struct net_device
*dev
;
1326 struct lance_private
*lp
;
1329 dev
= alloc_etherdev(sizeof(struct lance_private
) + 8);
1333 lp
= netdev_priv(dev
);
1334 memset(lp
, 0, sizeof(*lp
));
1336 if (sparc_lance_debug
&& version_printed
++ == 0)
1337 printk (KERN_INFO
"%s", version
);
1339 spin_lock_init(&lp
->lock
);
1341 /* Copy the IDPROM ethernet address to the device structure, later we
1342 * will copy the address in the device structure to the lance
1343 * initialization block.
1345 for (i
= 0; i
< 6; i
++)
1346 dev
->dev_addr
[i
] = idprom
->id_ethaddr
[i
];
1348 /* Get the IO region */
1349 lp
->lregs
= sbus_ioremap(&sdev
->resource
[0], 0,
1350 LANCE_REG_SIZE
, lancestr
);
1352 printk(KERN_ERR
"SunLance: Cannot map registers.\n");
1359 if (lebuffer
->resource
[0].start
& 7) {
1360 printk(KERN_ERR
"SunLance: ERROR: Rx and Tx rings not on even boundary.\n");
1363 lp
->init_block_iomem
=
1364 sbus_ioremap(&lebuffer
->resource
[0], 0,
1365 sizeof(struct lance_init_block
), "lebuffer");
1366 if (!lp
->init_block_iomem
) {
1367 printk(KERN_ERR
"SunLance: Cannot map PIO buffer.\n");
1370 lp
->init_block_dvma
= 0;
1372 lp
->init_ring
= lance_init_ring_pio
;
1373 lp
->rx
= lance_rx_pio
;
1374 lp
->tx
= lance_tx_pio
;
1376 lp
->init_block_mem
=
1377 sbus_alloc_consistent(sdev
, sizeof(struct lance_init_block
),
1378 &lp
->init_block_dvma
);
1379 if (!lp
->init_block_mem
|| lp
->init_block_dvma
== 0) {
1380 printk(KERN_ERR
"SunLance: Cannot allocate consistent DMA memory.\n");
1384 lp
->init_ring
= lance_init_ring_dvma
;
1385 lp
->rx
= lance_rx_dvma
;
1386 lp
->tx
= lance_tx_dvma
;
1388 lp
->busmaster_regval
= prom_getintdefault(sdev
->prom_node
,
1390 (LE_C3_BSWP
| LE_C3_ACON
|
1393 lp
->name
= lancestr
;
1396 lp
->burst_sizes
= 0;
1399 unsigned int sbmask
;
1402 /* Find burst-size property for ledma */
1403 lp
->burst_sizes
= prom_getintdefault(ledma
->sdev
->prom_node
,
1406 /* ledma may be capable of fast bursts, but sbus may not. */
1407 sbmask
= prom_getintdefault(ledma
->sdev
->bus
->prom_node
,
1408 "burst-sizes", DMA_BURSTBITS
);
1409 lp
->burst_sizes
&= sbmask
;
1411 /* Get the cable-selection property */
1412 memset(prop
, 0, sizeof(prop
));
1413 prom_getstring(ledma
->sdev
->prom_node
, "cable-selection",
1414 prop
, sizeof(prop
));
1418 printk(KERN_INFO
"SunLance: using auto-carrier-detection.\n");
1420 /* Is this found at /options .attributes in all
1421 * Prom versions? XXX
1423 topnd
= prom_getchild(prom_root_node
);
1425 nd
= prom_searchsiblings(topnd
, "options");
1429 if (!prom_node_has_property(nd
, "tpe-link-test?"))
1432 memset(prop
, 0, sizeof(prop
));
1433 prom_getstring(nd
, "tpe-link-test?", prop
,
1436 if (strcmp(prop
, "true")) {
1437 printk(KERN_NOTICE
"SunLance: warning: overriding option "
1438 "'tpe-link-test?'\n");
1439 printk(KERN_NOTICE
"SunLance: warning: mail any problems "
1440 "to ecd@skynet.be\n");
1441 auxio_set_lte(AUXIO_LTE_ON
);
1444 lp
->auto_select
= 1;
1446 } else if (!strcmp(prop
, "aui")) {
1447 lp
->auto_select
= 0;
1450 lp
->auto_select
= 0;
1454 lp
->dregs
= ledma
->regs
;
1457 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
1458 sbus_writel(csr
| DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1460 sbus_writel(csr
& ~DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1465 SET_MODULE_OWNER(dev
);
1466 dev
->open
= &lance_open
;
1467 dev
->stop
= &lance_close
;
1468 dev
->hard_start_xmit
= &lance_start_xmit
;
1469 dev
->tx_timeout
= &lance_tx_timeout
;
1470 dev
->watchdog_timeo
= 5*HZ
;
1471 dev
->get_stats
= &lance_get_stats
;
1472 dev
->set_multicast_list
= &lance_set_multicast
;
1473 dev
->ethtool_ops
= &sparc_lance_ethtool_ops
;
1475 dev
->irq
= sdev
->irqs
[0];
1479 /* We cannot sleep if the chip is busy during a
1480 * multicast list update event, because such events
1481 * can occur from interrupts (ex. IPv6). So we
1482 * use a timer to try again later when necessary. -DaveM
1484 init_timer(&lp
->multicast_timer
);
1485 lp
->multicast_timer
.data
= (unsigned long) dev
;
1486 lp
->multicast_timer
.function
= &lance_set_multicast_retry
;
1488 if (register_netdev(dev
)) {
1489 printk(KERN_ERR
"SunLance: Cannot register device.\n");
1493 lp
->next_module
= root_lance_dev
;
1494 root_lance_dev
= lp
;
1496 printk(KERN_INFO
"%s: LANCE ", dev
->name
);
1498 for (i
= 0; i
< 6; i
++)
1499 printk("%2.2x%c", dev
->dev_addr
[i
],
1506 lance_free_hwresources(lp
);
1511 /* On 4m, find the associated dma for the lance chip */
1512 static inline struct sbus_dma
*find_ledma(struct sbus_dev
*sdev
)
1517 if (p
->sdev
== sdev
)
1525 #include <asm/sun4paddr.h>
1526 #include <asm/machines.h>
1528 /* Find all the lance cards on the system and initialize them */
1529 static int __init
sparc_lance_probe(void)
1531 static struct sbus_dev sdev
;
1534 root_lance_dev
= NULL
;
1540 if ((idprom
->id_machtype
== (SM_SUN4
|SM_4_330
)) ||
1541 (idprom
->id_machtype
== (SM_SUN4
|SM_4_470
))) {
1542 memset(&sdev
, 0, sizeof(sdev
));
1543 sdev
.reg_addrs
[0].phys_addr
= sun4_eth_physaddr
;
1545 return sparc_lance_init(&sdev
, NULL
, NULL
);
1550 #else /* !CONFIG_SUN4 */
1552 /* Find all the lance cards on the system and initialize them */
1553 static int __init
sparc_lance_probe(void)
1555 struct sbus_bus
*bus
;
1556 struct sbus_dev
*sdev
= NULL
;
1557 struct sbus_dma
*ledma
= NULL
;
1561 root_lance_dev
= NULL
;
1567 for_each_sbus (bus
) {
1568 for_each_sbusdev (sdev
, bus
) {
1569 if (strcmp(sdev
->prom_name
, "le") == 0) {
1571 if ((v
= sparc_lance_init(sdev
, NULL
, NULL
)))
1575 if (strcmp(sdev
->prom_name
, "ledma") == 0) {
1577 ledma
= find_ledma(sdev
);
1578 if ((v
= sparc_lance_init(sdev
->child
,
1583 if (strcmp(sdev
->prom_name
, "lebuffer") == 0){
1585 if ((v
= sparc_lance_init(sdev
->child
,
1590 } /* for each sbusdev */
1591 } /* for each sbus */
1596 #endif /* !CONFIG_SUN4 */
1598 static void __exit
sparc_lance_cleanup(void)
1600 struct lance_private
*lp
;
1602 while (root_lance_dev
) {
1603 lp
= root_lance_dev
->next_module
;
1605 unregister_netdev(root_lance_dev
->dev
);
1606 lance_free_hwresources(root_lance_dev
);
1607 free_netdev(root_lance_dev
->dev
);
1608 root_lance_dev
= lp
;
1612 module_init(sparc_lance_probe
);
1613 module_exit(sparc_lance_cleanup
);
1614 MODULE_LICENSE("GPL");