| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 1 | /* sunqe.c: Sparc QuadEthernet 10baseT SBUS card driver. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 |  *          Once again I am out to prove that every ethernet | 
 | 3 |  *          controller out there can be most efficiently programmed | 
 | 4 |  *          if you make it look like a LANCE. | 
 | 5 |  * | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 6 |  * Copyright (C) 1996, 1999, 2003, 2006, 2008 David S. Miller (davem@davemloft.net) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 |  */ | 
 | 8 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/module.h> | 
 | 10 | #include <linux/kernel.h> | 
 | 11 | #include <linux/types.h> | 
 | 12 | #include <linux/errno.h> | 
 | 13 | #include <linux/fcntl.h> | 
 | 14 | #include <linux/interrupt.h> | 
 | 15 | #include <linux/ioport.h> | 
 | 16 | #include <linux/in.h> | 
 | 17 | #include <linux/slab.h> | 
 | 18 | #include <linux/string.h> | 
 | 19 | #include <linux/delay.h> | 
 | 20 | #include <linux/init.h> | 
 | 21 | #include <linux/crc32.h> | 
 | 22 | #include <linux/netdevice.h> | 
 | 23 | #include <linux/etherdevice.h> | 
 | 24 | #include <linux/skbuff.h> | 
 | 25 | #include <linux/ethtool.h> | 
 | 26 | #include <linux/bitops.h> | 
| David S. Miller | 738f2b7 | 2008-08-27 18:09:11 -0700 | [diff] [blame] | 27 | #include <linux/dma-mapping.h> | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 28 | #include <linux/of.h> | 
 | 29 | #include <linux/of_device.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 |  | 
 | 31 | #include <asm/system.h> | 
 | 32 | #include <asm/io.h> | 
 | 33 | #include <asm/dma.h> | 
 | 34 | #include <asm/byteorder.h> | 
 | 35 | #include <asm/idprom.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/openprom.h> | 
 | 37 | #include <asm/oplib.h> | 
 | 38 | #include <asm/auxio.h> | 
 | 39 | #include <asm/pgtable.h> | 
 | 40 | #include <asm/irq.h> | 
 | 41 |  | 
 | 42 | #include "sunqe.h" | 
 | 43 |  | 
| Tom 'spot' Callaway | 1015828 | 2005-04-24 20:35:20 -0700 | [diff] [blame] | 44 | #define DRV_NAME	"sunqe" | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 45 | #define DRV_VERSION	"4.1" | 
 | 46 | #define DRV_RELDATE	"August 27, 2008" | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 47 | #define DRV_AUTHOR	"David S. Miller (davem@davemloft.net)" | 
| Tom 'spot' Callaway | 1015828 | 2005-04-24 20:35:20 -0700 | [diff] [blame] | 48 |  | 
 | 49 | static char version[] = | 
 | 50 | 	DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " " DRV_AUTHOR "\n"; | 
 | 51 |  | 
 | 52 | MODULE_VERSION(DRV_VERSION); | 
 | 53 | MODULE_AUTHOR(DRV_AUTHOR); | 
 | 54 | MODULE_DESCRIPTION("Sun QuadEthernet 10baseT SBUS card driver"); | 
 | 55 | MODULE_LICENSE("GPL"); | 
 | 56 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | static struct sunqec *root_qec_dev; | 
 | 58 |  | 
 | 59 | static void qe_set_multicast(struct net_device *dev); | 
 | 60 |  | 
 | 61 | #define QEC_RESET_TRIES 200 | 
 | 62 |  | 
 | 63 | static inline int qec_global_reset(void __iomem *gregs) | 
 | 64 | { | 
 | 65 | 	int tries = QEC_RESET_TRIES; | 
 | 66 |  | 
 | 67 | 	sbus_writel(GLOB_CTRL_RESET, gregs + GLOB_CTRL); | 
 | 68 | 	while (--tries) { | 
 | 69 | 		u32 tmp = sbus_readl(gregs + GLOB_CTRL); | 
 | 70 | 		if (tmp & GLOB_CTRL_RESET) { | 
 | 71 | 			udelay(20); | 
 | 72 | 			continue; | 
 | 73 | 		} | 
 | 74 | 		break; | 
 | 75 | 	} | 
 | 76 | 	if (tries) | 
 | 77 | 		return 0; | 
 | 78 | 	printk(KERN_ERR "QuadEther: AIEEE cannot reset the QEC!\n"); | 
 | 79 | 	return -1; | 
 | 80 | } | 
 | 81 |  | 
 | 82 | #define MACE_RESET_RETRIES 200 | 
 | 83 | #define QE_RESET_RETRIES   200 | 
 | 84 |  | 
 | 85 | static inline int qe_stop(struct sunqe *qep) | 
 | 86 | { | 
 | 87 | 	void __iomem *cregs = qep->qcregs; | 
 | 88 | 	void __iomem *mregs = qep->mregs; | 
 | 89 | 	int tries; | 
 | 90 |  | 
 | 91 | 	/* Reset the MACE, then the QEC channel. */ | 
 | 92 | 	sbus_writeb(MREGS_BCONFIG_RESET, mregs + MREGS_BCONFIG); | 
 | 93 | 	tries = MACE_RESET_RETRIES; | 
 | 94 | 	while (--tries) { | 
 | 95 | 		u8 tmp = sbus_readb(mregs + MREGS_BCONFIG); | 
 | 96 | 		if (tmp & MREGS_BCONFIG_RESET) { | 
 | 97 | 			udelay(20); | 
 | 98 | 			continue; | 
 | 99 | 		} | 
 | 100 | 		break; | 
 | 101 | 	} | 
 | 102 | 	if (!tries) { | 
 | 103 | 		printk(KERN_ERR "QuadEther: AIEEE cannot reset the MACE!\n"); | 
 | 104 | 		return -1; | 
 | 105 | 	} | 
 | 106 |  | 
 | 107 | 	sbus_writel(CREG_CTRL_RESET, cregs + CREG_CTRL); | 
 | 108 | 	tries = QE_RESET_RETRIES; | 
 | 109 | 	while (--tries) { | 
 | 110 | 		u32 tmp = sbus_readl(cregs + CREG_CTRL); | 
 | 111 | 		if (tmp & CREG_CTRL_RESET) { | 
 | 112 | 			udelay(20); | 
 | 113 | 			continue; | 
 | 114 | 		} | 
 | 115 | 		break; | 
 | 116 | 	} | 
 | 117 | 	if (!tries) { | 
 | 118 | 		printk(KERN_ERR "QuadEther: Cannot reset QE channel!\n"); | 
 | 119 | 		return -1; | 
 | 120 | 	} | 
 | 121 | 	return 0; | 
 | 122 | } | 
 | 123 |  | 
 | 124 | static void qe_init_rings(struct sunqe *qep) | 
 | 125 | { | 
 | 126 | 	struct qe_init_block *qb = qep->qe_block; | 
 | 127 | 	struct sunqe_buffers *qbufs = qep->buffers; | 
 | 128 | 	__u32 qbufs_dvma = qep->buffers_dvma; | 
 | 129 | 	int i; | 
 | 130 |  | 
 | 131 | 	qep->rx_new = qep->rx_old = qep->tx_new = qep->tx_old = 0; | 
 | 132 | 	memset(qb, 0, sizeof(struct qe_init_block)); | 
 | 133 | 	memset(qbufs, 0, sizeof(struct sunqe_buffers)); | 
 | 134 | 	for (i = 0; i < RX_RING_SIZE; i++) { | 
 | 135 | 		qb->qe_rxd[i].rx_addr = qbufs_dvma + qebuf_offset(rx_buf, i); | 
 | 136 | 		qb->qe_rxd[i].rx_flags = | 
 | 137 | 			(RXD_OWN | ((RXD_PKT_SZ) & RXD_LENGTH)); | 
 | 138 | 	} | 
 | 139 | } | 
 | 140 |  | 
 | 141 | static int qe_init(struct sunqe *qep, int from_irq) | 
 | 142 | { | 
 | 143 | 	struct sunqec *qecp = qep->parent; | 
 | 144 | 	void __iomem *cregs = qep->qcregs; | 
 | 145 | 	void __iomem *mregs = qep->mregs; | 
 | 146 | 	void __iomem *gregs = qecp->gregs; | 
 | 147 | 	unsigned char *e = &qep->dev->dev_addr[0]; | 
 | 148 | 	u32 tmp; | 
 | 149 | 	int i; | 
 | 150 |  | 
 | 151 | 	/* Shut it up. */ | 
 | 152 | 	if (qe_stop(qep)) | 
 | 153 | 		return -EAGAIN; | 
 | 154 |  | 
 | 155 | 	/* Setup initial rx/tx init block pointers. */ | 
 | 156 | 	sbus_writel(qep->qblock_dvma + qib_offset(qe_rxd, 0), cregs + CREG_RXDS); | 
 | 157 | 	sbus_writel(qep->qblock_dvma + qib_offset(qe_txd, 0), cregs + CREG_TXDS); | 
 | 158 |  | 
 | 159 | 	/* Enable/mask the various irq's. */ | 
 | 160 | 	sbus_writel(0, cregs + CREG_RIMASK); | 
 | 161 | 	sbus_writel(1, cregs + CREG_TIMASK); | 
 | 162 |  | 
 | 163 | 	sbus_writel(0, cregs + CREG_QMASK); | 
 | 164 | 	sbus_writel(CREG_MMASK_RXCOLL, cregs + CREG_MMASK); | 
 | 165 |  | 
 | 166 | 	/* Setup the FIFO pointers into QEC local memory. */ | 
 | 167 | 	tmp = qep->channel * sbus_readl(gregs + GLOB_MSIZE); | 
 | 168 | 	sbus_writel(tmp, cregs + CREG_RXRBUFPTR); | 
 | 169 | 	sbus_writel(tmp, cregs + CREG_RXWBUFPTR); | 
 | 170 |  | 
 | 171 | 	tmp = sbus_readl(cregs + CREG_RXRBUFPTR) + | 
 | 172 | 		sbus_readl(gregs + GLOB_RSIZE); | 
 | 173 | 	sbus_writel(tmp, cregs + CREG_TXRBUFPTR); | 
 | 174 | 	sbus_writel(tmp, cregs + CREG_TXWBUFPTR); | 
 | 175 |  | 
 | 176 | 	/* Clear the channel collision counter. */ | 
 | 177 | 	sbus_writel(0, cregs + CREG_CCNT); | 
 | 178 |  | 
 | 179 | 	/* For 10baseT, inter frame space nor throttle seems to be necessary. */ | 
 | 180 | 	sbus_writel(0, cregs + CREG_PIPG); | 
 | 181 |  | 
 | 182 | 	/* Now dork with the AMD MACE. */ | 
 | 183 | 	sbus_writeb(MREGS_PHYCONFIG_AUTO, mregs + MREGS_PHYCONFIG); | 
 | 184 | 	sbus_writeb(MREGS_TXFCNTL_AUTOPAD, mregs + MREGS_TXFCNTL); | 
 | 185 | 	sbus_writeb(0, mregs + MREGS_RXFCNTL); | 
 | 186 |  | 
 | 187 | 	/* The QEC dma's the rx'd packets from local memory out to main memory, | 
 | 188 | 	 * and therefore it interrupts when the packet reception is "complete". | 
 | 189 | 	 * So don't listen for the MACE talking about it. | 
 | 190 | 	 */ | 
 | 191 | 	sbus_writeb(MREGS_IMASK_COLL | MREGS_IMASK_RXIRQ, mregs + MREGS_IMASK); | 
 | 192 | 	sbus_writeb(MREGS_BCONFIG_BSWAP | MREGS_BCONFIG_64TS, mregs + MREGS_BCONFIG); | 
 | 193 | 	sbus_writeb((MREGS_FCONFIG_TXF16 | MREGS_FCONFIG_RXF32 | | 
 | 194 | 		     MREGS_FCONFIG_RFWU | MREGS_FCONFIG_TFWU), | 
 | 195 | 		    mregs + MREGS_FCONFIG); | 
 | 196 |  | 
 | 197 | 	/* Only usable interface on QuadEther is twisted pair. */ | 
 | 198 | 	sbus_writeb(MREGS_PLSCONFIG_TP, mregs + MREGS_PLSCONFIG); | 
 | 199 |  | 
 | 200 | 	/* Tell MACE we are changing the ether address. */ | 
 | 201 | 	sbus_writeb(MREGS_IACONFIG_ACHNGE | MREGS_IACONFIG_PARESET, | 
 | 202 | 		    mregs + MREGS_IACONFIG); | 
 | 203 | 	while ((sbus_readb(mregs + MREGS_IACONFIG) & MREGS_IACONFIG_ACHNGE) != 0) | 
 | 204 | 		barrier(); | 
 | 205 | 	sbus_writeb(e[0], mregs + MREGS_ETHADDR); | 
 | 206 | 	sbus_writeb(e[1], mregs + MREGS_ETHADDR); | 
 | 207 | 	sbus_writeb(e[2], mregs + MREGS_ETHADDR); | 
 | 208 | 	sbus_writeb(e[3], mregs + MREGS_ETHADDR); | 
 | 209 | 	sbus_writeb(e[4], mregs + MREGS_ETHADDR); | 
 | 210 | 	sbus_writeb(e[5], mregs + MREGS_ETHADDR); | 
 | 211 |  | 
 | 212 | 	/* Clear out the address filter. */ | 
 | 213 | 	sbus_writeb(MREGS_IACONFIG_ACHNGE | MREGS_IACONFIG_LARESET, | 
 | 214 | 		    mregs + MREGS_IACONFIG); | 
 | 215 | 	while ((sbus_readb(mregs + MREGS_IACONFIG) & MREGS_IACONFIG_ACHNGE) != 0) | 
 | 216 | 		barrier(); | 
 | 217 | 	for (i = 0; i < 8; i++) | 
 | 218 | 		sbus_writeb(0, mregs + MREGS_FILTER); | 
 | 219 |  | 
 | 220 | 	/* Address changes are now complete. */ | 
 | 221 | 	sbus_writeb(0, mregs + MREGS_IACONFIG); | 
 | 222 |  | 
 | 223 | 	qe_init_rings(qep); | 
 | 224 |  | 
 | 225 | 	/* Wait a little bit for the link to come up... */ | 
 | 226 | 	mdelay(5); | 
 | 227 | 	if (!(sbus_readb(mregs + MREGS_PHYCONFIG) & MREGS_PHYCONFIG_LTESTDIS)) { | 
 | 228 | 		int tries = 50; | 
 | 229 |  | 
| Roel Kluin | 46578a69 | 2009-02-02 21:39:02 -0800 | [diff] [blame] | 230 | 		while (--tries) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | 			u8 tmp; | 
 | 232 |  | 
 | 233 | 			mdelay(5); | 
 | 234 | 			barrier(); | 
 | 235 | 			tmp = sbus_readb(mregs + MREGS_PHYCONFIG); | 
 | 236 | 			if ((tmp & MREGS_PHYCONFIG_LSTAT) != 0) | 
 | 237 | 				break; | 
 | 238 | 		} | 
 | 239 | 		if (tries == 0) | 
 | 240 | 			printk(KERN_NOTICE "%s: Warning, link state is down.\n", qep->dev->name); | 
 | 241 | 	} | 
 | 242 |  | 
 | 243 | 	/* Missed packet counter is cleared on a read. */ | 
 | 244 | 	sbus_readb(mregs + MREGS_MPCNT); | 
 | 245 |  | 
 | 246 | 	/* Reload multicast information, this will enable the receiver | 
 | 247 | 	 * and transmitter. | 
 | 248 | 	 */ | 
 | 249 | 	qe_set_multicast(qep->dev); | 
 | 250 |  | 
 | 251 | 	/* QEC should now start to show interrupts. */ | 
 | 252 | 	return 0; | 
 | 253 | } | 
 | 254 |  | 
 | 255 | /* Grrr, certain error conditions completely lock up the AMD MACE, | 
 | 256 |  * so when we get these we _must_ reset the chip. | 
 | 257 |  */ | 
 | 258 | static int qe_is_bolixed(struct sunqe *qep, u32 qe_status) | 
 | 259 | { | 
 | 260 | 	struct net_device *dev = qep->dev; | 
 | 261 | 	int mace_hwbug_workaround = 0; | 
 | 262 |  | 
 | 263 | 	if (qe_status & CREG_STAT_EDEFER) { | 
 | 264 | 		printk(KERN_ERR "%s: Excessive transmit defers.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 265 | 		dev->stats.tx_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | 	} | 
 | 267 |  | 
 | 268 | 	if (qe_status & CREG_STAT_CLOSS) { | 
 | 269 | 		printk(KERN_ERR "%s: Carrier lost, link down?\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 270 | 		dev->stats.tx_errors++; | 
 | 271 | 		dev->stats.tx_carrier_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | 	} | 
 | 273 |  | 
 | 274 | 	if (qe_status & CREG_STAT_ERETRIES) { | 
 | 275 | 		printk(KERN_ERR "%s: Excessive transmit retries (more than 16).\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 276 | 		dev->stats.tx_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | 		mace_hwbug_workaround = 1; | 
 | 278 | 	} | 
 | 279 |  | 
 | 280 | 	if (qe_status & CREG_STAT_LCOLL) { | 
 | 281 | 		printk(KERN_ERR "%s: Late transmit collision.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 282 | 		dev->stats.tx_errors++; | 
 | 283 | 		dev->stats.collisions++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | 		mace_hwbug_workaround = 1; | 
 | 285 | 	} | 
 | 286 |  | 
 | 287 | 	if (qe_status & CREG_STAT_FUFLOW) { | 
 | 288 | 		printk(KERN_ERR "%s: Transmit fifo underflow, driver bug.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 289 | 		dev->stats.tx_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | 		mace_hwbug_workaround = 1; | 
 | 291 | 	} | 
 | 292 |  | 
 | 293 | 	if (qe_status & CREG_STAT_JERROR) { | 
 | 294 | 		printk(KERN_ERR "%s: Jabber error.\n", dev->name); | 
 | 295 | 	} | 
 | 296 |  | 
 | 297 | 	if (qe_status & CREG_STAT_BERROR) { | 
 | 298 | 		printk(KERN_ERR "%s: Babble error.\n", dev->name); | 
 | 299 | 	} | 
 | 300 |  | 
 | 301 | 	if (qe_status & CREG_STAT_CCOFLOW) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 302 | 		dev->stats.tx_errors += 256; | 
 | 303 | 		dev->stats.collisions += 256; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | 	} | 
 | 305 |  | 
 | 306 | 	if (qe_status & CREG_STAT_TXDERROR) { | 
 | 307 | 		printk(KERN_ERR "%s: Transmit descriptor is bogus, driver bug.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 308 | 		dev->stats.tx_errors++; | 
 | 309 | 		dev->stats.tx_aborted_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | 		mace_hwbug_workaround = 1; | 
 | 311 | 	} | 
 | 312 |  | 
 | 313 | 	if (qe_status & CREG_STAT_TXLERR) { | 
 | 314 | 		printk(KERN_ERR "%s: Transmit late error.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 315 | 		dev->stats.tx_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | 		mace_hwbug_workaround = 1; | 
 | 317 | 	} | 
 | 318 |  | 
 | 319 | 	if (qe_status & CREG_STAT_TXPERR) { | 
 | 320 | 		printk(KERN_ERR "%s: Transmit DMA parity error.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 321 | 		dev->stats.tx_errors++; | 
 | 322 | 		dev->stats.tx_aborted_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | 		mace_hwbug_workaround = 1; | 
 | 324 | 	} | 
 | 325 |  | 
 | 326 | 	if (qe_status & CREG_STAT_TXSERR) { | 
 | 327 | 		printk(KERN_ERR "%s: Transmit DMA sbus error ack.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 328 | 		dev->stats.tx_errors++; | 
 | 329 | 		dev->stats.tx_aborted_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | 		mace_hwbug_workaround = 1; | 
 | 331 | 	} | 
 | 332 |  | 
 | 333 | 	if (qe_status & CREG_STAT_RCCOFLOW) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 334 | 		dev->stats.rx_errors += 256; | 
 | 335 | 		dev->stats.collisions += 256; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | 	} | 
 | 337 |  | 
 | 338 | 	if (qe_status & CREG_STAT_RUOFLOW) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 339 | 		dev->stats.rx_errors += 256; | 
 | 340 | 		dev->stats.rx_over_errors += 256; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | 	} | 
 | 342 |  | 
 | 343 | 	if (qe_status & CREG_STAT_MCOFLOW) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 344 | 		dev->stats.rx_errors += 256; | 
 | 345 | 		dev->stats.rx_missed_errors += 256; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | 	} | 
 | 347 |  | 
 | 348 | 	if (qe_status & CREG_STAT_RXFOFLOW) { | 
 | 349 | 		printk(KERN_ERR "%s: Receive fifo overflow.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 350 | 		dev->stats.rx_errors++; | 
 | 351 | 		dev->stats.rx_over_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | 	} | 
 | 353 |  | 
 | 354 | 	if (qe_status & CREG_STAT_RLCOLL) { | 
 | 355 | 		printk(KERN_ERR "%s: Late receive collision.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 356 | 		dev->stats.rx_errors++; | 
 | 357 | 		dev->stats.collisions++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | 	} | 
 | 359 |  | 
 | 360 | 	if (qe_status & CREG_STAT_FCOFLOW) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 361 | 		dev->stats.rx_errors += 256; | 
 | 362 | 		dev->stats.rx_frame_errors += 256; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | 	} | 
 | 364 |  | 
 | 365 | 	if (qe_status & CREG_STAT_CECOFLOW) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 366 | 		dev->stats.rx_errors += 256; | 
 | 367 | 		dev->stats.rx_crc_errors += 256; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | 	} | 
 | 369 |  | 
 | 370 | 	if (qe_status & CREG_STAT_RXDROP) { | 
 | 371 | 		printk(KERN_ERR "%s: Receive packet dropped.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 372 | 		dev->stats.rx_errors++; | 
 | 373 | 		dev->stats.rx_dropped++; | 
 | 374 | 		dev->stats.rx_missed_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | 	} | 
 | 376 |  | 
 | 377 | 	if (qe_status & CREG_STAT_RXSMALL) { | 
 | 378 | 		printk(KERN_ERR "%s: Receive buffer too small, driver bug.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 379 | 		dev->stats.rx_errors++; | 
 | 380 | 		dev->stats.rx_length_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | 	} | 
 | 382 |  | 
 | 383 | 	if (qe_status & CREG_STAT_RXLERR) { | 
 | 384 | 		printk(KERN_ERR "%s: Receive late error.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 385 | 		dev->stats.rx_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | 		mace_hwbug_workaround = 1; | 
 | 387 | 	} | 
 | 388 |  | 
 | 389 | 	if (qe_status & CREG_STAT_RXPERR) { | 
 | 390 | 		printk(KERN_ERR "%s: Receive DMA parity error.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 391 | 		dev->stats.rx_errors++; | 
 | 392 | 		dev->stats.rx_missed_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | 		mace_hwbug_workaround = 1; | 
 | 394 | 	} | 
 | 395 |  | 
 | 396 | 	if (qe_status & CREG_STAT_RXSERR) { | 
 | 397 | 		printk(KERN_ERR "%s: Receive DMA sbus error ack.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 398 | 		dev->stats.rx_errors++; | 
 | 399 | 		dev->stats.rx_missed_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | 		mace_hwbug_workaround = 1; | 
 | 401 | 	} | 
 | 402 |  | 
 | 403 | 	if (mace_hwbug_workaround) | 
 | 404 | 		qe_init(qep, 1); | 
 | 405 | 	return mace_hwbug_workaround; | 
 | 406 | } | 
 | 407 |  | 
 | 408 | /* Per-QE receive interrupt service routine.  Just like on the happy meal | 
 | 409 |  * we receive directly into skb's with a small packet copy water mark. | 
 | 410 |  */ | 
 | 411 | static void qe_rx(struct sunqe *qep) | 
 | 412 | { | 
 | 413 | 	struct qe_rxd *rxbase = &qep->qe_block->qe_rxd[0]; | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 414 | 	struct net_device *dev = qep->dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | 	struct qe_rxd *this; | 
 | 416 | 	struct sunqe_buffers *qbufs = qep->buffers; | 
 | 417 | 	__u32 qbufs_dvma = qep->buffers_dvma; | 
 | 418 | 	int elem = qep->rx_new, drops = 0; | 
 | 419 | 	u32 flags; | 
 | 420 |  | 
 | 421 | 	this = &rxbase[elem]; | 
 | 422 | 	while (!((flags = this->rx_flags) & RXD_OWN)) { | 
 | 423 | 		struct sk_buff *skb; | 
 | 424 | 		unsigned char *this_qbuf = | 
 | 425 | 			&qbufs->rx_buf[elem & (RX_RING_SIZE - 1)][0]; | 
 | 426 | 		__u32 this_qbuf_dvma = qbufs_dvma + | 
 | 427 | 			qebuf_offset(rx_buf, (elem & (RX_RING_SIZE - 1))); | 
 | 428 | 		struct qe_rxd *end_rxd = | 
 | 429 | 			&rxbase[(elem+RX_RING_SIZE)&(RX_RING_MAXSIZE-1)]; | 
 | 430 | 		int len = (flags & RXD_LENGTH) - 4;  /* QE adds ether FCS size to len */ | 
 | 431 |  | 
 | 432 | 		/* Check for errors. */ | 
 | 433 | 		if (len < ETH_ZLEN) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 434 | 			dev->stats.rx_errors++; | 
 | 435 | 			dev->stats.rx_length_errors++; | 
 | 436 | 			dev->stats.rx_dropped++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | 		} else { | 
 | 438 | 			skb = dev_alloc_skb(len + 2); | 
 | 439 | 			if (skb == NULL) { | 
 | 440 | 				drops++; | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 441 | 				dev->stats.rx_dropped++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | 			} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | 				skb_reserve(skb, 2); | 
 | 444 | 				skb_put(skb, len); | 
| David S. Miller | 8c7b7fa | 2007-07-10 22:08:12 -0700 | [diff] [blame] | 445 | 				skb_copy_to_linear_data(skb, (unsigned char *) this_qbuf, | 
 | 446 | 						 len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | 				skb->protocol = eth_type_trans(skb, qep->dev); | 
 | 448 | 				netif_rx(skb); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 449 | 				dev->stats.rx_packets++; | 
 | 450 | 				dev->stats.rx_bytes += len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | 			} | 
 | 452 | 		} | 
 | 453 | 		end_rxd->rx_addr = this_qbuf_dvma; | 
 | 454 | 		end_rxd->rx_flags = (RXD_OWN | ((RXD_PKT_SZ) & RXD_LENGTH)); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 455 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | 		elem = NEXT_RX(elem); | 
 | 457 | 		this = &rxbase[elem]; | 
 | 458 | 	} | 
 | 459 | 	qep->rx_new = elem; | 
 | 460 | 	if (drops) | 
 | 461 | 		printk(KERN_NOTICE "%s: Memory squeeze, deferring packet.\n", qep->dev->name); | 
 | 462 | } | 
 | 463 |  | 
 | 464 | static void qe_tx_reclaim(struct sunqe *qep); | 
 | 465 |  | 
 | 466 | /* Interrupts for all QE's get filtered out via the QEC master controller, | 
 | 467 |  * so we just run through each qe and check to see who is signaling | 
 | 468 |  * and thus needs to be serviced. | 
 | 469 |  */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 470 | static irqreturn_t qec_interrupt(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { | 
| Jeff Garzik | c31f28e | 2006-10-06 14:56:04 -0400 | [diff] [blame] | 472 | 	struct sunqec *qecp = dev_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | 	u32 qec_status; | 
 | 474 | 	int channel = 0; | 
 | 475 |  | 
 | 476 | 	/* Latch the status now. */ | 
 | 477 | 	qec_status = sbus_readl(qecp->gregs + GLOB_STAT); | 
 | 478 | 	while (channel < 4) { | 
 | 479 | 		if (qec_status & 0xf) { | 
 | 480 | 			struct sunqe *qep = qecp->qes[channel]; | 
 | 481 | 			u32 qe_status; | 
 | 482 |  | 
 | 483 | 			qe_status = sbus_readl(qep->qcregs + CREG_STAT); | 
 | 484 | 			if (qe_status & CREG_STAT_ERRORS) { | 
 | 485 | 				if (qe_is_bolixed(qep, qe_status)) | 
 | 486 | 					goto next; | 
 | 487 | 			} | 
 | 488 | 			if (qe_status & CREG_STAT_RXIRQ) | 
 | 489 | 				qe_rx(qep); | 
 | 490 | 			if (netif_queue_stopped(qep->dev) && | 
 | 491 | 			    (qe_status & CREG_STAT_TXIRQ)) { | 
 | 492 | 				spin_lock(&qep->lock); | 
 | 493 | 				qe_tx_reclaim(qep); | 
 | 494 | 				if (TX_BUFFS_AVAIL(qep) > 0) { | 
 | 495 | 					/* Wake net queue and return to | 
 | 496 | 					 * lazy tx reclaim. | 
 | 497 | 					 */ | 
 | 498 | 					netif_wake_queue(qep->dev); | 
 | 499 | 					sbus_writel(1, qep->qcregs + CREG_TIMASK); | 
 | 500 | 				} | 
 | 501 | 				spin_unlock(&qep->lock); | 
 | 502 | 			} | 
 | 503 | 	next: | 
 | 504 | 			; | 
 | 505 | 		} | 
 | 506 | 		qec_status >>= 4; | 
 | 507 | 		channel++; | 
 | 508 | 	} | 
 | 509 |  | 
 | 510 | 	return IRQ_HANDLED; | 
 | 511 | } | 
 | 512 |  | 
 | 513 | static int qe_open(struct net_device *dev) | 
 | 514 | { | 
| Wang Chen | 8f15ea4 | 2008-11-12 23:38:36 -0800 | [diff] [blame] | 515 | 	struct sunqe *qep = netdev_priv(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 |  | 
 | 517 | 	qep->mconfig = (MREGS_MCONFIG_TXENAB | | 
 | 518 | 			MREGS_MCONFIG_RXENAB | | 
 | 519 | 			MREGS_MCONFIG_MBAENAB); | 
 | 520 | 	return qe_init(qep, 0); | 
 | 521 | } | 
 | 522 |  | 
 | 523 | static int qe_close(struct net_device *dev) | 
 | 524 | { | 
| Wang Chen | 8f15ea4 | 2008-11-12 23:38:36 -0800 | [diff] [blame] | 525 | 	struct sunqe *qep = netdev_priv(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 |  | 
 | 527 | 	qe_stop(qep); | 
 | 528 | 	return 0; | 
 | 529 | } | 
 | 530 |  | 
 | 531 | /* Reclaim TX'd frames from the ring.  This must always run under | 
 | 532 |  * the IRQ protected qep->lock. | 
 | 533 |  */ | 
 | 534 | static void qe_tx_reclaim(struct sunqe *qep) | 
 | 535 | { | 
 | 536 | 	struct qe_txd *txbase = &qep->qe_block->qe_txd[0]; | 
 | 537 | 	int elem = qep->tx_old; | 
 | 538 |  | 
 | 539 | 	while (elem != qep->tx_new) { | 
 | 540 | 		u32 flags = txbase[elem].tx_flags; | 
 | 541 |  | 
 | 542 | 		if (flags & TXD_OWN) | 
 | 543 | 			break; | 
 | 544 | 		elem = NEXT_TX(elem); | 
 | 545 | 	} | 
 | 546 | 	qep->tx_old = elem; | 
 | 547 | } | 
 | 548 |  | 
 | 549 | static void qe_tx_timeout(struct net_device *dev) | 
 | 550 | { | 
| Wang Chen | 8f15ea4 | 2008-11-12 23:38:36 -0800 | [diff] [blame] | 551 | 	struct sunqe *qep = netdev_priv(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | 	int tx_full; | 
 | 553 |  | 
 | 554 | 	spin_lock_irq(&qep->lock); | 
 | 555 |  | 
 | 556 | 	/* Try to reclaim, if that frees up some tx | 
 | 557 | 	 * entries, we're fine. | 
 | 558 | 	 */ | 
 | 559 | 	qe_tx_reclaim(qep); | 
 | 560 | 	tx_full = TX_BUFFS_AVAIL(qep) <= 0; | 
 | 561 |  | 
 | 562 | 	spin_unlock_irq(&qep->lock); | 
 | 563 |  | 
 | 564 | 	if (! tx_full) | 
 | 565 | 		goto out; | 
 | 566 |  | 
 | 567 | 	printk(KERN_ERR "%s: transmit timed out, resetting\n", dev->name); | 
 | 568 | 	qe_init(qep, 1); | 
 | 569 |  | 
 | 570 | out: | 
 | 571 | 	netif_wake_queue(dev); | 
 | 572 | } | 
 | 573 |  | 
 | 574 | /* Get a packet queued to go onto the wire. */ | 
 | 575 | static int qe_start_xmit(struct sk_buff *skb, struct net_device *dev) | 
 | 576 | { | 
| Wang Chen | 8f15ea4 | 2008-11-12 23:38:36 -0800 | [diff] [blame] | 577 | 	struct sunqe *qep = netdev_priv(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | 	struct sunqe_buffers *qbufs = qep->buffers; | 
 | 579 | 	__u32 txbuf_dvma, qbufs_dvma = qep->buffers_dvma; | 
 | 580 | 	unsigned char *txbuf; | 
 | 581 | 	int len, entry; | 
 | 582 |  | 
 | 583 | 	spin_lock_irq(&qep->lock); | 
 | 584 |  | 
 | 585 | 	qe_tx_reclaim(qep); | 
 | 586 |  | 
 | 587 | 	len = skb->len; | 
 | 588 | 	entry = qep->tx_new; | 
 | 589 |  | 
 | 590 | 	txbuf = &qbufs->tx_buf[entry & (TX_RING_SIZE - 1)][0]; | 
 | 591 | 	txbuf_dvma = qbufs_dvma + | 
 | 592 | 		qebuf_offset(tx_buf, (entry & (TX_RING_SIZE - 1))); | 
 | 593 |  | 
 | 594 | 	/* Avoid a race... */ | 
 | 595 | 	qep->qe_block->qe_txd[entry].tx_flags = TXD_UPDATE; | 
 | 596 |  | 
| Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 597 | 	skb_copy_from_linear_data(skb, txbuf, len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 |  | 
 | 599 | 	qep->qe_block->qe_txd[entry].tx_addr = txbuf_dvma; | 
 | 600 | 	qep->qe_block->qe_txd[entry].tx_flags = | 
 | 601 | 		(TXD_OWN | TXD_SOP | TXD_EOP | (len & TXD_LENGTH)); | 
 | 602 | 	qep->tx_new = NEXT_TX(entry); | 
 | 603 |  | 
 | 604 | 	/* Get it going. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | 	sbus_writel(CREG_CTRL_TWAKEUP, qep->qcregs + CREG_CTRL); | 
 | 606 |  | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 607 | 	dev->stats.tx_packets++; | 
 | 608 | 	dev->stats.tx_bytes += len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 |  | 
 | 610 | 	if (TX_BUFFS_AVAIL(qep) <= 0) { | 
 | 611 | 		/* Halt the net queue and enable tx interrupts. | 
 | 612 | 		 * When the tx queue empties the tx irq handler | 
 | 613 | 		 * will wake up the queue and return us back to | 
 | 614 | 		 * the lazy tx reclaim scheme. | 
 | 615 | 		 */ | 
 | 616 | 		netif_stop_queue(dev); | 
 | 617 | 		sbus_writel(0, qep->qcregs + CREG_TIMASK); | 
 | 618 | 	} | 
 | 619 | 	spin_unlock_irq(&qep->lock); | 
 | 620 |  | 
 | 621 | 	dev_kfree_skb(skb); | 
 | 622 |  | 
| Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 623 | 	return NETDEV_TX_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } | 
 | 625 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | static void qe_set_multicast(struct net_device *dev) | 
 | 627 | { | 
| Wang Chen | 8f15ea4 | 2008-11-12 23:38:36 -0800 | [diff] [blame] | 628 | 	struct sunqe *qep = netdev_priv(dev); | 
| Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 629 | 	struct netdev_hw_addr *ha; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | 	u8 new_mconfig = qep->mconfig; | 
 | 631 | 	char *addrs; | 
 | 632 | 	int i; | 
 | 633 | 	u32 crc; | 
 | 634 |  | 
 | 635 | 	/* Lock out others. */ | 
 | 636 | 	netif_stop_queue(dev); | 
 | 637 |  | 
| Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 638 | 	if ((dev->flags & IFF_ALLMULTI) || (netdev_mc_count(dev) > 64)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | 		sbus_writeb(MREGS_IACONFIG_ACHNGE | MREGS_IACONFIG_LARESET, | 
 | 640 | 			    qep->mregs + MREGS_IACONFIG); | 
 | 641 | 		while ((sbus_readb(qep->mregs + MREGS_IACONFIG) & MREGS_IACONFIG_ACHNGE) != 0) | 
 | 642 | 			barrier(); | 
 | 643 | 		for (i = 0; i < 8; i++) | 
 | 644 | 			sbus_writeb(0xff, qep->mregs + MREGS_FILTER); | 
 | 645 | 		sbus_writeb(0, qep->mregs + MREGS_IACONFIG); | 
 | 646 | 	} else if (dev->flags & IFF_PROMISC) { | 
 | 647 | 		new_mconfig |= MREGS_MCONFIG_PROMISC; | 
 | 648 | 	} else { | 
 | 649 | 		u16 hash_table[4]; | 
 | 650 | 		u8 *hbytes = (unsigned char *) &hash_table[0]; | 
 | 651 |  | 
| Jiri Pirko | 5508590 | 2010-02-18 00:42:54 +0000 | [diff] [blame] | 652 | 		memset(hash_table, 0, sizeof(hash_table)); | 
| Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 653 | 		netdev_for_each_mc_addr(ha, dev) { | 
 | 654 | 			addrs = ha->addr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 |  | 
 | 656 | 			if (!(*addrs & 1)) | 
 | 657 | 				continue; | 
 | 658 | 			crc = ether_crc_le(6, addrs); | 
 | 659 | 			crc >>= 26; | 
 | 660 | 			hash_table[crc >> 4] |= 1 << (crc & 0xf); | 
 | 661 | 		} | 
 | 662 | 		/* Program the qe with the new filter value. */ | 
 | 663 | 		sbus_writeb(MREGS_IACONFIG_ACHNGE | MREGS_IACONFIG_LARESET, | 
 | 664 | 			    qep->mregs + MREGS_IACONFIG); | 
 | 665 | 		while ((sbus_readb(qep->mregs + MREGS_IACONFIG) & MREGS_IACONFIG_ACHNGE) != 0) | 
 | 666 | 			barrier(); | 
 | 667 | 		for (i = 0; i < 8; i++) { | 
 | 668 | 			u8 tmp = *hbytes++; | 
 | 669 | 			sbus_writeb(tmp, qep->mregs + MREGS_FILTER); | 
 | 670 | 		} | 
 | 671 | 		sbus_writeb(0, qep->mregs + MREGS_IACONFIG); | 
 | 672 | 	} | 
 | 673 |  | 
 | 674 | 	/* Any change of the logical address filter, the physical address, | 
 | 675 | 	 * or enabling/disabling promiscuous mode causes the MACE to disable | 
 | 676 | 	 * the receiver.  So we must re-enable them here or else the MACE | 
 | 677 | 	 * refuses to listen to anything on the network.  Sheesh, took | 
 | 678 | 	 * me a day or two to find this bug. | 
 | 679 | 	 */ | 
 | 680 | 	qep->mconfig = new_mconfig; | 
 | 681 | 	sbus_writeb(qep->mconfig, qep->mregs + MREGS_MCONFIG); | 
 | 682 |  | 
 | 683 | 	/* Let us get going again. */ | 
 | 684 | 	netif_wake_queue(dev); | 
 | 685 | } | 
 | 686 |  | 
 | 687 | /* Ethtool support... */ | 
 | 688 | static void qe_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) | 
 | 689 | { | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 690 | 	const struct linux_prom_registers *regs; | 
| Wang Chen | 8f15ea4 | 2008-11-12 23:38:36 -0800 | [diff] [blame] | 691 | 	struct sunqe *qep = netdev_priv(dev); | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 692 | 	struct platform_device *op; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 |  | 
 | 694 | 	strcpy(info->driver, "sunqe"); | 
 | 695 | 	strcpy(info->version, "3.0"); | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 696 |  | 
 | 697 | 	op = qep->op; | 
| Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 698 | 	regs = of_get_property(op->dev.of_node, "reg", NULL); | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 699 | 	if (regs) | 
 | 700 | 		sprintf(info->bus_info, "SBUS:%d", regs->which_io); | 
 | 701 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } | 
 | 703 |  | 
 | 704 | static u32 qe_get_link(struct net_device *dev) | 
 | 705 | { | 
| Wang Chen | 8f15ea4 | 2008-11-12 23:38:36 -0800 | [diff] [blame] | 706 | 	struct sunqe *qep = netdev_priv(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | 	void __iomem *mregs = qep->mregs; | 
 | 708 | 	u8 phyconfig; | 
 | 709 |  | 
 | 710 | 	spin_lock_irq(&qep->lock); | 
 | 711 | 	phyconfig = sbus_readb(mregs + MREGS_PHYCONFIG); | 
 | 712 | 	spin_unlock_irq(&qep->lock); | 
 | 713 |  | 
 | 714 | 	return (phyconfig & MREGS_PHYCONFIG_LSTAT); | 
 | 715 | } | 
 | 716 |  | 
| Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 717 | static const struct ethtool_ops qe_ethtool_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | 	.get_drvinfo		= qe_get_drvinfo, | 
 | 719 | 	.get_link		= qe_get_link, | 
 | 720 | }; | 
 | 721 |  | 
 | 722 | /* This is only called once at boot time for each card probed. */ | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 723 | static void qec_init_once(struct sunqec *qecp, struct platform_device *op) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | { | 
 | 725 | 	u8 bsizes = qecp->qec_bursts; | 
 | 726 |  | 
| David S. Miller | 63237ee | 2008-08-26 23:33:42 -0700 | [diff] [blame] | 727 | 	if (sbus_can_burst64() && (bsizes & DMA_BURST64)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | 		sbus_writel(GLOB_CTRL_B64, qecp->gregs + GLOB_CTRL); | 
 | 729 | 	} else if (bsizes & DMA_BURST32) { | 
 | 730 | 		sbus_writel(GLOB_CTRL_B32, qecp->gregs + GLOB_CTRL); | 
 | 731 | 	} else { | 
 | 732 | 		sbus_writel(GLOB_CTRL_B16, qecp->gregs + GLOB_CTRL); | 
 | 733 | 	} | 
 | 734 |  | 
 | 735 | 	/* Packetsize only used in 100baseT BigMAC configurations, | 
 | 736 | 	 * set it to zero just to be on the safe side. | 
 | 737 | 	 */ | 
 | 738 | 	sbus_writel(GLOB_PSIZE_2048, qecp->gregs + GLOB_PSIZE); | 
 | 739 |  | 
 | 740 | 	/* Set the local memsize register, divided up to one piece per QE channel. */ | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 741 | 	sbus_writel((resource_size(&op->resource[1]) >> 2), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | 		    qecp->gregs + GLOB_MSIZE); | 
 | 743 |  | 
 | 744 | 	/* Divide up the local QEC memory amongst the 4 QE receiver and | 
 | 745 | 	 * transmitter FIFOs.  Basically it is (total / 2 / num_channels). | 
 | 746 | 	 */ | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 747 | 	sbus_writel((resource_size(&op->resource[1]) >> 2) >> 1, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | 		    qecp->gregs + GLOB_TSIZE); | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 749 | 	sbus_writel((resource_size(&op->resource[1]) >> 2) >> 1, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | 		    qecp->gregs + GLOB_RSIZE); | 
 | 751 | } | 
 | 752 |  | 
| Adrian Bunk | 3edd76c | 2008-01-30 22:03:39 +0200 | [diff] [blame] | 753 | static u8 __devinit qec_get_burst(struct device_node *dp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | 	u8 bsizes, bsizes_more; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 757 | 	/* Find and set the burst sizes for the QEC, since it | 
 | 758 | 	 * does the actual dma for all 4 channels. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | 	 */ | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 760 | 	bsizes = of_getintprop_default(dp, "burst-sizes", 0xff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | 	bsizes &= 0xff; | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 762 | 	bsizes_more = of_getintprop_default(dp->parent, "burst-sizes", 0xff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 |  | 
 | 764 | 	if (bsizes_more != 0xff) | 
 | 765 | 		bsizes &= bsizes_more; | 
 | 766 | 	if (bsizes == 0xff || (bsizes & DMA_BURST16) == 0 || | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 767 | 	    (bsizes & DMA_BURST32)==0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | 		bsizes = (DMA_BURST32 - 1); | 
 | 769 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 770 | 	return bsizes; | 
 | 771 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 |  | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 773 | static struct sunqec * __devinit get_qec(struct platform_device *child) | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 774 | { | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 775 | 	struct platform_device *op = to_platform_device(child->dev.parent); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 776 | 	struct sunqec *qecp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 778 | 	qecp = dev_get_drvdata(&op->dev); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 779 | 	if (!qecp) { | 
 | 780 | 		qecp = kzalloc(sizeof(struct sunqec), GFP_KERNEL); | 
 | 781 | 		if (qecp) { | 
 | 782 | 			u32 ctrl; | 
 | 783 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 784 | 			qecp->op = op; | 
 | 785 | 			qecp->gregs = of_ioremap(&op->resource[0], 0, | 
 | 786 | 						 GLOB_REG_SIZE, | 
 | 787 | 						 "QEC Global Registers"); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 788 | 			if (!qecp->gregs) | 
 | 789 | 				goto fail; | 
 | 790 |  | 
 | 791 | 			/* Make sure the QEC is in MACE mode. */ | 
 | 792 | 			ctrl = sbus_readl(qecp->gregs + GLOB_CTRL); | 
 | 793 | 			ctrl &= 0xf0000000; | 
 | 794 | 			if (ctrl != GLOB_CTRL_MMODE) { | 
 | 795 | 				printk(KERN_ERR "qec: Not in MACE mode!\n"); | 
 | 796 | 				goto fail; | 
 | 797 | 			} | 
 | 798 |  | 
 | 799 | 			if (qec_global_reset(qecp->gregs)) | 
 | 800 | 				goto fail; | 
 | 801 |  | 
| Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 802 | 			qecp->qec_bursts = qec_get_burst(op->dev.of_node); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 803 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 804 | 			qec_init_once(qecp, op); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 805 |  | 
| Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 806 | 			if (request_irq(op->archdata.irqs[0], qec_interrupt, | 
| Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 807 | 					IRQF_SHARED, "qec", (void *) qecp)) { | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 808 | 				printk(KERN_ERR "qec: Can't register irq.\n"); | 
 | 809 | 				goto fail; | 
 | 810 | 			} | 
 | 811 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 812 | 			dev_set_drvdata(&op->dev, qecp); | 
 | 813 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 814 | 			qecp->next_module = root_qec_dev; | 
 | 815 | 			root_qec_dev = qecp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | 		} | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 817 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 819 | 	return qecp; | 
 | 820 |  | 
 | 821 | fail: | 
 | 822 | 	if (qecp->gregs) | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 823 | 		of_iounmap(&op->resource[0], qecp->gregs, GLOB_REG_SIZE); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 824 | 	kfree(qecp); | 
 | 825 | 	return NULL; | 
 | 826 | } | 
 | 827 |  | 
| David S. Miller | ecd4137 | 2009-03-23 13:33:37 -0700 | [diff] [blame] | 828 | static const struct net_device_ops qec_ops = { | 
 | 829 | 	.ndo_open		= qe_open, | 
 | 830 | 	.ndo_stop		= qe_close, | 
 | 831 | 	.ndo_start_xmit		= qe_start_xmit, | 
 | 832 | 	.ndo_set_multicast_list	= qe_set_multicast, | 
 | 833 | 	.ndo_tx_timeout		= qe_tx_timeout, | 
| David S. Miller | dac4696 | 2009-03-23 14:29:24 -0700 | [diff] [blame] | 834 | 	.ndo_change_mtu		= eth_change_mtu, | 
 | 835 | 	.ndo_set_mac_address	= eth_mac_addr, | 
 | 836 | 	.ndo_validate_addr	= eth_validate_addr, | 
| David S. Miller | ecd4137 | 2009-03-23 13:33:37 -0700 | [diff] [blame] | 837 | }; | 
 | 838 |  | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 839 | static int __devinit qec_ether_init(struct platform_device *op) | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 840 | { | 
 | 841 | 	static unsigned version_printed; | 
 | 842 | 	struct net_device *dev; | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 843 | 	struct sunqec *qecp; | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 844 | 	struct sunqe *qe; | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 845 | 	int i, res; | 
 | 846 |  | 
 | 847 | 	if (version_printed++ == 0) | 
 | 848 | 		printk(KERN_INFO "%s", version); | 
 | 849 |  | 
 | 850 | 	dev = alloc_etherdev(sizeof(struct sunqe)); | 
 | 851 | 	if (!dev) | 
 | 852 | 		return -ENOMEM; | 
 | 853 |  | 
| Marcel van Nies | d0dc112 | 2007-04-21 15:31:58 -0700 | [diff] [blame] | 854 | 	memcpy(dev->dev_addr, idprom->id_ethaddr, 6); | 
 | 855 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 856 | 	qe = netdev_priv(dev); | 
 | 857 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 858 | 	res = -ENODEV; | 
 | 859 |  | 
| Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 860 | 	i = of_getintprop_default(op->dev.of_node, "channel#", -1); | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 861 | 	if (i == -1) | 
 | 862 | 		goto fail; | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 863 | 	qe->channel = i; | 
 | 864 | 	spin_lock_init(&qe->lock); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 865 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 866 | 	qecp = get_qec(op); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 867 | 	if (!qecp) | 
 | 868 | 		goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 870 | 	qecp->qes[qe->channel] = qe; | 
 | 871 | 	qe->dev = dev; | 
 | 872 | 	qe->parent = qecp; | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 873 | 	qe->op = op; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 875 | 	res = -ENOMEM; | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 876 | 	qe->qcregs = of_ioremap(&op->resource[0], 0, | 
 | 877 | 				CREG_REG_SIZE, "QEC Channel Registers"); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 878 | 	if (!qe->qcregs) { | 
 | 879 | 		printk(KERN_ERR "qe: Cannot map channel registers.\n"); | 
 | 880 | 		goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | 	} | 
 | 882 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 883 | 	qe->mregs = of_ioremap(&op->resource[1], 0, | 
 | 884 | 			       MREGS_REG_SIZE, "QE MACE Registers"); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 885 | 	if (!qe->mregs) { | 
 | 886 | 		printk(KERN_ERR "qe: Cannot map MACE registers.\n"); | 
 | 887 | 		goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | 	} | 
 | 889 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 890 | 	qe->qe_block = dma_alloc_coherent(&op->dev, PAGE_SIZE, | 
| David S. Miller | 738f2b7 | 2008-08-27 18:09:11 -0700 | [diff] [blame] | 891 | 					  &qe->qblock_dvma, GFP_ATOMIC); | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 892 | 	qe->buffers = dma_alloc_coherent(&op->dev, sizeof(struct sunqe_buffers), | 
| David S. Miller | 738f2b7 | 2008-08-27 18:09:11 -0700 | [diff] [blame] | 893 | 					 &qe->buffers_dvma, GFP_ATOMIC); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 894 | 	if (qe->qe_block == NULL || qe->qblock_dvma == 0 || | 
 | 895 | 	    qe->buffers == NULL || qe->buffers_dvma == 0) | 
 | 896 | 		goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 898 | 	/* Stop this QE. */ | 
 | 899 | 	qe_stop(qe); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 901 | 	SET_NETDEV_DEV(dev, &op->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 903 | 	dev->watchdog_timeo = 5*HZ; | 
| Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 904 | 	dev->irq = op->archdata.irqs[0]; | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 905 | 	dev->dma = 0; | 
 | 906 | 	dev->ethtool_ops = &qe_ethtool_ops; | 
| David S. Miller | ecd4137 | 2009-03-23 13:33:37 -0700 | [diff] [blame] | 907 | 	dev->netdev_ops = &qec_ops; | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 908 |  | 
 | 909 | 	res = register_netdev(dev); | 
 | 910 | 	if (res) | 
 | 911 | 		goto fail; | 
 | 912 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 913 | 	dev_set_drvdata(&op->dev, qe); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 914 |  | 
 | 915 | 	printk(KERN_INFO "%s: qe channel[%d] ", dev->name, qe->channel); | 
 | 916 | 	for (i = 0; i < 6; i++) | 
 | 917 | 		printk ("%2.2x%c", | 
 | 918 | 			dev->dev_addr[i], | 
 | 919 | 			i == 5 ? ' ': ':'); | 
 | 920 | 	printk("\n"); | 
 | 921 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 |  | 
 | 923 | 	return 0; | 
 | 924 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 925 | fail: | 
 | 926 | 	if (qe->qcregs) | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 927 | 		of_iounmap(&op->resource[0], qe->qcregs, CREG_REG_SIZE); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 928 | 	if (qe->mregs) | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 929 | 		of_iounmap(&op->resource[1], qe->mregs, MREGS_REG_SIZE); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 930 | 	if (qe->qe_block) | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 931 | 		dma_free_coherent(&op->dev, PAGE_SIZE, | 
 | 932 | 				  qe->qe_block, qe->qblock_dvma); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 933 | 	if (qe->buffers) | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 934 | 		dma_free_coherent(&op->dev, | 
| David S. Miller | 738f2b7 | 2008-08-27 18:09:11 -0700 | [diff] [blame] | 935 | 				  sizeof(struct sunqe_buffers), | 
 | 936 | 				  qe->buffers, | 
 | 937 | 				  qe->buffers_dvma); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 939 | 	free_netdev(dev); | 
 | 940 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | 	return res; | 
 | 942 | } | 
 | 943 |  | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 944 | static int __devinit qec_sbus_probe(struct platform_device *op, const struct of_device_id *match) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | { | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 946 | 	return qec_ether_init(op); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } | 
 | 948 |  | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 949 | static int __devexit qec_sbus_remove(struct platform_device *op) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | { | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 951 | 	struct sunqe *qp = dev_get_drvdata(&op->dev); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 952 | 	struct net_device *net_dev = qp->dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 |  | 
| Marcel van Nies | d0dc112 | 2007-04-21 15:31:58 -0700 | [diff] [blame] | 954 | 	unregister_netdev(net_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 956 | 	of_iounmap(&op->resource[0], qp->qcregs, CREG_REG_SIZE); | 
 | 957 | 	of_iounmap(&op->resource[1], qp->mregs, MREGS_REG_SIZE); | 
 | 958 | 	dma_free_coherent(&op->dev, PAGE_SIZE, | 
 | 959 | 			  qp->qe_block, qp->qblock_dvma); | 
 | 960 | 	dma_free_coherent(&op->dev, sizeof(struct sunqe_buffers), | 
 | 961 | 			  qp->buffers, qp->buffers_dvma); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 963 | 	free_netdev(net_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 |  | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 965 | 	dev_set_drvdata(&op->dev, NULL); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 966 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | 	return 0; | 
 | 968 | } | 
 | 969 |  | 
| David S. Miller | fd09831 | 2008-08-31 01:23:17 -0700 | [diff] [blame] | 970 | static const struct of_device_id qec_sbus_match[] = { | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 971 | 	{ | 
 | 972 | 		.name = "qe", | 
 | 973 | 	}, | 
 | 974 | 	{}, | 
 | 975 | }; | 
 | 976 |  | 
 | 977 | MODULE_DEVICE_TABLE(of, qec_sbus_match); | 
 | 978 |  | 
 | 979 | static struct of_platform_driver qec_sbus_driver = { | 
| Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 980 | 	.driver = { | 
 | 981 | 		.name = "qec", | 
 | 982 | 		.owner = THIS_MODULE, | 
 | 983 | 		.of_match_table = qec_sbus_match, | 
 | 984 | 	}, | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 985 | 	.probe		= qec_sbus_probe, | 
 | 986 | 	.remove		= __devexit_p(qec_sbus_remove), | 
 | 987 | }; | 
 | 988 |  | 
 | 989 | static int __init qec_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | { | 
| Grant Likely | 1ab1d63 | 2010-06-24 15:14:37 -0600 | [diff] [blame] | 991 | 	return of_register_platform_driver(&qec_sbus_driver); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 992 | } | 
 | 993 |  | 
 | 994 | static void __exit qec_exit(void) | 
 | 995 | { | 
| Grant Likely | 1ab1d63 | 2010-06-24 15:14:37 -0600 | [diff] [blame] | 996 | 	of_unregister_platform_driver(&qec_sbus_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 |  | 
 | 998 | 	while (root_qec_dev) { | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 999 | 		struct sunqec *next = root_qec_dev->next_module; | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1000 | 		struct platform_device *op = root_qec_dev->op; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 |  | 
| Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 1002 | 		free_irq(op->archdata.irqs[0], (void *) root_qec_dev); | 
| David S. Miller | 8e912b3 | 2008-08-27 00:12:27 -0700 | [diff] [blame] | 1003 | 		of_iounmap(&op->resource[0], root_qec_dev->gregs, | 
 | 1004 | 			   GLOB_REG_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | 		kfree(root_qec_dev); | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 1006 |  | 
 | 1007 | 		root_qec_dev = next; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | 	} | 
 | 1009 | } | 
 | 1010 |  | 
| David S. Miller | ecba38a | 2006-06-23 21:23:01 -0700 | [diff] [blame] | 1011 | module_init(qec_init); | 
 | 1012 | module_exit(qec_exit); |