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