2 * Network device driver for the MACE ethernet controller on
3 * Apple Powermacs. Assumes it's under a DBDMA controller.
5 * Copyright (C) 1996 Paul Mackerras.
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/netdevice.h>
11 #include <linux/etherdevice.h>
12 #include <linux/delay.h>
13 #include <linux/string.h>
14 #include <linux/timer.h>
15 #include <linux/init.h>
16 #include <linux/crc32.h>
17 #include <linux/spinlock.h>
18 #include <linux/bitrev.h>
19 #include <linux/slab.h>
21 #include <asm/dbdma.h>
23 #include <asm/pgtable.h>
24 #include <asm/macio.h>
28 static int port_aaui
= -1;
32 #define MAX_TX_ACTIVE 1
33 #define NCMDS_TX 1 /* dma commands per element in tx ring */
34 #define RX_BUFLEN (ETH_FRAME_LEN + 8)
35 #define TX_TIMEOUT HZ /* 1 second */
37 /* Chip rev needs workaround on HW & multicast addr change */
38 #define BROKEN_ADDRCHG_REV 0x0941
40 /* Bits in transmit DMA status */
41 #define TX_DMA_ERR 0x80
44 volatile struct mace __iomem
*mace
;
45 volatile struct dbdma_regs __iomem
*tx_dma
;
47 volatile struct dbdma_regs __iomem
*rx_dma
;
49 volatile struct dbdma_cmd
*tx_cmds
; /* xmit dma command list */
50 volatile struct dbdma_cmd
*rx_cmds
; /* recv dma command list */
51 struct sk_buff
*rx_bufs
[N_RX_RING
];
54 struct sk_buff
*tx_bufs
[N_TX_RING
];
58 unsigned char tx_fullup
;
59 unsigned char tx_active
;
60 unsigned char tx_bad_runt
;
61 struct timer_list tx_timeout
;
65 struct macio_dev
*mdev
;
70 * Number of bytes of private data per MACE: allow enough for
71 * the rx and tx dma commands plus a branch dma command each,
72 * and another 16 bytes to allow us to align the dma command
73 * buffers on a 16 byte boundary.
75 #define PRIV_BYTES (sizeof(struct mace_data) \
76 + (N_RX_RING + NCMDS_TX * N_TX_RING + 3) * sizeof(struct dbdma_cmd))
78 static int mace_open(struct net_device
*dev
);
79 static int mace_close(struct net_device
*dev
);
80 static int mace_xmit_start(struct sk_buff
*skb
, struct net_device
*dev
);
81 static void mace_set_multicast(struct net_device
*dev
);
82 static void mace_reset(struct net_device
*dev
);
83 static int mace_set_address(struct net_device
*dev
, void *addr
);
84 static irqreturn_t
mace_interrupt(int irq
, void *dev_id
);
85 static irqreturn_t
mace_txdma_intr(int irq
, void *dev_id
);
86 static irqreturn_t
mace_rxdma_intr(int irq
, void *dev_id
);
87 static void mace_set_timeout(struct net_device
*dev
);
88 static void mace_tx_timeout(unsigned long data
);
89 static inline void dbdma_reset(volatile struct dbdma_regs __iomem
*dma
);
90 static inline void mace_clean_rings(struct mace_data
*mp
);
91 static void __mace_set_address(struct net_device
*dev
, void *addr
);
94 * If we can't get a skbuff when we need it, we use this area for DMA.
96 static unsigned char *dummy_buf
;
98 static const struct net_device_ops mace_netdev_ops
= {
99 .ndo_open
= mace_open
,
100 .ndo_stop
= mace_close
,
101 .ndo_start_xmit
= mace_xmit_start
,
102 .ndo_set_multicast_list
= mace_set_multicast
,
103 .ndo_set_mac_address
= mace_set_address
,
104 .ndo_change_mtu
= eth_change_mtu
,
105 .ndo_validate_addr
= eth_validate_addr
,
108 static int __devinit
mace_probe(struct macio_dev
*mdev
, const struct of_device_id
*match
)
110 struct device_node
*mace
= macio_get_of_node(mdev
);
111 struct net_device
*dev
;
112 struct mace_data
*mp
;
113 const unsigned char *addr
;
114 int j
, rev
, rc
= -EBUSY
;
116 if (macio_resource_count(mdev
) != 3 || macio_irq_count(mdev
) != 3) {
117 printk(KERN_ERR
"can't use MACE %s: need 3 addrs and 3 irqs\n",
122 addr
= of_get_property(mace
, "mac-address", NULL
);
124 addr
= of_get_property(mace
, "local-mac-address", NULL
);
126 printk(KERN_ERR
"Can't get mac-address for MACE %s\n",
133 * lazy allocate the driver-wide dummy buffer. (Note that we
134 * never have more than one MACE in the system anyway)
136 if (dummy_buf
== NULL
) {
137 dummy_buf
= kmalloc(RX_BUFLEN
+2, GFP_KERNEL
);
138 if (dummy_buf
== NULL
) {
139 printk(KERN_ERR
"MACE: couldn't allocate dummy buffer\n");
144 if (macio_request_resources(mdev
, "mace")) {
145 printk(KERN_ERR
"MACE: can't request IO resources !\n");
149 dev
= alloc_etherdev(PRIV_BYTES
);
151 printk(KERN_ERR
"MACE: can't allocate ethernet device !\n");
155 SET_NETDEV_DEV(dev
, &mdev
->ofdev
.dev
);
157 mp
= netdev_priv(dev
);
159 macio_set_drvdata(mdev
, dev
);
161 dev
->base_addr
= macio_resource_start(mdev
, 0);
162 mp
->mace
= ioremap(dev
->base_addr
, 0x1000);
163 if (mp
->mace
== NULL
) {
164 printk(KERN_ERR
"MACE: can't map IO resources !\n");
168 dev
->irq
= macio_irq(mdev
, 0);
170 rev
= addr
[0] == 0 && addr
[1] == 0xA0;
171 for (j
= 0; j
< 6; ++j
) {
172 dev
->dev_addr
[j
] = rev
? bitrev8(addr
[j
]): addr
[j
];
174 mp
->chipid
= (in_8(&mp
->mace
->chipid_hi
) << 8) |
175 in_8(&mp
->mace
->chipid_lo
);
178 mp
= netdev_priv(dev
);
179 mp
->maccc
= ENXMT
| ENRCV
;
181 mp
->tx_dma
= ioremap(macio_resource_start(mdev
, 1), 0x1000);
182 if (mp
->tx_dma
== NULL
) {
183 printk(KERN_ERR
"MACE: can't map TX DMA resources !\n");
187 mp
->tx_dma_intr
= macio_irq(mdev
, 1);
189 mp
->rx_dma
= ioremap(macio_resource_start(mdev
, 2), 0x1000);
190 if (mp
->rx_dma
== NULL
) {
191 printk(KERN_ERR
"MACE: can't map RX DMA resources !\n");
193 goto err_unmap_tx_dma
;
195 mp
->rx_dma_intr
= macio_irq(mdev
, 2);
197 mp
->tx_cmds
= (volatile struct dbdma_cmd
*) DBDMA_ALIGN(mp
+ 1);
198 mp
->rx_cmds
= mp
->tx_cmds
+ NCMDS_TX
* N_TX_RING
+ 1;
200 memset((char *) mp
->tx_cmds
, 0,
201 (NCMDS_TX
*N_TX_RING
+ N_RX_RING
+ 2) * sizeof(struct dbdma_cmd
));
202 init_timer(&mp
->tx_timeout
);
203 spin_lock_init(&mp
->lock
);
204 mp
->timeout_active
= 0;
207 mp
->port_aaui
= port_aaui
;
209 /* Apple Network Server uses the AAUI port */
210 if (of_machine_is_compatible("AAPL,ShinerESB"))
213 #ifdef CONFIG_MACE_AAUI_PORT
221 dev
->netdev_ops
= &mace_netdev_ops
;
224 * Most of what is below could be moved to mace_open()
228 rc
= request_irq(dev
->irq
, mace_interrupt
, 0, "MACE", dev
);
230 printk(KERN_ERR
"MACE: can't get irq %d\n", dev
->irq
);
231 goto err_unmap_rx_dma
;
233 rc
= request_irq(mp
->tx_dma_intr
, mace_txdma_intr
, 0, "MACE-txdma", dev
);
235 printk(KERN_ERR
"MACE: can't get irq %d\n", mp
->tx_dma_intr
);
238 rc
= request_irq(mp
->rx_dma_intr
, mace_rxdma_intr
, 0, "MACE-rxdma", dev
);
240 printk(KERN_ERR
"MACE: can't get irq %d\n", mp
->rx_dma_intr
);
241 goto err_free_tx_irq
;
244 rc
= register_netdev(dev
);
246 printk(KERN_ERR
"MACE: Cannot register net device, aborting.\n");
247 goto err_free_rx_irq
;
250 printk(KERN_INFO
"%s: MACE at %pM, chip revision %d.%d\n",
251 dev
->name
, dev
->dev_addr
,
252 mp
->chipid
>> 8, mp
->chipid
& 0xff);
257 free_irq(macio_irq(mdev
, 2), dev
);
259 free_irq(macio_irq(mdev
, 1), dev
);
261 free_irq(macio_irq(mdev
, 0), dev
);
271 macio_release_resources(mdev
);
276 static int __devexit
mace_remove(struct macio_dev
*mdev
)
278 struct net_device
*dev
= macio_get_drvdata(mdev
);
279 struct mace_data
*mp
;
283 macio_set_drvdata(mdev
, NULL
);
285 mp
= netdev_priv(dev
);
287 unregister_netdev(dev
);
289 free_irq(dev
->irq
, dev
);
290 free_irq(mp
->tx_dma_intr
, dev
);
291 free_irq(mp
->rx_dma_intr
, dev
);
299 macio_release_resources(mdev
);
304 static void dbdma_reset(volatile struct dbdma_regs __iomem
*dma
)
308 out_le32(&dma
->control
, (WAKE
|FLUSH
|PAUSE
|RUN
) << 16);
311 * Yes this looks peculiar, but apparently it needs to be this
312 * way on some machines.
314 for (i
= 200; i
> 0; --i
)
315 if (ld_le32(&dma
->control
) & RUN
)
319 static void mace_reset(struct net_device
*dev
)
321 struct mace_data
*mp
= netdev_priv(dev
);
322 volatile struct mace __iomem
*mb
= mp
->mace
;
325 /* soft-reset the chip */
328 out_8(&mb
->biucc
, SWRST
);
329 if (in_8(&mb
->biucc
) & SWRST
) {
336 printk(KERN_ERR
"mace: cannot reset chip!\n");
340 out_8(&mb
->imr
, 0xff); /* disable all intrs for now */
342 out_8(&mb
->maccc
, 0); /* turn off tx, rx */
344 out_8(&mb
->biucc
, XMTSP_64
);
345 out_8(&mb
->utr
, RTRD
);
346 out_8(&mb
->fifocc
, RCVFW_32
| XMTFW_16
| XMTFWU
| RCVFWU
| XMTBRST
);
347 out_8(&mb
->xmtfc
, AUTO_PAD_XMIT
); /* auto-pad short frames */
348 out_8(&mb
->rcvfc
, 0);
350 /* load up the hardware address */
351 __mace_set_address(dev
, dev
->dev_addr
);
353 /* clear the multicast filter */
354 if (mp
->chipid
== BROKEN_ADDRCHG_REV
)
355 out_8(&mb
->iac
, LOGADDR
);
357 out_8(&mb
->iac
, ADDRCHG
| LOGADDR
);
358 while ((in_8(&mb
->iac
) & ADDRCHG
) != 0)
361 for (i
= 0; i
< 8; ++i
)
362 out_8(&mb
->ladrf
, 0);
364 /* done changing address */
365 if (mp
->chipid
!= BROKEN_ADDRCHG_REV
)
369 out_8(&mb
->plscc
, PORTSEL_AUI
+ ENPLSIO
);
371 out_8(&mb
->plscc
, PORTSEL_GPSI
+ ENPLSIO
);
374 static void __mace_set_address(struct net_device
*dev
, void *addr
)
376 struct mace_data
*mp
= netdev_priv(dev
);
377 volatile struct mace __iomem
*mb
= mp
->mace
;
378 unsigned char *p
= addr
;
381 /* load up the hardware address */
382 if (mp
->chipid
== BROKEN_ADDRCHG_REV
)
383 out_8(&mb
->iac
, PHYADDR
);
385 out_8(&mb
->iac
, ADDRCHG
| PHYADDR
);
386 while ((in_8(&mb
->iac
) & ADDRCHG
) != 0)
389 for (i
= 0; i
< 6; ++i
)
390 out_8(&mb
->padr
, dev
->dev_addr
[i
] = p
[i
]);
391 if (mp
->chipid
!= BROKEN_ADDRCHG_REV
)
395 static int mace_set_address(struct net_device
*dev
, void *addr
)
397 struct mace_data
*mp
= netdev_priv(dev
);
398 volatile struct mace __iomem
*mb
= mp
->mace
;
401 spin_lock_irqsave(&mp
->lock
, flags
);
403 __mace_set_address(dev
, addr
);
405 /* note: setting ADDRCHG clears ENRCV */
406 out_8(&mb
->maccc
, mp
->maccc
);
408 spin_unlock_irqrestore(&mp
->lock
, flags
);
412 static inline void mace_clean_rings(struct mace_data
*mp
)
416 /* free some skb's */
417 for (i
= 0; i
< N_RX_RING
; ++i
) {
418 if (mp
->rx_bufs
[i
] != NULL
) {
419 dev_kfree_skb(mp
->rx_bufs
[i
]);
420 mp
->rx_bufs
[i
] = NULL
;
423 for (i
= mp
->tx_empty
; i
!= mp
->tx_fill
; ) {
424 dev_kfree_skb(mp
->tx_bufs
[i
]);
425 if (++i
>= N_TX_RING
)
430 static int mace_open(struct net_device
*dev
)
432 struct mace_data
*mp
= netdev_priv(dev
);
433 volatile struct mace __iomem
*mb
= mp
->mace
;
434 volatile struct dbdma_regs __iomem
*rd
= mp
->rx_dma
;
435 volatile struct dbdma_regs __iomem
*td
= mp
->tx_dma
;
436 volatile struct dbdma_cmd
*cp
;
444 /* initialize list of sk_buffs for receiving and set up recv dma */
445 mace_clean_rings(mp
);
446 memset((char *)mp
->rx_cmds
, 0, N_RX_RING
* sizeof(struct dbdma_cmd
));
448 for (i
= 0; i
< N_RX_RING
- 1; ++i
) {
449 skb
= dev_alloc_skb(RX_BUFLEN
+ 2);
453 skb_reserve(skb
, 2); /* so IP header lands on 4-byte bdry */
456 mp
->rx_bufs
[i
] = skb
;
457 st_le16(&cp
->req_count
, RX_BUFLEN
);
458 st_le16(&cp
->command
, INPUT_LAST
+ INTR_ALWAYS
);
459 st_le32(&cp
->phy_addr
, virt_to_bus(data
));
463 mp
->rx_bufs
[i
] = NULL
;
464 st_le16(&cp
->command
, DBDMA_STOP
);
468 /* Put a branch back to the beginning of the receive command list */
470 st_le16(&cp
->command
, DBDMA_NOP
+ BR_ALWAYS
);
471 st_le32(&cp
->cmd_dep
, virt_to_bus(mp
->rx_cmds
));
474 out_le32(&rd
->control
, (RUN
|PAUSE
|FLUSH
|WAKE
) << 16); /* clear run bit */
475 out_le32(&rd
->cmdptr
, virt_to_bus(mp
->rx_cmds
));
476 out_le32(&rd
->control
, (RUN
<< 16) | RUN
);
478 /* put a branch at the end of the tx command list */
479 cp
= mp
->tx_cmds
+ NCMDS_TX
* N_TX_RING
;
480 st_le16(&cp
->command
, DBDMA_NOP
+ BR_ALWAYS
);
481 st_le32(&cp
->cmd_dep
, virt_to_bus(mp
->tx_cmds
));
484 out_le32(&td
->control
, (RUN
|PAUSE
|FLUSH
|WAKE
) << 16);
485 out_le32(&td
->cmdptr
, virt_to_bus(mp
->tx_cmds
));
493 out_8(&mb
->maccc
, mp
->maccc
);
494 /* enable all interrupts except receive interrupts */
495 out_8(&mb
->imr
, RCVINT
);
500 static int mace_close(struct net_device
*dev
)
502 struct mace_data
*mp
= netdev_priv(dev
);
503 volatile struct mace __iomem
*mb
= mp
->mace
;
504 volatile struct dbdma_regs __iomem
*rd
= mp
->rx_dma
;
505 volatile struct dbdma_regs __iomem
*td
= mp
->tx_dma
;
507 /* disable rx and tx */
508 out_8(&mb
->maccc
, 0);
509 out_8(&mb
->imr
, 0xff); /* disable all intrs */
511 /* disable rx and tx dma */
512 st_le32(&rd
->control
, (RUN
|PAUSE
|FLUSH
|WAKE
) << 16); /* clear run bit */
513 st_le32(&td
->control
, (RUN
|PAUSE
|FLUSH
|WAKE
) << 16); /* clear run bit */
515 mace_clean_rings(mp
);
520 static inline void mace_set_timeout(struct net_device
*dev
)
522 struct mace_data
*mp
= netdev_priv(dev
);
524 if (mp
->timeout_active
)
525 del_timer(&mp
->tx_timeout
);
526 mp
->tx_timeout
.expires
= jiffies
+ TX_TIMEOUT
;
527 mp
->tx_timeout
.function
= mace_tx_timeout
;
528 mp
->tx_timeout
.data
= (unsigned long) dev
;
529 add_timer(&mp
->tx_timeout
);
530 mp
->timeout_active
= 1;
533 static int mace_xmit_start(struct sk_buff
*skb
, struct net_device
*dev
)
535 struct mace_data
*mp
= netdev_priv(dev
);
536 volatile struct dbdma_regs __iomem
*td
= mp
->tx_dma
;
537 volatile struct dbdma_cmd
*cp
, *np
;
541 /* see if there's a free slot in the tx ring */
542 spin_lock_irqsave(&mp
->lock
, flags
);
545 if (next
>= N_TX_RING
)
547 if (next
== mp
->tx_empty
) {
548 netif_stop_queue(dev
);
550 spin_unlock_irqrestore(&mp
->lock
, flags
);
551 return NETDEV_TX_BUSY
; /* can't take it at the moment */
553 spin_unlock_irqrestore(&mp
->lock
, flags
);
555 /* partially fill in the dma command block */
557 if (len
> ETH_FRAME_LEN
) {
558 printk(KERN_DEBUG
"mace: xmit frame too long (%d)\n", len
);
561 mp
->tx_bufs
[fill
] = skb
;
562 cp
= mp
->tx_cmds
+ NCMDS_TX
* fill
;
563 st_le16(&cp
->req_count
, len
);
564 st_le32(&cp
->phy_addr
, virt_to_bus(skb
->data
));
566 np
= mp
->tx_cmds
+ NCMDS_TX
* next
;
567 out_le16(&np
->command
, DBDMA_STOP
);
569 /* poke the tx dma channel */
570 spin_lock_irqsave(&mp
->lock
, flags
);
572 if (!mp
->tx_bad_runt
&& mp
->tx_active
< MAX_TX_ACTIVE
) {
573 out_le16(&cp
->xfer_status
, 0);
574 out_le16(&cp
->command
, OUTPUT_LAST
);
575 out_le32(&td
->control
, ((RUN
|WAKE
) << 16) + (RUN
|WAKE
));
577 mace_set_timeout(dev
);
579 if (++next
>= N_TX_RING
)
581 if (next
== mp
->tx_empty
)
582 netif_stop_queue(dev
);
583 spin_unlock_irqrestore(&mp
->lock
, flags
);
588 static void mace_set_multicast(struct net_device
*dev
)
590 struct mace_data
*mp
= netdev_priv(dev
);
591 volatile struct mace __iomem
*mb
= mp
->mace
;
596 spin_lock_irqsave(&mp
->lock
, flags
);
598 if (dev
->flags
& IFF_PROMISC
) {
601 unsigned char multicast_filter
[8];
602 struct netdev_hw_addr
*ha
;
604 if (dev
->flags
& IFF_ALLMULTI
) {
605 for (i
= 0; i
< 8; i
++)
606 multicast_filter
[i
] = 0xff;
608 for (i
= 0; i
< 8; i
++)
609 multicast_filter
[i
] = 0;
610 netdev_for_each_mc_addr(ha
, dev
) {
611 crc
= ether_crc_le(6, ha
->addr
);
612 i
= crc
>> 26; /* bit number in multicast_filter */
613 multicast_filter
[i
>> 3] |= 1 << (i
& 7);
617 printk("Multicast filter :");
618 for (i
= 0; i
< 8; i
++)
619 printk("%02x ", multicast_filter
[i
]);
623 if (mp
->chipid
== BROKEN_ADDRCHG_REV
)
624 out_8(&mb
->iac
, LOGADDR
);
626 out_8(&mb
->iac
, ADDRCHG
| LOGADDR
);
627 while ((in_8(&mb
->iac
) & ADDRCHG
) != 0)
630 for (i
= 0; i
< 8; ++i
)
631 out_8(&mb
->ladrf
, multicast_filter
[i
]);
632 if (mp
->chipid
!= BROKEN_ADDRCHG_REV
)
636 out_8(&mb
->maccc
, mp
->maccc
);
637 spin_unlock_irqrestore(&mp
->lock
, flags
);
640 static void mace_handle_misc_intrs(struct mace_data
*mp
, int intr
, struct net_device
*dev
)
642 volatile struct mace __iomem
*mb
= mp
->mace
;
643 static int mace_babbles
, mace_jabbers
;
646 dev
->stats
.rx_missed_errors
+= 256;
647 dev
->stats
.rx_missed_errors
+= in_8(&mb
->mpc
); /* reading clears it */
649 dev
->stats
.rx_length_errors
+= 256;
650 dev
->stats
.rx_length_errors
+= in_8(&mb
->rntpc
); /* reading clears it */
652 ++dev
->stats
.tx_heartbeat_errors
;
654 if (mace_babbles
++ < 4)
655 printk(KERN_DEBUG
"mace: babbling transmitter\n");
657 if (mace_jabbers
++ < 4)
658 printk(KERN_DEBUG
"mace: jabbering transceiver\n");
661 static irqreturn_t
mace_interrupt(int irq
, void *dev_id
)
663 struct net_device
*dev
= (struct net_device
*) dev_id
;
664 struct mace_data
*mp
= netdev_priv(dev
);
665 volatile struct mace __iomem
*mb
= mp
->mace
;
666 volatile struct dbdma_regs __iomem
*td
= mp
->tx_dma
;
667 volatile struct dbdma_cmd
*cp
;
668 int intr
, fs
, i
, stat
, x
;
671 /* static int mace_last_fs, mace_last_xcount; */
673 spin_lock_irqsave(&mp
->lock
, flags
);
674 intr
= in_8(&mb
->ir
); /* read interrupt register */
675 in_8(&mb
->xmtrc
); /* get retries */
676 mace_handle_misc_intrs(mp
, intr
, dev
);
679 while (in_8(&mb
->pr
) & XMTSV
) {
680 del_timer(&mp
->tx_timeout
);
681 mp
->timeout_active
= 0;
683 * Clear any interrupt indication associated with this status
684 * word. This appears to unlatch any error indication from
685 * the DMA controller.
687 intr
= in_8(&mb
->ir
);
689 mace_handle_misc_intrs(mp
, intr
, dev
);
690 if (mp
->tx_bad_runt
) {
691 fs
= in_8(&mb
->xmtfs
);
693 out_8(&mb
->xmtfc
, AUTO_PAD_XMIT
);
696 dstat
= ld_le32(&td
->status
);
697 /* stop DMA controller */
698 out_le32(&td
->control
, RUN
<< 16);
700 * xcount is the number of complete frames which have been
701 * written to the fifo but for which status has not been read.
703 xcount
= (in_8(&mb
->fifofc
) >> XMTFC_SH
) & XMTFC_MASK
;
704 if (xcount
== 0 || (dstat
& DEAD
)) {
706 * If a packet was aborted before the DMA controller has
707 * finished transferring it, it seems that there are 2 bytes
708 * which are stuck in some buffer somewhere. These will get
709 * transmitted as soon as we read the frame status (which
710 * reenables the transmit data transfer request). Turning
711 * off the DMA controller and/or resetting the MACE doesn't
712 * help. So we disable auto-padding and FCS transmission
713 * so the two bytes will only be a runt packet which should
714 * be ignored by other stations.
716 out_8(&mb
->xmtfc
, DXMTFCS
);
718 fs
= in_8(&mb
->xmtfs
);
719 if ((fs
& XMTSV
) == 0) {
720 printk(KERN_ERR
"mace: xmtfs not valid! (fs=%x xc=%d ds=%x)\n",
724 * XXX mace likes to hang the machine after a xmtfs error.
725 * This is hard to reproduce, reseting *may* help
728 cp
= mp
->tx_cmds
+ NCMDS_TX
* i
;
729 stat
= ld_le16(&cp
->xfer_status
);
730 if ((fs
& (UFLO
|LCOL
|LCAR
|RTRY
)) || (dstat
& DEAD
) || xcount
== 0) {
732 * Check whether there were in fact 2 bytes written to
736 x
= (in_8(&mb
->fifofc
) >> XMTFC_SH
) & XMTFC_MASK
;
738 /* there were two bytes with an end-of-packet indication */
740 mace_set_timeout(dev
);
743 * Either there weren't the two bytes buffered up, or they
744 * didn't have an end-of-packet indication.
745 * We flush the transmit FIFO just in case (by setting the
746 * XMTFWU bit with the transmitter disabled).
748 out_8(&mb
->maccc
, in_8(&mb
->maccc
) & ~ENXMT
);
749 out_8(&mb
->fifocc
, in_8(&mb
->fifocc
) | XMTFWU
);
751 out_8(&mb
->maccc
, in_8(&mb
->maccc
) | ENXMT
);
752 out_8(&mb
->xmtfc
, AUTO_PAD_XMIT
);
755 /* dma should have finished */
756 if (i
== mp
->tx_fill
) {
757 printk(KERN_DEBUG
"mace: tx ring ran out? (fs=%x xc=%d ds=%x)\n",
762 if (fs
& (UFLO
|LCOL
|LCAR
|RTRY
)) {
763 ++dev
->stats
.tx_errors
;
765 ++dev
->stats
.tx_carrier_errors
;
766 if (fs
& (UFLO
|LCOL
|RTRY
))
767 ++dev
->stats
.tx_aborted_errors
;
769 dev
->stats
.tx_bytes
+= mp
->tx_bufs
[i
]->len
;
770 ++dev
->stats
.tx_packets
;
772 dev_kfree_skb_irq(mp
->tx_bufs
[i
]);
774 if (++i
>= N_TX_RING
)
778 mace_last_xcount
= xcount
;
782 if (i
!= mp
->tx_empty
) {
784 netif_wake_queue(dev
);
790 if (!mp
->tx_bad_runt
&& i
!= mp
->tx_fill
&& mp
->tx_active
< MAX_TX_ACTIVE
) {
792 /* set up the next one */
793 cp
= mp
->tx_cmds
+ NCMDS_TX
* i
;
794 out_le16(&cp
->xfer_status
, 0);
795 out_le16(&cp
->command
, OUTPUT_LAST
);
797 if (++i
>= N_TX_RING
)
799 } while (i
!= mp
->tx_fill
&& mp
->tx_active
< MAX_TX_ACTIVE
);
800 out_le32(&td
->control
, ((RUN
|WAKE
) << 16) + (RUN
|WAKE
));
801 mace_set_timeout(dev
);
803 spin_unlock_irqrestore(&mp
->lock
, flags
);
807 static void mace_tx_timeout(unsigned long data
)
809 struct net_device
*dev
= (struct net_device
*) data
;
810 struct mace_data
*mp
= netdev_priv(dev
);
811 volatile struct mace __iomem
*mb
= mp
->mace
;
812 volatile struct dbdma_regs __iomem
*td
= mp
->tx_dma
;
813 volatile struct dbdma_regs __iomem
*rd
= mp
->rx_dma
;
814 volatile struct dbdma_cmd
*cp
;
818 spin_lock_irqsave(&mp
->lock
, flags
);
819 mp
->timeout_active
= 0;
820 if (mp
->tx_active
== 0 && !mp
->tx_bad_runt
)
823 /* update various counters */
824 mace_handle_misc_intrs(mp
, in_8(&mb
->ir
), dev
);
826 cp
= mp
->tx_cmds
+ NCMDS_TX
* mp
->tx_empty
;
828 /* turn off both tx and rx and reset the chip */
829 out_8(&mb
->maccc
, 0);
830 printk(KERN_ERR
"mace: transmit timeout - resetting\n");
835 cp
= bus_to_virt(ld_le32(&rd
->cmdptr
));
837 out_le16(&cp
->xfer_status
, 0);
838 out_le32(&rd
->cmdptr
, virt_to_bus(cp
));
839 out_le32(&rd
->control
, (RUN
<< 16) | RUN
);
841 /* fix up the transmit side */
844 ++dev
->stats
.tx_errors
;
845 if (mp
->tx_bad_runt
) {
847 } else if (i
!= mp
->tx_fill
) {
848 dev_kfree_skb(mp
->tx_bufs
[i
]);
849 if (++i
>= N_TX_RING
)
854 netif_wake_queue(dev
);
855 if (i
!= mp
->tx_fill
) {
856 cp
= mp
->tx_cmds
+ NCMDS_TX
* i
;
857 out_le16(&cp
->xfer_status
, 0);
858 out_le16(&cp
->command
, OUTPUT_LAST
);
859 out_le32(&td
->cmdptr
, virt_to_bus(cp
));
860 out_le32(&td
->control
, (RUN
<< 16) | RUN
);
862 mace_set_timeout(dev
);
865 /* turn it back on */
866 out_8(&mb
->imr
, RCVINT
);
867 out_8(&mb
->maccc
, mp
->maccc
);
870 spin_unlock_irqrestore(&mp
->lock
, flags
);
873 static irqreturn_t
mace_txdma_intr(int irq
, void *dev_id
)
878 static irqreturn_t
mace_rxdma_intr(int irq
, void *dev_id
)
880 struct net_device
*dev
= (struct net_device
*) dev_id
;
881 struct mace_data
*mp
= netdev_priv(dev
);
882 volatile struct dbdma_regs __iomem
*rd
= mp
->rx_dma
;
883 volatile struct dbdma_cmd
*cp
, *np
;
884 int i
, nb
, stat
, next
;
886 unsigned frame_status
;
887 static int mace_lost_status
;
891 spin_lock_irqsave(&mp
->lock
, flags
);
892 for (i
= mp
->rx_empty
; i
!= mp
->rx_fill
; ) {
893 cp
= mp
->rx_cmds
+ i
;
894 stat
= ld_le16(&cp
->xfer_status
);
895 if ((stat
& ACTIVE
) == 0) {
897 if (next
>= N_RX_RING
)
899 np
= mp
->rx_cmds
+ next
;
900 if (next
!= mp
->rx_fill
&&
901 (ld_le16(&np
->xfer_status
) & ACTIVE
) != 0) {
902 printk(KERN_DEBUG
"mace: lost a status word\n");
907 nb
= ld_le16(&cp
->req_count
) - ld_le16(&cp
->res_count
);
908 out_le16(&cp
->command
, DBDMA_STOP
);
909 /* got a packet, have a look at it */
910 skb
= mp
->rx_bufs
[i
];
912 ++dev
->stats
.rx_dropped
;
915 frame_status
= (data
[nb
-3] << 8) + data
[nb
-4];
916 if (frame_status
& (RS_OFLO
|RS_CLSN
|RS_FRAMERR
|RS_FCSERR
)) {
917 ++dev
->stats
.rx_errors
;
918 if (frame_status
& RS_OFLO
)
919 ++dev
->stats
.rx_over_errors
;
920 if (frame_status
& RS_FRAMERR
)
921 ++dev
->stats
.rx_frame_errors
;
922 if (frame_status
& RS_FCSERR
)
923 ++dev
->stats
.rx_crc_errors
;
925 /* Mace feature AUTO_STRIP_RCV is on by default, dropping the
926 * FCS on frames with 802.3 headers. This means that Ethernet
927 * frames have 8 extra octets at the end, while 802.3 frames
928 * have only 4. We need to correctly account for this. */
929 if (*(unsigned short *)(data
+12) < 1536) /* 802.3 header */
931 else /* Ethernet header; mace includes FCS */
934 skb
->protocol
= eth_type_trans(skb
, dev
);
935 dev
->stats
.rx_bytes
+= skb
->len
;
937 mp
->rx_bufs
[i
] = NULL
;
938 ++dev
->stats
.rx_packets
;
941 ++dev
->stats
.rx_errors
;
942 ++dev
->stats
.rx_length_errors
;
945 /* advance to next */
946 if (++i
>= N_RX_RING
)
954 if (next
>= N_RX_RING
)
956 if (next
== mp
->rx_empty
)
958 cp
= mp
->rx_cmds
+ i
;
959 skb
= mp
->rx_bufs
[i
];
961 skb
= dev_alloc_skb(RX_BUFLEN
+ 2);
964 mp
->rx_bufs
[i
] = skb
;
967 st_le16(&cp
->req_count
, RX_BUFLEN
);
968 data
= skb
? skb
->data
: dummy_buf
;
969 st_le32(&cp
->phy_addr
, virt_to_bus(data
));
970 out_le16(&cp
->xfer_status
, 0);
971 out_le16(&cp
->command
, INPUT_LAST
+ INTR_ALWAYS
);
973 if ((ld_le32(&rd
->status
) & ACTIVE
) != 0) {
974 out_le32(&rd
->control
, (PAUSE
<< 16) | PAUSE
);
975 while ((in_le32(&rd
->status
) & ACTIVE
) != 0)
981 if (i
!= mp
->rx_fill
) {
982 out_le32(&rd
->control
, ((RUN
|WAKE
) << 16) | (RUN
|WAKE
));
985 spin_unlock_irqrestore(&mp
->lock
, flags
);
989 static struct of_device_id mace_match
[] =
996 MODULE_DEVICE_TABLE (of
, mace_match
);
998 static struct macio_driver mace_driver
=
1002 .owner
= THIS_MODULE
,
1003 .of_match_table
= mace_match
,
1005 .probe
= mace_probe
,
1006 .remove
= mace_remove
,
1010 static int __init
mace_init(void)
1012 return macio_register_driver(&mace_driver
);
1015 static void __exit
mace_cleanup(void)
1017 macio_unregister_driver(&mace_driver
);
1023 MODULE_AUTHOR("Paul Mackerras");
1024 MODULE_DESCRIPTION("PowerMac MACE driver.");
1025 module_param(port_aaui
, int, 0);
1026 MODULE_PARM_DESC(port_aaui
, "MACE uses AAUI port (0-1)");
1027 MODULE_LICENSE("GPL");
1029 module_init(mace_init
);
1030 module_exit(mace_cleanup
);