1 /* myri_sbus.h: MyriCOM MyriNET SBUS card driver.
3 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
7 "myri_sbus.c:v1.0 10/Dec/96 David S. Miller (davem@caipfs.rutgers.edu)\n";
9 #include <linux/module.h>
11 #include <linux/config.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/types.h>
15 #include <linux/fcntl.h>
16 #include <linux/interrupt.h>
17 #include <linux/ptrace.h>
18 #include <linux/ioport.h>
20 #include <linux/malloc.h>
21 #include <linux/string.h>
22 #include <linux/delay.h>
23 #include <linux/init.h>
25 #include <asm/system.h>
26 #include <asm/bitops.h>
29 #include <linux/errno.h>
30 #include <asm/byteorder.h>
32 #include <asm/idprom.h>
34 #include <asm/openprom.h>
35 #include <asm/oplib.h>
36 #include <asm/auxio.h>
37 #include <asm/pgtable.h>
40 #include <linux/netdevice.h>
41 #include <linux/etherdevice.h>
42 #include <linux/skbuff.h>
49 #include <asm/checksum.h>
51 #include "myri_sbus.h"
53 #include "myri_code.h"
55 /* #define DEBUG_DETECT */
56 /* #define DEBUG_IRQ */
57 /* #define DEBUG_TRANSMIT */
58 /* #define DEBUG_RECEIVE */
59 /* #define DEBUG_HEADER */
62 #define DET(x) printk x
68 #define DIRQ(x) printk x
74 #define DTX(x) printk x
80 #define DRX(x) printk x
86 #define DHDR(x) printk x
92 static struct myri_eth
*root_myri_dev
= NULL
;
95 static inline void myri_reset_off(struct lanai_regs
*lp
, struct myri_control
*cregs
)
97 lp
->eimask
= 0; /* Clear IRQ mask. */
98 cregs
->ctrl
= CONTROL_ROFF
; /* Turn RESET function off. */
101 static inline void myri_reset_on(struct myri_control
*cregs
)
103 cregs
->ctrl
= CONTROL_RON
; /* Enable RESET function. */
104 cregs
->ctrl
= CONTROL_DIRQ
; /* Disable IRQ's. */
107 static inline void myri_disable_irq(struct lanai_regs
*lp
, struct myri_control
*cregs
)
109 cregs
->ctrl
= CONTROL_DIRQ
;
111 lp
->istat
= ISTAT_HOST
;
114 static inline void myri_enable_irq(struct lanai_regs
*lp
, struct myri_control
*cregs
)
116 cregs
->ctrl
= CONTROL_EIRQ
;
117 lp
->eimask
= ISTAT_HOST
;
120 static inline void bang_the_chip(struct myri_eth
*mp
)
122 struct myri_shmem
*shmem
= mp
->shmem
;
123 struct myri_control
*cregs
= mp
->cregs
;
126 cregs
->ctrl
= CONTROL_WON
;
129 static inline int myri_do_handshake(struct myri_eth
*mp
)
131 struct myri_shmem
*shmem
= mp
->shmem
;
132 struct myri_control
*cregs
= mp
->cregs
;
133 struct myri_channel
*chan
= &shmem
->channel
;
136 DET(("myri_do_handshake: "));
137 if(chan
->state
== STATE_READY
) {
138 DET(("Already STATE_READY, failed.\n"));
139 return -1; /* We're hosed... */
142 myri_disable_irq(mp
->lregs
, cregs
);
144 while(tick
++ <= 25) {
145 unsigned int softstate
;
148 DET(("shakedown, CONTROL_WON, "));
149 shmem
->shakedown
= 1;
150 cregs
->ctrl
= CONTROL_WON
;
152 softstate
= chan
->state
;
153 DET(("chanstate[%08x] ", softstate
));
154 if(softstate
== STATE_READY
) {
155 DET(("wakeup successful, "));
159 if(softstate
!= STATE_WFN
) {
160 DET(("not WFN setting that, "));
161 chan
->state
= STATE_WFN
;
167 myri_enable_irq(mp
->lregs
, cregs
);
170 DET(("25 ticks we lose, failure.\n"));
177 static inline int myri_load_lanai(struct myri_eth
*mp
)
179 struct net_device
*dev
= mp
->dev
;
180 struct myri_shmem
*shmem
= mp
->shmem
;
184 myri_disable_irq(mp
->lregs
, mp
->cregs
);
185 myri_reset_on(mp
->cregs
);
187 rptr
= (unsigned char *) mp
->lanai
;
188 for(i
= 0; i
< mp
->eeprom
.ramsz
; i
++)
191 if(mp
->eeprom
.cpuvers
>= CPUVERS_3_0
)
192 mp
->lregs
->cval
= mp
->eeprom
.cval
;
194 /* Load executable code. */
195 for(i
= 0; i
< sizeof(lanai4_code
); i
++)
196 rptr
[(lanai4_code_off
* 2) + i
] = lanai4_code
[i
];
198 /* Load data segment. */
199 for(i
= 0; i
< sizeof(lanai4_data
); i
++)
200 rptr
[(lanai4_data_off
* 2) + i
] = lanai4_data
[i
];
202 /* Set device address. */
203 shmem
->addr
[0] = shmem
->addr
[1] = 0;
204 for(i
= 0; i
< 6; i
++)
205 shmem
->addr
[i
+ 2] = dev
->dev_addr
[i
];
207 /* Set SBUS bursts and interrupt mask. */
208 shmem
->burst
= ((mp
->myri_bursts
& 0xf8) >> 3);
209 shmem
->imask
= SHMEM_IMASK_RX
;
211 /* Release the LANAI. */
212 myri_disable_irq(mp
->lregs
, mp
->cregs
);
213 myri_reset_off(mp
->lregs
, mp
->cregs
);
214 myri_disable_irq(mp
->lregs
, mp
->cregs
);
216 /* Wait for the reset to complete. */
217 for(i
= 0; i
< 5000; i
++) {
218 if(shmem
->channel
.state
!= STATE_READY
)
225 printk("myricom: Chip would not reset after firmware load.\n");
227 i
= myri_do_handshake(mp
);
229 printk("myricom: Handshake with LANAI failed.\n");
231 if(mp
->eeprom
.cpuvers
== CPUVERS_4_0
)
237 static void myri_clean_rings(struct myri_eth
*mp
)
239 struct sendq
*sq
= mp
->sq
;
240 struct recvq
*rq
= mp
->rq
;
243 rq
->tail
= rq
->head
= 0;
244 for(i
= 0; i
< (RX_RING_SIZE
+1); i
++) {
245 if(mp
->rx_skbs
[i
] != NULL
) {
246 dev_kfree_skb(mp
->rx_skbs
[i
]);
247 mp
->rx_skbs
[i
] = NULL
;
251 mp
->tx_old
= sq
->tail
= sq
->head
= 0;
252 for(i
= 0; i
< TX_RING_SIZE
; i
++) {
253 if(mp
->tx_skbs
[i
] != NULL
) {
254 dev_kfree_skb(mp
->tx_skbs
[i
]);
255 mp
->tx_skbs
[i
] = NULL
;
260 static void myri_init_rings(struct myri_eth
*mp
, int from_irq
)
262 struct recvq
*rq
= mp
->rq
;
263 struct myri_rxd
*rxd
= &rq
->myri_rxd
[0];
264 struct net_device
*dev
= mp
->dev
;
265 int gfp_flags
= GFP_KERNEL
;
268 if(from_irq
|| in_interrupt())
269 gfp_flags
= GFP_ATOMIC
;
271 myri_clean_rings(mp
);
272 for(i
= 0; i
< RX_RING_SIZE
; i
++) {
273 struct sk_buff
*skb
= myri_alloc_skb(RX_ALLOC_SIZE
, gfp_flags
);
277 mp
->rx_skbs
[i
] = skb
;
279 skb_put(skb
, RX_ALLOC_SIZE
);
280 rxd
[i
].myri_scatters
[0].addr
= sbus_dvma_addr(skb
->data
);
281 rxd
[i
].myri_scatters
[0].len
= RX_ALLOC_SIZE
;
286 rq
->tail
= RX_RING_SIZE
;
289 static int myri_init(struct myri_eth
*mp
, int from_irq
)
291 myri_init_rings(mp
, from_irq
);
295 static void myri_is_not_so_happy(struct myri_eth
*mp
)
300 static void dump_ehdr(struct ethhdr
*ehdr
)
302 printk("ehdr[h_dst(%02x:%02x:%02x:%02x:%02x:%02x)"
303 "h_source(%02x:%02x:%02x:%02x:%02x:%02x)h_proto(%04x)]\n",
304 ehdr
->h_dest
[0], ehdr
->h_dest
[1], ehdr
->h_dest
[2],
305 ehdr
->h_dest
[3], ehdr
->h_dest
[4], ehdr
->h_dest
[4],
306 ehdr
->h_source
[0], ehdr
->h_source
[1], ehdr
->h_source
[2],
307 ehdr
->h_source
[3], ehdr
->h_source
[4], ehdr
->h_source
[4],
311 static void dump_ehdr_and_myripad(unsigned char *stuff
)
313 struct ethhdr
*ehdr
= (struct ethhdr
*) (stuff
+ 2);
315 printk("pad[%02x:%02x]", stuff
[0], stuff
[1]);
316 printk("ehdr[h_dst(%02x:%02x:%02x:%02x:%02x:%02x)"
317 "h_source(%02x:%02x:%02x:%02x:%02x:%02x)h_proto(%04x)]\n",
318 ehdr
->h_dest
[0], ehdr
->h_dest
[1], ehdr
->h_dest
[2],
319 ehdr
->h_dest
[3], ehdr
->h_dest
[4], ehdr
->h_dest
[4],
320 ehdr
->h_source
[0], ehdr
->h_source
[1], ehdr
->h_source
[2],
321 ehdr
->h_source
[3], ehdr
->h_source
[4], ehdr
->h_source
[4],
326 static inline void myri_tx(struct myri_eth
*mp
, struct net_device
*dev
)
328 struct sendq
*sq
= mp
->sq
;
329 int entry
= mp
->tx_old
;
330 int limit
= sq
->head
;
332 DTX(("entry[%d] limit[%d] ", entry
, limit
));
335 while(entry
!= limit
) {
336 struct sk_buff
*skb
= mp
->tx_skbs
[entry
];
338 DTX(("SKB[%d] ", entry
));
340 mp
->tx_skbs
[entry
] = NULL
;
341 mp
->enet_stats
.tx_packets
++;
342 entry
= NEXT_TX(entry
);
347 /* Determine the packet's protocol ID. The rule here is that we
348 * assume 802.3 if the type field is short enough to be a length.
349 * This is normal practice and works for any 'now in use' protocol.
351 static unsigned short myri_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
356 skb
->mac
.raw
= (((unsigned char *)skb
->data
) + MYRI_PAD_LEN
);
357 skb_pull(skb
, dev
->hard_header_len
);
358 eth
= skb
->mac
.ethernet
;
361 DHDR(("myri_type_trans: "));
364 if(*eth
->h_dest
& 1) {
365 if(memcmp(eth
->h_dest
, dev
->broadcast
, ETH_ALEN
)==0)
366 skb
->pkt_type
= PACKET_BROADCAST
;
368 skb
->pkt_type
= PACKET_MULTICAST
;
369 } else if(dev
->flags
& (IFF_PROMISC
|IFF_ALLMULTI
)) {
370 if(memcmp(eth
->h_dest
, dev
->dev_addr
, ETH_ALEN
))
371 skb
->pkt_type
= PACKET_OTHERHOST
;
374 if(ntohs(eth
->h_proto
) >= 1536)
379 /* This is a magic hack to spot IPX packets. Older Novell breaks
380 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
381 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
382 * won't work for fault tolerant netware but does for the rest.
384 if (*(unsigned short *)rawp
== 0xFFFF)
385 return htons(ETH_P_802_3
);
388 return htons(ETH_P_802_2
);
391 static inline void myri_rx(struct myri_eth
*mp
, struct net_device
*dev
)
393 struct recvq
*rq
= mp
->rq
;
394 struct recvq
*rqa
= mp
->rqack
;
395 int entry
= rqa
->head
;
396 int limit
= rqa
->tail
;
399 DRX(("entry[%d] limit[%d] ", entry
, limit
));
404 while(entry
!= limit
) {
405 struct myri_rxd
*rxdack
= &rqa
->myri_rxd
[entry
];
406 unsigned int csum
= rxdack
->csum
;
407 int len
= rxdack
->myri_scatters
[0].len
;
408 int index
= rxdack
->ctx
;
409 struct myri_rxd
*rxd
= &rq
->myri_rxd
[rq
->tail
];
410 struct sk_buff
*skb
= mp
->rx_skbs
[index
];
413 rqa
->head
= NEXT_RX(entry
);
415 /* Check for errors. */
416 DRX(("rxd[%d]: %p len[%d] csum[%08x] ", entry
, rxd
, len
, csum
));
417 if((len
< (ETH_HLEN
+ MYRI_PAD_LEN
)) || (skb
->data
[0] != MYRI_PAD_LEN
)) {
419 mp
->enet_stats
.rx_errors
++;
420 if(len
< (ETH_HLEN
+ MYRI_PAD_LEN
)) {
421 DRX(("BAD_LENGTH] "));
422 mp
->enet_stats
.rx_length_errors
++;
424 DRX(("NO_PADDING] "));
425 mp
->enet_stats
.rx_frame_errors
++;
428 /* Return it to the LANAI. */
432 mp
->enet_stats
.rx_dropped
++;
433 rxd
->myri_scatters
[0].addr
= sbus_dvma_addr(skb
->data
);
434 rxd
->myri_scatters
[0].len
= RX_ALLOC_SIZE
;
437 rq
->tail
= NEXT_RX(rq
->tail
);
441 #ifdef NEED_DMA_SYNCHRONIZATION
442 mmu_sync_dma(sbus_dvma_addr(skb
->data
),
443 skb
->len
, mp
->myri_sbus_dev
->my_bus
);
446 DRX(("len[%d] ", len
));
447 if(len
> RX_COPY_THRESHOLD
) {
448 struct sk_buff
*new_skb
;
451 new_skb
= myri_alloc_skb(RX_ALLOC_SIZE
, GFP_ATOMIC
);
453 DRX(("skb_alloc(FAILED) "));
456 mp
->rx_skbs
[index
] = new_skb
;
458 skb_put(new_skb
, RX_ALLOC_SIZE
);
459 rxd
->myri_scatters
[0].addr
= sbus_dvma_addr(new_skb
->data
);
460 rxd
->myri_scatters
[0].len
= RX_ALLOC_SIZE
;
463 rq
->tail
= NEXT_RX(rq
->tail
);
465 /* Trim the original skb for the netif. */
466 DRX(("trim(%d) ", len
));
469 struct sk_buff
*copy_skb
= dev_alloc_skb(len
);
473 DRX(("dev_alloc_skb(FAILED) "));
477 DRX(("resv_and_put "));
478 skb_put(copy_skb
, len
);
479 memcpy(copy_skb
->data
, skb
->data
, len
);
481 /* Reuse original ring buffer. */
483 rxd
->myri_scatters
[0].addr
= sbus_dvma_addr(skb
->data
);
484 rxd
->myri_scatters
[0].len
= RX_ALLOC_SIZE
;
487 rq
->tail
= NEXT_RX(rq
->tail
);
492 /* Just like the happy meal we get checksums from this card. */
494 skb
->ip_summed
= CHECKSUM_UNNECESSARY
; /* XXX */
496 skb
->protocol
= myri_type_trans(skb
, dev
);
497 DRX(("prot[%04x] netif_rx ", skb
->protocol
));
500 mp
->enet_stats
.rx_packets
++;
503 entry
= NEXT_RX(entry
);
507 static void myri_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
509 struct net_device
*dev
= (struct net_device
*) dev_id
;
510 struct myri_eth
*mp
= (struct myri_eth
*) dev
->priv
;
511 struct lanai_regs
*lregs
= mp
->lregs
;
512 struct myri_channel
*chan
= &mp
->shmem
->channel
;
515 status
= lregs
->istat
;
516 DIRQ(("myri_interrupt: status[%08x] ", status
));
517 if(status
& ISTAT_HOST
) {
518 unsigned int softstate
;
520 DIRQ(("IRQ_DISAB "));
521 myri_disable_irq(lregs
, mp
->cregs
);
523 softstate
= chan
->state
;
524 DIRQ(("state[%08x] ", softstate
));
525 if(softstate
!= STATE_READY
) {
526 DIRQ(("myri_not_so_happy "));
527 myri_is_not_so_happy(mp
);
529 DIRQ(("\nmyri_rx: "));
531 DIRQ(("\nistat=ISTAT_HOST "));
532 lregs
->istat
= ISTAT_HOST
;
535 myri_enable_irq(lregs
, mp
->cregs
);
540 static int myri_open(struct net_device
*dev
)
542 struct myri_eth
*mp
= (struct myri_eth
*) dev
->priv
;
544 return myri_init(mp
, in_interrupt());
547 static int myri_close(struct net_device
*dev
)
549 struct myri_eth
*mp
= (struct myri_eth
*) dev
->priv
;
551 myri_clean_rings(mp
);
555 static int myri_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
557 struct myri_eth
*mp
= (struct myri_eth
*) dev
->priv
;
558 struct sendq
*sq
= mp
->sq
;
559 struct myri_txd
*txd
;
560 unsigned char *srcptr
;
562 unsigned int head
, tail
;
565 DTX(("myri_start_xmit: "));
570 int tickssofar
= jiffies
- dev
->trans_start
;
572 DTX(("tbusy tickssofar[%d] ", tickssofar
));
573 if(tickssofar
< 40) {
574 DTX(("returning 1\n"));
577 DTX(("resetting, return 0\n"));
578 printk("%s: transmit timed out, resetting\n", dev
->name
);
579 mp
->enet_stats
.tx_errors
++;
580 myri_init(mp
, in_interrupt());
582 dev
->trans_start
= jiffies
;
587 if(test_and_set_bit(0, (void *) &dev
->tbusy
) != 0) {
588 DTX(("tbusy, maybe a race? returning 1\n"));
589 printk("%s: Transmitter access conflict.\n", dev
->name
);
594 #ifdef NEED_DMA_SYNCHRONIZATION
595 mmu_sync_dma(sbus_dvma_addr(skb
->data
),
596 skb
->len
, mp
->myri_sbus_dev
->my_bus
);
599 /* This is just to prevent multiple PIO reads for TX_BUFFS_AVAIL. */
603 if(!TX_BUFFS_AVAIL(head
, tail
)) {
604 DTX(("no buffs available, returning 1\n"));
610 DHDR(("xmit[skbdata(%p)]\n", skb
->data
));
612 dump_ehdr_and_myripad(((unsigned char *) skb
->data
));
615 /* XXX Maybe this can go as well. */
619 len
= (len
+ 4) & (~3);
624 txd
= &sq
->myri_txd
[entry
];
625 mp
->tx_skbs
[entry
] = skb
;
627 txd
->myri_gathers
[0].addr
= sbus_dvma_addr(skb
->data
);
628 txd
->myri_gathers
[0].len
= len
;
630 txd
->chan
= KERNEL_CHANNEL
;
632 txd
->csum_off
= ((unsigned int)-1);
635 srcptr
= (((unsigned char *) skb
->data
) + MYRI_PAD_LEN
);
636 if(srcptr
[0] & 0x1) {
637 txd
->addr
[0] = txd
->addr
[1] = txd
->addr
[2] = txd
->addr
[3] = 0xffff;
640 txd
->addr
[1] = (srcptr
[0] << 8) | srcptr
[1];
641 txd
->addr
[2] = (srcptr
[2] << 8) | srcptr
[3];
642 txd
->addr
[3] = (srcptr
[4] << 8) | srcptr
[5];
644 sq
->tail
= NEXT_TX(entry
);
645 DTX(("BangTheChip "));
648 DTX(("tbusy=0, returning 0\n"));
650 restore_flags(flags
);
654 /* Create the MyriNet MAC header for an arbitrary protocol layer
656 * saddr=NULL means use device source address
657 * daddr=NULL means leave destination address (eg unresolved arp)
659 static int myri_header(struct sk_buff
*skb
, struct net_device
*dev
, unsigned short type
,
660 void *daddr
, void *saddr
, unsigned len
)
662 struct ethhdr
*eth
= (struct ethhdr
*)skb_push(skb
,ETH_HLEN
);
663 unsigned char *pad
= (unsigned char *)skb_push(skb
,MYRI_PAD_LEN
);
666 DHDR(("myri_header: pad[%02x,%02x] ", pad
[0], pad
[1]));
670 /* Set the MyriNET padding identifier. */
671 pad
[0] = MYRI_PAD_LEN
;
674 /* Set the protocol type. For a packet of type ETH_P_802_3 we put the length
675 * in here instead. It is up to the 802.2 layer to carry protocol information.
677 if(type
!= ETH_P_802_3
)
678 eth
->h_proto
= htons(type
);
680 eth
->h_proto
= htons(len
);
682 /* Set the source hardware address. */
684 memcpy(eth
->h_source
, saddr
, dev
->addr_len
);
686 memcpy(eth
->h_source
, dev
->dev_addr
, dev
->addr_len
);
688 /* Anyway, the loopback-device should never use this function... */
689 if (dev
->flags
& IFF_LOOPBACK
) {
691 for(i
= 0; i
< dev
->addr_len
; i
++)
693 return(dev
->hard_header_len
);
697 memcpy(eth
->h_dest
, daddr
, dev
->addr_len
);
698 return dev
->hard_header_len
;
700 return -dev
->hard_header_len
;
703 /* Rebuild the MyriNet MAC header. This is called after an ARP
704 * (or in future other address resolution) has completed on this
705 * sk_buff. We now let ARP fill in the other fields.
707 static int myri_rebuild_header(struct sk_buff
*skb
)
709 unsigned char *pad
= (unsigned char *)skb
->data
;
710 struct ethhdr
*eth
= (struct ethhdr
*)(pad
+ MYRI_PAD_LEN
);
711 struct net_device
*dev
= skb
->dev
;
714 DHDR(("myri_rebuild_header: pad[%02x,%02x] ", pad
[0], pad
[1]));
718 /* Refill MyriNet padding identifiers, this is just being anal. */
719 pad
[0] = MYRI_PAD_LEN
;
722 switch (eth
->h_proto
)
725 case __constant_htons(ETH_P_IP
):
726 return arp_find(eth
->h_dest
, skb
);
731 "%s: unable to resolve type %X addresses.\n",
732 dev
->name
, (int)eth
->h_proto
);
734 memcpy(eth
->h_source
, dev
->dev_addr
, dev
->addr_len
);
742 int myri_header_cache(struct neighbour
*neigh
, struct hh_cache
*hh
)
744 unsigned short type
= hh
->hh_type
;
745 unsigned char *pad
= (unsigned char *)hh
->hh_data
;
746 struct ethhdr
*eth
= (struct ethhdr
*)(pad
+ MYRI_PAD_LEN
);
747 struct net_device
*dev
= neigh
->dev
;
749 if (type
== __constant_htons(ETH_P_802_3
))
752 /* Refill MyriNet padding identifiers, this is just being anal. */
753 pad
[0] = MYRI_PAD_LEN
;
757 memcpy(eth
->h_source
, dev
->dev_addr
, dev
->addr_len
);
758 memcpy(eth
->h_dest
, neigh
->ha
, dev
->addr_len
);
764 /* Called by Address Resolution module to notify changes in address. */
765 void myri_header_cache_update(struct hh_cache
*hh
, struct net_device
*dev
, unsigned char * haddr
)
767 memcpy(((u8
*)hh
->hh_data
) + 2, haddr
, dev
->addr_len
);
770 static int myri_change_mtu(struct net_device
*dev
, int new_mtu
)
772 if ((new_mtu
< (ETH_HLEN
+ MYRI_PAD_LEN
)) || (new_mtu
> MYRINET_MTU
))
778 static struct net_device_stats
*myri_get_stats(struct net_device
*dev
)
779 { return &(((struct myri_eth
*)dev
->priv
)->enet_stats
); }
781 #define CRC_POLYNOMIAL_BE 0x04c11db7UL /* Ethernet CRC, big endian */
782 #define CRC_POLYNOMIAL_LE 0xedb88320UL /* Ethernet CRC, little endian */
784 static void myri_set_multicast(struct net_device
*dev
)
786 /* Do nothing, all MyriCOM nodes transmit multicast frames
787 * as broadcast packets...
791 static inline void set_boardid_from_idprom(struct myri_eth
*mp
, int num
)
793 mp
->eeprom
.id
[0] = 0;
794 mp
->eeprom
.id
[1] = idprom
->id_machtype
;
795 mp
->eeprom
.id
[2] = (idprom
->id_sernum
>> 16) & 0xff;
796 mp
->eeprom
.id
[3] = (idprom
->id_sernum
>> 8) & 0xff;
797 mp
->eeprom
.id
[4] = (idprom
->id_sernum
>> 0) & 0xff;
798 mp
->eeprom
.id
[5] = num
;
801 static inline void determine_reg_space_size(struct myri_eth
*mp
)
803 switch(mp
->eeprom
.cpuvers
) {
808 mp
->reg_size
= (3 * 128 * 1024) + 4096;
813 mp
->reg_size
= ((4096<<1) + mp
->eeprom
.ramsz
);
819 printk("myricom: AIEEE weird cpu version %04x assuming pre4.0\n",
821 mp
->reg_size
= (3 * 128 * 1024) + 4096;
826 static void dump_eeprom(struct myri_eth
*mp
)
828 printk("EEPROM: clockval[%08x] cpuvers[%04x] "
829 "id[%02x,%02x,%02x,%02x,%02x,%02x]\n",
830 mp
->eeprom
.cval
, mp
->eeprom
.cpuvers
,
831 mp
->eeprom
.id
[0], mp
->eeprom
.id
[1], mp
->eeprom
.id
[2],
832 mp
->eeprom
.id
[3], mp
->eeprom
.id
[4], mp
->eeprom
.id
[5]);
833 printk("EEPROM: ramsz[%08x]\n", mp
->eeprom
.ramsz
);
834 printk("EEPROM: fvers[%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
835 mp
->eeprom
.fvers
[0], mp
->eeprom
.fvers
[1], mp
->eeprom
.fvers
[2],
836 mp
->eeprom
.fvers
[3], mp
->eeprom
.fvers
[4], mp
->eeprom
.fvers
[5],
837 mp
->eeprom
.fvers
[6], mp
->eeprom
.fvers
[7]);
838 printk("EEPROM: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
839 mp
->eeprom
.fvers
[8], mp
->eeprom
.fvers
[9], mp
->eeprom
.fvers
[10],
840 mp
->eeprom
.fvers
[11], mp
->eeprom
.fvers
[12], mp
->eeprom
.fvers
[13],
841 mp
->eeprom
.fvers
[14], mp
->eeprom
.fvers
[15]);
842 printk("EEPROM: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
843 mp
->eeprom
.fvers
[16], mp
->eeprom
.fvers
[17], mp
->eeprom
.fvers
[18],
844 mp
->eeprom
.fvers
[19], mp
->eeprom
.fvers
[20], mp
->eeprom
.fvers
[21],
845 mp
->eeprom
.fvers
[22], mp
->eeprom
.fvers
[23]);
846 printk("EEPROM: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x]\n",
847 mp
->eeprom
.fvers
[24], mp
->eeprom
.fvers
[25], mp
->eeprom
.fvers
[26],
848 mp
->eeprom
.fvers
[27], mp
->eeprom
.fvers
[28], mp
->eeprom
.fvers
[29],
849 mp
->eeprom
.fvers
[30], mp
->eeprom
.fvers
[31]);
850 printk("EEPROM: mvers[%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
851 mp
->eeprom
.mvers
[0], mp
->eeprom
.mvers
[1], mp
->eeprom
.mvers
[2],
852 mp
->eeprom
.mvers
[3], mp
->eeprom
.mvers
[4], mp
->eeprom
.mvers
[5],
853 mp
->eeprom
.mvers
[6], mp
->eeprom
.mvers
[7]);
854 printk("EEPROM: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x]\n",
855 mp
->eeprom
.mvers
[8], mp
->eeprom
.mvers
[9], mp
->eeprom
.mvers
[10],
856 mp
->eeprom
.mvers
[11], mp
->eeprom
.mvers
[12], mp
->eeprom
.mvers
[13],
857 mp
->eeprom
.mvers
[14], mp
->eeprom
.mvers
[15]);
858 printk("EEPROM: dlval[%04x] brd_type[%04x] bus_type[%04x] prod_code[%04x]\n",
859 mp
->eeprom
.dlval
, mp
->eeprom
.brd_type
, mp
->eeprom
.bus_type
,
860 mp
->eeprom
.prod_code
);
861 printk("EEPROM: serial_num[%08x]\n", mp
->eeprom
.serial_num
);
865 static inline int myri_ether_init(struct net_device
*dev
, struct linux_sbus_device
*sdev
, int num
)
867 static unsigned version_printed
= 0;
869 unsigned char prop_buf
[32];
872 DET(("myri_ether_init(%p,%p,%d):\n", dev
, sdev
, num
));
873 dev
= init_etherdev(0, sizeof(struct myri_eth
));
875 if(version_printed
++ == 0)
878 printk("%s: MyriCOM MyriNET Ethernet ", dev
->name
);
879 dev
->base_addr
= (long) sdev
;
881 mp
= (struct myri_eth
*) dev
->priv
;
882 mp
->myri_sbus_dev
= sdev
;
884 /* Clean out skb arrays. */
885 for(i
= 0; i
< (RX_RING_SIZE
+ 1); i
++)
886 mp
->rx_skbs
[i
] = NULL
;
888 for(i
= 0; i
< TX_RING_SIZE
; i
++)
889 mp
->tx_skbs
[i
] = NULL
;
891 /* First check for EEPROM information. */
892 i
= prom_getproperty(sdev
->prom_node
, "myrinet-eeprom-info",
893 (char *)&mp
->eeprom
, sizeof(struct myri_eeprom
));
894 DET(("prom_getprop(myrinet-eeprom-info) returns %d\n", i
));
895 if(i
== 0 || i
== -1) {
896 /* No eeprom property, must cook up the values ourselves. */
897 DET(("No EEPROM: "));
898 mp
->eeprom
.bus_type
= BUS_TYPE_SBUS
;
899 mp
->eeprom
.cpuvers
= prom_getintdefault(sdev
->prom_node
,"cpu_version",0);
900 mp
->eeprom
.cval
= prom_getintdefault(sdev
->prom_node
,"clock_value",0);
901 mp
->eeprom
.ramsz
= prom_getintdefault(sdev
->prom_node
,"sram_size",0);
902 DET(("cpuvers[%d] cval[%d] ramsz[%d]\n", mp
->eeprom
.cpuvers
,
903 mp
->eeprom
.cval
, mp
->eeprom
.ramsz
));
904 if(mp
->eeprom
.cpuvers
== 0) {
905 DET(("EEPROM: cpuvers was zero, setting to %04x\n",CPUVERS_2_3
));
906 mp
->eeprom
.cpuvers
= CPUVERS_2_3
;
908 if(mp
->eeprom
.cpuvers
< CPUVERS_3_0
) {
909 DET(("EEPROM: cpuvers < CPUVERS_3_0, clockval set to zero.\n"));
912 if(mp
->eeprom
.ramsz
== 0) {
913 DET(("EEPROM: ramsz == 0, setting to 128k\n"));
914 mp
->eeprom
.ramsz
= (128 * 1024);
916 i
= prom_getproperty(sdev
->prom_node
, "myrinet-board-id",
918 DET(("EEPROM: prom_getprop(myrinet-board-id) returns %d\n", i
));
919 if((i
!= 0) && (i
!= -1))
920 memcpy(&mp
->eeprom
.id
[0], &prop_buf
[0], 6);
922 set_boardid_from_idprom(mp
, num
);
923 i
= prom_getproperty(sdev
->prom_node
, "fpga_version",
924 &mp
->eeprom
.fvers
[0], 32);
925 DET(("EEPROM: prom_getprop(fpga_version) returns %d\n", i
));
926 if(i
== 0 || i
== -1)
927 memset(&mp
->eeprom
.fvers
[0], 0, 32);
929 if(mp
->eeprom
.cpuvers
== CPUVERS_4_1
) {
930 DET(("EEPROM: cpuvers CPUVERS_4_1, "));
931 if(mp
->eeprom
.ramsz
== (128 * 1024)) {
932 DET(("ramsize 128k, setting to 256k, "));
933 mp
->eeprom
.ramsz
= (256 * 1024);
935 if((mp
->eeprom
.cval
==0x40414041)||(mp
->eeprom
.cval
==0x90449044)){
936 DET(("changing cval from %08x to %08x ",
937 mp
->eeprom
.cval
, 0x50e450e4));
938 mp
->eeprom
.cval
= 0x50e450e4;
947 for(i
= 0; i
< 6; i
++)
949 dev
->dev_addr
[i
] = mp
->eeprom
.id
[i
],
953 determine_reg_space_size(mp
);
955 /* Map in the MyriCOM register/localram set. */
956 prom_apply_sbus_ranges(sdev
->my_bus
, &sdev
->reg_addrs
[0],
957 sdev
->num_registers
, sdev
);
958 if(mp
->eeprom
.cpuvers
< CPUVERS_4_0
) {
959 /* XXX Makes no sense, if control reg is non-existant this
960 * XXX driver cannot function at all... maybe pre-4.0 is
961 * XXX only a valid version for PCI cards? Ask feldy...
963 DET(("Mapping regs for cpuvers < CPUVERS_4_0\n"));
964 mp
->regs
= (struct myri_regs
*)
965 sparc_alloc_io(sdev
->reg_addrs
[0].phys_addr
, 0,
966 mp
->reg_size
, "MyriCOM Regs",
967 sdev
->reg_addrs
[0].which_io
, 0);
969 printk("MyriCOM: Cannot map MyriCOM registers.\n");
972 mp
->lanai
= (unsigned short *) (((unsigned long)mp
->regs
) + (256*1024));
973 mp
->lanai3
= (unsigned int *) mp
->lanai
;
974 mp
->lregs
= (struct lanai_regs
*) &mp
->lanai
[0x10000];
976 DET(("Mapping regs for cpuvers >= CPUVERS_4_0\n"));
977 mp
->cregs
= (struct myri_control
*)
978 sparc_alloc_io(sdev
->reg_addrs
[0].phys_addr
, 0,
979 PAGE_SIZE
, "MyriCOM Control Regs",
980 sdev
->reg_addrs
[0].which_io
, 0);
981 mp
->lregs
= (struct lanai_regs
*)
982 sparc_alloc_io(sdev
->reg_addrs
[0].phys_addr
+ (256 * 1024),
983 0, PAGE_SIZE
, "MyriCOM LANAI Regs",
984 sdev
->reg_addrs
[0].which_io
, 0);
985 mp
->lanai
= (unsigned short *)
986 sparc_alloc_io(sdev
->reg_addrs
[0].phys_addr
+ (512 * 1024),
987 0, mp
->eeprom
.ramsz
, "MyriCOM SRAM",
988 sdev
->reg_addrs
[0].which_io
, 0);
989 mp
->lanai3
= (unsigned int *) mp
->lanai
;
991 DET(("Registers mapped: cregs[%p] lregs[%p] lanai[%p] lanai3[%p]\n",
992 mp
->cregs
, mp
->lregs
, mp
->lanai
, mp
->lanai3
));
994 if(mp
->eeprom
.cpuvers
>= CPUVERS_4_0
)
995 mp
->shmem_base
= 0xf000;
997 mp
->shmem_base
= 0x8000;
999 DET(("Shared memory base is %04x, ", mp
->shmem_base
));
1001 mp
->shmem
= (struct myri_shmem
*) &mp
->lanai
[mp
->shmem_base
];
1002 DET(("shmem mapped at %p\n", mp
->shmem
));
1004 mp
->rqack
= &mp
->shmem
->channel
.recvqa
;
1005 mp
->rq
= &mp
->shmem
->channel
.recvq
;
1006 mp
->sq
= &mp
->shmem
->channel
.sendq
;
1008 /* Reset the board. */
1009 DET(("Resetting LANAI\n"));
1010 myri_reset_off(mp
->lregs
, mp
->cregs
);
1011 myri_reset_on(mp
->cregs
);
1013 /* Turn IRQ's off. */
1014 myri_disable_irq(mp
->lregs
, mp
->cregs
);
1016 /* Reset once more. */
1017 myri_reset_on(mp
->cregs
);
1019 /* Get the supported DVMA burst sizes from our SBUS. */
1020 mp
->myri_bursts
= prom_getintdefault(mp
->myri_sbus_dev
->my_bus
->prom_node
,
1021 "burst-sizes", 0x00);
1023 #if 1 /* XXX Until sun4m SBUS burst workaround is written. */
1024 if(sparc_cpu_model
== sun4m
)
1025 mp
->myri_bursts
&= ~(DMA_BURST64
);
1027 DET(("MYRI bursts %02x\n", mp
->myri_bursts
));
1029 /* Encode SBUS interrupt level in second control register. */
1030 i
= prom_getint(sdev
->prom_node
, "interrupts");
1033 DET(("prom_getint(interrupts)==%d, irqlvl set to %04x\n",
1035 mp
->cregs
->irqlvl
= (1 << i
);
1038 dev
->open
= &myri_open
;
1039 dev
->stop
= &myri_close
;
1040 dev
->hard_start_xmit
= &myri_start_xmit
;
1041 dev
->get_stats
= &myri_get_stats
;
1042 dev
->set_multicast_list
= &myri_set_multicast
;
1043 dev
->irq
= sdev
->irqs
[0];
1046 /* Register interrupt handler now. */
1047 DET(("Requesting MYRIcom IRQ line.\n"));
1048 if(request_irq(dev
->irq
, &myri_interrupt
,
1049 SA_SHIRQ
, "MyriCOM Ethernet", (void *) dev
)) {
1050 printk("MyriCOM: Cannot register interrupt handler.\n");
1054 DET(("ether_setup()\n"));
1057 dev
->mtu
= MYRINET_MTU
;
1058 dev
->change_mtu
= myri_change_mtu
;
1059 dev
->hard_header
= myri_header
;
1060 dev
->rebuild_header
= myri_rebuild_header
;
1061 dev
->hard_header_len
= (ETH_HLEN
+ MYRI_PAD_LEN
);
1062 dev
->hard_header_cache
= myri_header_cache
;
1063 dev
->header_cache_update
= myri_header_cache_update
;
1065 /* Load code onto the LANai. */
1066 DET(("Loading LANAI firmware\n"));
1067 myri_load_lanai(mp
);
1070 dev
->ifindex
= dev_new_index();
1071 mp
->next_module
= root_myri_dev
;
1077 int __init
myri_sbus_probe(struct net_device
*dev
)
1079 struct linux_sbus
*bus
;
1080 struct linux_sbus_device
*sdev
= 0;
1081 static int called
= 0;
1088 for_each_sbus(bus
) {
1089 for_each_sbusdev(sdev
, bus
) {
1090 if(cards
) dev
= NULL
;
1091 if(!strcmp(sdev
->prom_name
, "MYRICOM,mlanai") ||
1092 !strcmp(sdev
->prom_name
, "myri")) {
1094 DET(("Found myricom myrinet as %s\n", sdev
->prom_name
));
1095 if((v
= myri_ether_init(dev
, sdev
, (cards
- 1))))
1110 root_myri_dev
= NULL
;
1111 return myri_sbus_probe(NULL
);
1115 cleanup_module(void)
1117 struct myri_eth
*mp
;
1119 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1120 while (root_myri_dev
) {
1121 mp
= root_myri_dev
->next_module
;
1123 unregister_netdev(root_myri_dev
->dev
);
1124 kfree(root_myri_dev
->dev
);