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