1 /* $Id: sunlance.c,v 1.81 1998/08/10 09:08:23 jj 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) 64 "sunlance.c:v1.11 27/Dec/97 Miguel de Icaza (miguel@nuclecu.unam.mx)\n"; 66 static char*lancestr
="LANCE"; 67 static char*lancedma
="LANCE DMA"; 69 #include <linux/config.h> 70 #include <linux/module.h> 72 #include <linux/kernel.h> 73 #include <linux/sched.h> 74 #include <linux/types.h> 75 #include <linux/fcntl.h> 76 #include <linux/interrupt.h> 77 #include <linux/ptrace.h> 78 #include <linux/ioport.h> 80 #include <linux/malloc.h> 81 #include <linux/string.h> 82 #include <linux/delay.h> 83 #include <linux/init.h> 84 #include <asm/system.h> 85 #include <asm/bitops.h> 88 #include <asm/pgtable.h> 89 #include <linux/errno.h> 90 #include <asm/byteorder.h>/* Used by the checksum routines */ 92 /* Used for the temporal inet entries and routing */ 93 #include <linux/socket.h> 94 #include <linux/route.h> 96 #include <asm/idprom.h> 98 #include <asm/openprom.h> 99 #include <asm/oplib.h> 100 #include <asm/auxio.h>/* For tpe-link-test? setting */ 103 #include <linux/netdevice.h> 104 #include <linux/etherdevice.h> 105 #include <linux/skbuff.h> 107 #include <asm/idprom.h> 108 #include <asm/machines.h> 110 /* Define: 2^4 Tx buffers and 2^4 Rx buffers */ 111 #ifndef LANCE_LOG_TX_BUFFERS 112 #define LANCE_LOG_TX_BUFFERS 4 113 #define LANCE_LOG_RX_BUFFERS 4 116 #define CRC_POLYNOMIAL_BE 0x04c11db7UL/* Ethernet CRC, big endian */ 117 #define CRC_POLYNOMIAL_LE 0xedb88320UL/* Ethernet CRC, little endian */ 124 #define LE_MO_PROM 0x8000/* Enable promiscuous mode */ 126 #define LE_C0_ERR 0x8000/* Error: set if BAB, SQE, MISS or ME is set */ 127 #define LE_C0_BABL 0x4000/* BAB: Babble: tx timeout. */ 128 #define LE_C0_CERR 0x2000/* SQE: Signal quality error */ 129 #define LE_C0_MISS 0x1000/* MISS: Missed a packet */ 130 #define LE_C0_MERR 0x0800/* ME: Memory error */ 131 #define LE_C0_RINT 0x0400/* Received interrupt */ 132 #define LE_C0_TINT 0x0200/* Transmitter Interrupt */ 133 #define LE_C0_IDON 0x0100/* IFIN: Init finished. */ 134 #define LE_C0_INTR 0x0080/* Interrupt or error */ 135 #define LE_C0_INEA 0x0040/* Interrupt enable */ 136 #define LE_C0_RXON 0x0020/* Receiver on */ 137 #define LE_C0_TXON 0x0010/* Transmitter on */ 138 #define LE_C0_TDMD 0x0008/* Transmitter demand */ 139 #define LE_C0_STOP 0x0004/* Stop the card */ 140 #define LE_C0_STRT 0x0002/* Start the card */ 141 #define LE_C0_INIT 0x0001/* Init the card */ 143 #define LE_C3_BSWP 0x4/* SWAP */ 144 #define LE_C3_ACON 0x2/* ALE Control */ 145 #define LE_C3_BCON 0x1/* Byte control */ 147 /* Receive message descriptor 1 */ 148 #define LE_R1_OWN 0x80/* Who owns the entry */ 149 #define LE_R1_ERR 0x40/* Error: if FRA, OFL, CRC or BUF is set */ 150 #define LE_R1_FRA 0x20/* FRA: Frame error */ 151 #define LE_R1_OFL 0x10/* OFL: Frame overflow */ 152 #define LE_R1_CRC 0x08/* CRC error */ 153 #define LE_R1_BUF 0x04/* BUF: Buffer error */ 154 #define LE_R1_SOP 0x02/* Start of packet */ 155 #define LE_R1_EOP 0x01/* End of packet */ 156 #define LE_R1_POK 0x03/* Packet is complete: SOP + EOP */ 158 #define LE_T1_OWN 0x80/* Lance owns the packet */ 159 #define LE_T1_ERR 0x40/* Error summary */ 160 #define LE_T1_EMORE 0x10/* Error: more than one retry needed */ 161 #define LE_T1_EONE 0x08/* Error: one retry needed */ 162 #define LE_T1_EDEF 0x04/* Error: deferred */ 163 #define LE_T1_SOP 0x02/* Start of packet */ 164 #define LE_T1_EOP 0x01/* End of packet */ 165 #define LE_T1_POK 0x03/* Packet is complete: SOP + EOP */ 167 #define LE_T3_BUF 0x8000/* Buffer error */ 168 #define LE_T3_UFL 0x4000/* Error underflow */ 169 #define LE_T3_LCOL 0x1000/* Error late collision */ 170 #define LE_T3_CLOS 0x0800/* Error carrier loss */ 171 #define LE_T3_RTY 0x0400/* Error retry */ 172 #define LE_T3_TDR 0x03ff/* Time Domain Reflectometry counter */ 174 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS)) 175 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1) 176 #define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29) 178 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS)) 179 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1) 180 #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29) 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 unsigned short rmd0
;/* low address of packet */ 188 unsigned char rmd1_bits
;/* descriptor bits */ 189 unsigned char rmd1_hadr
;/* high address of packet */ 190 short length
;/* This length is 2s complement (negative)! 193 unsigned short mblength
;/* This is the actual number of bytes received */ 196 struct lance_tx_desc
{ 197 unsigned short tmd0
;/* low address of packet */ 198 unsigned char tmd1_bits
;/* descriptor bits */ 199 unsigned char tmd1_hadr
;/* high address of packet */ 200 short 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 unsigned short mode
;/* Pre-set mode (reg. 15) */ 208 unsigned char phys_addr
[6];/* Physical ethernet address */ 209 unsigned filter
[2];/* Multicast filter. */ 211 /* Receive and transmit ring base, along with extra bits. */ 212 unsigned short rx_ptr
;/* receive descriptor addr */ 213 unsigned short rx_len
;/* receive len and high addr */ 214 unsigned short tx_ptr
;/* transmit descriptor addr */ 215 unsigned short 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 char tx_buf
[TX_RING_SIZE
][TX_BUFF_SIZE
]; 222 char pad
[2];/* align rx_buf for copy_and_sum(). */ 223 char 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
{ 234 volatilestruct lance_regs
*ll
; 235 volatilestruct lance_init_block
*init_block
; 236 __u32 init_block_dvma
; 241 struct net_device_stats stats
; 242 struct Linux_SBus_DMA
*ledma
;/* If set this points to ledma */ 243 /* and arch = sun4m */ 245 int tpe
;/* cable-selection is TPE */ 246 int auto_select
;/* cable-selection by carrier */ 247 int burst_sizes
;/* ledma SBus burst sizes */ 249 unsigned short busmaster_regval
; 250 unsigned short pio_buffer
; 252 struct device
*dev
;/* Backpointer */ 253 struct lance_private
*next_module
; 254 struct linux_sbus
*sbus
; 257 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\ 258 lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\ 259 lp->tx_old - lp->tx_new-1) 261 /* On the sparc, the lance control ports are memory mapped */ 263 unsigned short rdp
;/* register data port */ 264 unsigned short rap
;/* register address port */ 267 int sparc_lance_debug
=2; 269 /* The Lance uses 24 bit addresses */ 270 /* On the Sun4c the DVMA will provide the remaining bytes for us */ 271 /* On the Sun4m we have to instruct the ledma to provide them */ 272 /* Even worse, on scsi/ether SBUS cards, the init block and the 273 * transmit/receive buffers are addresses as offsets from absolute 274 * zero on the lebuffer PIO area. -davem 277 #define LANCE_ADDR(x) ((long)(x) & ~0xff000000) 280 static struct lance_private
*root_lance_dev
= NULL
; 283 /* Load the CSR registers */ 284 static voidload_csrs(struct lance_private
*lp
) 286 volatilestruct lance_regs
*ll
= lp
->ll
; 287 __u32 ib_dvma
= lp
->init_block_dvma
; 290 /* This is right now because when we are using a PIO buffered 291 * init block, init_block_dvma is set to zero. -DaveM 293 leptr
=LANCE_ADDR(ib_dvma
); 296 ll
->rdp
= (leptr
&0xFFFF); 298 ll
->rdp
= leptr
>>16; 300 ll
->rdp
= lp
->busmaster_regval
; 302 /* Point back to csr0 */ 308 /* Setup the Lance Rx and Tx rings */ 309 /* Sets dev->tbusy */ 310 static voidlance_init_ring(struct device
*dev
) 312 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
; 313 volatilestruct lance_init_block
*ib
= lp
->init_block
; 314 __u32 ib_dvma
= lp
->init_block_dvma
; 315 __u32 aib
;/* for LANCE_ADDR computations */ 319 /* This is right now because when we are using a PIO buffered 320 * init block, init_block_dvma is set to zero. -DaveM 324 /* Lock out other processes while setting up hardware */ 326 lp
->rx_new
= lp
->tx_new
=0; 327 lp
->rx_old
= lp
->tx_old
=0; 331 /* Copy the ethernet address to the lance init block 332 * Note that on the sparc you need to swap the ethernet address. 333 * Note also we want the CPU ptr of the init_block here. 335 ib
->phys_addr
[0] = dev
->dev_addr
[1]; 336 ib
->phys_addr
[1] = dev
->dev_addr
[0]; 337 ib
->phys_addr
[2] = dev
->dev_addr
[3]; 338 ib
->phys_addr
[3] = dev
->dev_addr
[2]; 339 ib
->phys_addr
[4] = dev
->dev_addr
[5]; 340 ib
->phys_addr
[5] = dev
->dev_addr
[4]; 343 printk("TX rings:\n"); 345 /* Setup the Tx ring entries */ 346 for(i
=0; i
<= TX_RING_SIZE
; i
++) { 347 leptr
=LANCE_ADDR(aib
+libbuff_offset(tx_buf
, i
)); 348 ib
->btx_ring
[i
].tmd0
= leptr
; 349 ib
->btx_ring
[i
].tmd1_hadr
= leptr
>>16; 350 ib
->btx_ring
[i
].tmd1_bits
=0; 351 ib
->btx_ring
[i
].length
=0xf000;/* The ones required by tmd2 */ 352 ib
->btx_ring
[i
].misc
=0; 354 if(ZERO
)printk("%d: 0x%8.8x\n", i
, leptr
); 357 /* Setup the Rx ring entries */ 359 printk("RX rings:\n"); 360 for(i
=0; i
< RX_RING_SIZE
; i
++) { 361 leptr
=LANCE_ADDR(aib
+libbuff_offset(rx_buf
, i
)); 363 ib
->brx_ring
[i
].rmd0
= leptr
; 364 ib
->brx_ring
[i
].rmd1_hadr
= leptr
>>16; 365 ib
->brx_ring
[i
].rmd1_bits
= LE_R1_OWN
; 366 ib
->brx_ring
[i
].length
= -RX_BUFF_SIZE
|0xf000; 367 ib
->brx_ring
[i
].mblength
=0; 369 printk("%d: 0x%8.8x\n", i
, leptr
); 372 /* Setup the initialization block */ 374 /* Setup rx descriptor pointer */ 375 leptr
=LANCE_ADDR(aib
+libdesc_offset(brx_ring
,0)); 376 ib
->rx_len
= (LANCE_LOG_RX_BUFFERS
<<13) | (leptr
>>16); 379 printk("RX ptr: %8.8x\n", leptr
); 381 /* Setup tx descriptor pointer */ 382 leptr
=LANCE_ADDR(aib
+libdesc_offset(btx_ring
,0)); 383 ib
->tx_len
= (LANCE_LOG_TX_BUFFERS
<<13) | (leptr
>>16); 386 printk("TX ptr: %8.8x\n", leptr
); 388 /* Clear the multicast filter */ 393 static intinit_restart_lance(struct lance_private
*lp
) 395 volatilestruct lance_regs
*ll
= lp
->ll
; 399 struct sparc_dma_registers
*dregs
= lp
->ledma
->regs
; 402 if(!(dregs
->cond_reg
& DMA_HNDL_ERROR
)) { 403 /* E-Cache draining */ 404 while(dregs
->cond_reg
& DMA_FIFO_ISDRAIN
) 408 creg
= dregs
->cond_reg
; 409 if(lp
->burst_sizes
& DMA_BURST32
) 410 creg
|= DMA_E_BURST8
; 412 creg
&= ~DMA_E_BURST8
; 414 creg
|= (DMA_DSBL_RD_DRN
| DMA_DSBL_WR_INV
| DMA_FIFO_INV
); 417 creg
|= DMA_EN_ENETAUI
; 419 creg
&= ~DMA_EN_ENETAUI
; 421 dregs
->cond_reg
= creg
; 426 ll
->rdp
= LE_C0_INIT
; 428 /* Wait for the lance to complete initialization */ 429 for(i
=0; (i
<100) && !(ll
->rdp
& (LE_C0_ERR
| LE_C0_IDON
)); i
++) 431 if((i
==100) || (ll
->rdp
& LE_C0_ERR
)) { 432 printk("LANCE unopened after %d ticks, csr0=%4.4x.\n", i
, ll
->rdp
); 434 printk("dcsr=%8.8x\n", 435 (unsigned int) lp
->ledma
->regs
->cond_reg
); 439 /* Clear IDON by writing a "1", enable interrupts and start lance */ 440 ll
->rdp
= LE_C0_IDON
; 441 ll
->rdp
= LE_C0_INEA
| LE_C0_STRT
; 444 lp
->ledma
->regs
->cond_reg
|= DMA_INT_ENAB
; 449 static intlance_rx(struct device
*dev
) 451 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
; 452 volatilestruct lance_init_block
*ib
= lp
->init_block
; 453 volatilestruct lance_rx_desc
*rd
; 460 for(i
=0; i
< RX_RING_SIZE
; i
++) { 463 ib
->brx_ring
[i
].rmd1_bits
& LE_R1_OWN
?"_":"X"); 466 ib
->brx_ring
[i
].rmd1_bits
& LE_R1_OWN
?".":"1"); 471 for(rd
= &ib
->brx_ring
[lp
->rx_new
]; 472 !((bits
= rd
->rmd1_bits
) & LE_R1_OWN
); 473 rd
= &ib
->brx_ring
[lp
->rx_new
]) { 475 /* We got an incomplete frame? */ 476 if((bits
& LE_R1_POK
) != LE_R1_POK
) { 477 lp
->stats
.rx_over_errors
++; 478 lp
->stats
.rx_errors
++; 479 }else if(bits
& LE_R1_ERR
) { 480 /* Count only the end frame as a rx error, 483 if(bits
& LE_R1_BUF
) lp
->stats
.rx_fifo_errors
++; 484 if(bits
& LE_R1_CRC
) lp
->stats
.rx_crc_errors
++; 485 if(bits
& LE_R1_OFL
) lp
->stats
.rx_over_errors
++; 486 if(bits
& LE_R1_FRA
) lp
->stats
.rx_frame_errors
++; 487 if(bits
& LE_R1_EOP
) lp
->stats
.rx_errors
++; 489 len
= (rd
->mblength
&0xfff) -4; 490 skb
=dev_alloc_skb(len
+2); 493 printk("%s: Memory squeeze, deferring packet.\n", 495 lp
->stats
.rx_dropped
++; 497 rd
->rmd1_bits
= LE_R1_OWN
; 498 lp
->rx_new
= (lp
->rx_new
+1) & RX_RING_MOD_MASK
; 502 lp
->stats
.rx_bytes
+= len
; 505 skb_reserve(skb
,2);/* 16 byte align */ 506 skb_put(skb
, len
);/* make room */ 507 eth_copy_and_sum(skb
, 508 (unsigned char*)&(ib
->rx_buf
[lp
->rx_new
][0]), 510 skb
->protocol
=eth_type_trans(skb
, dev
); 512 lp
->stats
.rx_packets
++; 515 /* Return the packet to the pool */ 517 rd
->rmd1_bits
= LE_R1_OWN
; 518 lp
->rx_new
= (lp
->rx_new
+1) & RX_RING_MOD_MASK
; 523 static intlance_tx(struct device
*dev
) 525 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
; 526 volatilestruct lance_init_block
*ib
= lp
->init_block
; 527 volatilestruct lance_regs
*ll
= lp
->ll
; 528 volatilestruct lance_tx_desc
*td
; 533 for(i
= j
; i
!= lp
->tx_new
; i
= j
) { 534 td
= &ib
->btx_ring
[i
]; 536 /* If we hit a packet not owned by us, stop */ 537 if(td
->tmd1_bits
& LE_T1_OWN
) 540 if(td
->tmd1_bits
& LE_T1_ERR
) { 543 lp
->stats
.tx_errors
++; 544 if(status
& LE_T3_RTY
) lp
->stats
.tx_aborted_errors
++; 545 if(status
& LE_T3_LCOL
) lp
->stats
.tx_window_errors
++; 547 if(status
& LE_T3_CLOS
) { 548 lp
->stats
.tx_carrier_errors
++; 549 if(lp
->auto_select
) { 551 printk("%s: Carrier Lost, trying %s\n", 552 dev
->name
, lp
->tpe
?"TPE":"AUI"); 555 ll
->rdp
= LE_C0_STOP
; 556 lance_init_ring(dev
); 558 init_restart_lance(lp
); 563 /* Buffer errors and underflows turn off the 564 * transmitter, restart the adapter. 566 if(status
& (LE_T3_BUF
|LE_T3_UFL
)) { 567 lp
->stats
.tx_fifo_errors
++; 569 printk("%s: Tx: ERR_BUF|ERR_UFL, restarting\n", 573 ll
->rdp
= LE_C0_STOP
; 574 lance_init_ring(dev
); 576 init_restart_lance(lp
); 579 }else if((td
->tmd1_bits
& LE_T1_POK
) == LE_T1_POK
) { 581 * So we don't count the packet more than once. 583 td
->tmd1_bits
&= ~(LE_T1_POK
); 585 /* One collision before packet was sent. */ 586 if(td
->tmd1_bits
& LE_T1_EONE
) 587 lp
->stats
.collisions
++; 589 /* More than one collision, be optimistic. */ 590 if(td
->tmd1_bits
& LE_T1_EMORE
) 591 lp
->stats
.collisions
+=2; 593 lp
->stats
.tx_packets
++; 596 j
= (j
+1) & TX_RING_MOD_MASK
; 602 static voidlance_interrupt(int irq
,void*dev_id
,struct pt_regs
*regs
) 604 struct device
*dev
= (struct device
*)dev_id
; 605 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
; 606 volatilestruct lance_regs
*ll
= lp
->ll
; 610 printk("%s: again", dev
->name
); 617 /* Acknowledge all the interrupt sources ASAP */ 618 ll
->rdp
= csr0
& (LE_C0_INTR
| LE_C0_TINT
| LE_C0_RINT
); 620 if((csr0
& LE_C0_ERR
)) { 621 /* Clear the error condition */ 622 ll
->rdp
= LE_C0_BABL
| LE_C0_ERR
| LE_C0_MISS
| 623 LE_C0_CERR
| LE_C0_MERR
; 626 if(csr0
& LE_C0_RINT
) 629 if(csr0
& LE_C0_TINT
) 632 if((TX_BUFFS_AVAIL
>=0) && dev
->tbusy
) { 637 if(csr0
& LE_C0_BABL
) 638 lp
->stats
.tx_errors
++; 640 if(csr0
& LE_C0_MISS
) 641 lp
->stats
.rx_errors
++; 643 if(csr0
& LE_C0_MERR
) { 644 struct sparc_dma_registers
*dregs
= lp
->ledma
->regs
; 645 unsigned long tst
= (unsigned long)dregs
->st_addr
; 647 printk("%s: Memory error, status %04x, addr %06lx\n", 648 dev
->name
, csr0
, tst
&0xffffff); 650 ll
->rdp
= LE_C0_STOP
; 653 lp
->ledma
->regs
->cond_reg
|= DMA_FIFO_INV
; 655 lance_init_ring(dev
); 657 init_restart_lance(lp
); 661 ll
->rdp
= LE_C0_INEA
; 665 struct device
*last_dev
=0; 667 static intlance_open(struct device
*dev
) 669 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
; 670 volatilestruct lance_regs
*ll
= lp
->ll
; 675 if(request_irq(dev
->irq
, &lance_interrupt
, SA_SHIRQ
, 676 lancestr
, (void*) dev
)) { 677 printk("Lance: Can't get irq %s\n",__irq_itoa(dev
->irq
)); 683 ll
->rdp
= LE_C0_STOP
; 685 /* On the 4m, setup the ledma to provide the upper bits for buffers */ 687 lp
->ledma
->regs
->dma_test
= ((__u32
) lp
->init_block_dvma
) &0xff000000; 689 lance_init_ring(dev
); 696 status
=init_restart_lance(lp
); 698 /* To emulate SunOS, we add a route to the local network */ 700 dev
->pa_addr
&ip_get_mask(dev
->pa_addr
), 701 ip_get_mask(dev
->pa_addr
), 702 0, dev
, dev
->mtu
,0,0); 704 if(!status
&& lp
->auto_select
) { 706 * Build a fake network packet and send it to ourselfs. 708 volatilestruct lance_init_block
*ib
= lp
->init_block
; 709 volatileunsigned long flush
; 710 unsigned char packet
[ETH_ZLEN
]; 711 struct ethhdr
*eth
= (struct ethhdr
*)packet
; 714 memset(packet
,0, ETH_ZLEN
); 715 for(i
=0; i
<6; i
++) { 716 eth
->h_dest
[i
] = dev
->dev_addr
[i
]; 717 eth
->h_source
[i
] = dev
->dev_addr
[i
]; 720 entry
= lp
->tx_new
& TX_RING_MOD_MASK
; 721 ib
->btx_ring
[entry
].length
= (-ETH_ZLEN
) |0xf000; 722 ib
->btx_ring
[entry
].misc
=0; 724 memcpy((char*)&ib
->tx_buf
[entry
][0], packet
, ETH_ZLEN
); 725 ib
->btx_ring
[entry
].tmd1_bits
= (LE_T1_POK
|LE_T1_OWN
); 726 lp
->tx_new
= (lp
->tx_new
+1) & TX_RING_MOD_MASK
; 728 ll
->rdp
= LE_C0_INEA
| LE_C0_TDMD
; 738 static intlance_close(struct device
*dev
) 740 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
; 741 volatilestruct lance_regs
*ll
= lp
->ll
; 748 ll
->rdp
= LE_C0_STOP
; 750 free_irq(dev
->irq
, (void*) dev
); 755 staticinlineintlance_reset(struct device
*dev
) 757 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
; 758 volatilestruct lance_regs
*ll
= lp
->ll
; 763 ll
->rdp
= LE_C0_STOP
; 765 /* On the 4m, reset the dma too */ 767 printk("resetting ledma\n"); 768 lp
->ledma
->regs
->cond_reg
|= DMA_RST_ENET
; 770 lp
->ledma
->regs
->cond_reg
&= ~DMA_RST_ENET
; 771 lp
->ledma
->regs
->dma_test
= ((__u32
) lp
->init_block_dvma
) &0xff000000; 773 lance_init_ring(dev
); 775 dev
->trans_start
= jiffies
; 779 status
=init_restart_lance(lp
); 781 printk("Lance restart=%d\n", status
); 786 static intlance_start_xmit(struct sk_buff
*skb
,struct device
*dev
) 788 struct lance_private
*lp
= (struct lance_private
*)dev
->priv
; 789 volatilestruct lance_regs
*ll
= lp
->ll
; 790 volatilestruct lance_init_block
*ib
= lp
->init_block
; 791 volatileunsigned long flush
; 793 int entry
, skblen
, len
; 797 /* Transmitter timeout, serious problems */ 799 int tickssofar
= jiffies
- dev
->trans_start
; 801 if(tickssofar
<100) { 804 printk("%s: transmit timed out, status %04x, reset\n", 811 /* Block a timer-based transmit from overlapping. */ 812 if(test_and_set_bit(0, (void*) &dev
->tbusy
) !=0) { 813 printk("Transmitter access conflict.\n"); 821 if(!TX_BUFFS_AVAIL
) { 822 restore_flags(flags
); 826 len
= (skblen
<= ETH_ZLEN
) ? ETH_ZLEN
: skblen
; 828 lp
->stats
.tx_bytes
+= len
; 830 entry
= lp
->tx_new
& TX_RING_MOD_MASK
; 831 ib
->btx_ring
[entry
].length
= (-len
) |0xf000; 832 ib
->btx_ring
[entry
].misc
=0; 834 memcpy((char*)&ib
->tx_buf
[entry
][0], skb
->data
, skblen
); 836 /* Clear the slack of the packet, do I need this? */ 837 /* For a firewall its a good idea - AC */ 839 memset((char*) &ib
->tx_buf
[entry
][skblen
],0, len
- skblen
); 841 /* Now, give the packet to the lance */ 842 ib
->btx_ring
[entry
].tmd1_bits
= (LE_T1_POK
|LE_T1_OWN
); 843 lp
->tx_new
= (lp
->tx_new
+1) & TX_RING_MOD_MASK
; 846 /* Kick the lance: transmit now */ 847 ll
->rdp
= LE_C0_INEA
| LE_C0_TDMD
; 848 dev
->trans_start
= jiffies
; 854 /* Read back CSR to invalidate the E-Cache. 855 * This is needed, because DMA_DSBL_WR_INV is set. */ 859 restore_flags(flags
); 863 static struct net_device_stats
*lance_get_stats(struct device
*dev
) 865 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
; 870 /* taken from the depca driver */ 871 static voidlance_load_multicast(struct device
*dev
) 873 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
; 874 volatilestruct lance_init_block
*ib
= lp
->init_block
; 875 volatile u16
*mcast_table
= (u16
*)&ib
->filter
; 876 struct dev_mc_list
*dmi
=dev
->mc_list
; 879 u32 crc
, poly
= CRC_POLYNOMIAL_LE
; 881 /* set all multicast bits */ 882 if(dev
->flags
& IFF_ALLMULTI
){ 883 ib
->filter
[0] =0xffffffff; 884 ib
->filter
[1] =0xffffffff; 887 /* clear the multicast filter */ 892 for(i
=0; i
< dev
->mc_count
; i
++){ 893 addrs
= dmi
->dmi_addr
; 896 /* multicast address? */ 901 for(byte
=0; byte
<6; byte
++) 902 for(bit
= *addrs
++, j
=0; j
<8; j
++, bit
>>=1) { 905 test
= ((bit
^ crc
) &0x01); 914 mcast_table
[crc
>>4] |=1<< (crc
&0xf); 919 static voidlance_set_multicast(struct device
*dev
) 921 struct lance_private
*lp
= (struct lance_private
*) dev
->priv
; 922 volatilestruct lance_init_block
*ib
= lp
->init_block
; 923 volatilestruct lance_regs
*ll
= lp
->ll
; 927 set_bit(0, (void*) &dev
->tbusy
); 929 while(lp
->tx_old
!= lp
->tx_new
) 933 ll
->rdp
= LE_C0_STOP
; 934 lance_init_ring(dev
); 936 if(dev
->flags
& IFF_PROMISC
) { 937 ib
->mode
|= LE_MO_PROM
; 939 ib
->mode
&= ~LE_MO_PROM
; 940 lance_load_multicast(dev
); 943 init_restart_lance(lp
); 947 __initfunc(static int 948 sparc_lance_init(struct device
*dev
,struct linux_sbus_device
*sdev
, 949 struct Linux_SBus_DMA
*ledma
, 950 struct linux_sbus_device
*lebuffer
)) 952 static unsigned version_printed
=0; 954 struct lance_private
*lp
; 955 volatilestruct lance_regs
*ll
; 958 dev
=init_etherdev(0,sizeof(struct lance_private
) +8); 960 dev
->priv
=kmalloc(sizeof(struct lance_private
) +8, 962 if(dev
->priv
== NULL
) 964 memset(dev
->priv
,0,sizeof(struct lance_private
) +8); 966 if(sparc_lance_debug
&& version_printed
++ ==0) 969 printk("%s: LANCE ", dev
->name
); 970 /* Fill the dev fields */ 971 dev
->base_addr
= (long) sdev
; 973 /* Copy the IDPROM ethernet address to the device structure, later we 974 * will copy the address in the device structure to the lance 975 * initialization block. 978 printk("%2.2x%c", dev
->dev_addr
[i
] = idprom
->id_ethaddr
[i
], 982 /* Get the IO region */ 983 prom_apply_sbus_ranges(sdev
->my_bus
, &sdev
->reg_addrs
[0], 984 sdev
->num_registers
, sdev
); 985 ll
=sparc_alloc_io(sdev
->reg_addrs
[0].phys_addr
,0, 986 sizeof(struct lance_regs
), lancestr
, 987 sdev
->reg_addrs
[0].which_io
,0x0); 989 /* Make certain the data structures used by the LANCE are aligned. */ 990 dev
->priv
= (void*)(((unsigned long)dev
->priv
+7) & ~7); 991 lp
= (struct lance_private
*) dev
->priv
; 992 lp
->sbus
= sdev
->my_bus
; 994 prom_apply_sbus_ranges(lebuffer
->my_bus
, 995 &lebuffer
->reg_addrs
[0], 996 lebuffer
->num_registers
, 999 lp
->init_block
= (void*) 1000 sparc_alloc_io(lebuffer
->reg_addrs
[0].phys_addr
,0, 1001 sizeof(struct lance_init_block
),"lebuffer", 1002 lebuffer
->reg_addrs
[0].which_io
,0); 1003 lp
->init_block_dvma
=0; 1007 lp
->init_block
= (void*) 1008 sparc_dvma_malloc(sizeof(struct lance_init_block
), 1009 lancedma
, &lp
->init_block_dvma
); 1012 lp
->busmaster_regval
=prom_getintdefault(sdev
->prom_node
, 1014 (LE_C3_BSWP
| LE_C3_ACON
| 1018 lp
->name
= lancestr
; 1024 unsigned int sbmask
; 1026 /* Find burst-size property for ledma */ 1027 lp
->burst_sizes
=prom_getintdefault(ledma
->SBus_dev
->prom_node
, 1030 /* ledma may be capable of fast bursts, but sbus may not. */ 1031 sbmask
=prom_getintdefault(ledma
->SBus_dev
->my_bus
->prom_node
, 1032 "burst-sizes", DMA_BURSTBITS
); 1033 lp
->burst_sizes
&= sbmask
; 1035 /* Get the cable-selection property */ 1036 memset(prop
,0,sizeof(prop
)); 1037 prom_getstring(ledma
->SBus_dev
->prom_node
,"cable-selection", 1042 printk("%s: using auto-carrier-detection.\n", 1045 /* Is this found at /options .attributes in all 1046 * Prom versions? XXX 1048 topnd
=prom_getchild(prom_root_node
); 1050 nd
=prom_searchsiblings(topnd
,"options"); 1054 if(!prom_node_has_property(nd
,"tpe-link-test?")) 1057 memset(prop
,0,sizeof(prop
)); 1058 prom_getstring(nd
,"tpe-link-test?", prop
, 1061 if(strcmp(prop
,"true")) { 1062 printk("%s: warning: overriding option " 1063 "'tpe-link-test?'\n", dev
->name
); 1064 printk("%s: warning: mail any problems " 1065 "to ecd@skynet.be\n", dev
->name
); 1066 set_auxio(AUXIO_LINK_TEST
,0); 1071 }else if(!strcmp(prop
,"aui")) { 1080 lp
->ledma
->regs
->cond_reg
|= DMA_RST_ENET
; 1082 lp
->ledma
->regs
->cond_reg
&= ~DMA_RST_ENET
; 1085 /* This should never happen. */ 1086 if((unsigned long)(lp
->init_block
->brx_ring
) &0x07) { 1087 printk("%s: ERROR: Rx and Tx rings not on even boundary.\n", 1093 dev
->open
= &lance_open
; 1094 dev
->stop
= &lance_close
; 1095 dev
->hard_start_xmit
= &lance_start_xmit
; 1096 dev
->get_stats
= &lance_get_stats
; 1097 dev
->set_multicast_list
= &lance_set_multicast
; 1099 dev
->irq
= sdev
->irqs
[0]; 1105 dev
->ifindex
=dev_new_index(); 1106 lp
->next_module
= root_lance_dev
; 1107 root_lance_dev
= lp
; 1112 /* On 4m, find the associated dma for the lance chip */ 1113 staticinlinestruct Linux_SBus_DMA
* 1114 find_ledma(struct linux_sbus_device
*dev
) 1116 struct Linux_SBus_DMA
*p
; 1119 if(p
->SBus_dev
== dev
) 1126 #include <asm/sun4paddr.h> 1128 /* Find all the lance cards on the system and initialize them */ 1129 __initfunc(intsparc_lance_probe(struct device
*dev
)) 1131 static struct linux_sbus_device sdev
; 1132 static int called
=0; 1138 if((idprom
->id_machtype
== (SM_SUN4
|SM_4_330
)) || 1139 (idprom
->id_machtype
== (SM_SUN4
|SM_4_470
))) { 1140 memset(&sdev
,0,sizeof(sdev
)); 1141 sdev
.reg_addrs
[0].phys_addr
= sun4_eth_physaddr
; 1143 returnsparc_lance_init(dev
, &sdev
,0,0); 1148 #else/* !CONFIG_SUN4 */ 1150 /* Find all the lance cards on the system and initialize them */ 1151 __initfunc(intsparc_lance_probe(struct device
*dev
)) 1153 struct linux_sbus
*bus
; 1154 struct linux_sbus_device
*sdev
=0; 1155 struct Linux_SBus_DMA
*ledma
=0; 1156 static int called
=0; 1163 for_each_sbus(bus
) { 1164 for_each_sbusdev(sdev
, bus
) { 1165 if(cards
) dev
= NULL
; 1166 if(strcmp(sdev
->prom_name
,"le") ==0) { 1168 if((v
=sparc_lance_init(dev
, sdev
,0,0))) 1172 if(strcmp(sdev
->prom_name
,"ledma") ==0) { 1174 ledma
=find_ledma(sdev
); 1175 if((v
=sparc_lance_init(dev
, sdev
->child
, 1180 if(strcmp(sdev
->prom_name
,"lebuffer") ==0){ 1182 if((v
=sparc_lance_init(dev
, sdev
->child
, 1187 }/* for each sbusdev */ 1188 }/* for each sbus */ 1193 #endif/* !CONFIG_SUN4 */ 1200 root_lance_dev
= NULL
; 1201 returnsparc_lance_probe(NULL
); 1205 cleanup_module(void) 1207 struct lance_private
*lp
; 1209 while(root_lance_dev
) { 1210 lp
= root_lance_dev
->next_module
; 1212 unregister_netdev(root_lance_dev
->dev
); 1213 kfree(root_lance_dev
->dev
); 1214 root_lance_dev
= lp
;