2 * Amiga Linux/m68k Ariadne II Ethernet Driver
4 * (C) Copyright 1998 by some Elitist 680x0 Users(TM)
6 * ---------------------------------------------------------------------------
8 * This program is based on all the other NE2000 drivers for Linux
10 * ---------------------------------------------------------------------------
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file COPYING in the main directory of the Linux
14 * distribution for more details.
16 * ---------------------------------------------------------------------------
18 * The Ariadne II is a Zorro-II board made by Village Tronic. It contains a
19 * Realtek RTL8019AS Ethernet Controller.
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
25 #include <linux/errno.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/netdevice.h>
29 #include <linux/etherdevice.h>
30 #include <linux/zorro.h>
32 #include <asm/system.h>
35 #include <asm/amigaints.h>
36 #include <asm/amigahw.h>
41 #define ARIADNE2_BASE 0x0300
42 #define ARIADNE2_BOOTROM 0xc000
45 #define NE_BASE (dev->base_addr)
46 #define NE_CMD (0x00*2)
47 #define NE_DATAPORT (0x10*2) /* NatSemi-defined port window offset. */
48 #define NE_RESET (0x1f*2) /* Issue a read to reset, a write to clear. */
49 #define NE_IO_EXTENT (0x20*2)
51 #define NE_EN0_ISR (0x07*2)
52 #define NE_EN0_DCFG (0x0e*2)
54 #define NE_EN0_RSARLO (0x08*2)
55 #define NE_EN0_RSARHI (0x09*2)
56 #define NE_EN0_RCNTLO (0x0a*2)
57 #define NE_EN0_RXCR (0x0c*2)
58 #define NE_EN0_TXCR (0x0d*2)
59 #define NE_EN0_RCNTHI (0x0b*2)
60 #define NE_EN0_IMR (0x0f*2)
62 #define NESM_START_PG 0x40 /* First page of TX buffer */
63 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
66 #define WORDSWAP(a) ((((a)>>8)&0xff) | ((a)<<8))
68 int ariadne2_probe(struct net_device
*dev
);
69 static int ariadne2_init(struct net_device
*dev
, unsigned int key
,
72 static int ariadne2_open(struct net_device
*dev
);
73 static int ariadne2_close(struct net_device
*dev
);
75 static void ariadne2_reset_8390(struct net_device
*dev
);
76 static void ariadne2_get_8390_hdr(struct net_device
*dev
,
77 struct e8390_pkt_hdr
*hdr
, int ring_page
);
78 static void ariadne2_block_input(struct net_device
*dev
, int count
,
79 struct sk_buff
*skb
, int ring_offset
);
80 static void ariadne2_block_output(struct net_device
*dev
, const int count
,
81 const unsigned char *buf
,
82 const int start_page
);
84 int __init
ariadne2_probe(struct net_device
*dev
)
87 const struct ConfigDev
*cd
;
91 if ((key
= zorro_find(ZORRO_PROD_VILLAGE_TRONIC_ARIADNE2
, 0, 0))) {
92 cd
= zorro_get_board(key
);
93 if ((board
= (u_long
)cd
->cd_BoardAddr
)) {
94 if ((err
= ariadne2_init(dev
, key
, ZTWO_VADDR(board
))))
96 zorro_config_board(key
, 0);
103 static int __init
ariadne2_init(struct net_device
*dev
, unsigned int key
,
107 unsigned char SA_prom
[32];
108 const char *name
= NULL
;
109 int start_page
, stop_page
;
110 static u32 ariadne2_offsets
[16] = {
111 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
112 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
114 int ioaddr
= board
+ARIADNE2_BASE
*2;
116 if (load_8390_module("ariadne2.c"))
119 /* We should have a "dev" from Space.c or the static module table. */
121 printk(KERN_ERR
"ariadne2.c: Passed a NULL device.\n");
122 dev
= init_etherdev(0, 0);
125 /* Reset card. Who knows what dain-bramaged state it was left in. */
127 unsigned long reset_start_time
= jiffies
;
129 writeb(readb(ioaddr
+ NE_RESET
), ioaddr
+ NE_RESET
);
131 while ((readb(ioaddr
+ NE_EN0_ISR
) & ENISR_RESET
) == 0)
132 if (jiffies
- reset_start_time
> 2*HZ
/100) {
133 printk(" not found (no reset ack).\n");
137 writeb(0xff, ioaddr
+ NE_EN0_ISR
); /* Ack all intr. */
140 /* Read the 16 bytes of station address PROM.
141 We must first initialize registers, similar to NS8390_init(eifdev, 0).
142 We can't reliably read the SAPROM address without this.
143 (I learned the hard way!). */
149 {E8390_NODMA
+E8390_PAGE0
+E8390_STOP
, NE_CMD
}, /* Select page 0*/
150 {0x48, NE_EN0_DCFG
}, /* Set byte-wide (0x48) access. */
151 {0x00, NE_EN0_RCNTLO
}, /* Clear the count regs. */
152 {0x00, NE_EN0_RCNTHI
},
153 {0x00, NE_EN0_IMR
}, /* Mask completion irq. */
155 {E8390_RXOFF
, NE_EN0_RXCR
}, /* 0x20 Set to monitor */
156 {E8390_TXOFF
, NE_EN0_TXCR
}, /* 0x02 and loopback mode. */
158 {0x00, NE_EN0_RCNTHI
},
159 {0x00, NE_EN0_RSARLO
}, /* DMA starting at 0x0000. */
160 {0x00, NE_EN0_RSARHI
},
161 {E8390_RREAD
+E8390_START
, NE_CMD
},
163 for (i
= 0; i
< sizeof(program_seq
)/sizeof(program_seq
[0]); i
++) {
164 writeb(program_seq
[i
].value
, ioaddr
+ program_seq
[i
].offset
);
167 for (i
= 0; i
< 16; i
++) {
168 SA_prom
[i
] = readb(ioaddr
+ NE_DATAPORT
);
169 (void)readb(ioaddr
+ NE_DATAPORT
);
172 /* We must set the 8390 for word mode. */
173 writeb(0x49, ioaddr
+ NE_EN0_DCFG
);
174 start_page
= NESM_START_PG
;
175 stop_page
= NESM_STOP_PG
;
179 dev
->base_addr
= ioaddr
;
180 dev
->irq
= IRQ_AMIGA_PORTS
;
182 /* Install the Interrupt handler */
183 if (request_irq(IRQ_AMIGA_PORTS
, ei_interrupt
, SA_SHIRQ
,
184 "AriadNE2 Ethernet", dev
))
187 /* Allocate dev->priv and fill in 8390 specific dev fields. */
188 if (ethdev_init(dev
)) {
189 printk("Unable to get memory for dev->priv.\n");
192 ((struct ei_device
*)dev
->priv
)->priv
= key
;
194 for(i
= 0; i
< ETHER_ADDR_LEN
; i
++) {
196 printk(" %2.2x", SA_prom
[i
]);
198 dev
->dev_addr
[i
] = SA_prom
[i
];
201 printk("%s: AriadNE2 at 0x%08lx, Ethernet Address "
202 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev
->name
, board
,
203 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
204 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
206 ei_status
.name
= name
;
207 ei_status
.tx_start_page
= start_page
;
208 ei_status
.stop_page
= stop_page
;
209 ei_status
.word16
= 1;
211 ei_status
.rx_start_page
= start_page
+ TX_PAGES
;
213 ei_status
.reset_8390
= &ariadne2_reset_8390
;
214 ei_status
.block_input
= &ariadne2_block_input
;
215 ei_status
.block_output
= &ariadne2_block_output
;
216 ei_status
.get_8390_hdr
= &ariadne2_get_8390_hdr
;
217 ei_status
.reg_offset
= ariadne2_offsets
;
218 dev
->open
= &ariadne2_open
;
219 dev
->stop
= &ariadne2_close
;
224 static int ariadne2_open(struct net_device
*dev
)
231 static int ariadne2_close(struct net_device
*dev
)
234 printk("%s: Shutting down ethercard.\n", dev
->name
);
240 /* Hard reset the card. This used to pause for the same period that a
241 8390 reset command required, but that shouldn't be necessary. */
242 static void ariadne2_reset_8390(struct net_device
*dev
)
244 unsigned long reset_start_time
= jiffies
;
247 printk("resetting the 8390 t=%ld...", jiffies
);
249 writeb(readb(NE_BASE
+ NE_RESET
), NE_BASE
+ NE_RESET
);
252 ei_status
.dmaing
= 0;
254 /* This check _should_not_ be necessary, omit eventually. */
255 while ((readb(NE_BASE
+NE_EN0_ISR
) & ENISR_RESET
) == 0)
256 if (jiffies
- reset_start_time
> 2*HZ
/100) {
257 printk("%s: ne_reset_8390() did not complete.\n", dev
->name
);
260 writeb(ENISR_RESET
, NE_BASE
+ NE_EN0_ISR
); /* Ack intr. */
263 /* Grab the 8390 specific header. Similar to the block_input routine, but
264 we don't need to be concerned with ring wrap as the header will be at
265 the start of a page, so we optimize accordingly. */
267 static void ariadne2_get_8390_hdr(struct net_device
*dev
,
268 struct e8390_pkt_hdr
*hdr
, int ring_page
)
270 int nic_base
= dev
->base_addr
;
274 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
275 if (ei_status
.dmaing
) {
276 printk("%s: DMAing conflict in ne_get_8390_hdr "
277 "[DMAstat:%d][irqlock:%d][intr:%ld].\n", dev
->name
, ei_status
.dmaing
,
278 ei_status
.irqlock
, dev
->interrupt
);
282 ei_status
.dmaing
|= 0x01;
283 writeb(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
284 writeb(ENISR_RDC
, nic_base
+ NE_EN0_ISR
);
285 writeb(sizeof(struct e8390_pkt_hdr
), nic_base
+ NE_EN0_RCNTLO
);
286 writeb(0, nic_base
+ NE_EN0_RCNTHI
);
287 writeb(0, nic_base
+ NE_EN0_RSARLO
); /* On page boundary */
288 writeb(ring_page
, nic_base
+ NE_EN0_RSARHI
);
289 writeb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
292 for (cnt
= 0; cnt
< (sizeof(struct e8390_pkt_hdr
)>>1); cnt
++)
293 *ptrs
++ = readw(NE_BASE
+ NE_DATAPORT
);
295 writeb(ENISR_RDC
, nic_base
+ NE_EN0_ISR
); /* Ack intr. */
297 hdr
->count
= WORDSWAP(hdr
->count
);
299 ei_status
.dmaing
&= ~0x01;
302 /* Block input and output, similar to the Crynwr packet driver. If you
303 are porting to a new ethercard, look at the packet driver source for hints.
304 The NEx000 doesn't share the on-board packet memory -- you have to put
305 the packet out through the "remote DMA" dataport using writeb. */
307 static void ariadne2_block_input(struct net_device
*dev
, int count
,
308 struct sk_buff
*skb
, int ring_offset
)
310 int nic_base
= dev
->base_addr
;
311 char *buf
= skb
->data
;
315 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
316 if (ei_status
.dmaing
) {
317 printk("%s: DMAing conflict in ne_block_input "
318 "[DMAstat:%d][irqlock:%d][intr:%ld].\n",
319 dev
->name
, ei_status
.dmaing
, ei_status
.irqlock
,
323 ei_status
.dmaing
|= 0x01;
324 writeb(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
325 writeb(ENISR_RDC
, nic_base
+ NE_EN0_ISR
);
326 writeb(count
& 0xff, nic_base
+ NE_EN0_RCNTLO
);
327 writeb(count
>> 8, nic_base
+ NE_EN0_RCNTHI
);
328 writeb(ring_offset
& 0xff, nic_base
+ NE_EN0_RSARLO
);
329 writeb(ring_offset
>> 8, nic_base
+ NE_EN0_RSARHI
);
330 writeb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
332 for (cnt
= 0; cnt
< (count
>>1); cnt
++)
333 *ptrs
++ = readw(NE_BASE
+ NE_DATAPORT
);
335 buf
[count
-1] = readb(NE_BASE
+ NE_DATAPORT
);
337 writeb(ENISR_RDC
, nic_base
+ NE_EN0_ISR
); /* Ack intr. */
338 ei_status
.dmaing
&= ~0x01;
341 static void ariadne2_block_output(struct net_device
*dev
, int count
,
342 const unsigned char *buf
,
343 const int start_page
)
345 int nic_base
= NE_BASE
;
346 unsigned long dma_start
;
350 /* Round the count up for word writes. Do we need to do this?
351 What effect will an odd byte count have on the 8390?
352 I should check someday. */
356 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
357 if (ei_status
.dmaing
) {
358 printk("%s: DMAing conflict in ne_block_output."
359 "[DMAstat:%d][irqlock:%d][intr:%ld]\n", dev
->name
, ei_status
.dmaing
,
360 ei_status
.irqlock
, dev
->interrupt
);
363 ei_status
.dmaing
|= 0x01;
364 /* We should already be in page 0, but to be safe... */
365 writeb(E8390_PAGE0
+E8390_START
+E8390_NODMA
, nic_base
+ NE_CMD
);
367 writeb(ENISR_RDC
, nic_base
+ NE_EN0_ISR
);
369 /* Now the normal output. */
370 writeb(count
& 0xff, nic_base
+ NE_EN0_RCNTLO
);
371 writeb(count
>> 8, nic_base
+ NE_EN0_RCNTHI
);
372 writeb(0x00, nic_base
+ NE_EN0_RSARLO
);
373 writeb(start_page
, nic_base
+ NE_EN0_RSARHI
);
375 writeb(E8390_RWRITE
+E8390_START
, nic_base
+ NE_CMD
);
377 for (cnt
= 0; cnt
< count
>>1; cnt
++)
378 writew(*ptrs
++, NE_BASE
+NE_DATAPORT
);
382 while ((readb(NE_BASE
+ NE_EN0_ISR
) & ENISR_RDC
) == 0)
383 if (jiffies
- dma_start
> 2*HZ
/100) { /* 20ms */
384 printk("%s: timeout waiting for Tx RDC.\n", dev
->name
);
385 ariadne2_reset_8390(dev
);
390 writeb(ENISR_RDC
, nic_base
+ NE_EN0_ISR
); /* Ack intr. */
391 ei_status
.dmaing
&= ~0x01;
396 static char devicename
[9] = { 0, };
398 static struct net_device ariadne2_dev
=
403 0, 0, 0, NULL
, ariadne2_probe
,
406 int init_module(void)
409 if ((err
= register_netdev(&ariadne2_dev
))) {
411 printk("No AriadNE2 ethernet card found.\n");
418 void cleanup_module(void)
420 unsigned int key
= ((struct ei_device
*)ariadne2_dev
.priv
)->priv
;
421 free_irq(IRQ_AMIGA_PORTS
, &ariadne2_dev
);
422 unregister_netdev(&ariadne2_dev
);
423 zorro_unconfig_board(key
, 0);
424 unlock_8390_module();