| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Amiga Linux/68k A2065 Ethernet Driver | 
 | 3 |  * | 
 | 4 |  * (C) Copyright 1995-2003 by Geert Uytterhoeven <geert@linux-m68k.org> | 
 | 5 |  * | 
 | 6 |  * Fixes and tips by: | 
 | 7 |  *	- Janos Farkas (CHEXUM@sparta.banki.hu) | 
 | 8 |  *	- Jes Degn Soerensen (jds@kom.auc.dk) | 
 | 9 |  *	- Matt Domsch (Matt_Domsch@dell.com) | 
 | 10 |  * | 
 | 11 |  * ---------------------------------------------------------------------------- | 
 | 12 |  * | 
 | 13 |  * This program is based on | 
 | 14 |  * | 
 | 15 |  *	ariadne.?:	Amiga Linux/68k Ariadne Ethernet Driver | 
 | 16 |  *			(C) Copyright 1995 by Geert Uytterhoeven, | 
 | 17 |  *                                            Peter De Schrijver | 
 | 18 |  * | 
 | 19 |  *	lance.c:	An AMD LANCE ethernet driver for linux. | 
 | 20 |  *			Written 1993-94 by Donald Becker. | 
 | 21 |  * | 
 | 22 |  *	Am79C960:	PCnet(tm)-ISA Single-Chip Ethernet Controller | 
 | 23 |  *			Advanced Micro Devices | 
 | 24 |  *			Publication #16907, Rev. B, Amendment/0, May 1994 | 
 | 25 |  * | 
 | 26 |  * ---------------------------------------------------------------------------- | 
 | 27 |  * | 
 | 28 |  * This file is subject to the terms and conditions of the GNU General Public | 
 | 29 |  * License.  See the file COPYING in the main directory of the Linux | 
 | 30 |  * distribution for more details. | 
 | 31 |  * | 
 | 32 |  * ---------------------------------------------------------------------------- | 
 | 33 |  * | 
 | 34 |  * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains: | 
 | 35 |  * | 
 | 36 |  *	- an Am7990 Local Area Network Controller for Ethernet (LANCE) with | 
 | 37 |  *	  both 10BASE-2 (thin coax) and AUI (DB-15) connectors | 
 | 38 |  */ | 
 | 39 |  | 
 | 40 | #include <linux/errno.h> | 
 | 41 | #include <linux/netdevice.h> | 
 | 42 | #include <linux/etherdevice.h> | 
 | 43 | #include <linux/module.h> | 
 | 44 | #include <linux/stddef.h> | 
 | 45 | #include <linux/kernel.h> | 
 | 46 | #include <linux/interrupt.h> | 
 | 47 | #include <linux/ioport.h> | 
 | 48 | #include <linux/skbuff.h> | 
 | 49 | #include <linux/slab.h> | 
 | 50 | #include <linux/string.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/init.h> | 
 | 52 | #include <linux/crc32.h> | 
 | 53 | #include <linux/zorro.h> | 
 | 54 | #include <linux/bitops.h> | 
 | 55 |  | 
 | 56 | #include <asm/irq.h> | 
 | 57 | #include <asm/amigaints.h> | 
 | 58 | #include <asm/amigahw.h> | 
 | 59 |  | 
 | 60 | #include "a2065.h" | 
 | 61 |  | 
 | 62 |  | 
 | 63 | 	/* | 
 | 64 | 	 *		Transmit/Receive Ring Definitions | 
 | 65 | 	 */ | 
 | 66 |  | 
 | 67 | #define LANCE_LOG_TX_BUFFERS	(2) | 
 | 68 | #define LANCE_LOG_RX_BUFFERS	(4) | 
 | 69 |  | 
 | 70 | #define TX_RING_SIZE		(1<<LANCE_LOG_TX_BUFFERS) | 
 | 71 | #define RX_RING_SIZE		(1<<LANCE_LOG_RX_BUFFERS) | 
 | 72 |  | 
 | 73 | #define TX_RING_MOD_MASK	(TX_RING_SIZE-1) | 
 | 74 | #define RX_RING_MOD_MASK	(RX_RING_SIZE-1) | 
 | 75 |  | 
 | 76 | #define PKT_BUF_SIZE		(1544) | 
 | 77 | #define RX_BUFF_SIZE            PKT_BUF_SIZE | 
 | 78 | #define TX_BUFF_SIZE            PKT_BUF_SIZE | 
 | 79 |  | 
 | 80 |  | 
 | 81 | 	/* | 
 | 82 | 	 *		Layout of the Lance's RAM Buffer | 
 | 83 | 	 */ | 
 | 84 |  | 
 | 85 |  | 
 | 86 | struct lance_init_block { | 
 | 87 | 	unsigned short mode;		/* Pre-set mode (reg. 15) */ | 
 | 88 | 	unsigned char phys_addr[6];     /* Physical ethernet address */ | 
 | 89 | 	unsigned filter[2];		/* Multicast filter. */ | 
 | 90 |  | 
 | 91 | 	/* Receive and transmit ring base, along with extra bits. */ | 
 | 92 | 	unsigned short rx_ptr;		/* receive descriptor addr */ | 
 | 93 | 	unsigned short rx_len;		/* receive len and high addr */ | 
 | 94 | 	unsigned short tx_ptr;		/* transmit descriptor addr */ | 
 | 95 | 	unsigned short tx_len;		/* transmit len and high addr */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 96 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | 	/* The Tx and Rx ring entries must aligned on 8-byte boundaries. */ | 
 | 98 | 	struct lance_rx_desc brx_ring[RX_RING_SIZE]; | 
 | 99 | 	struct lance_tx_desc btx_ring[TX_RING_SIZE]; | 
 | 100 |  | 
 | 101 | 	char   rx_buf [RX_RING_SIZE][RX_BUFF_SIZE]; | 
 | 102 | 	char   tx_buf [TX_RING_SIZE][TX_BUFF_SIZE]; | 
 | 103 | }; | 
 | 104 |  | 
 | 105 |  | 
 | 106 | 	/* | 
 | 107 | 	 *		Private Device Data | 
 | 108 | 	 */ | 
 | 109 |  | 
 | 110 | struct lance_private { | 
 | 111 | 	char *name; | 
 | 112 | 	volatile struct lance_regs *ll; | 
 | 113 | 	volatile struct lance_init_block *init_block;	    /* Hosts view */ | 
 | 114 | 	volatile struct lance_init_block *lance_init_block; /* Lance view */ | 
 | 115 |  | 
 | 116 | 	int rx_new, tx_new; | 
 | 117 | 	int rx_old, tx_old; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 118 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | 	int lance_log_rx_bufs, lance_log_tx_bufs; | 
 | 120 | 	int rx_ring_mod_mask, tx_ring_mod_mask; | 
 | 121 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | 	int tpe;		      /* cable-selection is TPE */ | 
 | 123 | 	int auto_select;	      /* cable-selection by carrier */ | 
 | 124 | 	unsigned short busmaster_regval; | 
 | 125 |  | 
 | 126 | #ifdef CONFIG_SUNLANCE | 
 | 127 | 	struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */ | 
 | 128 | 	int burst_sizes;	      /* ledma SBus burst sizes */ | 
 | 129 | #endif | 
 | 130 | 	struct timer_list         multicast_timer; | 
 | 131 | }; | 
 | 132 |  | 
 | 133 | #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\ | 
 | 134 | 			lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\ | 
 | 135 | 			lp->tx_old - lp->tx_new-1) | 
 | 136 |  | 
 | 137 |  | 
 | 138 | #define LANCE_ADDR(x) ((int)(x) & ~0xff000000) | 
 | 139 |  | 
 | 140 | /* Load the CSR registers */ | 
 | 141 | static void load_csrs (struct lance_private *lp) | 
 | 142 | { | 
 | 143 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 144 | 	volatile struct lance_init_block *aib = lp->lance_init_block; | 
 | 145 | 	int leptr; | 
 | 146 |  | 
 | 147 | 	leptr = LANCE_ADDR (aib); | 
 | 148 |  | 
 | 149 | 	ll->rap = LE_CSR1; | 
 | 150 | 	ll->rdp = (leptr & 0xFFFF); | 
 | 151 | 	ll->rap = LE_CSR2; | 
 | 152 | 	ll->rdp = leptr >> 16; | 
 | 153 | 	ll->rap = LE_CSR3; | 
 | 154 | 	ll->rdp = lp->busmaster_regval; | 
 | 155 |  | 
 | 156 | 	/* Point back to csr0 */ | 
 | 157 | 	ll->rap = LE_CSR0; | 
 | 158 | } | 
 | 159 |  | 
 | 160 | #define ZERO 0 | 
 | 161 |  | 
 | 162 | /* Setup the Lance Rx and Tx rings */ | 
 | 163 | static void lance_init_ring (struct net_device *dev) | 
 | 164 | { | 
 | 165 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 166 | 	volatile struct lance_init_block *ib = lp->init_block; | 
 | 167 | 	volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */ | 
 | 168 | 	int leptr; | 
 | 169 | 	int i; | 
 | 170 |  | 
 | 171 | 	aib = lp->lance_init_block; | 
 | 172 |  | 
 | 173 | 	/* Lock out other processes while setting up hardware */ | 
 | 174 | 	netif_stop_queue(dev); | 
 | 175 | 	lp->rx_new = lp->tx_new = 0; | 
 | 176 | 	lp->rx_old = lp->tx_old = 0; | 
 | 177 |  | 
 | 178 | 	ib->mode = 0; | 
 | 179 |  | 
 | 180 | 	/* Copy the ethernet address to the lance init block | 
 | 181 | 	 * Note that on the sparc you need to swap the ethernet address. | 
 | 182 | 	 */ | 
 | 183 | 	ib->phys_addr [0] = dev->dev_addr [1]; | 
 | 184 | 	ib->phys_addr [1] = dev->dev_addr [0]; | 
 | 185 | 	ib->phys_addr [2] = dev->dev_addr [3]; | 
 | 186 | 	ib->phys_addr [3] = dev->dev_addr [2]; | 
 | 187 | 	ib->phys_addr [4] = dev->dev_addr [5]; | 
 | 188 | 	ib->phys_addr [5] = dev->dev_addr [4]; | 
 | 189 |  | 
 | 190 | 	if (ZERO) | 
 | 191 | 		printk(KERN_DEBUG "TX rings:\n"); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 192 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | 	/* Setup the Tx ring entries */ | 
 | 194 | 	for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) { | 
 | 195 | 		leptr = LANCE_ADDR(&aib->tx_buf[i][0]); | 
 | 196 | 		ib->btx_ring [i].tmd0      = leptr; | 
 | 197 | 		ib->btx_ring [i].tmd1_hadr = leptr >> 16; | 
 | 198 | 		ib->btx_ring [i].tmd1_bits = 0; | 
 | 199 | 		ib->btx_ring [i].length    = 0xf000; /* The ones required by tmd2 */ | 
 | 200 | 		ib->btx_ring [i].misc      = 0; | 
 | 201 | 		if (i < 3 && ZERO) | 
 | 202 | 			printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr); | 
 | 203 | 	} | 
 | 204 |  | 
 | 205 | 	/* Setup the Rx ring entries */ | 
 | 206 | 	if (ZERO) | 
 | 207 | 		printk(KERN_DEBUG "RX rings:\n"); | 
 | 208 | 	for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) { | 
 | 209 | 		leptr = LANCE_ADDR(&aib->rx_buf[i][0]); | 
 | 210 |  | 
 | 211 | 		ib->brx_ring [i].rmd0      = leptr; | 
 | 212 | 		ib->brx_ring [i].rmd1_hadr = leptr >> 16; | 
 | 213 | 		ib->brx_ring [i].rmd1_bits = LE_R1_OWN; | 
 | 214 | 		ib->brx_ring [i].length    = -RX_BUFF_SIZE | 0xf000; | 
 | 215 | 		ib->brx_ring [i].mblength  = 0; | 
 | 216 | 		if (i < 3 && ZERO) | 
 | 217 | 			printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr); | 
 | 218 | 	} | 
 | 219 |  | 
 | 220 | 	/* Setup the initialization block */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 221 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | 	/* Setup rx descriptor pointer */ | 
 | 223 | 	leptr = LANCE_ADDR(&aib->brx_ring); | 
 | 224 | 	ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16); | 
 | 225 | 	ib->rx_ptr = leptr; | 
 | 226 | 	if (ZERO) | 
 | 227 | 		printk(KERN_DEBUG "RX ptr: %8.8x\n", leptr); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 228 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | 	/* Setup tx descriptor pointer */ | 
 | 230 | 	leptr = LANCE_ADDR(&aib->btx_ring); | 
 | 231 | 	ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16); | 
 | 232 | 	ib->tx_ptr = leptr; | 
 | 233 | 	if (ZERO) | 
 | 234 | 		printk(KERN_DEBUG "TX ptr: %8.8x\n", leptr); | 
 | 235 |  | 
 | 236 | 	/* Clear the multicast filter */ | 
 | 237 | 	ib->filter [0] = 0; | 
 | 238 | 	ib->filter [1] = 0; | 
 | 239 | } | 
 | 240 |  | 
 | 241 | static int init_restart_lance (struct lance_private *lp) | 
 | 242 | { | 
 | 243 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 244 | 	int i; | 
 | 245 |  | 
 | 246 | 	ll->rap = LE_CSR0; | 
 | 247 | 	ll->rdp = LE_C0_INIT; | 
 | 248 |  | 
 | 249 | 	/* Wait for the lance to complete initialization */ | 
 | 250 | 	for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++) | 
 | 251 | 		barrier(); | 
 | 252 | 	if ((i == 100) || (ll->rdp & LE_C0_ERR)) { | 
 | 253 | 		printk(KERN_ERR "LANCE unopened after %d ticks, csr0=%4.4x.\n", | 
 | 254 | 		       i, ll->rdp); | 
 | 255 | 		return -EIO; | 
 | 256 | 	} | 
 | 257 |  | 
 | 258 | 	/* Clear IDON by writing a "1", enable interrupts and start lance */ | 
 | 259 | 	ll->rdp = LE_C0_IDON; | 
 | 260 | 	ll->rdp = LE_C0_INEA | LE_C0_STRT; | 
 | 261 |  | 
 | 262 | 	return 0; | 
 | 263 | } | 
 | 264 |  | 
 | 265 | static int lance_rx (struct net_device *dev) | 
 | 266 | { | 
 | 267 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 268 | 	volatile struct lance_init_block *ib = lp->init_block; | 
 | 269 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 270 | 	volatile struct lance_rx_desc *rd; | 
 | 271 | 	unsigned char bits; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 |  | 
 | 273 | #ifdef TEST_HITS | 
 | 274 | 	int i; | 
 | 275 | 	printk(KERN_DEBUG "["); | 
 | 276 | 	for (i = 0; i < RX_RING_SIZE; i++) { | 
 | 277 | 		if (i == lp->rx_new) | 
 | 278 | 			printk ("%s", | 
 | 279 | 				ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X"); | 
 | 280 | 		else | 
 | 281 | 			printk ("%s", | 
 | 282 | 				ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1"); | 
 | 283 | 	} | 
 | 284 | 	printk ("]\n"); | 
 | 285 | #endif | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 286 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | 	ll->rdp = LE_C0_RINT|LE_C0_INEA; | 
 | 288 | 	for (rd = &ib->brx_ring [lp->rx_new]; | 
 | 289 | 	     !((bits = rd->rmd1_bits) & LE_R1_OWN); | 
 | 290 | 	     rd = &ib->brx_ring [lp->rx_new]) { | 
 | 291 |  | 
 | 292 | 		/* We got an incomplete frame? */ | 
 | 293 | 		if ((bits & LE_R1_POK) != LE_R1_POK) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 294 | 			dev->stats.rx_over_errors++; | 
 | 295 | 			dev->stats.rx_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | 			continue; | 
 | 297 | 		} else if (bits & LE_R1_ERR) { | 
 | 298 | 			/* Count only the end frame as a rx error, | 
 | 299 | 			 * not the beginning | 
 | 300 | 			 */ | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 301 | 			if (bits & LE_R1_BUF) dev->stats.rx_fifo_errors++; | 
 | 302 | 			if (bits & LE_R1_CRC) dev->stats.rx_crc_errors++; | 
 | 303 | 			if (bits & LE_R1_OFL) dev->stats.rx_over_errors++; | 
 | 304 | 			if (bits & LE_R1_FRA) dev->stats.rx_frame_errors++; | 
 | 305 | 			if (bits & LE_R1_EOP) dev->stats.rx_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | 		} else { | 
| Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 307 | 			int len = (rd->mblength & 0xfff) - 4; | 
 | 308 | 			struct sk_buff *skb = dev_alloc_skb (len+2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 |  | 
| Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 310 | 			if (!skb) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | 				printk(KERN_WARNING "%s: Memory squeeze, " | 
 | 312 | 				       "deferring packet.\n", dev->name); | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 313 | 				dev->stats.rx_dropped++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | 				rd->mblength = 0; | 
 | 315 | 				rd->rmd1_bits = LE_R1_OWN; | 
 | 316 | 				lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask; | 
 | 317 | 				return 0; | 
 | 318 | 			} | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 319 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | 			skb_reserve (skb, 2);		/* 16 byte align */ | 
 | 321 | 			skb_put (skb, len);		/* make room */ | 
| David S. Miller | 8c7b7fa | 2007-07-10 22:08:12 -0700 | [diff] [blame] | 322 | 			skb_copy_to_linear_data(skb, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | 					 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]), | 
| David S. Miller | 8c7b7fa | 2007-07-10 22:08:12 -0700 | [diff] [blame] | 324 | 					 len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | 			skb->protocol = eth_type_trans (skb, dev); | 
 | 326 | 			netif_rx (skb); | 
 | 327 | 			dev->last_rx = jiffies; | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 328 | 			dev->stats.rx_packets++; | 
 | 329 | 			dev->stats.rx_bytes += len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | 		} | 
 | 331 |  | 
 | 332 | 		/* Return the packet to the pool */ | 
 | 333 | 		rd->mblength = 0; | 
 | 334 | 		rd->rmd1_bits = LE_R1_OWN; | 
 | 335 | 		lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask; | 
 | 336 | 	} | 
 | 337 | 	return 0; | 
 | 338 | } | 
 | 339 |  | 
 | 340 | static int lance_tx (struct net_device *dev) | 
 | 341 | { | 
 | 342 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 343 | 	volatile struct lance_init_block *ib = lp->init_block; | 
 | 344 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 345 | 	volatile struct lance_tx_desc *td; | 
 | 346 | 	int i, j; | 
 | 347 | 	int status; | 
 | 348 |  | 
 | 349 | 	/* csr0 is 2f3 */ | 
 | 350 | 	ll->rdp = LE_C0_TINT | LE_C0_INEA; | 
 | 351 | 	/* csr0 is 73 */ | 
 | 352 |  | 
 | 353 | 	j = lp->tx_old; | 
 | 354 | 	for (i = j; i != lp->tx_new; i = j) { | 
 | 355 | 		td = &ib->btx_ring [i]; | 
 | 356 |  | 
 | 357 | 		/* If we hit a packet not owned by us, stop */ | 
 | 358 | 		if (td->tmd1_bits & LE_T1_OWN) | 
 | 359 | 			break; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 360 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | 		if (td->tmd1_bits & LE_T1_ERR) { | 
 | 362 | 			status = td->misc; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 363 |  | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 364 | 			dev->stats.tx_errors++; | 
 | 365 | 			if (status & LE_T3_RTY)  dev->stats.tx_aborted_errors++; | 
 | 366 | 			if (status & LE_T3_LCOL) dev->stats.tx_window_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 |  | 
 | 368 | 			if (status & LE_T3_CLOS) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 369 | 				dev->stats.tx_carrier_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | 				if (lp->auto_select) { | 
 | 371 | 					lp->tpe = 1 - lp->tpe; | 
 | 372 | 					printk(KERN_ERR "%s: Carrier Lost, " | 
 | 373 | 					       "trying %s\n", dev->name, | 
 | 374 | 					       lp->tpe?"TPE":"AUI"); | 
 | 375 | 					/* Stop the lance */ | 
 | 376 | 					ll->rap = LE_CSR0; | 
 | 377 | 					ll->rdp = LE_C0_STOP; | 
 | 378 | 					lance_init_ring (dev); | 
 | 379 | 					load_csrs (lp); | 
 | 380 | 					init_restart_lance (lp); | 
 | 381 | 					return 0; | 
 | 382 | 				} | 
 | 383 | 			} | 
 | 384 |  | 
 | 385 | 			/* buffer errors and underflows turn off the transmitter */ | 
 | 386 | 			/* Restart the adapter */ | 
 | 387 | 			if (status & (LE_T3_BUF|LE_T3_UFL)) { | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 388 | 				dev->stats.tx_fifo_errors++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 |  | 
 | 390 | 				printk(KERN_ERR "%s: Tx: ERR_BUF|ERR_UFL, " | 
 | 391 | 				       "restarting\n", dev->name); | 
 | 392 | 				/* Stop the lance */ | 
 | 393 | 				ll->rap = LE_CSR0; | 
 | 394 | 				ll->rdp = LE_C0_STOP; | 
 | 395 | 				lance_init_ring (dev); | 
 | 396 | 				load_csrs (lp); | 
 | 397 | 				init_restart_lance (lp); | 
 | 398 | 				return 0; | 
 | 399 | 			} | 
 | 400 | 		} else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) { | 
 | 401 | 			/* | 
 | 402 | 			 * So we don't count the packet more than once. | 
 | 403 | 			 */ | 
 | 404 | 			td->tmd1_bits &= ~(LE_T1_POK); | 
 | 405 |  | 
 | 406 | 			/* One collision before packet was sent. */ | 
 | 407 | 			if (td->tmd1_bits & LE_T1_EONE) | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 408 | 				dev->stats.collisions++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 |  | 
 | 410 | 			/* More than one collision, be optimistic. */ | 
 | 411 | 			if (td->tmd1_bits & LE_T1_EMORE) | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 412 | 				dev->stats.collisions += 2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 |  | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 414 | 			dev->stats.tx_packets++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | 		} | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 416 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | 		j = (j + 1) & lp->tx_ring_mod_mask; | 
 | 418 | 	} | 
 | 419 | 	lp->tx_old = j; | 
 | 420 | 	ll->rdp = LE_C0_TINT | LE_C0_INEA; | 
 | 421 | 	return 0; | 
 | 422 | } | 
 | 423 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 424 | static irqreturn_t lance_interrupt (int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | { | 
 | 426 | 	struct net_device *dev; | 
 | 427 | 	struct lance_private *lp; | 
 | 428 | 	volatile struct lance_regs *ll; | 
 | 429 | 	int csr0; | 
 | 430 |  | 
 | 431 | 	dev = (struct net_device *) dev_id; | 
 | 432 |  | 
 | 433 | 	lp = netdev_priv(dev); | 
 | 434 | 	ll = lp->ll; | 
 | 435 |  | 
 | 436 | 	ll->rap = LE_CSR0;		/* LANCE Controller Status */ | 
 | 437 | 	csr0 = ll->rdp; | 
 | 438 |  | 
 | 439 | 	if (!(csr0 & LE_C0_INTR))	/* Check if any interrupt has */ | 
 | 440 | 		return IRQ_NONE;	/* been generated by the Lance. */ | 
 | 441 |  | 
 | 442 | 	/* Acknowledge all the interrupt sources ASAP */ | 
 | 443 | 	ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT| | 
 | 444 | 			   LE_C0_INIT); | 
 | 445 |  | 
 | 446 | 	if ((csr0 & LE_C0_ERR)) { | 
 | 447 | 		/* Clear the error condition */ | 
 | 448 | 		ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA; | 
 | 449 | 	} | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 450 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | 	if (csr0 & LE_C0_RINT) | 
 | 452 | 		lance_rx (dev); | 
 | 453 |  | 
 | 454 | 	if (csr0 & LE_C0_TINT) | 
 | 455 | 		lance_tx (dev); | 
 | 456 |  | 
 | 457 | 	/* Log misc errors. */ | 
 | 458 | 	if (csr0 & LE_C0_BABL) | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 459 | 		dev->stats.tx_errors++;       /* Tx babble. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | 	if (csr0 & LE_C0_MISS) | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 461 | 		dev->stats.rx_errors++;       /* Missed a Rx frame. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | 	if (csr0 & LE_C0_MERR) { | 
 | 463 | 		printk(KERN_ERR "%s: Bus master arbitration failure, status " | 
 | 464 | 		       "%4.4x.\n", dev->name, csr0); | 
 | 465 | 		/* Restart the chip. */ | 
 | 466 | 		ll->rdp = LE_C0_STRT; | 
 | 467 | 	} | 
 | 468 |  | 
 | 469 | 	if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0) | 
 | 470 | 		netif_wake_queue(dev); | 
 | 471 |  | 
 | 472 | 	ll->rap = LE_CSR0; | 
 | 473 | 	ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR| | 
 | 474 | 					LE_C0_IDON|LE_C0_INEA; | 
 | 475 | 	return IRQ_HANDLED; | 
 | 476 | } | 
 | 477 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | static int lance_open (struct net_device *dev) | 
 | 479 | { | 
 | 480 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 481 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 482 | 	int ret; | 
 | 483 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | 	/* Stop the Lance */ | 
 | 485 | 	ll->rap = LE_CSR0; | 
 | 486 | 	ll->rdp = LE_C0_STOP; | 
 | 487 |  | 
 | 488 | 	/* Install the Interrupt handler */ | 
| Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 489 | 	ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | 			  dev->name, dev); | 
 | 491 | 	if (ret) return ret; | 
 | 492 |  | 
 | 493 | 	load_csrs (lp); | 
 | 494 | 	lance_init_ring (dev); | 
 | 495 |  | 
 | 496 | 	netif_start_queue(dev); | 
 | 497 |  | 
 | 498 | 	return init_restart_lance (lp); | 
 | 499 | } | 
 | 500 |  | 
 | 501 | static int lance_close (struct net_device *dev) | 
 | 502 | { | 
 | 503 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 504 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 505 |  | 
 | 506 | 	netif_stop_queue(dev); | 
 | 507 | 	del_timer_sync(&lp->multicast_timer); | 
 | 508 |  | 
 | 509 | 	/* Stop the card */ | 
 | 510 | 	ll->rap = LE_CSR0; | 
 | 511 | 	ll->rdp = LE_C0_STOP; | 
 | 512 |  | 
 | 513 | 	free_irq(IRQ_AMIGA_PORTS, dev); | 
 | 514 | 	return 0; | 
 | 515 | } | 
 | 516 |  | 
 | 517 | static inline int lance_reset (struct net_device *dev) | 
 | 518 | { | 
 | 519 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 520 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 521 | 	int status; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 522 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | 	/* Stop the lance */ | 
 | 524 | 	ll->rap = LE_CSR0; | 
 | 525 | 	ll->rdp = LE_C0_STOP; | 
 | 526 |  | 
 | 527 | 	load_csrs (lp); | 
 | 528 |  | 
 | 529 | 	lance_init_ring (dev); | 
 | 530 | 	dev->trans_start = jiffies; | 
 | 531 | 	netif_start_queue(dev); | 
 | 532 |  | 
 | 533 | 	status = init_restart_lance (lp); | 
 | 534 | #ifdef DEBUG_DRIVER | 
 | 535 | 	printk(KERN_DEBUG "Lance restart=%d\n", status); | 
 | 536 | #endif | 
 | 537 | 	return status; | 
 | 538 | } | 
 | 539 |  | 
 | 540 | static void lance_tx_timeout(struct net_device *dev) | 
 | 541 | { | 
 | 542 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 543 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 544 |  | 
 | 545 | 	printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n", | 
 | 546 | 	       dev->name, ll->rdp); | 
 | 547 | 	lance_reset(dev); | 
 | 548 | 	netif_wake_queue(dev); | 
 | 549 | } | 
 | 550 |  | 
 | 551 | static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev) | 
 | 552 | { | 
 | 553 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 554 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 555 | 	volatile struct lance_init_block *ib = lp->init_block; | 
 | 556 | 	int entry, skblen, len; | 
 | 557 | 	int status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | 	unsigned long flags; | 
 | 559 |  | 
 | 560 | 	skblen = skb->len; | 
 | 561 | 	len = skblen; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 562 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | 	if (len < ETH_ZLEN) { | 
 | 564 | 		len = ETH_ZLEN; | 
| Herbert Xu | 5b057c6 | 2006-06-23 02:06:41 -0700 | [diff] [blame] | 565 | 		if (skb_padto(skb, ETH_ZLEN)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | 			return 0; | 
 | 567 | 	} | 
 | 568 |  | 
 | 569 | 	local_irq_save(flags); | 
 | 570 |  | 
 | 571 | 	if (!TX_BUFFS_AVAIL){ | 
 | 572 | 		local_irq_restore(flags); | 
 | 573 | 		return -1; | 
 | 574 | 	} | 
 | 575 |  | 
 | 576 | #ifdef DEBUG_DRIVER | 
 | 577 | 	/* dump the packet */ | 
 | 578 | 	{ | 
 | 579 | 		int i; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 580 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | 		for (i = 0; i < 64; i++) { | 
 | 582 | 			if ((i % 16) == 0) | 
 | 583 | 				printk("\n" KERN_DEBUG); | 
 | 584 | 			printk ("%2.2x ", skb->data [i]); | 
 | 585 | 		} | 
 | 586 | 		printk("\n"); | 
 | 587 | 	} | 
 | 588 | #endif | 
 | 589 | 	entry = lp->tx_new & lp->tx_ring_mod_mask; | 
 | 590 | 	ib->btx_ring [entry].length = (-len) | 0xf000; | 
 | 591 | 	ib->btx_ring [entry].misc = 0; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 592 |  | 
| Geert Uytterhoeven | cfa08bb | 2007-05-01 22:33:05 +0200 | [diff] [blame] | 593 | 	skb_copy_from_linear_data(skb, (void *)&ib->tx_buf [entry][0], skblen); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 |  | 
 | 595 | 	/* Clear the slack of the packet, do I need this? */ | 
 | 596 | 	if (len != skblen) | 
| Geert Uytterhoeven | cfa08bb | 2007-05-01 22:33:05 +0200 | [diff] [blame] | 597 | 		memset ((void *) &ib->tx_buf [entry][skblen], 0, len - skblen); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 598 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | 	/* Now, give the packet to the lance */ | 
 | 600 | 	ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN); | 
 | 601 | 	lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask; | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 602 | 	dev->stats.tx_bytes += skblen; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 |  | 
 | 604 | 	if (TX_BUFFS_AVAIL <= 0) | 
 | 605 | 		netif_stop_queue(dev); | 
 | 606 |  | 
 | 607 | 	/* Kick the lance: transmit now */ | 
 | 608 | 	ll->rdp = LE_C0_INEA | LE_C0_TDMD; | 
 | 609 | 	dev->trans_start = jiffies; | 
 | 610 | 	dev_kfree_skb (skb); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 611 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | 	local_irq_restore(flags); | 
 | 613 |  | 
 | 614 | 	return status; | 
 | 615 | } | 
 | 616 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* taken from the depca driver */ | 
 | 618 | static void lance_load_multicast (struct net_device *dev) | 
 | 619 | { | 
 | 620 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 621 | 	volatile struct lance_init_block *ib = lp->init_block; | 
 | 622 | 	volatile u16 *mcast_table = (u16 *)&ib->filter; | 
 | 623 | 	struct dev_mc_list *dmi=dev->mc_list; | 
 | 624 | 	char *addrs; | 
 | 625 | 	int i; | 
 | 626 | 	u32 crc; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 627 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | 	/* set all multicast bits */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 629 | 	if (dev->flags & IFF_ALLMULTI){ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | 		ib->filter [0] = 0xffffffff; | 
 | 631 | 		ib->filter [1] = 0xffffffff; | 
 | 632 | 		return; | 
 | 633 | 	} | 
 | 634 | 	/* clear the multicast filter */ | 
 | 635 | 	ib->filter [0] = 0; | 
 | 636 | 	ib->filter [1] = 0; | 
 | 637 |  | 
 | 638 | 	/* Add addresses */ | 
 | 639 | 	for (i = 0; i < dev->mc_count; i++){ | 
 | 640 | 		addrs = dmi->dmi_addr; | 
 | 641 | 		dmi   = dmi->next; | 
 | 642 |  | 
 | 643 | 		/* multicast address? */ | 
 | 644 | 		if (!(*addrs & 1)) | 
 | 645 | 			continue; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 646 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | 		crc = ether_crc_le(6, addrs); | 
 | 648 | 		crc = crc >> 26; | 
 | 649 | 		mcast_table [crc >> 4] |= 1 << (crc & 0xf); | 
 | 650 | 	} | 
 | 651 | 	return; | 
 | 652 | } | 
 | 653 |  | 
 | 654 | static void lance_set_multicast (struct net_device *dev) | 
 | 655 | { | 
 | 656 | 	struct lance_private *lp = netdev_priv(dev); | 
 | 657 | 	volatile struct lance_init_block *ib = lp->init_block; | 
 | 658 | 	volatile struct lance_regs *ll = lp->ll; | 
 | 659 |  | 
 | 660 | 	if (!netif_running(dev)) | 
 | 661 | 		return; | 
 | 662 |  | 
 | 663 | 	if (lp->tx_old != lp->tx_new) { | 
 | 664 | 		mod_timer(&lp->multicast_timer, jiffies + 4); | 
 | 665 | 		netif_wake_queue(dev); | 
 | 666 | 		return; | 
 | 667 | 	} | 
 | 668 |  | 
 | 669 | 	netif_stop_queue(dev); | 
 | 670 |  | 
 | 671 | 	ll->rap = LE_CSR0; | 
 | 672 | 	ll->rdp = LE_C0_STOP; | 
 | 673 | 	lance_init_ring (dev); | 
 | 674 |  | 
 | 675 | 	if (dev->flags & IFF_PROMISC) { | 
 | 676 | 		ib->mode |= LE_MO_PROM; | 
 | 677 | 	} else { | 
 | 678 | 		ib->mode &= ~LE_MO_PROM; | 
 | 679 | 		lance_load_multicast (dev); | 
 | 680 | 	} | 
 | 681 | 	load_csrs (lp); | 
 | 682 | 	init_restart_lance (lp); | 
 | 683 | 	netif_wake_queue(dev); | 
 | 684 | } | 
 | 685 |  | 
 | 686 | static int __devinit a2065_init_one(struct zorro_dev *z, | 
 | 687 | 				    const struct zorro_device_id *ent); | 
 | 688 | static void __devexit a2065_remove_one(struct zorro_dev *z); | 
 | 689 |  | 
 | 690 |  | 
 | 691 | static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = { | 
 | 692 | 	{ ZORRO_PROD_CBM_A2065_1 }, | 
 | 693 | 	{ ZORRO_PROD_CBM_A2065_2 }, | 
 | 694 | 	{ ZORRO_PROD_AMERISTAR_A2065 }, | 
 | 695 | 	{ 0 } | 
 | 696 | }; | 
 | 697 |  | 
 | 698 | static struct zorro_driver a2065_driver = { | 
 | 699 | 	.name		= "a2065", | 
 | 700 | 	.id_table	= a2065_zorro_tbl, | 
 | 701 | 	.probe		= a2065_init_one, | 
 | 702 | 	.remove		= __devexit_p(a2065_remove_one), | 
 | 703 | }; | 
 | 704 |  | 
 | 705 | static int __devinit a2065_init_one(struct zorro_dev *z, | 
 | 706 | 				    const struct zorro_device_id *ent) | 
 | 707 | { | 
 | 708 | 	struct net_device *dev; | 
 | 709 | 	struct lance_private *priv; | 
 | 710 | 	unsigned long board, base_addr, mem_start; | 
 | 711 | 	struct resource *r1, *r2; | 
 | 712 | 	int err; | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 713 | 	DECLARE_MAC_BUF(mac); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 |  | 
 | 715 | 	board = z->resource.start; | 
 | 716 | 	base_addr = board+A2065_LANCE; | 
 | 717 | 	mem_start = board+A2065_RAM; | 
 | 718 |  | 
 | 719 | 	r1 = request_mem_region(base_addr, sizeof(struct lance_regs), | 
 | 720 | 				"Am7990"); | 
 | 721 | 	if (!r1) | 
 | 722 | 		return -EBUSY; | 
 | 723 | 	r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM"); | 
 | 724 | 	if (!r2) { | 
 | 725 | 		release_resource(r1); | 
 | 726 | 		return -EBUSY; | 
 | 727 | 	} | 
 | 728 |  | 
 | 729 | 	dev = alloc_etherdev(sizeof(struct lance_private)); | 
 | 730 | 	if (dev == NULL) { | 
 | 731 | 		release_resource(r1); | 
 | 732 | 		release_resource(r2); | 
 | 733 | 		return -ENOMEM; | 
 | 734 | 	} | 
 | 735 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | 	priv = netdev_priv(dev); | 
 | 737 |  | 
 | 738 | 	r1->name = dev->name; | 
 | 739 | 	r2->name = dev->name; | 
 | 740 |  | 
 | 741 | 	dev->dev_addr[0] = 0x00; | 
 | 742 | 	if (z->id != ZORRO_PROD_AMERISTAR_A2065) {	/* Commodore */ | 
 | 743 | 		dev->dev_addr[1] = 0x80; | 
 | 744 | 		dev->dev_addr[2] = 0x10; | 
 | 745 | 	} else {					/* Ameristar */ | 
 | 746 | 		dev->dev_addr[1] = 0x00; | 
 | 747 | 		dev->dev_addr[2] = 0x9f; | 
 | 748 | 	} | 
 | 749 | 	dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff; | 
 | 750 | 	dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff; | 
 | 751 | 	dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff; | 
 | 752 | 	dev->base_addr = ZTWO_VADDR(base_addr); | 
 | 753 | 	dev->mem_start = ZTWO_VADDR(mem_start); | 
 | 754 | 	dev->mem_end = dev->mem_start+A2065_RAM_SIZE; | 
 | 755 |  | 
 | 756 | 	priv->ll = (volatile struct lance_regs *)dev->base_addr; | 
 | 757 | 	priv->init_block = (struct lance_init_block *)dev->mem_start; | 
 | 758 | 	priv->lance_init_block = (struct lance_init_block *)A2065_RAM; | 
 | 759 | 	priv->auto_select = 0; | 
 | 760 | 	priv->busmaster_regval = LE_C3_BSWP; | 
 | 761 |  | 
 | 762 | 	priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS; | 
 | 763 | 	priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS; | 
 | 764 | 	priv->rx_ring_mod_mask = RX_RING_MOD_MASK; | 
 | 765 | 	priv->tx_ring_mod_mask = TX_RING_MOD_MASK; | 
 | 766 |  | 
 | 767 | 	dev->open = &lance_open; | 
 | 768 | 	dev->stop = &lance_close; | 
 | 769 | 	dev->hard_start_xmit = &lance_start_xmit; | 
 | 770 | 	dev->tx_timeout = &lance_tx_timeout; | 
 | 771 | 	dev->watchdog_timeo = 5*HZ; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | 	dev->set_multicast_list = &lance_set_multicast; | 
 | 773 | 	dev->dma = 0; | 
 | 774 |  | 
 | 775 | 	init_timer(&priv->multicast_timer); | 
 | 776 | 	priv->multicast_timer.data = (unsigned long) dev; | 
 | 777 | 	priv->multicast_timer.function = | 
 | 778 | 		(void (*)(unsigned long)) &lance_set_multicast; | 
 | 779 |  | 
 | 780 | 	err = register_netdev(dev); | 
 | 781 | 	if (err) { | 
 | 782 | 		release_resource(r1); | 
 | 783 | 		release_resource(r2); | 
 | 784 | 		free_netdev(dev); | 
 | 785 | 		return err; | 
 | 786 | 	} | 
 | 787 | 	zorro_set_drvdata(z, dev); | 
 | 788 |  | 
 | 789 | 	printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address " | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 790 | 	       "%s\n", dev->name, board, | 
 | 791 | 	       print_mac(mac, dev->dev_addr)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 |  | 
 | 793 | 	return 0; | 
 | 794 | } | 
 | 795 |  | 
 | 796 |  | 
 | 797 | static void __devexit a2065_remove_one(struct zorro_dev *z) | 
 | 798 | { | 
 | 799 | 	struct net_device *dev = zorro_get_drvdata(z); | 
 | 800 |  | 
 | 801 | 	unregister_netdev(dev); | 
 | 802 | 	release_mem_region(ZTWO_PADDR(dev->base_addr), | 
 | 803 | 			   sizeof(struct lance_regs)); | 
 | 804 | 	release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE); | 
 | 805 | 	free_netdev(dev); | 
 | 806 | } | 
 | 807 |  | 
 | 808 | static int __init a2065_init_module(void) | 
 | 809 | { | 
| Bjorn Helgaas | 33d8675 | 2006-03-25 03:07:20 -0800 | [diff] [blame] | 810 | 	return zorro_register_driver(&a2065_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } | 
 | 812 |  | 
 | 813 | static void __exit a2065_cleanup_module(void) | 
 | 814 | { | 
 | 815 | 	zorro_unregister_driver(&a2065_driver); | 
 | 816 | } | 
 | 817 |  | 
 | 818 | module_init(a2065_init_module); | 
 | 819 | module_exit(a2065_cleanup_module); | 
 | 820 |  | 
 | 821 | MODULE_LICENSE("GPL"); |