12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
28fb6b090SJeff Kirsher /*
38fb6b090SJeff Kirsher * Driver for the Macintosh 68K onboard MACE controller with PSC
48fb6b090SJeff Kirsher * driven DMA. The MACE driver code is derived from mace.c. The
58fb6b090SJeff Kirsher * Mac68k theory of operation is courtesy of the MacBSD wizards.
68fb6b090SJeff Kirsher *
78fb6b090SJeff Kirsher * Copyright (C) 1996 Paul Mackerras.
88fb6b090SJeff Kirsher * Copyright (C) 1998 Alan Cox <alan@lxorguk.ukuu.org.uk>
98fb6b090SJeff Kirsher *
108fb6b090SJeff Kirsher * Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver
118fb6b090SJeff Kirsher *
128fb6b090SJeff Kirsher * Copyright (C) 2007 Finn Thain
138fb6b090SJeff Kirsher *
148fb6b090SJeff Kirsher * Converted to DMA API, converted to unified driver model,
158fb6b090SJeff Kirsher * sync'd some routines with mace.c and fixed various bugs.
168fb6b090SJeff Kirsher */
178fb6b090SJeff Kirsher
188fb6b090SJeff Kirsher
198fb6b090SJeff Kirsher #include <linux/kernel.h>
208fb6b090SJeff Kirsher #include <linux/module.h>
218fb6b090SJeff Kirsher #include <linux/netdevice.h>
228fb6b090SJeff Kirsher #include <linux/etherdevice.h>
238fb6b090SJeff Kirsher #include <linux/delay.h>
248fb6b090SJeff Kirsher #include <linux/string.h>
258fb6b090SJeff Kirsher #include <linux/crc32.h>
268fb6b090SJeff Kirsher #include <linux/bitrev.h>
278fb6b090SJeff Kirsher #include <linux/dma-mapping.h>
288fb6b090SJeff Kirsher #include <linux/platform_device.h>
298fb6b090SJeff Kirsher #include <linux/gfp.h>
30ce43aa6cSFinn Thain #include <linux/interrupt.h>
318fb6b090SJeff Kirsher #include <asm/io.h>
328fb6b090SJeff Kirsher #include <asm/macints.h>
338fb6b090SJeff Kirsher #include <asm/mac_psc.h>
348fb6b090SJeff Kirsher #include <asm/page.h>
358fb6b090SJeff Kirsher #include "mace.h"
368fb6b090SJeff Kirsher
378fb6b090SJeff Kirsher static char mac_mace_string[] = "macmace";
388fb6b090SJeff Kirsher
398fb6b090SJeff Kirsher #define N_TX_BUFF_ORDER 0
408fb6b090SJeff Kirsher #define N_TX_RING (1 << N_TX_BUFF_ORDER)
418fb6b090SJeff Kirsher #define N_RX_BUFF_ORDER 3
428fb6b090SJeff Kirsher #define N_RX_RING (1 << N_RX_BUFF_ORDER)
438fb6b090SJeff Kirsher
448fb6b090SJeff Kirsher #define TX_TIMEOUT HZ
458fb6b090SJeff Kirsher
468fb6b090SJeff Kirsher #define MACE_BUFF_SIZE 0x800
478fb6b090SJeff Kirsher
488fb6b090SJeff Kirsher /* Chip rev needs workaround on HW & multicast addr change */
498fb6b090SJeff Kirsher #define BROKEN_ADDRCHG_REV 0x0941
508fb6b090SJeff Kirsher
518fb6b090SJeff Kirsher /* The MACE is simply wired down on a Mac68K box */
528fb6b090SJeff Kirsher
538fb6b090SJeff Kirsher #define MACE_BASE (void *)(0x50F1C000)
548fb6b090SJeff Kirsher #define MACE_PROM (void *)(0x50F08001)
558fb6b090SJeff Kirsher
568fb6b090SJeff Kirsher struct mace_data {
578fb6b090SJeff Kirsher volatile struct mace *mace;
588fb6b090SJeff Kirsher unsigned char *tx_ring;
598fb6b090SJeff Kirsher dma_addr_t tx_ring_phys;
608fb6b090SJeff Kirsher unsigned char *rx_ring;
618fb6b090SJeff Kirsher dma_addr_t rx_ring_phys;
628fb6b090SJeff Kirsher int dma_intr;
638fb6b090SJeff Kirsher int rx_slot, rx_tail;
648fb6b090SJeff Kirsher int tx_slot, tx_sloti, tx_count;
658fb6b090SJeff Kirsher int chipid;
668fb6b090SJeff Kirsher struct device *device;
678fb6b090SJeff Kirsher };
688fb6b090SJeff Kirsher
698fb6b090SJeff Kirsher struct mace_frame {
708fb6b090SJeff Kirsher u8 rcvcnt;
718fb6b090SJeff Kirsher u8 pad1;
728fb6b090SJeff Kirsher u8 rcvsts;
738fb6b090SJeff Kirsher u8 pad2;
748fb6b090SJeff Kirsher u8 rntpc;
758fb6b090SJeff Kirsher u8 pad3;
768fb6b090SJeff Kirsher u8 rcvcc;
778fb6b090SJeff Kirsher u8 pad4;
788fb6b090SJeff Kirsher u32 pad5;
798fb6b090SJeff Kirsher u32 pad6;
80*005c9600SAtul Raut DECLARE_FLEX_ARRAY(u8, data);
818fb6b090SJeff Kirsher /* And frame continues.. */
828fb6b090SJeff Kirsher };
838fb6b090SJeff Kirsher
848fb6b090SJeff Kirsher #define PRIV_BYTES sizeof(struct mace_data)
858fb6b090SJeff Kirsher
868fb6b090SJeff Kirsher static int mace_open(struct net_device *dev);
878fb6b090SJeff Kirsher static int mace_close(struct net_device *dev);
88e6ce3822SYueHaibing static netdev_tx_t mace_xmit_start(struct sk_buff *skb, struct net_device *dev);
898fb6b090SJeff Kirsher static void mace_set_multicast(struct net_device *dev);
908fb6b090SJeff Kirsher static int mace_set_address(struct net_device *dev, void *addr);
918fb6b090SJeff Kirsher static void mace_reset(struct net_device *dev);
928fb6b090SJeff Kirsher static irqreturn_t mace_interrupt(int irq, void *dev_id);
938fb6b090SJeff Kirsher static irqreturn_t mace_dma_intr(int irq, void *dev_id);
940290bd29SMichael S. Tsirkin static void mace_tx_timeout(struct net_device *dev, unsigned int txqueue);
95e217fc4aSJakub Kicinski static void __mace_set_address(struct net_device *dev, const void *addr);
968fb6b090SJeff Kirsher
978fb6b090SJeff Kirsher /*
988fb6b090SJeff Kirsher * Load a receive DMA channel with a base address and ring length
998fb6b090SJeff Kirsher */
1008fb6b090SJeff Kirsher
mace_load_rxdma_base(struct net_device * dev,int set)1018fb6b090SJeff Kirsher static void mace_load_rxdma_base(struct net_device *dev, int set)
1028fb6b090SJeff Kirsher {
1038fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
1048fb6b090SJeff Kirsher
1058fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CMD + set, 0x0100);
1068fb6b090SJeff Kirsher psc_write_long(PSC_ENETRD_ADDR + set, (u32) mp->rx_ring_phys);
1078fb6b090SJeff Kirsher psc_write_long(PSC_ENETRD_LEN + set, N_RX_RING);
1088fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CMD + set, 0x9800);
1098fb6b090SJeff Kirsher mp->rx_tail = 0;
1108fb6b090SJeff Kirsher }
1118fb6b090SJeff Kirsher
1128fb6b090SJeff Kirsher /*
1138fb6b090SJeff Kirsher * Reset the receive DMA subsystem
1148fb6b090SJeff Kirsher */
1158fb6b090SJeff Kirsher
mace_rxdma_reset(struct net_device * dev)1168fb6b090SJeff Kirsher static void mace_rxdma_reset(struct net_device *dev)
1178fb6b090SJeff Kirsher {
1188fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
1198fb6b090SJeff Kirsher volatile struct mace *mace = mp->mace;
1208fb6b090SJeff Kirsher u8 maccc = mace->maccc;
1218fb6b090SJeff Kirsher
1228fb6b090SJeff Kirsher mace->maccc = maccc & ~ENRCV;
1238fb6b090SJeff Kirsher
1248fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CTL, 0x8800);
1258fb6b090SJeff Kirsher mace_load_rxdma_base(dev, 0x00);
1268fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CTL, 0x0400);
1278fb6b090SJeff Kirsher
1288fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CTL, 0x8800);
1298fb6b090SJeff Kirsher mace_load_rxdma_base(dev, 0x10);
1308fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CTL, 0x0400);
1318fb6b090SJeff Kirsher
1328fb6b090SJeff Kirsher mace->maccc = maccc;
1338fb6b090SJeff Kirsher mp->rx_slot = 0;
1348fb6b090SJeff Kirsher
1358fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x9800);
1368fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x9800);
1378fb6b090SJeff Kirsher }
1388fb6b090SJeff Kirsher
1398fb6b090SJeff Kirsher /*
1408fb6b090SJeff Kirsher * Reset the transmit DMA subsystem
1418fb6b090SJeff Kirsher */
1428fb6b090SJeff Kirsher
mace_txdma_reset(struct net_device * dev)1438fb6b090SJeff Kirsher static void mace_txdma_reset(struct net_device *dev)
1448fb6b090SJeff Kirsher {
1458fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
1468fb6b090SJeff Kirsher volatile struct mace *mace = mp->mace;
1478fb6b090SJeff Kirsher u8 maccc;
1488fb6b090SJeff Kirsher
1498fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CTL, 0x8800);
1508fb6b090SJeff Kirsher
1518fb6b090SJeff Kirsher maccc = mace->maccc;
1528fb6b090SJeff Kirsher mace->maccc = maccc & ~ENXMT;
1538fb6b090SJeff Kirsher
1548fb6b090SJeff Kirsher mp->tx_slot = mp->tx_sloti = 0;
1558fb6b090SJeff Kirsher mp->tx_count = N_TX_RING;
1568fb6b090SJeff Kirsher
1578fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CTL, 0x0400);
1588fb6b090SJeff Kirsher mace->maccc = maccc;
1598fb6b090SJeff Kirsher }
1608fb6b090SJeff Kirsher
1618fb6b090SJeff Kirsher /*
1628fb6b090SJeff Kirsher * Disable DMA
1638fb6b090SJeff Kirsher */
1648fb6b090SJeff Kirsher
mace_dma_off(struct net_device * dev)1658fb6b090SJeff Kirsher static void mace_dma_off(struct net_device *dev)
1668fb6b090SJeff Kirsher {
1678fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CTL, 0x8800);
1688fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CTL, 0x1000);
1698fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x1100);
1708fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x1100);
1718fb6b090SJeff Kirsher
1728fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CTL, 0x8800);
1738fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CTL, 0x1000);
1748fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CMD + PSC_SET0, 0x1100);
1758fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CMD + PSC_SET1, 0x1100);
1768fb6b090SJeff Kirsher }
1778fb6b090SJeff Kirsher
1788fb6b090SJeff Kirsher static const struct net_device_ops mace_netdev_ops = {
1798fb6b090SJeff Kirsher .ndo_open = mace_open,
1808fb6b090SJeff Kirsher .ndo_stop = mace_close,
1818fb6b090SJeff Kirsher .ndo_start_xmit = mace_xmit_start,
1828fb6b090SJeff Kirsher .ndo_tx_timeout = mace_tx_timeout,
183afc4b13dSJiri Pirko .ndo_set_rx_mode = mace_set_multicast,
1848fb6b090SJeff Kirsher .ndo_set_mac_address = mace_set_address,
1858fb6b090SJeff Kirsher .ndo_validate_addr = eth_validate_addr,
1868fb6b090SJeff Kirsher };
1878fb6b090SJeff Kirsher
1888fb6b090SJeff Kirsher /*
1898fb6b090SJeff Kirsher * Not really much of a probe. The hardware table tells us if this
1908fb6b090SJeff Kirsher * model of Macintrash has a MACE (AV macintoshes)
1918fb6b090SJeff Kirsher */
1928fb6b090SJeff Kirsher
mace_probe(struct platform_device * pdev)19397c71ad4SBill Pemberton static int mace_probe(struct platform_device *pdev)
1948fb6b090SJeff Kirsher {
1958fb6b090SJeff Kirsher int j;
1968fb6b090SJeff Kirsher struct mace_data *mp;
1978fb6b090SJeff Kirsher unsigned char *addr;
1988fb6b090SJeff Kirsher struct net_device *dev;
1998fb6b090SJeff Kirsher unsigned char checksum = 0;
200e217fc4aSJakub Kicinski u8 macaddr[ETH_ALEN];
2018fb6b090SJeff Kirsher int err;
2028fb6b090SJeff Kirsher
2038fb6b090SJeff Kirsher dev = alloc_etherdev(PRIV_BYTES);
2048fb6b090SJeff Kirsher if (!dev)
2058fb6b090SJeff Kirsher return -ENOMEM;
2068fb6b090SJeff Kirsher
2078fb6b090SJeff Kirsher mp = netdev_priv(dev);
2088fb6b090SJeff Kirsher
2098fb6b090SJeff Kirsher mp->device = &pdev->dev;
21006a2feb9SWei Yongjun platform_set_drvdata(pdev, dev);
2118fb6b090SJeff Kirsher SET_NETDEV_DEV(dev, &pdev->dev);
2128fb6b090SJeff Kirsher
2138fb6b090SJeff Kirsher dev->base_addr = (u32)MACE_BASE;
2148fb6b090SJeff Kirsher mp->mace = MACE_BASE;
2158fb6b090SJeff Kirsher
2168fb6b090SJeff Kirsher dev->irq = IRQ_MAC_MACE;
2178fb6b090SJeff Kirsher mp->dma_intr = IRQ_MAC_MACE_DMA;
2188fb6b090SJeff Kirsher
2198fb6b090SJeff Kirsher mp->chipid = mp->mace->chipid_hi << 8 | mp->mace->chipid_lo;
2208fb6b090SJeff Kirsher
2218fb6b090SJeff Kirsher /*
2228fb6b090SJeff Kirsher * The PROM contains 8 bytes which total 0xFF when XOR'd
2238fb6b090SJeff Kirsher * together. Due to the usual peculiar apple brain damage
2248fb6b090SJeff Kirsher * the bytes are spaced out in a strange boundary and the
2258fb6b090SJeff Kirsher * bits are reversed.
2268fb6b090SJeff Kirsher */
2278fb6b090SJeff Kirsher
22864699336SJoe Perches addr = MACE_PROM;
2298fb6b090SJeff Kirsher
2308fb6b090SJeff Kirsher for (j = 0; j < 6; ++j) {
2318fb6b090SJeff Kirsher u8 v = bitrev8(addr[j<<4]);
2328fb6b090SJeff Kirsher checksum ^= v;
233e217fc4aSJakub Kicinski macaddr[j] = v;
2348fb6b090SJeff Kirsher }
235e217fc4aSJakub Kicinski eth_hw_addr_set(dev, macaddr);
2368fb6b090SJeff Kirsher for (; j < 8; ++j) {
2378fb6b090SJeff Kirsher checksum ^= bitrev8(addr[j<<4]);
2388fb6b090SJeff Kirsher }
2398fb6b090SJeff Kirsher
2408fb6b090SJeff Kirsher if (checksum != 0xFF) {
2418fb6b090SJeff Kirsher free_netdev(dev);
2428fb6b090SJeff Kirsher return -ENODEV;
2438fb6b090SJeff Kirsher }
2448fb6b090SJeff Kirsher
2458fb6b090SJeff Kirsher dev->netdev_ops = &mace_netdev_ops;
2468fb6b090SJeff Kirsher dev->watchdog_timeo = TX_TIMEOUT;
2478fb6b090SJeff Kirsher
24866e19689SFinn Thain pr_info("Onboard MACE, hardware address %pM, chip revision 0x%04X\n",
24966e19689SFinn Thain dev->dev_addr, mp->chipid);
2508fb6b090SJeff Kirsher
2518fb6b090SJeff Kirsher err = register_netdev(dev);
2528fb6b090SJeff Kirsher if (!err)
2538fb6b090SJeff Kirsher return 0;
2548fb6b090SJeff Kirsher
2558fb6b090SJeff Kirsher free_netdev(dev);
2568fb6b090SJeff Kirsher return err;
2578fb6b090SJeff Kirsher }
2588fb6b090SJeff Kirsher
2598fb6b090SJeff Kirsher /*
2608fb6b090SJeff Kirsher * Reset the chip.
2618fb6b090SJeff Kirsher */
2628fb6b090SJeff Kirsher
mace_reset(struct net_device * dev)2638fb6b090SJeff Kirsher static void mace_reset(struct net_device *dev)
2648fb6b090SJeff Kirsher {
2658fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
2668fb6b090SJeff Kirsher volatile struct mace *mb = mp->mace;
2678fb6b090SJeff Kirsher int i;
2688fb6b090SJeff Kirsher
2698fb6b090SJeff Kirsher /* soft-reset the chip */
2708fb6b090SJeff Kirsher i = 200;
2718fb6b090SJeff Kirsher while (--i) {
2728fb6b090SJeff Kirsher mb->biucc = SWRST;
2738fb6b090SJeff Kirsher if (mb->biucc & SWRST) {
2748fb6b090SJeff Kirsher udelay(10);
2758fb6b090SJeff Kirsher continue;
2768fb6b090SJeff Kirsher }
2778fb6b090SJeff Kirsher break;
2788fb6b090SJeff Kirsher }
2798fb6b090SJeff Kirsher if (!i) {
2808fb6b090SJeff Kirsher printk(KERN_ERR "macmace: cannot reset chip!\n");
2818fb6b090SJeff Kirsher return;
2828fb6b090SJeff Kirsher }
2838fb6b090SJeff Kirsher
2848fb6b090SJeff Kirsher mb->maccc = 0; /* turn off tx, rx */
2858fb6b090SJeff Kirsher mb->imr = 0xFF; /* disable all intrs for now */
2868fb6b090SJeff Kirsher i = mb->ir;
2878fb6b090SJeff Kirsher
2888fb6b090SJeff Kirsher mb->biucc = XMTSP_64;
2898fb6b090SJeff Kirsher mb->utr = RTRD;
2908fb6b090SJeff Kirsher mb->fifocc = XMTFW_8 | RCVFW_64 | XMTFWU | RCVFWU;
2918fb6b090SJeff Kirsher
2928fb6b090SJeff Kirsher mb->xmtfc = AUTO_PAD_XMIT; /* auto-pad short frames */
2938fb6b090SJeff Kirsher mb->rcvfc = 0;
2948fb6b090SJeff Kirsher
2958fb6b090SJeff Kirsher /* load up the hardware address */
2968fb6b090SJeff Kirsher __mace_set_address(dev, dev->dev_addr);
2978fb6b090SJeff Kirsher
2988fb6b090SJeff Kirsher /* clear the multicast filter */
2998fb6b090SJeff Kirsher if (mp->chipid == BROKEN_ADDRCHG_REV)
3008fb6b090SJeff Kirsher mb->iac = LOGADDR;
3018fb6b090SJeff Kirsher else {
3028fb6b090SJeff Kirsher mb->iac = ADDRCHG | LOGADDR;
3038fb6b090SJeff Kirsher while ((mb->iac & ADDRCHG) != 0)
3048fb6b090SJeff Kirsher ;
3058fb6b090SJeff Kirsher }
3068fb6b090SJeff Kirsher for (i = 0; i < 8; ++i)
3078fb6b090SJeff Kirsher mb->ladrf = 0;
3088fb6b090SJeff Kirsher
3098fb6b090SJeff Kirsher /* done changing address */
3108fb6b090SJeff Kirsher if (mp->chipid != BROKEN_ADDRCHG_REV)
3118fb6b090SJeff Kirsher mb->iac = 0;
3128fb6b090SJeff Kirsher
3138fb6b090SJeff Kirsher mb->plscc = PORTSEL_AUI;
3148fb6b090SJeff Kirsher }
3158fb6b090SJeff Kirsher
3168fb6b090SJeff Kirsher /*
3178fb6b090SJeff Kirsher * Load the address on a mace controller.
3188fb6b090SJeff Kirsher */
3198fb6b090SJeff Kirsher
__mace_set_address(struct net_device * dev,const void * addr)320e217fc4aSJakub Kicinski static void __mace_set_address(struct net_device *dev, const void *addr)
3218fb6b090SJeff Kirsher {
3228fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
3238fb6b090SJeff Kirsher volatile struct mace *mb = mp->mace;
324e217fc4aSJakub Kicinski const unsigned char *p = addr;
325e217fc4aSJakub Kicinski u8 macaddr[ETH_ALEN];
3268fb6b090SJeff Kirsher int i;
3278fb6b090SJeff Kirsher
3288fb6b090SJeff Kirsher /* load up the hardware address */
3298fb6b090SJeff Kirsher if (mp->chipid == BROKEN_ADDRCHG_REV)
3308fb6b090SJeff Kirsher mb->iac = PHYADDR;
3318fb6b090SJeff Kirsher else {
3328fb6b090SJeff Kirsher mb->iac = ADDRCHG | PHYADDR;
3338fb6b090SJeff Kirsher while ((mb->iac & ADDRCHG) != 0)
3348fb6b090SJeff Kirsher ;
3358fb6b090SJeff Kirsher }
3368fb6b090SJeff Kirsher for (i = 0; i < 6; ++i)
337e217fc4aSJakub Kicinski mb->padr = macaddr[i] = p[i];
338e217fc4aSJakub Kicinski eth_hw_addr_set(dev, macaddr);
3398fb6b090SJeff Kirsher if (mp->chipid != BROKEN_ADDRCHG_REV)
3408fb6b090SJeff Kirsher mb->iac = 0;
3418fb6b090SJeff Kirsher }
3428fb6b090SJeff Kirsher
mace_set_address(struct net_device * dev,void * addr)3438fb6b090SJeff Kirsher static int mace_set_address(struct net_device *dev, void *addr)
3448fb6b090SJeff Kirsher {
3458fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
3468fb6b090SJeff Kirsher volatile struct mace *mb = mp->mace;
3478fb6b090SJeff Kirsher unsigned long flags;
3488fb6b090SJeff Kirsher u8 maccc;
3498fb6b090SJeff Kirsher
3508fb6b090SJeff Kirsher local_irq_save(flags);
3518fb6b090SJeff Kirsher
3528fb6b090SJeff Kirsher maccc = mb->maccc;
3538fb6b090SJeff Kirsher
3548fb6b090SJeff Kirsher __mace_set_address(dev, addr);
3558fb6b090SJeff Kirsher
3568fb6b090SJeff Kirsher mb->maccc = maccc;
3578fb6b090SJeff Kirsher
3588fb6b090SJeff Kirsher local_irq_restore(flags);
3598fb6b090SJeff Kirsher
3608fb6b090SJeff Kirsher return 0;
3618fb6b090SJeff Kirsher }
3628fb6b090SJeff Kirsher
3638fb6b090SJeff Kirsher /*
3648fb6b090SJeff Kirsher * Open the Macintosh MACE. Most of this is playing with the DMA
3658fb6b090SJeff Kirsher * engine. The ethernet chip is quite friendly.
3668fb6b090SJeff Kirsher */
3678fb6b090SJeff Kirsher
mace_open(struct net_device * dev)3688fb6b090SJeff Kirsher static int mace_open(struct net_device *dev)
3698fb6b090SJeff Kirsher {
3708fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
3718fb6b090SJeff Kirsher volatile struct mace *mb = mp->mace;
3728fb6b090SJeff Kirsher
3738fb6b090SJeff Kirsher /* reset the chip */
3748fb6b090SJeff Kirsher mace_reset(dev);
3758fb6b090SJeff Kirsher
3768fb6b090SJeff Kirsher if (request_irq(dev->irq, mace_interrupt, 0, dev->name, dev)) {
3778fb6b090SJeff Kirsher printk(KERN_ERR "%s: can't get irq %d\n", dev->name, dev->irq);
3788fb6b090SJeff Kirsher return -EAGAIN;
3798fb6b090SJeff Kirsher }
3808fb6b090SJeff Kirsher if (request_irq(mp->dma_intr, mace_dma_intr, 0, dev->name, dev)) {
3818fb6b090SJeff Kirsher printk(KERN_ERR "%s: can't get irq %d\n", dev->name, mp->dma_intr);
3828fb6b090SJeff Kirsher free_irq(dev->irq, dev);
3838fb6b090SJeff Kirsher return -EAGAIN;
3848fb6b090SJeff Kirsher }
3858fb6b090SJeff Kirsher
3868fb6b090SJeff Kirsher /* Allocate the DMA ring buffers */
3878fb6b090SJeff Kirsher
3888fb6b090SJeff Kirsher mp->tx_ring = dma_alloc_coherent(mp->device,
3898fb6b090SJeff Kirsher N_TX_RING * MACE_BUFF_SIZE,
3908fb6b090SJeff Kirsher &mp->tx_ring_phys, GFP_KERNEL);
391d0320f75SJoe Perches if (mp->tx_ring == NULL)
3928fb6b090SJeff Kirsher goto out1;
3938fb6b090SJeff Kirsher
3948fb6b090SJeff Kirsher mp->rx_ring = dma_alloc_coherent(mp->device,
3958fb6b090SJeff Kirsher N_RX_RING * MACE_BUFF_SIZE,
3968fb6b090SJeff Kirsher &mp->rx_ring_phys, GFP_KERNEL);
397d0320f75SJoe Perches if (mp->rx_ring == NULL)
3988fb6b090SJeff Kirsher goto out2;
3998fb6b090SJeff Kirsher
4008fb6b090SJeff Kirsher mace_dma_off(dev);
4018fb6b090SJeff Kirsher
4028fb6b090SJeff Kirsher /* Not sure what these do */
4038fb6b090SJeff Kirsher
4048fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CTL, 0x9000);
4058fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CTL, 0x9000);
4068fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CTL, 0x0400);
4078fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CTL, 0x0400);
4088fb6b090SJeff Kirsher
4098fb6b090SJeff Kirsher mace_rxdma_reset(dev);
4108fb6b090SJeff Kirsher mace_txdma_reset(dev);
4118fb6b090SJeff Kirsher
4128fb6b090SJeff Kirsher /* turn it on! */
4138fb6b090SJeff Kirsher mb->maccc = ENXMT | ENRCV;
4148fb6b090SJeff Kirsher /* enable all interrupts except receive interrupts */
4158fb6b090SJeff Kirsher mb->imr = RCVINT;
4168fb6b090SJeff Kirsher return 0;
4178fb6b090SJeff Kirsher
4188fb6b090SJeff Kirsher out2:
4198fb6b090SJeff Kirsher dma_free_coherent(mp->device, N_TX_RING * MACE_BUFF_SIZE,
4208fb6b090SJeff Kirsher mp->tx_ring, mp->tx_ring_phys);
4218fb6b090SJeff Kirsher out1:
4228fb6b090SJeff Kirsher free_irq(dev->irq, dev);
4238fb6b090SJeff Kirsher free_irq(mp->dma_intr, dev);
4248fb6b090SJeff Kirsher return -ENOMEM;
4258fb6b090SJeff Kirsher }
4268fb6b090SJeff Kirsher
4278fb6b090SJeff Kirsher /*
4288fb6b090SJeff Kirsher * Shut down the mace and its interrupt channel
4298fb6b090SJeff Kirsher */
4308fb6b090SJeff Kirsher
mace_close(struct net_device * dev)4318fb6b090SJeff Kirsher static int mace_close(struct net_device *dev)
4328fb6b090SJeff Kirsher {
4338fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
4348fb6b090SJeff Kirsher volatile struct mace *mb = mp->mace;
4358fb6b090SJeff Kirsher
4368fb6b090SJeff Kirsher mb->maccc = 0; /* disable rx and tx */
4378fb6b090SJeff Kirsher mb->imr = 0xFF; /* disable all irqs */
4388fb6b090SJeff Kirsher mace_dma_off(dev); /* disable rx and tx dma */
4398fb6b090SJeff Kirsher
4408fb6b090SJeff Kirsher return 0;
4418fb6b090SJeff Kirsher }
4428fb6b090SJeff Kirsher
4438fb6b090SJeff Kirsher /*
4448fb6b090SJeff Kirsher * Transmit a frame
4458fb6b090SJeff Kirsher */
4468fb6b090SJeff Kirsher
mace_xmit_start(struct sk_buff * skb,struct net_device * dev)447e6ce3822SYueHaibing static netdev_tx_t mace_xmit_start(struct sk_buff *skb, struct net_device *dev)
4488fb6b090SJeff Kirsher {
4498fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
4508fb6b090SJeff Kirsher unsigned long flags;
4518fb6b090SJeff Kirsher
4528fb6b090SJeff Kirsher /* Stop the queue since there's only the one buffer */
4538fb6b090SJeff Kirsher
4548fb6b090SJeff Kirsher local_irq_save(flags);
4558fb6b090SJeff Kirsher netif_stop_queue(dev);
4568fb6b090SJeff Kirsher if (!mp->tx_count) {
4578fb6b090SJeff Kirsher printk(KERN_ERR "macmace: tx queue running but no free buffers.\n");
4588fb6b090SJeff Kirsher local_irq_restore(flags);
4598fb6b090SJeff Kirsher return NETDEV_TX_BUSY;
4608fb6b090SJeff Kirsher }
4618fb6b090SJeff Kirsher mp->tx_count--;
4628fb6b090SJeff Kirsher local_irq_restore(flags);
4638fb6b090SJeff Kirsher
4648fb6b090SJeff Kirsher dev->stats.tx_packets++;
4658fb6b090SJeff Kirsher dev->stats.tx_bytes += skb->len;
4668fb6b090SJeff Kirsher
4678fb6b090SJeff Kirsher /* We need to copy into our xmit buffer to take care of alignment and caching issues */
4688fb6b090SJeff Kirsher skb_copy_from_linear_data(skb, mp->tx_ring, skb->len);
4698fb6b090SJeff Kirsher
4708fb6b090SJeff Kirsher /* load the Tx DMA and fire it off */
4718fb6b090SJeff Kirsher
4728fb6b090SJeff Kirsher psc_write_long(PSC_ENETWR_ADDR + mp->tx_slot, (u32) mp->tx_ring_phys);
4738fb6b090SJeff Kirsher psc_write_long(PSC_ENETWR_LEN + mp->tx_slot, skb->len);
4748fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CMD + mp->tx_slot, 0x9800);
4758fb6b090SJeff Kirsher
4768fb6b090SJeff Kirsher mp->tx_slot ^= 0x10;
4778fb6b090SJeff Kirsher
4788fb6b090SJeff Kirsher dev_kfree_skb(skb);
4798fb6b090SJeff Kirsher
4808fb6b090SJeff Kirsher return NETDEV_TX_OK;
4818fb6b090SJeff Kirsher }
4828fb6b090SJeff Kirsher
mace_set_multicast(struct net_device * dev)4838fb6b090SJeff Kirsher static void mace_set_multicast(struct net_device *dev)
4848fb6b090SJeff Kirsher {
4858fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
4868fb6b090SJeff Kirsher volatile struct mace *mb = mp->mace;
4878fb6b090SJeff Kirsher int i;
4888fb6b090SJeff Kirsher u32 crc;
4898fb6b090SJeff Kirsher u8 maccc;
4908fb6b090SJeff Kirsher unsigned long flags;
4918fb6b090SJeff Kirsher
4928fb6b090SJeff Kirsher local_irq_save(flags);
4938fb6b090SJeff Kirsher maccc = mb->maccc;
4948fb6b090SJeff Kirsher mb->maccc &= ~PROM;
4958fb6b090SJeff Kirsher
4968fb6b090SJeff Kirsher if (dev->flags & IFF_PROMISC) {
4978fb6b090SJeff Kirsher mb->maccc |= PROM;
4988fb6b090SJeff Kirsher } else {
4998fb6b090SJeff Kirsher unsigned char multicast_filter[8];
5008fb6b090SJeff Kirsher struct netdev_hw_addr *ha;
5018fb6b090SJeff Kirsher
5028fb6b090SJeff Kirsher if (dev->flags & IFF_ALLMULTI) {
5038fb6b090SJeff Kirsher for (i = 0; i < 8; i++) {
5048fb6b090SJeff Kirsher multicast_filter[i] = 0xFF;
5058fb6b090SJeff Kirsher }
5068fb6b090SJeff Kirsher } else {
5078fb6b090SJeff Kirsher for (i = 0; i < 8; i++)
5088fb6b090SJeff Kirsher multicast_filter[i] = 0;
5098fb6b090SJeff Kirsher netdev_for_each_mc_addr(ha, dev) {
5108fb6b090SJeff Kirsher crc = ether_crc_le(6, ha->addr);
5118fb6b090SJeff Kirsher /* bit number in multicast_filter */
5128fb6b090SJeff Kirsher i = crc >> 26;
5138fb6b090SJeff Kirsher multicast_filter[i >> 3] |= 1 << (i & 7);
5148fb6b090SJeff Kirsher }
5158fb6b090SJeff Kirsher }
5168fb6b090SJeff Kirsher
5178fb6b090SJeff Kirsher if (mp->chipid == BROKEN_ADDRCHG_REV)
5188fb6b090SJeff Kirsher mb->iac = LOGADDR;
5198fb6b090SJeff Kirsher else {
5208fb6b090SJeff Kirsher mb->iac = ADDRCHG | LOGADDR;
5218fb6b090SJeff Kirsher while ((mb->iac & ADDRCHG) != 0)
5228fb6b090SJeff Kirsher ;
5238fb6b090SJeff Kirsher }
5248fb6b090SJeff Kirsher for (i = 0; i < 8; ++i)
5258fb6b090SJeff Kirsher mb->ladrf = multicast_filter[i];
5268fb6b090SJeff Kirsher if (mp->chipid != BROKEN_ADDRCHG_REV)
5278fb6b090SJeff Kirsher mb->iac = 0;
5288fb6b090SJeff Kirsher }
5298fb6b090SJeff Kirsher
5308fb6b090SJeff Kirsher mb->maccc = maccc;
5318fb6b090SJeff Kirsher local_irq_restore(flags);
5328fb6b090SJeff Kirsher }
5338fb6b090SJeff Kirsher
mace_handle_misc_intrs(struct net_device * dev,int intr)5348fb6b090SJeff Kirsher static void mace_handle_misc_intrs(struct net_device *dev, int intr)
5358fb6b090SJeff Kirsher {
5368fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
5378fb6b090SJeff Kirsher volatile struct mace *mb = mp->mace;
5388fb6b090SJeff Kirsher static int mace_babbles, mace_jabbers;
5398fb6b090SJeff Kirsher
5408fb6b090SJeff Kirsher if (intr & MPCO)
5418fb6b090SJeff Kirsher dev->stats.rx_missed_errors += 256;
5428fb6b090SJeff Kirsher dev->stats.rx_missed_errors += mb->mpc; /* reading clears it */
5438fb6b090SJeff Kirsher if (intr & RNTPCO)
5448fb6b090SJeff Kirsher dev->stats.rx_length_errors += 256;
5458fb6b090SJeff Kirsher dev->stats.rx_length_errors += mb->rntpc; /* reading clears it */
5468fb6b090SJeff Kirsher if (intr & CERR)
5478fb6b090SJeff Kirsher ++dev->stats.tx_heartbeat_errors;
5488fb6b090SJeff Kirsher if (intr & BABBLE)
5498fb6b090SJeff Kirsher if (mace_babbles++ < 4)
5508fb6b090SJeff Kirsher printk(KERN_DEBUG "macmace: babbling transmitter\n");
5518fb6b090SJeff Kirsher if (intr & JABBER)
5528fb6b090SJeff Kirsher if (mace_jabbers++ < 4)
5538fb6b090SJeff Kirsher printk(KERN_DEBUG "macmace: jabbering transceiver\n");
5548fb6b090SJeff Kirsher }
5558fb6b090SJeff Kirsher
mace_interrupt(int irq,void * dev_id)5568fb6b090SJeff Kirsher static irqreturn_t mace_interrupt(int irq, void *dev_id)
5578fb6b090SJeff Kirsher {
5588fb6b090SJeff Kirsher struct net_device *dev = (struct net_device *) dev_id;
5598fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
5608fb6b090SJeff Kirsher volatile struct mace *mb = mp->mace;
5618fb6b090SJeff Kirsher int intr, fs;
5628fb6b090SJeff Kirsher unsigned long flags;
5638fb6b090SJeff Kirsher
5648fb6b090SJeff Kirsher /* don't want the dma interrupt handler to fire */
5658fb6b090SJeff Kirsher local_irq_save(flags);
5668fb6b090SJeff Kirsher
5678fb6b090SJeff Kirsher intr = mb->ir; /* read interrupt register */
5688fb6b090SJeff Kirsher mace_handle_misc_intrs(dev, intr);
5698fb6b090SJeff Kirsher
5708fb6b090SJeff Kirsher if (intr & XMTINT) {
5718fb6b090SJeff Kirsher fs = mb->xmtfs;
5728fb6b090SJeff Kirsher if ((fs & XMTSV) == 0) {
5738fb6b090SJeff Kirsher printk(KERN_ERR "macmace: xmtfs not valid! (fs=%x)\n", fs);
5748fb6b090SJeff Kirsher mace_reset(dev);
5758fb6b090SJeff Kirsher /*
5768fb6b090SJeff Kirsher * XXX mace likes to hang the machine after a xmtfs error.
577dbedd44eSJoe Perches * This is hard to reproduce, resetting *may* help
5788fb6b090SJeff Kirsher */
5798fb6b090SJeff Kirsher }
5808fb6b090SJeff Kirsher /* dma should have finished */
5818fb6b090SJeff Kirsher if (!mp->tx_count) {
5828fb6b090SJeff Kirsher printk(KERN_DEBUG "macmace: tx ring ran out? (fs=%x)\n", fs);
5838fb6b090SJeff Kirsher }
5848fb6b090SJeff Kirsher /* Update stats */
5858fb6b090SJeff Kirsher if (fs & (UFLO|LCOL|LCAR|RTRY)) {
5868fb6b090SJeff Kirsher ++dev->stats.tx_errors;
5878fb6b090SJeff Kirsher if (fs & LCAR)
5888fb6b090SJeff Kirsher ++dev->stats.tx_carrier_errors;
5898fb6b090SJeff Kirsher else if (fs & (UFLO|LCOL|RTRY)) {
5908fb6b090SJeff Kirsher ++dev->stats.tx_aborted_errors;
5918fb6b090SJeff Kirsher if (mb->xmtfs & UFLO) {
5928fb6b090SJeff Kirsher dev->stats.tx_fifo_errors++;
5938fb6b090SJeff Kirsher mace_txdma_reset(dev);
5948fb6b090SJeff Kirsher }
5958fb6b090SJeff Kirsher }
5968fb6b090SJeff Kirsher }
5978fb6b090SJeff Kirsher }
5988fb6b090SJeff Kirsher
5998fb6b090SJeff Kirsher if (mp->tx_count)
6008fb6b090SJeff Kirsher netif_wake_queue(dev);
6018fb6b090SJeff Kirsher
6028fb6b090SJeff Kirsher local_irq_restore(flags);
6038fb6b090SJeff Kirsher
6048fb6b090SJeff Kirsher return IRQ_HANDLED;
6058fb6b090SJeff Kirsher }
6068fb6b090SJeff Kirsher
mace_tx_timeout(struct net_device * dev,unsigned int txqueue)6070290bd29SMichael S. Tsirkin static void mace_tx_timeout(struct net_device *dev, unsigned int txqueue)
6088fb6b090SJeff Kirsher {
6098fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
6108fb6b090SJeff Kirsher volatile struct mace *mb = mp->mace;
6118fb6b090SJeff Kirsher unsigned long flags;
6128fb6b090SJeff Kirsher
6138fb6b090SJeff Kirsher local_irq_save(flags);
6148fb6b090SJeff Kirsher
6158fb6b090SJeff Kirsher /* turn off both tx and rx and reset the chip */
6168fb6b090SJeff Kirsher mb->maccc = 0;
6178fb6b090SJeff Kirsher printk(KERN_ERR "macmace: transmit timeout - resetting\n");
6188fb6b090SJeff Kirsher mace_txdma_reset(dev);
6198fb6b090SJeff Kirsher mace_reset(dev);
6208fb6b090SJeff Kirsher
6218fb6b090SJeff Kirsher /* restart rx dma */
6228fb6b090SJeff Kirsher mace_rxdma_reset(dev);
6238fb6b090SJeff Kirsher
6248fb6b090SJeff Kirsher mp->tx_count = N_TX_RING;
6258fb6b090SJeff Kirsher netif_wake_queue(dev);
6268fb6b090SJeff Kirsher
6278fb6b090SJeff Kirsher /* turn it on! */
6288fb6b090SJeff Kirsher mb->maccc = ENXMT | ENRCV;
6298fb6b090SJeff Kirsher /* enable all interrupts except receive interrupts */
6308fb6b090SJeff Kirsher mb->imr = RCVINT;
6318fb6b090SJeff Kirsher
6328fb6b090SJeff Kirsher local_irq_restore(flags);
6338fb6b090SJeff Kirsher }
6348fb6b090SJeff Kirsher
6358fb6b090SJeff Kirsher /*
6368fb6b090SJeff Kirsher * Handle a newly arrived frame
6378fb6b090SJeff Kirsher */
6388fb6b090SJeff Kirsher
mace_dma_rx_frame(struct net_device * dev,struct mace_frame * mf)6398fb6b090SJeff Kirsher static void mace_dma_rx_frame(struct net_device *dev, struct mace_frame *mf)
6408fb6b090SJeff Kirsher {
6418fb6b090SJeff Kirsher struct sk_buff *skb;
6428fb6b090SJeff Kirsher unsigned int frame_status = mf->rcvsts;
6438fb6b090SJeff Kirsher
6448fb6b090SJeff Kirsher if (frame_status & (RS_OFLO | RS_CLSN | RS_FRAMERR | RS_FCSERR)) {
6458fb6b090SJeff Kirsher dev->stats.rx_errors++;
64666e19689SFinn Thain if (frame_status & RS_OFLO)
6478fb6b090SJeff Kirsher dev->stats.rx_fifo_errors++;
6488fb6b090SJeff Kirsher if (frame_status & RS_CLSN)
6498fb6b090SJeff Kirsher dev->stats.collisions++;
6508fb6b090SJeff Kirsher if (frame_status & RS_FRAMERR)
6518fb6b090SJeff Kirsher dev->stats.rx_frame_errors++;
6528fb6b090SJeff Kirsher if (frame_status & RS_FCSERR)
6538fb6b090SJeff Kirsher dev->stats.rx_crc_errors++;
6548fb6b090SJeff Kirsher } else {
6558fb6b090SJeff Kirsher unsigned int frame_length = mf->rcvcnt + ((frame_status & 0x0F) << 8 );
6568fb6b090SJeff Kirsher
6571d266430SPradeep A Dalvi skb = netdev_alloc_skb(dev, frame_length + 2);
6588fb6b090SJeff Kirsher if (!skb) {
6598fb6b090SJeff Kirsher dev->stats.rx_dropped++;
6608fb6b090SJeff Kirsher return;
6618fb6b090SJeff Kirsher }
6628fb6b090SJeff Kirsher skb_reserve(skb, 2);
66359ae1d12SJohannes Berg skb_put_data(skb, mf->data, frame_length);
6648fb6b090SJeff Kirsher
6658fb6b090SJeff Kirsher skb->protocol = eth_type_trans(skb, dev);
6668fb6b090SJeff Kirsher netif_rx(skb);
6678fb6b090SJeff Kirsher dev->stats.rx_packets++;
6688fb6b090SJeff Kirsher dev->stats.rx_bytes += frame_length;
6698fb6b090SJeff Kirsher }
6708fb6b090SJeff Kirsher }
6718fb6b090SJeff Kirsher
6728fb6b090SJeff Kirsher /*
6738fb6b090SJeff Kirsher * The PSC has passed us a DMA interrupt event.
6748fb6b090SJeff Kirsher */
6758fb6b090SJeff Kirsher
mace_dma_intr(int irq,void * dev_id)6768fb6b090SJeff Kirsher static irqreturn_t mace_dma_intr(int irq, void *dev_id)
6778fb6b090SJeff Kirsher {
6788fb6b090SJeff Kirsher struct net_device *dev = (struct net_device *) dev_id;
6798fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
6808fb6b090SJeff Kirsher int left, head;
6818fb6b090SJeff Kirsher u16 status;
6828fb6b090SJeff Kirsher u32 baka;
6838fb6b090SJeff Kirsher
6848fb6b090SJeff Kirsher /* Not sure what this does */
6858fb6b090SJeff Kirsher
6868fb6b090SJeff Kirsher while ((baka = psc_read_long(PSC_MYSTERY)) != psc_read_long(PSC_MYSTERY));
6878fb6b090SJeff Kirsher if (!(baka & 0x60000000)) return IRQ_NONE;
6888fb6b090SJeff Kirsher
6898fb6b090SJeff Kirsher /*
6908fb6b090SJeff Kirsher * Process the read queue
6918fb6b090SJeff Kirsher */
6928fb6b090SJeff Kirsher
6938fb6b090SJeff Kirsher status = psc_read_word(PSC_ENETRD_CTL);
6948fb6b090SJeff Kirsher
6958fb6b090SJeff Kirsher if (status & 0x2000) {
6968fb6b090SJeff Kirsher mace_rxdma_reset(dev);
6978fb6b090SJeff Kirsher } else if (status & 0x0100) {
6988fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x1100);
6998fb6b090SJeff Kirsher
7008fb6b090SJeff Kirsher left = psc_read_long(PSC_ENETRD_LEN + mp->rx_slot);
7018fb6b090SJeff Kirsher head = N_RX_RING - left;
7028fb6b090SJeff Kirsher
7038fb6b090SJeff Kirsher /* Loop through the ring buffer and process new packages */
7048fb6b090SJeff Kirsher
7058fb6b090SJeff Kirsher while (mp->rx_tail < head) {
7068fb6b090SJeff Kirsher mace_dma_rx_frame(dev, (struct mace_frame*) (mp->rx_ring
7078fb6b090SJeff Kirsher + (mp->rx_tail * MACE_BUFF_SIZE)));
7088fb6b090SJeff Kirsher mp->rx_tail++;
7098fb6b090SJeff Kirsher }
7108fb6b090SJeff Kirsher
7118fb6b090SJeff Kirsher /* If we're out of buffers in this ring then switch to */
7128fb6b090SJeff Kirsher /* the other set, otherwise just reactivate this one. */
7138fb6b090SJeff Kirsher
7148fb6b090SJeff Kirsher if (!left) {
7158fb6b090SJeff Kirsher mace_load_rxdma_base(dev, mp->rx_slot);
7168fb6b090SJeff Kirsher mp->rx_slot ^= 0x10;
7178fb6b090SJeff Kirsher } else {
7188fb6b090SJeff Kirsher psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x9800);
7198fb6b090SJeff Kirsher }
7208fb6b090SJeff Kirsher }
7218fb6b090SJeff Kirsher
7228fb6b090SJeff Kirsher /*
7238fb6b090SJeff Kirsher * Process the write queue
7248fb6b090SJeff Kirsher */
7258fb6b090SJeff Kirsher
7268fb6b090SJeff Kirsher status = psc_read_word(PSC_ENETWR_CTL);
7278fb6b090SJeff Kirsher
7288fb6b090SJeff Kirsher if (status & 0x2000) {
7298fb6b090SJeff Kirsher mace_txdma_reset(dev);
7308fb6b090SJeff Kirsher } else if (status & 0x0100) {
7318fb6b090SJeff Kirsher psc_write_word(PSC_ENETWR_CMD + mp->tx_sloti, 0x0100);
7328fb6b090SJeff Kirsher mp->tx_sloti ^= 0x10;
7338fb6b090SJeff Kirsher mp->tx_count++;
7348fb6b090SJeff Kirsher }
7358fb6b090SJeff Kirsher return IRQ_HANDLED;
7368fb6b090SJeff Kirsher }
7378fb6b090SJeff Kirsher
7388fb6b090SJeff Kirsher MODULE_LICENSE("GPL");
7398fb6b090SJeff Kirsher MODULE_DESCRIPTION("Macintosh MACE ethernet driver");
7408fb6b090SJeff Kirsher MODULE_ALIAS("platform:macmace");
7418fb6b090SJeff Kirsher
mac_mace_device_remove(struct platform_device * pdev)74297c71ad4SBill Pemberton static int mac_mace_device_remove(struct platform_device *pdev)
7438fb6b090SJeff Kirsher {
7448fb6b090SJeff Kirsher struct net_device *dev = platform_get_drvdata(pdev);
7458fb6b090SJeff Kirsher struct mace_data *mp = netdev_priv(dev);
7468fb6b090SJeff Kirsher
7478fb6b090SJeff Kirsher unregister_netdev(dev);
7488fb6b090SJeff Kirsher
7498fb6b090SJeff Kirsher free_irq(dev->irq, dev);
7508fb6b090SJeff Kirsher free_irq(IRQ_MAC_MACE_DMA, dev);
7518fb6b090SJeff Kirsher
7528fb6b090SJeff Kirsher dma_free_coherent(mp->device, N_RX_RING * MACE_BUFF_SIZE,
7538fb6b090SJeff Kirsher mp->rx_ring, mp->rx_ring_phys);
7548fb6b090SJeff Kirsher dma_free_coherent(mp->device, N_TX_RING * MACE_BUFF_SIZE,
7558fb6b090SJeff Kirsher mp->tx_ring, mp->tx_ring_phys);
7568fb6b090SJeff Kirsher
7578fb6b090SJeff Kirsher free_netdev(dev);
7588fb6b090SJeff Kirsher
7598fb6b090SJeff Kirsher return 0;
7608fb6b090SJeff Kirsher }
7618fb6b090SJeff Kirsher
7628fb6b090SJeff Kirsher static struct platform_driver mac_mace_driver = {
7638fb6b090SJeff Kirsher .probe = mace_probe,
76497c71ad4SBill Pemberton .remove = mac_mace_device_remove,
7658fb6b090SJeff Kirsher .driver = {
7668fb6b090SJeff Kirsher .name = mac_mace_string,
7678fb6b090SJeff Kirsher },
7688fb6b090SJeff Kirsher };
7698fb6b090SJeff Kirsher
7701e9b9a8bSFinn Thain module_platform_driver(mac_mace_driver);
771