1 /* sunbmac.c: Driver for Sparc BigMAC 100baseT ethernet adapters.
3 * Copyright (C) 1997, 1998 David S. Miller (davem@caip.rutgers.edu)
7 "sunbmac.c:v1.1 8/Dec/98 David S. Miller (davem@caipfs.rutgers.edu)\n";
9 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/types.h>
14 #include <linux/fcntl.h>
15 #include <linux/interrupt.h>
16 #include <linux/ptrace.h>
17 #include <linux/ioport.h>
19 #include <linux/malloc.h>
20 #include <linux/string.h>
21 #include <linux/delay.h>
22 #include <linux/init.h>
23 #include <asm/system.h>
24 #include <asm/bitops.h>
27 #include <linux/errno.h>
28 #include <asm/byteorder.h>
30 #include <asm/idprom.h>
32 #include <asm/openprom.h>
33 #include <asm/oplib.h>
34 #include <asm/auxio.h>
35 #include <asm/pgtable.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <linux/skbuff.h>
48 #define DP(x) printk x
54 #define DTX(x) printk x
60 #define DIRQ(x) printk x
66 static struct bigmac
*root_bigmac_dev
= NULL
;
69 #define DEFAULT_JAMSIZE 4 /* Toe jam */
71 #define QEC_RESET_TRIES 200
73 static inline int qec_global_reset(struct qe_globreg
*gregs
)
75 int tries
= QEC_RESET_TRIES
;
77 gregs
->ctrl
= GLOB_CTRL_RESET
;
79 if(gregs
->ctrl
& GLOB_CTRL_RESET
) {
87 printk("BigMAC: Cannot reset the QEC.\n");
91 static void qec_init(struct bigmac
*bp
)
93 struct qe_globreg
*gregs
= bp
->gregs
;
94 struct linux_sbus_device
*qec_sdev
= bp
->qec_sbus_dev
;
95 unsigned char bsizes
= bp
->bigmac_bursts
;
98 /* 64byte bursts do not work at the moment, do
99 * not even try to enable them. -DaveM
101 if(bsizes
& DMA_BURST32
)
102 regval
= GLOB_CTRL_B32
;
104 regval
= GLOB_CTRL_B16
;
105 gregs
->ctrl
= regval
| GLOB_CTRL_BMODE
;
107 gregs
->psize
= GLOB_PSIZE_2048
;
109 /* All of memsize is given to bigmac. */
110 gregs
->msize
= qec_sdev
->reg_addrs
[1].reg_size
;
112 /* Half to the transmitter, half to the receiver. */
113 gregs
->rsize
= gregs
->tsize
= qec_sdev
->reg_addrs
[1].reg_size
>> 1;
116 /* XXX auto negotiation on these things might not be pleasant... */
118 #define TX_RESET_TRIES 32
119 #define RX_RESET_TRIES 32
121 static inline void bigmac_tx_reset(struct BIG_MAC_regs
*bregs
)
123 int tries
= TX_RESET_TRIES
;
127 /* The fifo threshold bit is read-only and does
130 while((bregs
->tx_cfg
& ~(BIGMAC_TXCFG_FIFO
)) != 0 &&
135 printk("BIGMAC: Transmitter will not reset.\n");
136 printk("BIGMAC: tx_cfg is %08x\n", bregs
->tx_cfg
);
140 static inline void bigmac_rx_reset(struct BIG_MAC_regs
*bregs
)
142 int tries
= RX_RESET_TRIES
;
145 while((bregs
->rx_cfg
) && --tries
)
149 printk("BIGMAC: Receiver will not reset.\n");
150 printk("BIGMAC: rx_cfg is %08x\n", bregs
->rx_cfg
);
154 /* Reset the transmitter and receiver. */
155 static void bigmac_stop(struct bigmac
*bp
)
157 bigmac_tx_reset(bp
->bregs
);
158 bigmac_rx_reset(bp
->bregs
);
161 static void bigmac_get_counters(struct bigmac
*bp
, struct BIG_MAC_regs
*bregs
)
163 struct enet_statistics
*stats
= &bp
->enet_stats
;
165 stats
->rx_crc_errors
+= bregs
->rcrce_ctr
;
166 bregs
->rcrce_ctr
= 0;
168 stats
->rx_frame_errors
+= bregs
->unale_ctr
;
169 bregs
->unale_ctr
= 0;
171 stats
->rx_length_errors
+= bregs
->gle_ctr
;
174 stats
->tx_aborted_errors
+= bregs
->ex_ctr
;
176 stats
->collisions
+= (bregs
->ex_ctr
+ bregs
->lt_ctr
);
177 bregs
->ex_ctr
= bregs
->lt_ctr
= 0;
180 static inline void bigmac_clean_rings(struct bigmac
*bp
)
184 for(i
= 0; i
< RX_RING_SIZE
; i
++) {
185 if(bp
->rx_skbs
[i
] != NULL
) {
186 dev_kfree_skb(bp
->rx_skbs
[i
]);
187 bp
->rx_skbs
[i
] = NULL
;
191 for(i
= 0; i
< TX_RING_SIZE
; i
++) {
192 if(bp
->tx_skbs
[i
] != NULL
) {
193 dev_kfree_skb(bp
->tx_skbs
[i
]);
194 bp
->tx_skbs
[i
] = NULL
;
199 static void bigmac_init_rings(struct bigmac
*bp
, int from_irq
)
201 struct bmac_init_block
*bb
= bp
->bmac_block
;
202 struct net_device
*dev
= bp
->dev
;
203 int i
, gfp_flags
= GFP_KERNEL
;
205 if(from_irq
|| in_interrupt())
206 gfp_flags
= GFP_ATOMIC
;
208 bp
->rx_new
= bp
->rx_old
= bp
->tx_new
= bp
->tx_old
= 0;
210 /* Free any skippy bufs left around in the rings. */
211 bigmac_clean_rings(bp
);
213 /* Now get new skippy bufs for the receive ring. */
214 for(i
= 0; i
< RX_RING_SIZE
; i
++) {
217 skb
= big_mac_alloc_skb(RX_BUF_ALLOC_SIZE
, gfp_flags
);
221 bp
->rx_skbs
[i
] = skb
;
224 /* Because we reserve afterwards. */
225 skb_put(skb
, ETH_FRAME_LEN
);
226 skb_reserve(skb
, 34);
228 bb
->be_rxd
[i
].rx_addr
= sbus_dvma_addr(skb
->data
);
229 bb
->be_rxd
[i
].rx_flags
=
230 (RXD_OWN
| ((RX_BUF_ALLOC_SIZE
- 34) & RXD_LENGTH
));
233 for(i
= 0; i
< TX_RING_SIZE
; i
++)
234 bb
->be_txd
[i
].tx_flags
= bb
->be_txd
[i
].tx_addr
= 0;
238 static void sun4c_bigmac_init_rings(struct bigmac
*bp
)
240 struct bmac_init_block
*bb
= bp
->bmac_block
;
241 __u32 bbufs_dvma
= bp
->s4c_buf_dvma
;
244 bp
->rx_new
= bp
->rx_old
= bp
->tx_new
= bp
->tx_old
= 0;
246 for(i
= 0; i
< RX_RING_SIZE
; i
++) {
247 bb
->be_rxd
[i
].rx_addr
= bbufs_dvma
+ bbuf_offset(rx_buf
, i
);
248 bb
->be_rxd
[i
].rx_flags
=
249 (RXD_OWN
| (SUN4C_RX_BUFF_SIZE
& RXD_LENGTH
));
252 for(i
= 0; i
< TX_RING_SIZE
; i
++)
253 bb
->be_txd
[i
].tx_flags
= bb
->be_txd
[i
].tx_addr
= 0;
257 #define MGMT_CLKON (MGMT_PAL_INT_MDIO|MGMT_PAL_EXT_MDIO|MGMT_PAL_OENAB|MGMT_PAL_DCLOCK)
258 #define MGMT_CLKOFF (MGMT_PAL_INT_MDIO|MGMT_PAL_EXT_MDIO|MGMT_PAL_OENAB)
260 static inline void idle_transceiver(struct bmac_tcvr
*tregs
)
262 volatile unsigned int garbage
;
266 tregs
->mgmt_pal
= MGMT_CLKOFF
;
267 garbage
= tregs
->mgmt_pal
;
268 tregs
->mgmt_pal
= MGMT_CLKON
;
269 garbage
= tregs
->mgmt_pal
;
273 static void write_tcvr_bit(struct bigmac
*bp
, struct bmac_tcvr
*tregs
, int bit
)
275 volatile unsigned int garbage
;
277 if(bp
->tcvr_type
== internal
) {
278 bit
= (bit
& 1) << 3;
279 tregs
->mgmt_pal
= bit
| (MGMT_PAL_OENAB
| MGMT_PAL_EXT_MDIO
);
280 garbage
= tregs
->mgmt_pal
;
281 tregs
->mgmt_pal
= bit
| (MGMT_PAL_OENAB
|
284 garbage
= tregs
->mgmt_pal
;
285 } else if(bp
->tcvr_type
== external
) {
286 bit
= (bit
& 1) << 2;
287 tregs
->mgmt_pal
= bit
| (MGMT_PAL_INT_MDIO
| MGMT_PAL_OENAB
);
288 garbage
= tregs
->mgmt_pal
;
289 tregs
->mgmt_pal
= bit
| (MGMT_PAL_INT_MDIO
|
292 garbage
= tregs
->mgmt_pal
;
294 printk("write_tcvr_bit: No transceiver type known!\n");
298 static int read_tcvr_bit(struct bigmac
*bp
, struct bmac_tcvr
*tregs
)
300 volatile unsigned int garbage
;
303 if(bp
->tcvr_type
== internal
) {
304 tregs
->mgmt_pal
= MGMT_PAL_EXT_MDIO
;
305 garbage
= tregs
->mgmt_pal
;
306 tregs
->mgmt_pal
= MGMT_PAL_EXT_MDIO
| MGMT_PAL_DCLOCK
;
307 garbage
= tregs
->mgmt_pal
;
308 retval
= (tregs
->mgmt_pal
& MGMT_PAL_INT_MDIO
) >> 3;
309 } else if(bp
->tcvr_type
== external
) {
310 tregs
->mgmt_pal
= MGMT_PAL_INT_MDIO
;
311 garbage
= tregs
->mgmt_pal
;
312 tregs
->mgmt_pal
= MGMT_PAL_INT_MDIO
| MGMT_PAL_DCLOCK
;
313 garbage
= tregs
->mgmt_pal
;
314 retval
= (tregs
->mgmt_pal
& MGMT_PAL_EXT_MDIO
) >> 2;
316 printk("read_tcvr_bit: No transceiver type known!\n");
321 static int read_tcvr_bit2(struct bigmac
*bp
, struct bmac_tcvr
*tregs
)
323 volatile unsigned int garbage
;
326 if(bp
->tcvr_type
== internal
) {
327 tregs
->mgmt_pal
= MGMT_PAL_EXT_MDIO
;
328 garbage
= tregs
->mgmt_pal
;
329 retval
= (tregs
->mgmt_pal
& MGMT_PAL_INT_MDIO
) >> 3;
330 tregs
->mgmt_pal
= (MGMT_PAL_EXT_MDIO
| MGMT_PAL_DCLOCK
);
331 garbage
= tregs
->mgmt_pal
;
332 } else if(bp
->tcvr_type
== external
) {
333 tregs
->mgmt_pal
= MGMT_PAL_INT_MDIO
;
334 garbage
= tregs
->mgmt_pal
;
335 retval
= (tregs
->mgmt_pal
& MGMT_PAL_EXT_MDIO
) >> 2;
336 tregs
->mgmt_pal
= (MGMT_PAL_INT_MDIO
| MGMT_PAL_DCLOCK
);
337 garbage
= tregs
->mgmt_pal
;
339 printk("read_tcvr_bit2: No transceiver type known!\n");
344 static inline void put_tcvr_byte(struct bigmac
*bp
,
345 struct bmac_tcvr
*tregs
,
351 write_tcvr_bit(bp
, tregs
, ((byte
>> shift
) & 1));
353 } while (shift
>= 0);
356 static void bigmac_tcvr_write(struct bigmac
*bp
, struct bmac_tcvr
*tregs
,
357 int reg
, unsigned short val
)
363 switch(bp
->tcvr_type
) {
369 printk("bigmac_tcvr_read: Whoops, no known transceiver type.\n");
373 idle_transceiver(tregs
);
374 write_tcvr_bit(bp
, tregs
, 0);
375 write_tcvr_bit(bp
, tregs
, 1);
376 write_tcvr_bit(bp
, tregs
, 0);
377 write_tcvr_bit(bp
, tregs
, 1);
379 put_tcvr_byte(bp
, tregs
,
380 ((bp
->tcvr_type
== internal
) ?
381 BIGMAC_PHY_INTERNAL
: BIGMAC_PHY_EXTERNAL
));
383 put_tcvr_byte(bp
, tregs
, reg
);
385 write_tcvr_bit(bp
, tregs
, 1);
386 write_tcvr_bit(bp
, tregs
, 0);
390 write_tcvr_bit(bp
, tregs
, (val
>> shift
) & 1);
395 static unsigned short bigmac_tcvr_read(struct bigmac
*bp
,
396 struct bmac_tcvr
*tregs
,
399 unsigned short retval
= 0;
402 switch(bp
->tcvr_type
) {
408 printk("bigmac_tcvr_read: Whoops, no known transceiver type.\n");
412 idle_transceiver(tregs
);
413 write_tcvr_bit(bp
, tregs
, 0);
414 write_tcvr_bit(bp
, tregs
, 1);
415 write_tcvr_bit(bp
, tregs
, 1);
416 write_tcvr_bit(bp
, tregs
, 0);
418 put_tcvr_byte(bp
, tregs
,
419 ((bp
->tcvr_type
== internal
) ?
420 BIGMAC_PHY_INTERNAL
: BIGMAC_PHY_EXTERNAL
));
422 put_tcvr_byte(bp
, tregs
, reg
);
424 if(bp
->tcvr_type
== external
) {
427 (void) read_tcvr_bit2(bp
, tregs
);
428 (void) read_tcvr_bit2(bp
, tregs
);
433 tmp
= read_tcvr_bit2(bp
, tregs
);
434 retval
|= ((tmp
& 1) << shift
);
438 (void) read_tcvr_bit2(bp
, tregs
);
439 (void) read_tcvr_bit2(bp
, tregs
);
440 (void) read_tcvr_bit2(bp
, tregs
);
444 (void) read_tcvr_bit(bp
, tregs
);
445 (void) read_tcvr_bit(bp
, tregs
);
450 tmp
= read_tcvr_bit(bp
, tregs
);
451 retval
|= ((tmp
& 1) << shift
);
455 (void) read_tcvr_bit(bp
, tregs
);
456 (void) read_tcvr_bit(bp
, tregs
);
457 (void) read_tcvr_bit(bp
, tregs
);
462 static void bigmac_tcvr_init(struct bigmac
*bp
)
464 volatile unsigned int garbage
;
465 struct bmac_tcvr
*tregs
= bp
->tregs
;
467 idle_transceiver(tregs
);
468 tregs
->mgmt_pal
= (MGMT_PAL_INT_MDIO
|
471 garbage
= tregs
->mgmt_pal
;
473 /* Only the bit for the present transceiver (internal or
474 * external) will stick, set them both and see what stays.
476 tregs
->mgmt_pal
= (MGMT_PAL_INT_MDIO
|
478 garbage
= tregs
->mgmt_pal
;
481 if(tregs
->mgmt_pal
& MGMT_PAL_EXT_MDIO
) {
482 bp
->tcvr_type
= external
;
483 tregs
->tcvr_pal
= ~(TCVR_PAL_EXTLBACK
|
486 garbage
= tregs
->tcvr_pal
;
487 } else if(tregs
->mgmt_pal
& MGMT_PAL_INT_MDIO
) {
488 bp
->tcvr_type
= internal
;
489 tregs
->tcvr_pal
= ~(TCVR_PAL_SERIAL
|
493 garbage
= tregs
->tcvr_pal
;
495 printk("BIGMAC: AIEEE, neither internal nor "
496 "external MDIO available!\n");
497 printk("BIGMAC: mgmt_pal[%08x] tcvr_pal[%08x]\n",
498 tregs
->mgmt_pal
, tregs
->tcvr_pal
);
502 static int bigmac_init(struct bigmac
*, int);
504 static int try_next_permutation(struct bigmac
*bp
, struct bmac_tcvr
*tregs
)
506 if(bp
->sw_bmcr
& BMCR_SPEED100
) {
510 bp
->sw_bmcr
= (BMCR_ISOLATE
| BMCR_PDOWN
| BMCR_LOOPBACK
);
511 bigmac_tcvr_write(bp
, tregs
, BIGMAC_BMCR
, bp
->sw_bmcr
);
512 bp
->sw_bmcr
= (BMCR_RESET
);
513 bigmac_tcvr_write(bp
, tregs
, BIGMAC_BMCR
, bp
->sw_bmcr
);
517 bp
->sw_bmcr
= bigmac_tcvr_read(bp
, tregs
, BIGMAC_BMCR
);
518 if((bp
->sw_bmcr
& BMCR_RESET
) == 0)
523 printk("%s: PHY reset failed.\n", bp
->dev
->name
);
525 bp
->sw_bmcr
= bigmac_tcvr_read(bp
, tregs
, BIGMAC_BMCR
);
527 /* Now we try 10baseT. */
528 bp
->sw_bmcr
&= ~(BMCR_SPEED100
);
529 bigmac_tcvr_write(bp
, tregs
, BIGMAC_BMCR
, bp
->sw_bmcr
);
533 /* We've tried them all. */
537 static void bigmac_timer(unsigned long data
)
539 struct bigmac
*bp
= (struct bigmac
*) data
;
540 struct bmac_tcvr
*tregs
= bp
->tregs
;
541 int restart_timer
= 0;
544 if(bp
->timer_state
== ltrywait
) {
545 bp
->sw_bmsr
= bigmac_tcvr_read(bp
, tregs
, BIGMAC_BMSR
);
546 bp
->sw_bmcr
= bigmac_tcvr_read(bp
, tregs
, BIGMAC_BMCR
);
547 if(bp
->sw_bmsr
& BMSR_LSTATUS
) {
548 printk("%s: Link is now up at %s.\n",
550 (bp
->sw_bmcr
& BMCR_SPEED100
) ?
551 "100baseT" : "10baseT");
552 bp
->timer_state
= asleep
;
555 if(bp
->timer_ticks
>= 4) {
558 ret
= try_next_permutation(bp
, tregs
);
560 printk("%s: Link down, cable problem?\n",
562 ret
= bigmac_init(bp
, 0);
564 printk("%s: Error, cannot re-init the "
565 "BigMAC.\n", bp
->dev
->name
);
576 /* Can't happens.... */
577 printk("%s: Aieee, link timer is asleep but we got one anyways!\n",
581 bp
->timer_state
= asleep
; /* foo on you */
584 if(restart_timer
!= 0) {
585 bp
->bigmac_timer
.expires
= jiffies
+ ((12 * HZ
)/10); /* 1.2 sec. */
586 add_timer(&bp
->bigmac_timer
);
590 /* Well, really we just force the chip into 100baseT then
591 * 10baseT, each time checking for a link status.
593 static void bigmac_begin_auto_negotiation(struct bigmac
*bp
)
595 struct bmac_tcvr
*tregs
= bp
->tregs
;
598 /* Grab new software copies of PHY registers. */
599 bp
->sw_bmsr
= bigmac_tcvr_read(bp
, tregs
, BIGMAC_BMSR
);
600 bp
->sw_bmcr
= bigmac_tcvr_read(bp
, tregs
, BIGMAC_BMCR
);
603 bp
->sw_bmcr
= (BMCR_ISOLATE
| BMCR_PDOWN
| BMCR_LOOPBACK
);
604 bigmac_tcvr_write(bp
, tregs
, BIGMAC_BMCR
, bp
->sw_bmcr
);
605 bp
->sw_bmcr
= (BMCR_RESET
);
606 bigmac_tcvr_write(bp
, tregs
, BIGMAC_BMCR
, bp
->sw_bmcr
);
610 bp
->sw_bmcr
= bigmac_tcvr_read(bp
, tregs
, BIGMAC_BMCR
);
611 if((bp
->sw_bmcr
& BMCR_RESET
) == 0)
616 printk("%s: PHY reset failed.\n", bp
->dev
->name
);
618 bp
->sw_bmcr
= bigmac_tcvr_read(bp
, tregs
, BIGMAC_BMCR
);
620 /* First we try 100baseT. */
621 bp
->sw_bmcr
|= BMCR_SPEED100
;
622 bigmac_tcvr_write(bp
, tregs
, BIGMAC_BMCR
, bp
->sw_bmcr
);
624 bp
->timer_state
= ltrywait
;
626 bp
->bigmac_timer
.expires
= jiffies
+ (12 * HZ
) / 10;
627 bp
->bigmac_timer
.data
= (unsigned long) bp
;
628 bp
->bigmac_timer
.function
= &bigmac_timer
;
629 add_timer(&bp
->bigmac_timer
);
632 static int bigmac_init(struct bigmac
*bp
, int from_irq
)
634 struct qe_globreg
*gregs
= bp
->gregs
;
635 struct qe_creg
*cregs
= bp
->creg
;
636 struct BIG_MAC_regs
*bregs
= bp
->bregs
;
637 unsigned char *e
= &bp
->dev
->dev_addr
[0];
639 /* Latch current counters into statistics. */
640 bigmac_get_counters(bp
, bregs
);
643 qec_global_reset(gregs
);
648 /* Alloc and reset the tx/rx descriptor chains. */
650 if(sparc_cpu_model
== sun4c
)
651 sun4c_bigmac_init_rings(bp
);
654 bigmac_init_rings(bp
, from_irq
);
656 /* Initialize the PHY. */
657 bigmac_tcvr_init(bp
);
659 /* Stop transmitter and receiver. */
662 /* Set hardware ethernet address. */
663 bregs
->mac_addr2
= ((e
[4] << 8) | e
[5]);
664 bregs
->mac_addr1
= ((e
[2] << 8) | e
[3]);
665 bregs
->mac_addr0
= ((e
[0] << 8) | e
[1]);
667 /* Clear the hash table until mc upload occurs. */
673 /* Enable Big Mac hash table filter. */
674 bregs
->rx_cfg
= (BIGMAC_RXCFG_HENABLE
| BIGMAC_RXCFG_FIFO
);
678 /* Ok, configure the Big Mac transmitter. */
679 bregs
->tx_cfg
= BIGMAC_TXCFG_FIFO
;
681 /* The HME docs recommend to use the 10LSB of our MAC here. */
682 bregs
->rand_seed
= ((e
[5] | e
[4] << 8) & 0x3ff);
684 /* Enable the output drivers no matter what. */
685 bregs
->xif_cfg
= (BIGMAC_XCFG_ODENABLE
| BIGMAC_XCFG_RESV
);
687 /* Tell the QEC where the ring descriptors are. */
688 cregs
->rxds
= bp
->bblock_dvma
+ bib_offset(be_rxd
, 0);
689 cregs
->txds
= bp
->bblock_dvma
+ bib_offset(be_txd
, 0);
691 /* Setup the FIFO pointers into QEC local memory. */
692 cregs
->rxwbufptr
= cregs
->rxrbufptr
= 0;
693 cregs
->txwbufptr
= cregs
->txrbufptr
= gregs
->rsize
;
695 /* Tell bigmac what interrupts we don't want to hear about. */
696 bregs
->imask
= (BIGMAC_IMASK_GOTFRAME
| BIGMAC_IMASK_SENTFRAME
);
698 /* Enable the various other irq's. */
704 /* Set jam size to a reasonable default. */
705 bregs
->jsize
= DEFAULT_JAMSIZE
;
707 /* Clear collision counter. */
710 /* Enable transmitter and receiver. */
711 bregs
->tx_cfg
|= BIGMAC_TXCFG_ENABLE
;
712 bregs
->rx_cfg
|= BIGMAC_RXCFG_ENABLE
;
714 /* Ok, start detecting link speed/duplex. */
715 bigmac_begin_auto_negotiation(bp
);
721 /* Error interrupts get sent here. */
722 static void bigmac_is_medium_rare(struct bigmac
*bp
,
723 unsigned int qec_status
,
724 unsigned int bmac_status
)
726 printk("bigmac_is_medium_rare: ");
727 if(qec_status
& (GLOB_STAT_ER
| GLOB_STAT_BM
)) {
728 if(qec_status
& GLOB_STAT_ER
)
729 printk("QEC_ERROR, ");
730 if(qec_status
& GLOB_STAT_BM
)
731 printk("QEC_BMAC_ERROR, ");
733 if(bmac_status
& CREG_STAT_ERRORS
) {
734 if(bmac_status
& CREG_STAT_BERROR
)
735 printk("BMAC_ERROR, ");
736 if(bmac_status
& CREG_STAT_TXDERROR
)
737 printk("TXD_ERROR, ");
738 if(bmac_status
& CREG_STAT_TXLERR
)
739 printk("TX_LATE_ERROR, ");
740 if(bmac_status
& CREG_STAT_TXPERR
)
741 printk("TX_PARITY_ERROR, ");
742 if(bmac_status
& CREG_STAT_TXSERR
)
743 printk("TX_SBUS_ERROR, ");
745 if(bmac_status
& CREG_STAT_RXDROP
)
746 printk("RX_DROP_ERROR, ");
748 if(bmac_status
& CREG_STAT_RXSMALL
)
749 printk("RX_SMALL_ERROR, ");
750 if(bmac_status
& CREG_STAT_RXLERR
)
751 printk("RX_LATE_ERROR, ");
752 if(bmac_status
& CREG_STAT_RXPERR
)
753 printk("RX_PARITY_ERROR, ");
754 if(bmac_status
& CREG_STAT_RXSERR
)
755 printk("RX_SBUS_ERROR, ");
762 /* BigMAC transmit complete service routines. */
763 static inline void bigmac_tx(struct bigmac
*bp
)
765 struct be_txd
*txbase
= &bp
->bmac_block
->be_txd
[0];
767 int elem
= bp
->tx_old
;
769 DTX(("bigmac_tx: tx_old[%d] ", elem
));
770 while(elem
!= bp
->tx_new
) {
773 this = &txbase
[elem
];
775 DTX(("this(%p) [flags(%08x)addr(%08x)]",
776 this, this->tx_flags
, this->tx_addr
));
778 if(this->tx_flags
& TXD_OWN
)
780 skb
= bp
->tx_skbs
[elem
];
781 DTX(("skb(%p) ", skb
));
782 bp
->tx_skbs
[elem
] = NULL
;
785 bp
->enet_stats
.tx_packets
++;
786 elem
= NEXT_TX(elem
);
788 DTX((" DONE, tx_old=%d\n", elem
));
793 static inline void sun4c_bigmac_tx(struct bigmac
*bp
)
795 struct be_txd
*txbase
= &bp
->bmac_block
->be_txd
[0];
797 int elem
= bp
->tx_old
;
799 while(elem
!= bp
->tx_new
) {
800 this = &txbase
[elem
];
801 if(this->tx_flags
& TXD_OWN
)
803 bp
->enet_stats
.tx_packets
++;
804 elem
= NEXT_TX(elem
);
810 /* BigMAC receive complete service routines. */
811 static inline void bigmac_rx(struct bigmac
*bp
)
813 struct be_rxd
*rxbase
= &bp
->bmac_block
->be_rxd
[0];
815 int elem
= bp
->rx_new
, drops
= 0;
817 this = &rxbase
[elem
];
818 while(!(this->rx_flags
& RXD_OWN
)) {
820 unsigned int flags
= this->rx_flags
;
821 int len
= (flags
& RXD_LENGTH
); /* FCS not included */
823 /* Check for errors. */
825 bp
->enet_stats
.rx_errors
++;
826 bp
->enet_stats
.rx_length_errors
++;
829 /* Return it to the BigMAC. */
830 bp
->enet_stats
.rx_dropped
++;
831 this->rx_addr
= sbus_dvma_addr(bp
->rx_skbs
[elem
]->data
);
833 (RXD_OWN
| (RX_BUF_ALLOC_SIZE
& RXD_LENGTH
));
836 skb
= bp
->rx_skbs
[elem
];
837 #ifdef NEED_DMA_SYNCHRONIZATION
839 if ((unsigned long) (skb
->data
+ skb
->len
) >= MAX_DMA_ADDRESS
) {
840 printk("sunbmac: Bogus DMA buffer address "
841 "[%016lx]\n", ((unsigned long) skb
->data
));
842 panic("DMA address too large, tell DaveM");
845 mmu_sync_dma(sbus_dvma_addr(skb
->data
),
846 skb
->len
, bp
->bigmac_sbus_dev
->my_bus
);
848 if(len
> RX_COPY_THRESHOLD
) {
849 struct sk_buff
*new_skb
;
851 /* Now refill the entry, if we can. */
852 new_skb
= big_mac_alloc_skb(RX_BUF_ALLOC_SIZE
, GFP_ATOMIC
);
857 bp
->rx_skbs
[elem
] = new_skb
;
858 new_skb
->dev
= bp
->dev
;
859 skb_put(new_skb
, ETH_FRAME_LEN
);
860 skb_reserve(new_skb
, 34);
861 rxbase
[elem
].rx_addr
= sbus_dvma_addr(new_skb
->data
);
862 rxbase
[elem
].rx_flags
=
863 (RXD_OWN
| ((RX_BUF_ALLOC_SIZE
- 34) & RXD_LENGTH
));
865 /* Trim the original skb for the netif. */
868 struct sk_buff
*copy_skb
= dev_alloc_skb(len
+ 2);
874 copy_skb
->dev
= bp
->dev
;
875 skb_reserve(copy_skb
, 2);
876 skb_put(copy_skb
, len
);
877 eth_copy_and_sum(copy_skb
, (unsigned char *)skb
->data
, len
, 0);
879 /* Reuse otiginal ring buffer. */
880 rxbase
[elem
].rx_addr
= sbus_dvma_addr(skb
->data
);
881 rxbase
[elem
].rx_flags
=
882 (RXD_OWN
| ((RX_BUF_ALLOC_SIZE
- 34) & RXD_LENGTH
));
887 /* No checksums done by the BigMAC ;-( */
888 skb
->protocol
= eth_type_trans(skb
, bp
->dev
);
890 bp
->enet_stats
.rx_packets
++;
892 elem
= NEXT_RX(elem
);
893 this = &rxbase
[elem
];
897 printk("%s: Memory squeeze, deferring packet.\n", bp
->dev
->name
);
901 static inline void sun4c_bigmac_rx(struct bigmac
*bp
)
903 struct be_rxd
*rxbase
= &bp
->bmac_block
->be_rxd
[0];
905 struct bigmac_buffers
*bbufs
= bp
->sun4c_buffers
;
906 __u32 bbufs_dvma
= bp
->s4c_buf_dvma
;
907 int elem
= bp
->rx_new
, drops
= 0;
909 this = &rxbase
[elem
];
910 while(!(this->rx_flags
& RXD_OWN
)) {
912 unsigned char *this_bbuf
=
913 bbufs
->rx_buf
[elem
& (SUN4C_RX_RING_SIZE
- 1)];
914 __u32 this_bbuf_dvma
= bbufs_dvma
+
915 bbuf_offset(rx_buf
, (elem
& (SUN4C_RX_RING_SIZE
- 1)));
916 struct be_rxd
*end_rxd
=
917 &rxbase
[(elem
+SUN4C_RX_RING_SIZE
)&(RX_RING_SIZE
-1)];
918 unsigned int flags
= this->rx_flags
;
919 int len
= (flags
& RXD_LENGTH
) - 4; /* FCS not included */
921 /* Check for errors. */
923 bp
->enet_stats
.rx_errors
++;
924 bp
->enet_stats
.rx_length_errors
++;
925 bp
->enet_stats
.rx_dropped
++;
927 skb
= dev_alloc_skb(len
+ 2);
930 bp
->enet_stats
.rx_dropped
++;
935 eth_copy_and_sum(skb
, (unsigned char *)this_bbuf
,
937 skb
->protocol
= eth_type_trans(skb
, bp
->dev
);
939 bp
->enet_stats
.rx_packets
++;
942 end_rxd
->rx_addr
= this_bbuf_dvma
;
943 end_rxd
->rx_flags
= (RXD_OWN
| (SUN4C_RX_BUFF_SIZE
& RXD_LENGTH
));
945 elem
= NEXT_RX(elem
);
946 this = &rxbase
[elem
];
950 printk("%s: Memory squeeze, deferring packet.\n", bp
->dev
->name
);
954 static void bigmac_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
956 struct bigmac
*bp
= (struct bigmac
*) dev_id
;
957 unsigned int qec_status
, bmac_status
;
959 DIRQ(("bigmac_interrupt: "));
961 /* Latch status registers now. */
962 bmac_status
= bp
->creg
->stat
;
963 qec_status
= bp
->gregs
->stat
;
965 bp
->dev
->interrupt
= 1;
967 DIRQ(("qec_status=%08x bmac_status=%08x\n", qec_status
, bmac_status
));
968 if((qec_status
& (GLOB_STAT_ER
| GLOB_STAT_BM
)) ||
969 (bmac_status
& CREG_STAT_ERRORS
))
970 bigmac_is_medium_rare(bp
, qec_status
, bmac_status
);
972 if(bmac_status
& CREG_STAT_TXIRQ
)
975 if(bmac_status
& CREG_STAT_RXIRQ
)
978 if(bp
->dev
->tbusy
&& (TX_BUFFS_AVAIL(bp
) >= 0)) {
983 bp
->dev
->interrupt
= 0;
987 static void sun4c_bigmac_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
989 struct bigmac
*bp
= (struct bigmac
*) dev_id
;
990 unsigned int qec_status
, bmac_status
;
992 /* Latch status registers now. */
993 bmac_status
= bp
->creg
->stat
;
994 qec_status
= bp
->gregs
->stat
;
996 bp
->dev
->interrupt
= 1;
998 if(qec_status
& (GLOB_STAT_ER
| GLOB_STAT_BM
) ||
999 (bmac_status
& CREG_STAT_ERRORS
))
1000 bigmac_is_medium_rare(bp
, qec_status
, bmac_status
);
1002 if(bmac_status
& CREG_STAT_TXIRQ
)
1003 sun4c_bigmac_tx(bp
);
1005 if(bmac_status
& CREG_STAT_RXIRQ
)
1006 sun4c_bigmac_rx(bp
);
1008 if(bp
->dev
->tbusy
&& (SUN4C_TX_BUFFS_AVAIL(bp
) >= 0)) {
1013 bp
->dev
->interrupt
= 0;
1017 static int bigmac_open(struct net_device
*dev
)
1019 struct bigmac
*bp
= (struct bigmac
*) dev
->priv
;
1022 #ifndef __sparc_v9__
1023 if(sparc_cpu_model
== sun4c
) {
1024 if(request_irq(dev
->irq
, &sun4c_bigmac_interrupt
,
1025 SA_SHIRQ
, "BIG MAC", (void *) bp
)) {
1026 printk("BIGMAC: Can't order irq %d to go.\n", dev
->irq
);
1031 if(request_irq(dev
->irq
, &bigmac_interrupt
,
1032 SA_SHIRQ
, "BIG MAC", (void *) bp
)) {
1033 printk("BIGMAC: Can't order irq %d to go.\n", dev
->irq
);
1036 init_timer(&bp
->bigmac_timer
);
1037 res
= bigmac_init(bp
, 0);
1044 static int bigmac_close(struct net_device
*dev
)
1046 struct bigmac
*bp
= (struct bigmac
*) dev
->priv
;
1048 del_timer(&bp
->bigmac_timer
);
1049 bp
->timer_state
= asleep
;
1050 bp
->timer_ticks
= 0;
1053 bigmac_clean_rings(bp
);
1054 free_irq(dev
->irq
, (void *)bp
);
1059 /* Put a packet on the wire. */
1060 static int bigmac_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1062 struct bigmac
*bp
= (struct bigmac
*) dev
->priv
;
1066 int tickssofar
= jiffies
- dev
->trans_start
;
1068 if (tickssofar
< 40) {
1071 printk ("%s: transmit timed out, resetting\n", dev
->name
);
1072 bp
->enet_stats
.tx_errors
++;
1075 dev
->trans_start
= jiffies
;
1081 if(test_and_set_bit(0, (void *) &dev
->tbusy
) != 0) {
1082 printk("%s: Transmitter access conflict.\n", dev
->name
);
1086 if(!TX_BUFFS_AVAIL(bp
))
1089 #ifdef NEED_DMA_SYNCHRONIZATION
1091 if ((unsigned long) (skb
->data
+ skb
->len
) >= MAX_DMA_ADDRESS
) {
1092 struct sk_buff
*new_skb
= skb_copy(skb
, GFP_DMA
| GFP_ATOMIC
);
1099 mmu_sync_dma(sbus_dvma_addr(skb
->data
),
1100 skb
->len
, bp
->bigmac_sbus_dev
->my_bus
);
1104 DTX(("bigmac_start_xmit: len(%d) entry(%d)\n", len
, entry
));
1106 /* Avoid a race... */
1107 bp
->bmac_block
->be_txd
[entry
].tx_flags
= TXD_UPDATE
;
1109 bp
->tx_skbs
[entry
] = skb
;
1110 bp
->bmac_block
->be_txd
[entry
].tx_addr
= sbus_dvma_addr(skb
->data
);
1111 bp
->bmac_block
->be_txd
[entry
].tx_flags
=
1112 (TXD_OWN
| TXD_SOP
| TXD_EOP
| (len
& TXD_LENGTH
));
1113 dev
->trans_start
= jiffies
;
1114 bp
->tx_new
= NEXT_TX(entry
);
1117 bp
->creg
->ctrl
= CREG_CTRL_TWAKEUP
;
1119 if(TX_BUFFS_AVAIL(bp
))
1125 #ifndef __sparc_v9__
1126 static int sun4c_bigmac_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1128 struct bigmac
*bp
= (struct bigmac
*) dev
->priv
;
1129 struct bigmac_buffers
*bbufs
= bp
->sun4c_buffers
;
1130 __u32 txbuf_dvma
, bbufs_dvma
= bp
->s4c_buf_dvma
;
1131 unsigned char *txbuf
;
1135 int tickssofar
= jiffies
- dev
->trans_start
;
1137 if (tickssofar
< 40) {
1140 printk ("%s: transmit timed out, resetting\n", dev
->name
);
1141 bp
->enet_stats
.tx_errors
++;
1144 dev
->trans_start
= jiffies
;
1149 if(test_and_set_bit(0, (void *) &dev
->tbusy
) != 0) {
1150 printk("%s: Transmitter access conflict.\n", dev
->name
);
1154 if(!SUN4C_TX_BUFFS_AVAIL(bp
))
1160 txbuf
= &bbufs
->tx_buf
[entry
][0];
1161 txbuf_dvma
= bbufs_dvma
+ bbuf_offset(tx_buf
, entry
);
1162 memcpy(txbuf
, skb
->data
, len
);
1164 /* Avoid a race... */
1165 bp
->bmac_block
->be_txd
[entry
].tx_flags
= TXD_UPDATE
;
1167 bp
->bmac_block
->be_txd
[entry
].tx_addr
= txbuf_dvma
;
1168 bp
->bmac_block
->be_txd
[entry
].tx_flags
=
1169 (TXD_OWN
| TXD_SOP
| TXD_EOP
| (len
& TXD_LENGTH
));
1170 bp
->tx_new
= NEXT_TX(entry
);
1173 dev
->trans_start
= jiffies
;
1174 bp
->creg
->ctrl
= CREG_CTRL_TWAKEUP
;
1178 if(SUN4C_TX_BUFFS_AVAIL(bp
))
1185 static struct enet_statistics
*bigmac_get_stats(struct net_device
*dev
)
1187 struct bigmac
*bp
= (struct bigmac
*) dev
->priv
;
1189 bigmac_get_counters(bp
, bp
->bregs
);
1190 return &bp
->enet_stats
;
1193 #define CRC_POLYNOMIAL_BE 0x04c11db7UL /* Ethernet CRC, big endian */
1194 #define CRC_POLYNOMIAL_LE 0xedb88320UL /* Ethernet CRC, little endian */
1196 static void bigmac_set_multicast(struct net_device
*dev
)
1198 struct bigmac
*bp
= (struct bigmac
*) dev
->priv
;
1199 struct BIG_MAC_regs
*bregs
= bp
->bregs
;
1200 struct dev_mc_list
*dmi
= dev
->mc_list
;
1202 int i
, j
, bit
, byte
;
1203 u32 crc
, poly
= CRC_POLYNOMIAL_LE
;
1205 /* Disable the receiver. The bit self-clears when
1206 * the operation is complete.
1208 bregs
->rx_cfg
&= ~(BIGMAC_RXCFG_ENABLE
);
1209 while((bregs
->rx_cfg
& BIGMAC_RXCFG_ENABLE
) != 0)
1212 if((dev
->flags
& IFF_ALLMULTI
) || (dev
->mc_count
> 64)) {
1213 bregs
->htable0
= 0xffff;
1214 bregs
->htable1
= 0xffff;
1215 bregs
->htable2
= 0xffff;
1216 bregs
->htable3
= 0xffff;
1217 } else if(dev
->flags
& IFF_PROMISC
) {
1218 bregs
->rx_cfg
|= BIGMAC_RXCFG_PMISC
;
1222 for(i
= 0; i
< 4; i
++)
1225 for(i
= 0; i
< dev
->mc_count
; i
++) {
1226 addrs
= dmi
->dmi_addr
;
1233 for(byte
= 0; byte
< 6; byte
++) {
1234 for(bit
= *addrs
++, j
= 0; j
< 8; j
++, bit
>>= 1) {
1237 test
= ((bit
^ crc
) & 0x01);
1244 hash_table
[crc
>> 4] |= 1 << (crc
& 0xf);
1246 bregs
->htable0
= hash_table
[0];
1247 bregs
->htable1
= hash_table
[1];
1248 bregs
->htable2
= hash_table
[2];
1249 bregs
->htable3
= hash_table
[3];
1252 /* Re-enable the receiver. */
1253 bregs
->rx_cfg
|= BIGMAC_RXCFG_ENABLE
;
1256 static int __init
bigmac_ether_init(struct net_device
*dev
, struct linux_sbus_device
*qec_sdev
)
1258 static unsigned version_printed
= 0;
1259 struct bigmac
*bp
= 0;
1260 unsigned char bsizes
, bsizes_more
;
1261 int i
, j
, num_qranges
, res
= ENOMEM
;
1262 struct linux_prom_ranges qranges
[8];
1264 /* Get a new device struct for this interface. */
1265 dev
= init_etherdev(0, sizeof(struct bigmac
));
1267 if(version_printed
++ == 0)
1270 /* Report what we have found to the user. */
1271 printk("%s: BigMAC 100baseT Ethernet ", dev
->name
);
1272 dev
->base_addr
= (long) qec_sdev
;
1273 for(i
= 0; i
< 6; i
++)
1274 printk("%2.2x%c", dev
->dev_addr
[i
] = idprom
->id_ethaddr
[i
],
1275 i
== 5 ? ' ' : ':');
1278 /* Setup softc, with backpointers to QEC and BigMAC SBUS device structs. */
1279 bp
= (struct bigmac
*) dev
->priv
;
1280 bp
->qec_sbus_dev
= qec_sdev
;
1281 bp
->bigmac_sbus_dev
= qec_sdev
->child
;
1283 /* All further failures we find return this. */
1286 /* Verify the registers we expect, are actually there. */
1287 if((bp
->bigmac_sbus_dev
->num_registers
!= 3) ||
1288 (bp
->qec_sbus_dev
->num_registers
!= 2)) {
1289 printk("BIGMAC: Device does not have 2 and 3 regs, it has %d and %d.\n",
1290 bp
->qec_sbus_dev
->num_registers
,
1291 bp
->bigmac_sbus_dev
->num_registers
);
1292 printk("BIGMAC: Would you like that for here or to go?\n");
1293 goto fail_and_cleanup
;
1296 /* Fun with QEC ranges... */
1297 if(bp
->bigmac_sbus_dev
->ranges_applied
== 0) {
1298 i
= prom_getproperty(bp
->qec_sbus_dev
->prom_node
, "ranges",
1299 (char *)&qranges
[0], sizeof(qranges
));
1300 num_qranges
= (i
/ sizeof(struct linux_prom_ranges
));
1302 /* Now, apply all the ranges for the BigMAC. */
1303 for(j
= 0; j
< bp
->bigmac_sbus_dev
->num_registers
; j
++) {
1306 for(k
= 0; k
< num_qranges
; k
++)
1307 if(bp
->bigmac_sbus_dev
->reg_addrs
[j
].which_io
==
1308 qranges
[k
].ot_child_space
)
1310 if(k
>= num_qranges
) {
1311 printk("BigMAC: Aieee, bogus QEC range for space %08x\n",
1312 bp
->bigmac_sbus_dev
->reg_addrs
[j
].which_io
);
1313 goto fail_and_cleanup
;
1315 bp
->bigmac_sbus_dev
->reg_addrs
[j
].which_io
= qranges
[k
].ot_parent_space
;
1316 bp
->bigmac_sbus_dev
->reg_addrs
[j
].phys_addr
+= qranges
[k
].ot_parent_base
;
1319 /* Next, apply SBUS ranges on top of what we just changed. */
1320 prom_apply_sbus_ranges(bp
->bigmac_sbus_dev
->my_bus
,
1321 &bp
->bigmac_sbus_dev
->reg_addrs
[0],
1322 bp
->bigmac_sbus_dev
->num_registers
,
1323 bp
->bigmac_sbus_dev
);
1326 /* Apply SBUS ranges for the QEC parent. */
1327 prom_apply_sbus_ranges(bp
->qec_sbus_dev
->my_bus
,
1328 &bp
->qec_sbus_dev
->reg_addrs
[0],
1329 bp
->qec_sbus_dev
->num_registers
,
1332 /* Map in QEC global control registers. */
1333 bp
->gregs
= sparc_alloc_io(bp
->qec_sbus_dev
->reg_addrs
[0].phys_addr
,
1335 sizeof(struct qe_globreg
),
1336 "BigMAC QEC Global Regs",
1337 bp
->qec_sbus_dev
->reg_addrs
[0].which_io
,
1340 printk("BIGMAC: Cannot map QEC global registers.\n");
1341 goto fail_and_cleanup
;
1344 /* Make sure QEC is in BigMAC mode. */
1345 if((bp
->gregs
->ctrl
& 0xf0000000) != GLOB_CTRL_BMODE
) {
1346 printk("BigMAC: AIEEE, QEC is not in BigMAC mode!\n");
1347 goto fail_and_cleanup
;
1350 /* Reset the QEC. */
1351 if(qec_global_reset(bp
->gregs
))
1352 goto fail_and_cleanup
;
1354 /* Get supported SBUS burst sizes. */
1355 bsizes
= prom_getintdefault(bp
->qec_sbus_dev
->prom_node
,
1359 bsizes_more
= prom_getintdefault(bp
->qec_sbus_dev
->my_bus
->prom_node
,
1364 if(bsizes_more
!= 0xff)
1365 bsizes
&= bsizes_more
;
1366 if(bsizes
== 0xff || (bsizes
& DMA_BURST16
) == 0 ||
1367 (bsizes
& DMA_BURST32
) == 0)
1368 bsizes
= (DMA_BURST32
- 1);
1369 bp
->bigmac_bursts
= bsizes
;
1371 /* Perform QEC initialization. */
1374 /* Map in the BigMAC channel registers. */
1375 bp
->creg
= sparc_alloc_io(bp
->bigmac_sbus_dev
->reg_addrs
[0].phys_addr
,
1377 sizeof(struct qe_creg
),
1378 "BigMAC QEC Channel Regs",
1379 bp
->bigmac_sbus_dev
->reg_addrs
[0].which_io
,
1382 printk("BIGMAC: Cannot map QEC channel registers.\n");
1383 goto fail_and_cleanup
;
1386 /* Map in the BigMAC control registers. */
1387 bp
->bregs
= sparc_alloc_io(bp
->bigmac_sbus_dev
->reg_addrs
[1].phys_addr
,
1389 sizeof(struct BIG_MAC_regs
),
1390 "BigMAC Primary Regs",
1391 bp
->bigmac_sbus_dev
->reg_addrs
[1].which_io
,
1394 printk("BIGMAC: Cannot map BigMAC primary registers.\n");
1395 goto fail_and_cleanup
;
1398 /* Map in the BigMAC transceiver registers, this is how you poke at
1401 bp
->tregs
= sparc_alloc_io(bp
->bigmac_sbus_dev
->reg_addrs
[2].phys_addr
,
1403 sizeof(struct bmac_tcvr
),
1404 "BigMAC Transceiver Regs",
1405 bp
->bigmac_sbus_dev
->reg_addrs
[2].which_io
,
1408 printk("BIGMAC: Cannot map BigMAC transceiver registers.\n");
1409 goto fail_and_cleanup
;
1412 /* Stop the BigMAC. */
1415 /* Allocate transmit/receive descriptor DVMA block. */
1416 bp
->bmac_block
= (struct bmac_init_block
*)
1417 sparc_dvma_malloc(PAGE_SIZE
, "BigMAC Init Block",
1420 /* Get the board revision of this BigMAC. */
1421 bp
->board_rev
= prom_getintdefault(bp
->bigmac_sbus_dev
->prom_node
,
1422 "board-version", 1);
1424 /* If on sun4c, we use a static buffer pool, on sun4m we DMA directly
1425 * in and out of sk_buffs instead for speed and one copy to userspace.
1427 #ifndef __sparc_v9__
1428 if(sparc_cpu_model
== sun4c
)
1429 bp
->sun4c_buffers
= (struct bigmac_buffers
*)
1430 sparc_dvma_malloc(sizeof(struct bigmac_buffers
),
1435 bp
->sun4c_buffers
= 0;
1437 /* Init auto-negotiation timer state. */
1438 init_timer(&bp
->bigmac_timer
);
1439 bp
->timer_state
= asleep
;
1440 bp
->timer_ticks
= 0;
1442 /* Backlink to generic net device struct. */
1445 /* Set links to our BigMAC open and close routines. */
1446 dev
->open
= &bigmac_open
;
1447 dev
->stop
= &bigmac_close
;
1449 /* Choose transmit routine based upon buffering scheme. */
1450 #ifndef __sparc_v9__
1451 if(sparc_cpu_model
== sun4c
)
1452 dev
->hard_start_xmit
= &sun4c_bigmac_start_xmit
;
1455 dev
->hard_start_xmit
= &bigmac_start_xmit
;
1457 /* Set links to BigMAC statistic and multi-cast loading code. */
1458 dev
->get_stats
= &bigmac_get_stats
;
1459 dev
->set_multicast_list
= &bigmac_set_multicast
;
1461 /* Finish net device registration. */
1462 dev
->irq
= bp
->bigmac_sbus_dev
->irqs
[0];
1467 /* Put us into the list of instances attached for later module unloading. */
1468 bp
->next_module
= root_bigmac_dev
;
1469 root_bigmac_dev
= bp
;
1474 /* Something went wrong, undo whatever we did so far. */
1476 /* Free register mappings if any. */
1478 sparc_free_io(bp
->gregs
, sizeof(struct qe_globreg
));
1480 sparc_free_io(bp
->creg
, sizeof(struct qe_creg
));
1482 sparc_free_io(bp
->bregs
, sizeof(struct BIG_MAC_regs
));
1484 sparc_free_io(bp
->tregs
, sizeof(struct bmac_tcvr
));
1486 /* XXX todo, bmac_block and sun4c_buffers */
1488 /* Free the BigMAC softc. */
1492 return res
; /* Return error code. */
1495 int __init
bigmac_probe(struct net_device
*dev
)
1497 struct linux_sbus
*bus
;
1498 struct linux_sbus_device
*sdev
= 0;
1499 static int called
= 0;
1506 for_each_sbus(bus
) {
1507 for_each_sbusdev(sdev
, bus
) {
1508 if(cards
) dev
= NULL
;
1510 /* QEC can be the parent of either QuadEthernet or
1511 * a BigMAC. We want the latter.
1513 if(!strcmp(sdev
->prom_name
, "qec") && sdev
->child
&&
1514 !strcmp(sdev
->child
->prom_name
, "be")) {
1516 if((v
= bigmac_ether_init(dev
, sdev
)))
1531 root_bigmac_dev
= NULL
;
1532 return bigmac_probe(NULL
);
1536 cleanup_module(void)
1538 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1539 while (root_bigmac_dev
) {
1540 struct bigmac
*bp
= root_bigmac_dev
;
1541 struct bigmac
*bp_nxt
= root_bigmac_dev
->next_module
;
1543 sparc_free_io(bp
->gregs
, sizeof(struct qe_globreg
));
1544 sparc_free_io(bp
->creg
, sizeof(struct qe_creg
));
1545 sparc_free_io(bp
->bregs
, sizeof(struct BIG_MAC_regs
));
1546 sparc_free_io(bp
->tregs
, sizeof(struct bmac_tcvr
));
1548 /* XXX todo, bmac_block and sun4c_buffers */
1550 unregister_netdev(bp
->dev
);
1552 root_bigmac_dev
= bp_nxt
;