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/module.h>
75 #include <linux/kernel.h>
76 #include <linux/types.h>
77 #include <linux/fcntl.h>
78 #include <linux/interrupt.h>
79 #include <linux/ioport.h>
81 #include <linux/string.h>
82 #include <linux/delay.h>
83 #include <linux/crc32.h>
84 #include <linux/errno.h>
85 #include <linux/socket.h> /* Used for the temporal inet entries and routing */
86 #include <linux/route.h>
87 #include <linux/netdevice.h>
88 #include <linux/etherdevice.h>
89 #include <linux/skbuff.h>
90 #include <linux/ethtool.h>
91 #include <linux/bitops.h>
92 #include <linux/dma-mapping.h>
94 #include <linux/of_device.h>
95 #include <linux/gfp.h>
99 #include <asm/pgtable.h>
100 #include <asm/byteorder.h> /* Used by the checksum routines */
101 #include <asm/idprom.h>
102 #include <asm/prom.h>
103 #include <asm/auxio.h> /* For tpe-link-test? setting */
106 #define DRV_NAME "sunlance"
107 #define DRV_VERSION "2.02"
108 #define DRV_RELDATE "8/24/03"
109 #define DRV_AUTHOR "Miguel de Icaza (miguel@nuclecu.unam.mx)"
111 static char version
[] =
112 DRV_NAME
".c:v" DRV_VERSION
" " DRV_RELDATE
" " DRV_AUTHOR
"\n";
114 MODULE_VERSION(DRV_VERSION
);
115 MODULE_AUTHOR(DRV_AUTHOR
);
116 MODULE_DESCRIPTION("Sun Lance ethernet driver");
117 MODULE_LICENSE("GPL");
119 /* Define: 2^4 Tx buffers and 2^4 Rx buffers */
120 #ifndef LANCE_LOG_TX_BUFFERS
121 #define LANCE_LOG_TX_BUFFERS 4
122 #define LANCE_LOG_RX_BUFFERS 4
130 #define LE_MO_PROM 0x8000 /* Enable promiscuous mode */
132 #define LE_C0_ERR 0x8000 /* Error: set if BAB, SQE, MISS or ME is set */
133 #define LE_C0_BABL 0x4000 /* BAB: Babble: tx timeout. */
134 #define LE_C0_CERR 0x2000 /* SQE: Signal quality error */
135 #define LE_C0_MISS 0x1000 /* MISS: Missed a packet */
136 #define LE_C0_MERR 0x0800 /* ME: Memory error */
137 #define LE_C0_RINT 0x0400 /* Received interrupt */
138 #define LE_C0_TINT 0x0200 /* Transmitter Interrupt */
139 #define LE_C0_IDON 0x0100 /* IFIN: Init finished. */
140 #define LE_C0_INTR 0x0080 /* Interrupt or error */
141 #define LE_C0_INEA 0x0040 /* Interrupt enable */
142 #define LE_C0_RXON 0x0020 /* Receiver on */
143 #define LE_C0_TXON 0x0010 /* Transmitter on */
144 #define LE_C0_TDMD 0x0008 /* Transmitter demand */
145 #define LE_C0_STOP 0x0004 /* Stop the card */
146 #define LE_C0_STRT 0x0002 /* Start the card */
147 #define LE_C0_INIT 0x0001 /* Init the card */
149 #define LE_C3_BSWP 0x4 /* SWAP */
150 #define LE_C3_ACON 0x2 /* ALE Control */
151 #define LE_C3_BCON 0x1 /* Byte control */
153 /* Receive message descriptor 1 */
154 #define LE_R1_OWN 0x80 /* Who owns the entry */
155 #define LE_R1_ERR 0x40 /* Error: if FRA, OFL, CRC or BUF is set */
156 #define LE_R1_FRA 0x20 /* FRA: Frame error */
157 #define LE_R1_OFL 0x10 /* OFL: Frame overflow */
158 #define LE_R1_CRC 0x08 /* CRC error */
159 #define LE_R1_BUF 0x04 /* BUF: Buffer error */
160 #define LE_R1_SOP 0x02 /* Start of packet */
161 #define LE_R1_EOP 0x01 /* End of packet */
162 #define LE_R1_POK 0x03 /* Packet is complete: SOP + EOP */
164 #define LE_T1_OWN 0x80 /* Lance owns the packet */
165 #define LE_T1_ERR 0x40 /* Error summary */
166 #define LE_T1_EMORE 0x10 /* Error: more than one retry needed */
167 #define LE_T1_EONE 0x08 /* Error: one retry needed */
168 #define LE_T1_EDEF 0x04 /* Error: deferred */
169 #define LE_T1_SOP 0x02 /* Start of packet */
170 #define LE_T1_EOP 0x01 /* End of packet */
171 #define LE_T1_POK 0x03 /* Packet is complete: SOP + EOP */
173 #define LE_T3_BUF 0x8000 /* Buffer error */
174 #define LE_T3_UFL 0x4000 /* Error underflow */
175 #define LE_T3_LCOL 0x1000 /* Error late collision */
176 #define LE_T3_CLOS 0x0800 /* Error carrier loss */
177 #define LE_T3_RTY 0x0400 /* Error retry */
178 #define LE_T3_TDR 0x03ff /* Time Domain Reflectometry counter */
180 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
181 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
182 #define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29)
183 #define TX_NEXT(__x) (((__x)+1) & TX_RING_MOD_MASK)
185 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
186 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
187 #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29)
188 #define RX_NEXT(__x) (((__x)+1) & RX_RING_MOD_MASK)
190 #define PKT_BUF_SZ 1544
191 #define RX_BUFF_SIZE PKT_BUF_SZ
192 #define TX_BUFF_SIZE PKT_BUF_SZ
194 struct lance_rx_desc
{
195 u16 rmd0
; /* low address of packet */
196 u8 rmd1_bits
; /* descriptor bits */
197 u8 rmd1_hadr
; /* high address of packet */
198 s16 length
; /* This length is 2s complement (negative)!
201 u16 mblength
; /* This is the actual number of bytes received */
204 struct lance_tx_desc
{
205 u16 tmd0
; /* low address of packet */
206 u8 tmd1_bits
; /* descriptor bits */
207 u8 tmd1_hadr
; /* high address of packet */
208 s16 length
; /* Length is 2s complement (negative)! */
212 /* The LANCE initialization block, described in databook. */
213 /* On the Sparc, this block should be on a DMA region */
214 struct lance_init_block
{
215 u16 mode
; /* Pre-set mode (reg. 15) */
216 u8 phys_addr
[6]; /* Physical ethernet address */
217 u32 filter
[2]; /* Multicast filter. */
219 /* Receive and transmit ring base, along with extra bits. */
220 u16 rx_ptr
; /* receive descriptor addr */
221 u16 rx_len
; /* receive len and high addr */
222 u16 tx_ptr
; /* transmit descriptor addr */
223 u16 tx_len
; /* transmit len and high addr */
225 /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
226 struct lance_rx_desc brx_ring
[RX_RING_SIZE
];
227 struct lance_tx_desc btx_ring
[TX_RING_SIZE
];
229 u8 tx_buf
[TX_RING_SIZE
][TX_BUFF_SIZE
];
230 u8 pad
[2]; /* align rx_buf for copy_and_sum(). */
231 u8 rx_buf
[RX_RING_SIZE
][RX_BUFF_SIZE
];
234 #define libdesc_offset(rt, elem) \
235 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem])))))
237 #define libbuff_offset(rt, elem) \
238 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem][0])))))
240 struct lance_private
{
241 void __iomem
*lregs
; /* Lance RAP/RDP regs. */
242 void __iomem
*dregs
; /* DMA controller regs. */
243 struct lance_init_block __iomem
*init_block_iomem
;
244 struct lance_init_block
*init_block_mem
;
251 struct platform_device
*ledma
; /* If set this points to ledma */
252 char tpe
; /* cable-selection is TPE */
253 char auto_select
; /* cable-selection by carrier */
254 char burst_sizes
; /* ledma SBus burst sizes */
255 char pio_buffer
; /* init block in PIO space? */
257 unsigned short busmaster_regval
;
259 void (*init_ring
)(struct net_device
*);
260 void (*rx
)(struct net_device
*);
261 void (*tx
)(struct net_device
*);
264 dma_addr_t init_block_dvma
;
265 struct net_device
*dev
; /* Backpointer */
266 struct platform_device
*op
;
267 struct platform_device
*lebuffer
;
268 struct timer_list multicast_timer
;
271 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
272 lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\
273 lp->tx_old - lp->tx_new-1)
275 /* Lance registers. */
276 #define RDP 0x00UL /* register data port */
277 #define RAP 0x02UL /* register address port */
278 #define LANCE_REG_SIZE 0x04UL
280 #define STOP_LANCE(__lp) \
281 do { void __iomem *__base = (__lp)->lregs; \
282 sbus_writew(LE_CSR0, __base + RAP); \
283 sbus_writew(LE_C0_STOP, __base + RDP); \
286 int sparc_lance_debug
= 2;
288 /* The Lance uses 24 bit addresses */
289 /* On the Sun4c the DVMA will provide the remaining bytes for us */
290 /* On the Sun4m we have to instruct the ledma to provide them */
291 /* Even worse, on scsi/ether SBUS cards, the init block and the
292 * transmit/receive buffers are addresses as offsets from absolute
293 * zero on the lebuffer PIO area. -DaveM
296 #define LANCE_ADDR(x) ((long)(x) & ~0xff000000)
298 /* Load the CSR registers */
299 static void load_csrs(struct lance_private
*lp
)
306 leptr
= LANCE_ADDR(lp
->init_block_dvma
);
308 sbus_writew(LE_CSR1
, lp
->lregs
+ RAP
);
309 sbus_writew(leptr
& 0xffff, lp
->lregs
+ RDP
);
310 sbus_writew(LE_CSR2
, lp
->lregs
+ RAP
);
311 sbus_writew(leptr
>> 16, lp
->lregs
+ RDP
);
312 sbus_writew(LE_CSR3
, lp
->lregs
+ RAP
);
313 sbus_writew(lp
->busmaster_regval
, lp
->lregs
+ RDP
);
315 /* Point back to csr0 */
316 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
319 /* Setup the Lance Rx and Tx rings */
320 static void lance_init_ring_dvma(struct net_device
*dev
)
322 struct lance_private
*lp
= netdev_priv(dev
);
323 struct lance_init_block
*ib
= lp
->init_block_mem
;
324 dma_addr_t aib
= lp
->init_block_dvma
;
328 /* Lock out other processes while setting up hardware */
329 netif_stop_queue(dev
);
330 lp
->rx_new
= lp
->tx_new
= 0;
331 lp
->rx_old
= lp
->tx_old
= 0;
333 /* Copy the ethernet address to the lance init block
334 * Note that on the sparc you need to swap the ethernet address.
336 ib
->phys_addr
[0] = dev
->dev_addr
[1];
337 ib
->phys_addr
[1] = dev
->dev_addr
[0];
338 ib
->phys_addr
[2] = dev
->dev_addr
[3];
339 ib
->phys_addr
[3] = dev
->dev_addr
[2];
340 ib
->phys_addr
[4] = dev
->dev_addr
[5];
341 ib
->phys_addr
[5] = dev
->dev_addr
[4];
343 /* Setup the Tx ring entries */
344 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
345 leptr
= LANCE_ADDR(aib
+ libbuff_offset(tx_buf
, i
));
346 ib
->btx_ring
[i
].tmd0
= leptr
;
347 ib
->btx_ring
[i
].tmd1_hadr
= leptr
>> 16;
348 ib
->btx_ring
[i
].tmd1_bits
= 0;
349 ib
->btx_ring
[i
].length
= 0xf000; /* The ones required by tmd2 */
350 ib
->btx_ring
[i
].misc
= 0;
353 /* Setup the Rx ring entries */
354 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
355 leptr
= LANCE_ADDR(aib
+ libbuff_offset(rx_buf
, i
));
357 ib
->brx_ring
[i
].rmd0
= leptr
;
358 ib
->brx_ring
[i
].rmd1_hadr
= leptr
>> 16;
359 ib
->brx_ring
[i
].rmd1_bits
= LE_R1_OWN
;
360 ib
->brx_ring
[i
].length
= -RX_BUFF_SIZE
| 0xf000;
361 ib
->brx_ring
[i
].mblength
= 0;
364 /* Setup the initialization block */
366 /* Setup rx descriptor pointer */
367 leptr
= LANCE_ADDR(aib
+ libdesc_offset(brx_ring
, 0));
368 ib
->rx_len
= (LANCE_LOG_RX_BUFFERS
<< 13) | (leptr
>> 16);
371 /* Setup tx descriptor pointer */
372 leptr
= LANCE_ADDR(aib
+ libdesc_offset(btx_ring
, 0));
373 ib
->tx_len
= (LANCE_LOG_TX_BUFFERS
<< 13) | (leptr
>> 16);
377 static void lance_init_ring_pio(struct net_device
*dev
)
379 struct lance_private
*lp
= netdev_priv(dev
);
380 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
384 /* Lock out other processes while setting up hardware */
385 netif_stop_queue(dev
);
386 lp
->rx_new
= lp
->tx_new
= 0;
387 lp
->rx_old
= lp
->tx_old
= 0;
389 /* Copy the ethernet address to the lance init block
390 * Note that on the sparc you need to swap the ethernet address.
392 sbus_writeb(dev
->dev_addr
[1], &ib
->phys_addr
[0]);
393 sbus_writeb(dev
->dev_addr
[0], &ib
->phys_addr
[1]);
394 sbus_writeb(dev
->dev_addr
[3], &ib
->phys_addr
[2]);
395 sbus_writeb(dev
->dev_addr
[2], &ib
->phys_addr
[3]);
396 sbus_writeb(dev
->dev_addr
[5], &ib
->phys_addr
[4]);
397 sbus_writeb(dev
->dev_addr
[4], &ib
->phys_addr
[5]);
399 /* Setup the Tx ring entries */
400 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
401 leptr
= libbuff_offset(tx_buf
, i
);
402 sbus_writew(leptr
, &ib
->btx_ring
[i
].tmd0
);
403 sbus_writeb(leptr
>> 16,&ib
->btx_ring
[i
].tmd1_hadr
);
404 sbus_writeb(0, &ib
->btx_ring
[i
].tmd1_bits
);
406 /* The ones required by tmd2 */
407 sbus_writew(0xf000, &ib
->btx_ring
[i
].length
);
408 sbus_writew(0, &ib
->btx_ring
[i
].misc
);
411 /* Setup the Rx ring entries */
412 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
413 leptr
= libbuff_offset(rx_buf
, i
);
415 sbus_writew(leptr
, &ib
->brx_ring
[i
].rmd0
);
416 sbus_writeb(leptr
>> 16,&ib
->brx_ring
[i
].rmd1_hadr
);
417 sbus_writeb(LE_R1_OWN
, &ib
->brx_ring
[i
].rmd1_bits
);
418 sbus_writew(-RX_BUFF_SIZE
|0xf000,
419 &ib
->brx_ring
[i
].length
);
420 sbus_writew(0, &ib
->brx_ring
[i
].mblength
);
423 /* Setup the initialization block */
425 /* Setup rx descriptor pointer */
426 leptr
= libdesc_offset(brx_ring
, 0);
427 sbus_writew((LANCE_LOG_RX_BUFFERS
<< 13) | (leptr
>> 16),
429 sbus_writew(leptr
, &ib
->rx_ptr
);
431 /* Setup tx descriptor pointer */
432 leptr
= libdesc_offset(btx_ring
, 0);
433 sbus_writew((LANCE_LOG_TX_BUFFERS
<< 13) | (leptr
>> 16),
435 sbus_writew(leptr
, &ib
->tx_ptr
);
438 static void init_restart_ledma(struct lance_private
*lp
)
440 u32 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
442 if (!(csr
& DMA_HNDL_ERROR
)) {
443 /* E-Cache draining */
444 while (sbus_readl(lp
->dregs
+ DMA_CSR
) & DMA_FIFO_ISDRAIN
)
448 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
449 csr
&= ~DMA_E_BURSTS
;
450 if (lp
->burst_sizes
& DMA_BURST32
)
451 csr
|= DMA_E_BURST32
;
453 csr
|= DMA_E_BURST16
;
455 csr
|= (DMA_DSBL_RD_DRN
| DMA_DSBL_WR_INV
| DMA_FIFO_INV
);
458 csr
|= DMA_EN_ENETAUI
;
460 csr
&= ~DMA_EN_ENETAUI
;
462 sbus_writel(csr
, lp
->dregs
+ DMA_CSR
);
466 static int init_restart_lance(struct lance_private
*lp
)
472 init_restart_ledma(lp
);
474 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
475 sbus_writew(LE_C0_INIT
, lp
->lregs
+ RDP
);
477 /* Wait for the lance to complete initialization */
478 for (i
= 0; i
< 100; i
++) {
479 regval
= sbus_readw(lp
->lregs
+ RDP
);
481 if (regval
& (LE_C0_ERR
| LE_C0_IDON
))
485 if (i
== 100 || (regval
& LE_C0_ERR
)) {
486 printk(KERN_ERR
"LANCE unopened after %d ticks, csr0=%4.4x.\n",
489 printk("dcsr=%8.8x\n", sbus_readl(lp
->dregs
+ DMA_CSR
));
493 /* Clear IDON by writing a "1", enable interrupts and start lance */
494 sbus_writew(LE_C0_IDON
, lp
->lregs
+ RDP
);
495 sbus_writew(LE_C0_INEA
| LE_C0_STRT
, lp
->lregs
+ RDP
);
498 u32 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
501 sbus_writel(csr
, lp
->dregs
+ DMA_CSR
);
507 static void lance_rx_dvma(struct net_device
*dev
)
509 struct lance_private
*lp
= netdev_priv(dev
);
510 struct lance_init_block
*ib
= lp
->init_block_mem
;
511 struct lance_rx_desc
*rd
;
513 int len
, entry
= lp
->rx_new
;
516 for (rd
= &ib
->brx_ring
[entry
];
517 !((bits
= rd
->rmd1_bits
) & LE_R1_OWN
);
518 rd
= &ib
->brx_ring
[entry
]) {
520 /* We got an incomplete frame? */
521 if ((bits
& LE_R1_POK
) != LE_R1_POK
) {
522 dev
->stats
.rx_over_errors
++;
523 dev
->stats
.rx_errors
++;
524 } else if (bits
& LE_R1_ERR
) {
525 /* Count only the end frame as a rx error,
528 if (bits
& LE_R1_BUF
) dev
->stats
.rx_fifo_errors
++;
529 if (bits
& LE_R1_CRC
) dev
->stats
.rx_crc_errors
++;
530 if (bits
& LE_R1_OFL
) dev
->stats
.rx_over_errors
++;
531 if (bits
& LE_R1_FRA
) dev
->stats
.rx_frame_errors
++;
532 if (bits
& LE_R1_EOP
) dev
->stats
.rx_errors
++;
534 len
= (rd
->mblength
& 0xfff) - 4;
535 skb
= netdev_alloc_skb(dev
, len
+ 2);
538 dev
->stats
.rx_dropped
++;
540 rd
->rmd1_bits
= LE_R1_OWN
;
541 lp
->rx_new
= RX_NEXT(entry
);
545 dev
->stats
.rx_bytes
+= len
;
547 skb_reserve(skb
, 2); /* 16 byte align */
548 skb_put(skb
, len
); /* make room */
549 skb_copy_to_linear_data(skb
,
550 (unsigned char *)&(ib
->rx_buf
[entry
][0]),
552 skb
->protocol
= eth_type_trans(skb
, dev
);
554 dev
->stats
.rx_packets
++;
557 /* Return the packet to the pool */
559 rd
->rmd1_bits
= LE_R1_OWN
;
560 entry
= RX_NEXT(entry
);
566 static void lance_tx_dvma(struct net_device
*dev
)
568 struct lance_private
*lp
= netdev_priv(dev
);
569 struct lance_init_block
*ib
= lp
->init_block_mem
;
572 spin_lock(&lp
->lock
);
575 for (i
= j
; i
!= lp
->tx_new
; i
= j
) {
576 struct lance_tx_desc
*td
= &ib
->btx_ring
[i
];
577 u8 bits
= td
->tmd1_bits
;
579 /* If we hit a packet not owned by us, stop */
580 if (bits
& LE_T1_OWN
)
583 if (bits
& LE_T1_ERR
) {
584 u16 status
= td
->misc
;
586 dev
->stats
.tx_errors
++;
587 if (status
& LE_T3_RTY
) dev
->stats
.tx_aborted_errors
++;
588 if (status
& LE_T3_LCOL
) dev
->stats
.tx_window_errors
++;
590 if (status
& LE_T3_CLOS
) {
591 dev
->stats
.tx_carrier_errors
++;
592 if (lp
->auto_select
) {
593 lp
->tpe
= 1 - lp
->tpe
;
594 printk(KERN_NOTICE
"%s: Carrier Lost, trying %s\n",
595 dev
->name
, lp
->tpe
?"TPE":"AUI");
599 init_restart_lance(lp
);
604 /* Buffer errors and underflows turn off the
605 * transmitter, restart the adapter.
607 if (status
& (LE_T3_BUF
|LE_T3_UFL
)) {
608 dev
->stats
.tx_fifo_errors
++;
610 printk(KERN_ERR
"%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
615 init_restart_lance(lp
);
618 } else if ((bits
& LE_T1_POK
) == LE_T1_POK
) {
620 * So we don't count the packet more than once.
622 td
->tmd1_bits
= bits
& ~(LE_T1_POK
);
624 /* One collision before packet was sent. */
625 if (bits
& LE_T1_EONE
)
626 dev
->stats
.collisions
++;
628 /* More than one collision, be optimistic. */
629 if (bits
& LE_T1_EMORE
)
630 dev
->stats
.collisions
+= 2;
632 dev
->stats
.tx_packets
++;
639 if (netif_queue_stopped(dev
) &&
641 netif_wake_queue(dev
);
643 spin_unlock(&lp
->lock
);
646 static void lance_piocopy_to_skb(struct sk_buff
*skb
, void __iomem
*piobuf
, int len
)
648 u16
*p16
= (u16
*) skb
->data
;
651 void __iomem
*pbuf
= piobuf
;
653 /* We know here that both src and dest are on a 16bit boundary. */
654 *p16
++ = sbus_readw(pbuf
);
660 *p32
++ = sbus_readl(pbuf
);
667 *p16
++ = sbus_readw(pbuf
);
673 *p8
= sbus_readb(pbuf
);
676 static void lance_rx_pio(struct net_device
*dev
)
678 struct lance_private
*lp
= netdev_priv(dev
);
679 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
680 struct lance_rx_desc __iomem
*rd
;
686 for (rd
= &ib
->brx_ring
[entry
];
687 !((bits
= sbus_readb(&rd
->rmd1_bits
)) & LE_R1_OWN
);
688 rd
= &ib
->brx_ring
[entry
]) {
690 /* We got an incomplete frame? */
691 if ((bits
& LE_R1_POK
) != LE_R1_POK
) {
692 dev
->stats
.rx_over_errors
++;
693 dev
->stats
.rx_errors
++;
694 } else if (bits
& LE_R1_ERR
) {
695 /* Count only the end frame as a rx error,
698 if (bits
& LE_R1_BUF
) dev
->stats
.rx_fifo_errors
++;
699 if (bits
& LE_R1_CRC
) dev
->stats
.rx_crc_errors
++;
700 if (bits
& LE_R1_OFL
) dev
->stats
.rx_over_errors
++;
701 if (bits
& LE_R1_FRA
) dev
->stats
.rx_frame_errors
++;
702 if (bits
& LE_R1_EOP
) dev
->stats
.rx_errors
++;
704 len
= (sbus_readw(&rd
->mblength
) & 0xfff) - 4;
705 skb
= netdev_alloc_skb(dev
, len
+ 2);
708 dev
->stats
.rx_dropped
++;
709 sbus_writew(0, &rd
->mblength
);
710 sbus_writeb(LE_R1_OWN
, &rd
->rmd1_bits
);
711 lp
->rx_new
= RX_NEXT(entry
);
715 dev
->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
->stats
.rx_packets
++;
725 /* Return the packet to the pool */
726 sbus_writew(0, &rd
->mblength
);
727 sbus_writeb(LE_R1_OWN
, &rd
->rmd1_bits
);
728 entry
= RX_NEXT(entry
);
734 static void lance_tx_pio(struct net_device
*dev
)
736 struct lance_private
*lp
= netdev_priv(dev
);
737 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
740 spin_lock(&lp
->lock
);
743 for (i
= j
; i
!= lp
->tx_new
; i
= j
) {
744 struct lance_tx_desc __iomem
*td
= &ib
->btx_ring
[i
];
745 u8 bits
= sbus_readb(&td
->tmd1_bits
);
747 /* If we hit a packet not owned by us, stop */
748 if (bits
& LE_T1_OWN
)
751 if (bits
& LE_T1_ERR
) {
752 u16 status
= sbus_readw(&td
->misc
);
754 dev
->stats
.tx_errors
++;
755 if (status
& LE_T3_RTY
) dev
->stats
.tx_aborted_errors
++;
756 if (status
& LE_T3_LCOL
) dev
->stats
.tx_window_errors
++;
758 if (status
& LE_T3_CLOS
) {
759 dev
->stats
.tx_carrier_errors
++;
760 if (lp
->auto_select
) {
761 lp
->tpe
= 1 - lp
->tpe
;
762 printk(KERN_NOTICE
"%s: Carrier Lost, trying %s\n",
763 dev
->name
, lp
->tpe
?"TPE":"AUI");
767 init_restart_lance(lp
);
772 /* Buffer errors and underflows turn off the
773 * transmitter, restart the adapter.
775 if (status
& (LE_T3_BUF
|LE_T3_UFL
)) {
776 dev
->stats
.tx_fifo_errors
++;
778 printk(KERN_ERR
"%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
783 init_restart_lance(lp
);
786 } else if ((bits
& LE_T1_POK
) == LE_T1_POK
) {
788 * So we don't count the packet more than once.
790 sbus_writeb(bits
& ~(LE_T1_POK
), &td
->tmd1_bits
);
792 /* One collision before packet was sent. */
793 if (bits
& LE_T1_EONE
)
794 dev
->stats
.collisions
++;
796 /* More than one collision, be optimistic. */
797 if (bits
& LE_T1_EMORE
)
798 dev
->stats
.collisions
+= 2;
800 dev
->stats
.tx_packets
++;
807 if (netif_queue_stopped(dev
) &&
809 netif_wake_queue(dev
);
811 spin_unlock(&lp
->lock
);
814 static irqreturn_t
lance_interrupt(int irq
, void *dev_id
)
816 struct net_device
*dev
= dev_id
;
817 struct lance_private
*lp
= netdev_priv(dev
);
820 sbus_writew(LE_CSR0
, lp
->lregs
+ RAP
);
821 csr0
= sbus_readw(lp
->lregs
+ RDP
);
823 /* Acknowledge all the interrupt sources ASAP */
824 sbus_writew(csr0
& (LE_C0_INTR
| LE_C0_TINT
| LE_C0_RINT
),
827 if ((csr0
& LE_C0_ERR
) != 0) {
828 /* Clear the error condition */
829 sbus_writew((LE_C0_BABL
| LE_C0_ERR
| LE_C0_MISS
|
830 LE_C0_CERR
| LE_C0_MERR
),
834 if (csr0
& LE_C0_RINT
)
837 if (csr0
& LE_C0_TINT
)
840 if (csr0
& LE_C0_BABL
)
841 dev
->stats
.tx_errors
++;
843 if (csr0
& LE_C0_MISS
)
844 dev
->stats
.rx_errors
++;
846 if (csr0
& LE_C0_MERR
) {
848 u32 addr
= sbus_readl(lp
->dregs
+ DMA_ADDR
);
850 printk(KERN_ERR
"%s: Memory error, status %04x, addr %06x\n",
851 dev
->name
, csr0
, addr
& 0xffffff);
853 printk(KERN_ERR
"%s: Memory error, status %04x\n",
857 sbus_writew(LE_C0_STOP
, lp
->lregs
+ RDP
);
860 u32 dma_csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
862 dma_csr
|= DMA_FIFO_INV
;
863 sbus_writel(dma_csr
, lp
->dregs
+ DMA_CSR
);
868 init_restart_lance(lp
);
869 netif_wake_queue(dev
);
872 sbus_writew(LE_C0_INEA
, lp
->lregs
+ RDP
);
877 /* Build a fake network packet and send it to ourselves. */
878 static void build_fake_packet(struct lance_private
*lp
)
880 struct net_device
*dev
= lp
->dev
;
883 entry
= lp
->tx_new
& TX_RING_MOD_MASK
;
884 if (lp
->pio_buffer
) {
885 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
886 u16 __iomem
*packet
= (u16 __iomem
*) &(ib
->tx_buf
[entry
][0]);
887 struct ethhdr __iomem
*eth
= (struct ethhdr __iomem
*) packet
;
888 for (i
= 0; i
< (ETH_ZLEN
/ sizeof(u16
)); i
++)
889 sbus_writew(0, &packet
[i
]);
890 for (i
= 0; i
< 6; i
++) {
891 sbus_writeb(dev
->dev_addr
[i
], ð
->h_dest
[i
]);
892 sbus_writeb(dev
->dev_addr
[i
], ð
->h_source
[i
]);
894 sbus_writew((-ETH_ZLEN
) | 0xf000, &ib
->btx_ring
[entry
].length
);
895 sbus_writew(0, &ib
->btx_ring
[entry
].misc
);
896 sbus_writeb(LE_T1_POK
|LE_T1_OWN
, &ib
->btx_ring
[entry
].tmd1_bits
);
898 struct lance_init_block
*ib
= lp
->init_block_mem
;
899 u16
*packet
= (u16
*) &(ib
->tx_buf
[entry
][0]);
900 struct ethhdr
*eth
= (struct ethhdr
*) packet
;
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 static int lance_open(struct net_device
*dev
)
915 struct lance_private
*lp
= netdev_priv(dev
);
920 if (request_irq(dev
->irq
, lance_interrupt
, IRQF_SHARED
,
921 lancestr
, (void *) dev
)) {
922 printk(KERN_ERR
"Lance: Can't get irq %d\n", dev
->irq
);
926 /* On the 4m, setup the ledma to provide the upper bits for buffers */
928 u32 regval
= lp
->init_block_dvma
& 0xff000000;
930 sbus_writel(regval
, lp
->dregs
+ DMA_TEST
);
933 /* Set mode and clear multicast filter only at device open,
934 * so that lance_init_ring() called at any error will not
935 * forget multicast filters.
937 * BTW it is common bug in all lance drivers! --ANK
939 if (lp
->pio_buffer
) {
940 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
941 sbus_writew(0, &ib
->mode
);
942 sbus_writel(0, &ib
->filter
[0]);
943 sbus_writel(0, &ib
->filter
[1]);
945 struct lance_init_block
*ib
= lp
->init_block_mem
;
954 netif_start_queue(dev
);
956 status
= init_restart_lance(lp
);
957 if (!status
&& lp
->auto_select
) {
958 build_fake_packet(lp
);
959 sbus_writew(LE_C0_INEA
| LE_C0_TDMD
, lp
->lregs
+ RDP
);
965 static int lance_close(struct net_device
*dev
)
967 struct lance_private
*lp
= netdev_priv(dev
);
969 netif_stop_queue(dev
);
970 del_timer_sync(&lp
->multicast_timer
);
974 free_irq(dev
->irq
, (void *) dev
);
978 static int lance_reset(struct net_device
*dev
)
980 struct lance_private
*lp
= netdev_priv(dev
);
985 /* On the 4m, reset the dma too */
989 printk(KERN_ERR
"resetting ledma\n");
990 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
991 sbus_writel(csr
| DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
993 sbus_writel(csr
& ~DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
995 addr
= lp
->init_block_dvma
& 0xff000000;
996 sbus_writel(addr
, lp
->dregs
+ DMA_TEST
);
1000 netif_trans_update(dev
); /* prevent tx timeout */
1001 status
= init_restart_lance(lp
);
1005 static void lance_piocopy_from_skb(void __iomem
*dest
, unsigned char *src
, int len
)
1007 void __iomem
*piobuf
= dest
;
1012 switch ((unsigned long)src
& 0x3) {
1016 sbus_writel(*p32
, piobuf
);
1033 sbus_writel(val
, piobuf
);
1043 u32 val
= p16
[0]<<16 | p16
[1];
1044 sbus_writel(val
, piobuf
);
1053 u16 val
= src
[0] << 8 | src
[1];
1054 sbus_writew(val
, piobuf
);
1060 sbus_writeb(src
[0], piobuf
);
1063 static void lance_piozero(void __iomem
*dest
, int len
)
1065 void __iomem
*piobuf
= dest
;
1067 if ((unsigned long)piobuf
& 1) {
1068 sbus_writeb(0, piobuf
);
1075 sbus_writeb(0, piobuf
);
1078 if ((unsigned long)piobuf
& 2) {
1079 sbus_writew(0, piobuf
);
1086 sbus_writel(0, piobuf
);
1091 sbus_writew(0, piobuf
);
1096 sbus_writeb(0, piobuf
);
1099 static void lance_tx_timeout(struct net_device
*dev
)
1101 struct lance_private
*lp
= netdev_priv(dev
);
1103 printk(KERN_ERR
"%s: transmit timed out, status %04x, reset\n",
1104 dev
->name
, sbus_readw(lp
->lregs
+ RDP
));
1106 netif_wake_queue(dev
);
1109 static int lance_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1111 struct lance_private
*lp
= netdev_priv(dev
);
1112 int entry
, skblen
, len
;
1116 len
= (skblen
<= ETH_ZLEN
) ? ETH_ZLEN
: skblen
;
1118 spin_lock_irq(&lp
->lock
);
1120 dev
->stats
.tx_bytes
+= len
;
1122 entry
= lp
->tx_new
& TX_RING_MOD_MASK
;
1123 if (lp
->pio_buffer
) {
1124 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
1125 sbus_writew((-len
) | 0xf000, &ib
->btx_ring
[entry
].length
);
1126 sbus_writew(0, &ib
->btx_ring
[entry
].misc
);
1127 lance_piocopy_from_skb(&ib
->tx_buf
[entry
][0], skb
->data
, skblen
);
1129 lance_piozero(&ib
->tx_buf
[entry
][skblen
], len
- skblen
);
1130 sbus_writeb(LE_T1_POK
| LE_T1_OWN
, &ib
->btx_ring
[entry
].tmd1_bits
);
1132 struct lance_init_block
*ib
= lp
->init_block_mem
;
1133 ib
->btx_ring
[entry
].length
= (-len
) | 0xf000;
1134 ib
->btx_ring
[entry
].misc
= 0;
1135 skb_copy_from_linear_data(skb
, &ib
->tx_buf
[entry
][0], skblen
);
1137 memset((char *) &ib
->tx_buf
[entry
][skblen
], 0, len
- skblen
);
1138 ib
->btx_ring
[entry
].tmd1_bits
= (LE_T1_POK
| LE_T1_OWN
);
1141 lp
->tx_new
= TX_NEXT(entry
);
1143 if (TX_BUFFS_AVAIL
<= 0)
1144 netif_stop_queue(dev
);
1146 /* Kick the lance: transmit now */
1147 sbus_writew(LE_C0_INEA
| LE_C0_TDMD
, lp
->lregs
+ RDP
);
1149 /* Read back CSR to invalidate the E-Cache.
1150 * This is needed, because DMA_DSBL_WR_INV is set.
1153 sbus_readw(lp
->lregs
+ RDP
);
1155 spin_unlock_irq(&lp
->lock
);
1159 return NETDEV_TX_OK
;
1162 /* taken from the depca driver */
1163 static void lance_load_multicast(struct net_device
*dev
)
1165 struct lance_private
*lp
= netdev_priv(dev
);
1166 struct netdev_hw_addr
*ha
;
1170 /* set all multicast bits */
1171 if (dev
->flags
& IFF_ALLMULTI
)
1176 if (lp
->pio_buffer
) {
1177 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
1178 sbus_writel(val
, &ib
->filter
[0]);
1179 sbus_writel(val
, &ib
->filter
[1]);
1181 struct lance_init_block
*ib
= lp
->init_block_mem
;
1182 ib
->filter
[0] = val
;
1183 ib
->filter
[1] = val
;
1186 if (dev
->flags
& IFF_ALLMULTI
)
1190 netdev_for_each_mc_addr(ha
, dev
) {
1191 crc
= ether_crc_le(6, ha
->addr
);
1193 if (lp
->pio_buffer
) {
1194 struct lance_init_block __iomem
*ib
= lp
->init_block_iomem
;
1195 u16 __iomem
*mcast_table
= (u16 __iomem
*) &ib
->filter
;
1196 u16 tmp
= sbus_readw(&mcast_table
[crc
>>4]);
1197 tmp
|= 1 << (crc
& 0xf);
1198 sbus_writew(tmp
, &mcast_table
[crc
>>4]);
1200 struct lance_init_block
*ib
= lp
->init_block_mem
;
1201 u16
*mcast_table
= (u16
*) &ib
->filter
;
1202 mcast_table
[crc
>> 4] |= 1 << (crc
& 0xf);
1207 static void lance_set_multicast(struct net_device
*dev
)
1209 struct lance_private
*lp
= netdev_priv(dev
);
1210 struct lance_init_block
*ib_mem
= lp
->init_block_mem
;
1211 struct lance_init_block __iomem
*ib_iomem
= lp
->init_block_iomem
;
1214 if (!netif_running(dev
))
1217 if (lp
->tx_old
!= lp
->tx_new
) {
1218 mod_timer(&lp
->multicast_timer
, jiffies
+ 4);
1219 netif_wake_queue(dev
);
1223 netif_stop_queue(dev
);
1229 mode
= sbus_readw(&ib_iomem
->mode
);
1231 mode
= ib_mem
->mode
;
1232 if (dev
->flags
& IFF_PROMISC
) {
1235 sbus_writew(mode
, &ib_iomem
->mode
);
1237 ib_mem
->mode
= mode
;
1239 mode
&= ~LE_MO_PROM
;
1241 sbus_writew(mode
, &ib_iomem
->mode
);
1243 ib_mem
->mode
= mode
;
1244 lance_load_multicast(dev
);
1247 init_restart_lance(lp
);
1248 netif_wake_queue(dev
);
1251 static void lance_set_multicast_retry(unsigned long _opaque
)
1253 struct net_device
*dev
= (struct net_device
*) _opaque
;
1255 lance_set_multicast(dev
);
1258 static void lance_free_hwresources(struct lance_private
*lp
)
1261 of_iounmap(&lp
->op
->resource
[0], lp
->lregs
, LANCE_REG_SIZE
);
1263 struct platform_device
*ledma
= lp
->ledma
;
1265 of_iounmap(&ledma
->resource
[0], lp
->dregs
,
1266 resource_size(&ledma
->resource
[0]));
1268 if (lp
->init_block_iomem
) {
1269 of_iounmap(&lp
->lebuffer
->resource
[0], lp
->init_block_iomem
,
1270 sizeof(struct lance_init_block
));
1271 } else if (lp
->init_block_mem
) {
1272 dma_free_coherent(&lp
->op
->dev
,
1273 sizeof(struct lance_init_block
),
1275 lp
->init_block_dvma
);
1279 /* Ethtool support... */
1280 static void sparc_lance_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1282 strlcpy(info
->driver
, "sunlance", sizeof(info
->driver
));
1283 strlcpy(info
->version
, "2.02", sizeof(info
->version
));
1286 static const struct ethtool_ops sparc_lance_ethtool_ops
= {
1287 .get_drvinfo
= sparc_lance_get_drvinfo
,
1288 .get_link
= ethtool_op_get_link
,
1291 static const struct net_device_ops sparc_lance_ops
= {
1292 .ndo_open
= lance_open
,
1293 .ndo_stop
= lance_close
,
1294 .ndo_start_xmit
= lance_start_xmit
,
1295 .ndo_set_rx_mode
= lance_set_multicast
,
1296 .ndo_tx_timeout
= lance_tx_timeout
,
1297 .ndo_set_mac_address
= eth_mac_addr
,
1298 .ndo_validate_addr
= eth_validate_addr
,
1301 static int sparc_lance_probe_one(struct platform_device
*op
,
1302 struct platform_device
*ledma
,
1303 struct platform_device
*lebuffer
)
1305 struct device_node
*dp
= op
->dev
.of_node
;
1306 static unsigned version_printed
;
1307 struct lance_private
*lp
;
1308 struct net_device
*dev
;
1311 dev
= alloc_etherdev(sizeof(struct lance_private
) + 8);
1315 lp
= netdev_priv(dev
);
1317 if (sparc_lance_debug
&& version_printed
++ == 0)
1318 printk (KERN_INFO
"%s", version
);
1320 spin_lock_init(&lp
->lock
);
1322 /* Copy the IDPROM ethernet address to the device structure, later we
1323 * will copy the address in the device structure to the lance
1324 * initialization block.
1326 for (i
= 0; i
< 6; i
++)
1327 dev
->dev_addr
[i
] = idprom
->id_ethaddr
[i
];
1329 /* Get the IO region */
1330 lp
->lregs
= of_ioremap(&op
->resource
[0], 0,
1331 LANCE_REG_SIZE
, lancestr
);
1333 printk(KERN_ERR
"SunLance: Cannot map registers.\n");
1339 lp
->dregs
= of_ioremap(&ledma
->resource
[0], 0,
1340 resource_size(&ledma
->resource
[0]),
1343 printk(KERN_ERR
"SunLance: Cannot map "
1344 "ledma registers.\n");
1350 lp
->lebuffer
= lebuffer
;
1353 if (lebuffer
->resource
[0].start
& 7) {
1354 printk(KERN_ERR
"SunLance: ERROR: Rx and Tx rings not on even boundary.\n");
1357 lp
->init_block_iomem
=
1358 of_ioremap(&lebuffer
->resource
[0], 0,
1359 sizeof(struct lance_init_block
), "lebuffer");
1360 if (!lp
->init_block_iomem
) {
1361 printk(KERN_ERR
"SunLance: Cannot map PIO buffer.\n");
1364 lp
->init_block_dvma
= 0;
1366 lp
->init_ring
= lance_init_ring_pio
;
1367 lp
->rx
= lance_rx_pio
;
1368 lp
->tx
= lance_tx_pio
;
1370 lp
->init_block_mem
=
1371 dma_alloc_coherent(&op
->dev
,
1372 sizeof(struct lance_init_block
),
1373 &lp
->init_block_dvma
, GFP_ATOMIC
);
1374 if (!lp
->init_block_mem
)
1378 lp
->init_ring
= lance_init_ring_dvma
;
1379 lp
->rx
= lance_rx_dvma
;
1380 lp
->tx
= lance_tx_dvma
;
1382 lp
->busmaster_regval
= of_getintprop_default(dp
, "busmaster-regval",
1387 lp
->name
= lancestr
;
1389 lp
->burst_sizes
= 0;
1391 struct device_node
*ledma_dp
= ledma
->dev
.of_node
;
1392 struct device_node
*sbus_dp
;
1393 unsigned int sbmask
;
1397 /* Find burst-size property for ledma */
1398 lp
->burst_sizes
= of_getintprop_default(ledma_dp
,
1401 /* ledma may be capable of fast bursts, but sbus may not. */
1402 sbus_dp
= ledma_dp
->parent
;
1403 sbmask
= of_getintprop_default(sbus_dp
, "burst-sizes",
1405 lp
->burst_sizes
&= sbmask
;
1407 /* Get the cable-selection property */
1408 prop
= of_get_property(ledma_dp
, "cable-selection", NULL
);
1409 if (!prop
|| prop
[0] == '\0') {
1410 struct device_node
*nd
;
1412 printk(KERN_INFO
"SunLance: using "
1413 "auto-carrier-detection.\n");
1415 nd
= of_find_node_by_path("/options");
1419 prop
= of_get_property(nd
, "tpe-link-test?", NULL
);
1423 if (strcmp(prop
, "true")) {
1424 printk(KERN_NOTICE
"SunLance: warning: overriding option "
1425 "'tpe-link-test?'\n");
1426 printk(KERN_NOTICE
"SunLance: warning: mail any problems "
1427 "to ecd@skynet.be\n");
1428 auxio_set_lte(AUXIO_LTE_ON
);
1431 lp
->auto_select
= 1;
1433 } else if (!strcmp(prop
, "aui")) {
1434 lp
->auto_select
= 0;
1437 lp
->auto_select
= 0;
1442 csr
= sbus_readl(lp
->dregs
+ DMA_CSR
);
1443 sbus_writel(csr
| DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1445 sbus_writel(csr
& ~DMA_RST_ENET
, lp
->dregs
+ DMA_CSR
);
1450 SET_NETDEV_DEV(dev
, &op
->dev
);
1451 dev
->watchdog_timeo
= 5*HZ
;
1452 dev
->ethtool_ops
= &sparc_lance_ethtool_ops
;
1453 dev
->netdev_ops
= &sparc_lance_ops
;
1455 dev
->irq
= op
->archdata
.irqs
[0];
1457 /* We cannot sleep if the chip is busy during a
1458 * multicast list update event, because such events
1459 * can occur from interrupts (ex. IPv6). So we
1460 * use a timer to try again later when necessary. -DaveM
1462 init_timer(&lp
->multicast_timer
);
1463 lp
->multicast_timer
.data
= (unsigned long) dev
;
1464 lp
->multicast_timer
.function
= lance_set_multicast_retry
;
1466 if (register_netdev(dev
)) {
1467 printk(KERN_ERR
"SunLance: Cannot register device.\n");
1471 platform_set_drvdata(op
, lp
);
1473 printk(KERN_INFO
"%s: LANCE %pM\n",
1474 dev
->name
, dev
->dev_addr
);
1479 lance_free_hwresources(lp
);
1484 static int sunlance_sbus_probe(struct platform_device
*op
)
1486 struct platform_device
*parent
= to_platform_device(op
->dev
.parent
);
1487 struct device_node
*parent_dp
= parent
->dev
.of_node
;
1490 if (!strcmp(parent_dp
->name
, "ledma")) {
1491 err
= sparc_lance_probe_one(op
, parent
, NULL
);
1492 } else if (!strcmp(parent_dp
->name
, "lebuffer")) {
1493 err
= sparc_lance_probe_one(op
, NULL
, parent
);
1495 err
= sparc_lance_probe_one(op
, NULL
, NULL
);
1500 static int sunlance_sbus_remove(struct platform_device
*op
)
1502 struct lance_private
*lp
= platform_get_drvdata(op
);
1503 struct net_device
*net_dev
= lp
->dev
;
1505 unregister_netdev(net_dev
);
1507 lance_free_hwresources(lp
);
1509 free_netdev(net_dev
);
1514 static const struct of_device_id sunlance_sbus_match
[] = {
1521 MODULE_DEVICE_TABLE(of
, sunlance_sbus_match
);
1523 static struct platform_driver sunlance_sbus_driver
= {
1526 .of_match_table
= sunlance_sbus_match
,
1528 .probe
= sunlance_sbus_probe
,
1529 .remove
= sunlance_sbus_remove
,
1532 module_platform_driver(sunlance_sbus_driver
);