ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / net / arm / am79c961a.c
1 /*
2  *  linux/drivers/net/am79c961.c
3  *
4  *  by Russell King <rmk@arm.linux.org.uk> 1995-2001.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * Derived from various things including skeleton.c
11  *
12  * This is a special driver for the am79c961A Lance chip used in the
13  * Intel (formally Digital Equipment Corp) EBSA110 platform.  Please
14  * note that this can not be built as a module (it doesn't make sense).
15  */
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/fcntl.h>
19 #include <linux/interrupt.h>
20 #include <linux/ioport.h>
21 #include <linux/in.h>
22 #include <linux/slab.h>
23 #include <linux/string.h>
24 #include <linux/errno.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/skbuff.h>
28 #include <linux/delay.h>
29 #include <linux/init.h>
30 #include <linux/crc32.h>
31
32 #include <asm/system.h>
33 #include <asm/bitops.h>
34 #include <asm/irq.h>
35 #include <asm/io.h>
36 #include <asm/dma.h>
37
38 #define TX_BUFFERS 15
39 #define RX_BUFFERS 25
40
41 #include "am79c961a.h"
42
43 static irqreturn_t
44 am79c961_interrupt (int irq, void *dev_id, struct pt_regs *regs);
45
46 static unsigned int net_debug = NET_DEBUG;
47
48 static const char version[] =
49         "am79c961 ethernet driver (C) 1995-2001 Russell King v0.04\n";
50
51 /* --------------------------------------------------------------------------- */
52
53 #ifdef __arm__
54 static void write_rreg(u_long base, u_int reg, u_int val)
55 {
56         __asm__("str%?h %1, [%2]        @ NET_RAP
57                 str%?h  %0, [%2, #-4]   @ NET_RDP
58                 " : : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464));
59 }
60
61 static inline unsigned short read_rreg(u_long base_addr, u_int reg)
62 {
63         unsigned short v;
64         __asm__("str%?h %1, [%2]        @ NET_RAP
65                 ldr%?h  %0, [%2, #-4]   @ NET_RDP
66                 " : "=r" (v): "r" (reg), "r" (ISAIO_BASE + 0x0464));
67         return v;
68 }
69
70 static inline void write_ireg(u_long base, u_int reg, u_int val)
71 {
72         __asm__("str%?h %1, [%2]        @ NET_RAP
73                 str%?h  %0, [%2, #8]    @ NET_IDP
74                 " : : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464));
75 }
76
77 static inline unsigned short read_ireg(u_long base_addr, u_int reg)
78 {
79         u_short v;
80         __asm__(
81         "str%?h %1, [%2]        @ NAT_RAP\n\t"
82         "str%?h %0, [%2, #8]    @ NET_IDP\n\t"
83         : "=r" (v)
84         : "r" (reg), "r" (ISAIO_BASE + 0x0464));
85         return v;
86 }
87
88 #define am_writeword(dev,off,val) __raw_writew(val, ISAMEM_BASE + ((off) << 1))
89 #define am_readword(dev,off)      __raw_readw(ISAMEM_BASE + ((off) << 1))
90
91 static inline void
92 am_writebuffer(struct net_device *dev, u_int offset, unsigned char *buf, unsigned int length)
93 {
94         offset = ISAMEM_BASE + (offset << 1);
95         length = (length + 1) & ~1;
96         if ((int)buf & 2) {
97                 __asm__ __volatile__("str%?h    %2, [%0], #4"
98                  : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8)));
99                 buf += 2;
100                 length -= 2;
101         }
102         while (length > 8) {
103                 unsigned int tmp, tmp2;
104                 __asm__ __volatile__("
105                         ldm%?ia %1!, {%2, %3}
106                         str%?h  %2, [%0], #4
107                         mov%?   %2, %2, lsr #16
108                         str%?h  %2, [%0], #4
109                         str%?h  %3, [%0], #4
110                         mov%?   %3, %3, lsr #16
111                         str%?h  %3, [%0], #4
112                 " : "=&r" (offset), "=&r" (buf), "=r" (tmp), "=r" (tmp2)
113                   : "0" (offset), "1" (buf));
114                 length -= 8;
115         }
116         while (length > 0) {
117                 __asm__ __volatile__("str%?h    %2, [%0], #4"
118                  : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8)));
119                 buf += 2;
120                 length -= 2;
121         }
122 }
123
124 static inline void
125 am_readbuffer(struct net_device *dev, u_int offset, unsigned char *buf, unsigned int length)
126 {
127         offset = ISAMEM_BASE + (offset << 1);
128         length = (length + 1) & ~1;
129         if ((int)buf & 2) {
130                 unsigned int tmp;
131                 __asm__ __volatile__("
132                         ldr%?h  %2, [%0], #4
133                         str%?b  %2, [%1], #1
134                         mov%?   %2, %2, lsr #8
135                         str%?b  %2, [%1], #1
136                 " : "=&r" (offset), "=&r" (buf), "=r" (tmp): "0" (offset), "1" (buf));
137                 length -= 2;
138         }
139         while (length > 8) {
140                 unsigned int tmp, tmp2, tmp3;
141                 __asm__ __volatile__("
142                         ldr%?h  %2, [%0], #4
143                         ldr%?h  %3, [%0], #4
144                         orr%?   %2, %2, %3, lsl #16
145                         ldr%?h  %3, [%0], #4
146                         ldr%?h  %4, [%0], #4
147                         orr%?   %3, %3, %4, lsl #16
148                         stm%?ia %1!, {%2, %3}
149                 " : "=&r" (offset), "=&r" (buf), "=r" (tmp), "=r" (tmp2), "=r" (tmp3)
150                   : "0" (offset), "1" (buf));
151                 length -= 8;
152         }
153         while (length > 0) {
154                 unsigned int tmp;
155                 __asm__ __volatile__("
156                         ldr%?h  %2, [%0], #4
157                         str%?b  %2, [%1], #1
158                         mov%?   %2, %2, lsr #8
159                         str%?b  %2, [%1], #1
160                 " : "=&r" (offset), "=&r" (buf), "=r" (tmp) : "0" (offset), "1" (buf));
161                 length -= 2;
162         }
163 }
164 #else
165 #error Not compatible
166 #endif
167
168 static int
169 am79c961_ramtest(struct net_device *dev, unsigned int val)
170 {
171         unsigned char *buffer = kmalloc (65536, GFP_KERNEL);
172         int i, error = 0, errorcount = 0;
173
174         if (!buffer)
175                 return 0;
176         memset (buffer, val, 65536);
177         am_writebuffer(dev, 0, buffer, 65536);
178         memset (buffer, val ^ 255, 65536);
179         am_readbuffer(dev, 0, buffer, 65536);
180         for (i = 0; i < 65536; i++) {
181                 if (buffer[i] != val && !error) {
182                         printk ("%s: buffer error (%02X %02X) %05X - ", dev->name, val, buffer[i], i);
183                         error = 1;
184                         errorcount ++;
185                 } else if (error && buffer[i] == val) {
186                         printk ("%05X\n", i);
187                         error = 0;
188                 }
189         }
190         if (error)
191                 printk ("10000\n");
192         kfree (buffer);
193         return errorcount;
194 }
195
196 static void
197 am79c961_init_for_open(struct net_device *dev)
198 {
199         struct dev_priv *priv = netdev_priv(dev);
200         unsigned long flags;
201         unsigned char *p;
202         u_int hdr_addr, first_free_addr;
203         int i;
204
205         /*
206          * Stop the chip.
207          */
208         spin_lock_irqsave(priv->chip_lock, flags);
209         write_rreg (dev->base_addr, CSR0, CSR0_BABL|CSR0_CERR|CSR0_MISS|CSR0_MERR|CSR0_TINT|CSR0_RINT|CSR0_STOP);
210         spin_unlock_irqrestore(priv->chip_lock, flags);
211
212         write_ireg (dev->base_addr, 5, 0x00a0); /* Receive address LED */
213         write_ireg (dev->base_addr, 6, 0x0081); /* Collision LED */
214         write_ireg (dev->base_addr, 7, 0x0090); /* XMIT LED */
215         write_ireg (dev->base_addr, 2, 0x0000); /* MODE register selects media */
216
217         for (i = LADRL; i <= LADRH; i++)
218                 write_rreg (dev->base_addr, i, 0);
219
220         for (i = PADRL, p = dev->dev_addr; i <= PADRH; i++, p += 2)
221                 write_rreg (dev->base_addr, i, p[0] | (p[1] << 8));
222
223         i = MODE_PORT_10BT;
224         if (dev->flags & IFF_PROMISC)
225                 i |= MODE_PROMISC;
226
227         write_rreg (dev->base_addr, MODE, i);
228         write_rreg (dev->base_addr, POLLINT, 0);
229         write_rreg (dev->base_addr, SIZERXR, -RX_BUFFERS);
230         write_rreg (dev->base_addr, SIZETXR, -TX_BUFFERS);
231
232         first_free_addr = RX_BUFFERS * 8 + TX_BUFFERS * 8 + 16;
233         hdr_addr = 0;
234
235         priv->rxhead = 0;
236         priv->rxtail = 0;
237         priv->rxhdr = hdr_addr;
238
239         for (i = 0; i < RX_BUFFERS; i++) {
240                 priv->rxbuffer[i] = first_free_addr;
241                 am_writeword (dev, hdr_addr, first_free_addr);
242                 am_writeword (dev, hdr_addr + 2, RMD_OWN);
243                 am_writeword (dev, hdr_addr + 4, (-1600));
244                 am_writeword (dev, hdr_addr + 6, 0);
245                 first_free_addr += 1600;
246                 hdr_addr += 8;
247         }
248         priv->txhead = 0;
249         priv->txtail = 0;
250         priv->txhdr = hdr_addr;
251         for (i = 0; i < TX_BUFFERS; i++) {
252                 priv->txbuffer[i] = first_free_addr;
253                 am_writeword (dev, hdr_addr, first_free_addr);
254                 am_writeword (dev, hdr_addr + 2, TMD_STP|TMD_ENP);
255                 am_writeword (dev, hdr_addr + 4, 0xf000);
256                 am_writeword (dev, hdr_addr + 6, 0);
257                 first_free_addr += 1600;
258                 hdr_addr += 8;
259         }
260
261         write_rreg (dev->base_addr, BASERXL, priv->rxhdr);
262         write_rreg (dev->base_addr, BASERXH, 0);
263         write_rreg (dev->base_addr, BASETXL, priv->txhdr);
264         write_rreg (dev->base_addr, BASERXH, 0);
265         write_rreg (dev->base_addr, CSR0, CSR0_STOP);
266         write_rreg (dev->base_addr, CSR3, CSR3_IDONM|CSR3_BABLM|CSR3_DXSUFLO);
267         write_rreg (dev->base_addr, CSR4, CSR4_APAD_XMIT|CSR4_MFCOM|CSR4_RCVCCOM|CSR4_TXSTRTM|CSR4_JABM);
268         write_rreg (dev->base_addr, CSR0, CSR0_IENA|CSR0_STRT);
269 }
270
271 static void am79c961_timer(unsigned long data)
272 {
273         struct net_device *dev = (struct net_device *)data;
274         struct dev_priv *priv = netdev_priv(dev);
275         unsigned int lnkstat, carrier;
276
277         lnkstat = read_ireg(dev->base_addr, ISALED0) & ISALED0_LNKST;
278         carrier = netif_carrier_ok(dev);
279
280         if (lnkstat && !carrier)
281                 netif_carrier_on(dev);
282         else if (!lnkstat && carrier)
283                 netif_carrier_off(dev);
284
285         mod_timer(&priv->timer, jiffies + 5*HZ);
286 }
287
288 /*
289  * Open/initialize the board.
290  */
291 static int
292 am79c961_open(struct net_device *dev)
293 {
294         struct dev_priv *priv = netdev_priv(dev);
295         int ret;
296
297         memset (&priv->stats, 0, sizeof (priv->stats));
298
299         ret = request_irq(dev->irq, am79c961_interrupt, 0, dev->name, dev);
300         if (ret)
301                 return ret;
302
303         am79c961_init_for_open(dev);
304
305         netif_carrier_off(dev);
306
307         priv->timer.expires = jiffies;
308         add_timer(&priv->timer);
309
310         netif_start_queue(dev);
311
312         return 0;
313 }
314
315 /*
316  * The inverse routine to am79c961_open().
317  */
318 static int
319 am79c961_close(struct net_device *dev)
320 {
321         struct dev_priv *priv = netdev_priv(dev);
322         unsigned long flags;
323
324         del_timer_sync(&priv->timer);
325
326         netif_stop_queue(dev);
327         netif_carrier_off(dev);
328
329         spin_lock_irqsave(priv->chip_lock, flags);
330         write_rreg (dev->base_addr, CSR0, CSR0_STOP);
331         write_rreg (dev->base_addr, CSR3, CSR3_MASKALL);
332         spin_unlock_irqrestore(priv->chip_lock, flags);
333
334         free_irq (dev->irq, dev);
335
336         return 0;
337 }
338
339 /*
340  * Get the current statistics.
341  */
342 static struct net_device_stats *am79c961_getstats (struct net_device *dev)
343 {
344         struct dev_priv *priv = netdev_priv(dev);
345         return &priv->stats;
346 }
347
348 static void am79c961_mc_hash(struct dev_mc_list *dmi, unsigned short *hash)
349 {
350         if (dmi->dmi_addrlen == ETH_ALEN && dmi->dmi_addr[0] & 0x01) {
351                 int idx, bit;
352                 u32 crc;
353
354                 crc = ether_crc_le(ETH_ALEN, dmi->dmi_addr);
355
356                 idx = crc >> 30;
357                 bit = (crc >> 26) & 15;
358
359                 hash[idx] |= 1 << bit;
360         }
361 }
362
363 /*
364  * Set or clear promiscuous/multicast mode filter for this adapter.
365  */
366 static void am79c961_setmulticastlist (struct net_device *dev)
367 {
368         struct dev_priv *priv = netdev_priv(dev);
369         unsigned long flags;
370         unsigned short multi_hash[4], mode;
371         int i, stopped;
372
373         mode = MODE_PORT_10BT;
374
375         if (dev->flags & IFF_PROMISC) {
376                 mode |= MODE_PROMISC;
377         } else if (dev->flags & IFF_ALLMULTI) {
378                 memset(multi_hash, 0xff, sizeof(multi_hash));
379         } else {
380                 struct dev_mc_list *dmi;
381
382                 memset(multi_hash, 0x00, sizeof(multi_hash));
383
384                 for (dmi = dev->mc_list; dmi; dmi = dmi->next)
385                         am79c961_mc_hash(dmi, multi_hash);
386         }
387
388         spin_lock_irqsave(priv->chip_lock, flags);
389
390         stopped = read_rreg(dev->base_addr, CSR0) & CSR0_STOP;
391
392         if (!stopped) {
393                 /*
394                  * Put the chip into suspend mode
395                  */
396                 write_rreg(dev->base_addr, CTRL1, CTRL1_SPND);
397
398                 /*
399                  * Spin waiting for chip to report suspend mode
400                  */
401                 while ((read_rreg(dev->base_addr, CTRL1) & CTRL1_SPND) == 0) {
402                         spin_unlock_irqrestore(priv->chip_lock, flags);
403                         nop();
404                         spin_lock_irqsave(priv->chip_lock, flags);
405                 }
406         }
407
408         /*
409          * Update the multicast hash table
410          */
411         for (i = 0; i < sizeof(multi_hash) / sizeof(multi_hash[0]); i++)
412                 write_rreg(dev->base_addr, i + LADRL, multi_hash[i]);
413
414         /*
415          * Write the mode register
416          */
417         write_rreg(dev->base_addr, MODE, mode);
418
419         if (!stopped) {
420                 /*
421                  * Put the chip back into running mode
422                  */
423                 write_rreg(dev->base_addr, CTRL1, 0);
424         }
425
426         spin_unlock_irqrestore(priv->chip_lock, flags);
427 }
428
429 static void am79c961_timeout(struct net_device *dev)
430 {
431         printk(KERN_WARNING "%s: transmit timed out, network cable problem?\n",
432                 dev->name);
433
434         /*
435          * ought to do some setup of the tx side here
436          */
437
438         netif_wake_queue(dev);
439 }
440
441 /*
442  * Transmit a packet
443  */
444 static int
445 am79c961_sendpacket(struct sk_buff *skb, struct net_device *dev)
446 {
447         struct dev_priv *priv = netdev_priv(dev);
448         unsigned int hdraddr, bufaddr;
449         unsigned int head;
450         unsigned long flags;
451
452         head = priv->txhead;
453         hdraddr = priv->txhdr + (head << 3);
454         bufaddr = priv->txbuffer[head];
455         head += 1;
456         if (head >= TX_BUFFERS)
457                 head = 0;
458
459         am_writebuffer (dev, bufaddr, skb->data, skb->len);
460         am_writeword (dev, hdraddr + 4, -skb->len);
461         am_writeword (dev, hdraddr + 2, TMD_OWN|TMD_STP|TMD_ENP);
462         priv->txhead = head;
463
464         spin_lock_irqsave(priv->chip_lock, flags);
465         write_rreg (dev->base_addr, CSR0, CSR0_TDMD|CSR0_IENA);
466         dev->trans_start = jiffies;
467         spin_unlock_irqrestore(priv->chip_lock, flags);
468
469         /*
470          * If the next packet is owned by the ethernet device,
471          * then the tx ring is full and we can't add another
472          * packet.
473          */
474         if (am_readword(dev, priv->txhdr + (priv->txhead << 3) + 2) & TMD_OWN)
475                 netif_stop_queue(dev);
476
477         dev_kfree_skb(skb);
478
479         return 0;
480 }
481
482 /*
483  * If we have a good packet(s), get it/them out of the buffers.
484  */
485 static void
486 am79c961_rx(struct net_device *dev, struct dev_priv *priv)
487 {
488         do {
489                 struct sk_buff *skb;
490                 u_int hdraddr;
491                 u_int pktaddr;
492                 u_int status;
493                 int len;
494
495                 hdraddr = priv->rxhdr + (priv->rxtail << 3);
496                 pktaddr = priv->rxbuffer[priv->rxtail];
497
498                 status = am_readword (dev, hdraddr + 2);
499                 if (status & RMD_OWN) /* do we own it? */
500                         break;
501
502                 priv->rxtail ++;
503                 if (priv->rxtail >= RX_BUFFERS)
504                         priv->rxtail = 0;
505
506                 if ((status & (RMD_ERR|RMD_STP|RMD_ENP)) != (RMD_STP|RMD_ENP)) {
507                         am_writeword (dev, hdraddr + 2, RMD_OWN);
508                         priv->stats.rx_errors ++;
509                         if (status & RMD_ERR) {
510                                 if (status & RMD_FRAM)
511                                         priv->stats.rx_frame_errors ++;
512                                 if (status & RMD_CRC)
513                                         priv->stats.rx_crc_errors ++;
514                         } else if (status & RMD_STP)
515                                 priv->stats.rx_length_errors ++;
516                         continue;
517                 }
518
519                 len = am_readword(dev, hdraddr + 6);
520                 skb = dev_alloc_skb(len + 2);
521
522                 if (skb) {
523                         skb->dev = dev;
524                         skb_reserve(skb, 2);
525
526                         am_readbuffer(dev, pktaddr, skb_put(skb, len), len);
527                         am_writeword(dev, hdraddr + 2, RMD_OWN);
528                         skb->protocol = eth_type_trans(skb, dev);
529                         netif_rx(skb);
530                         dev->last_rx = jiffies;
531                         priv->stats.rx_bytes += len;
532                         priv->stats.rx_packets ++;
533                 } else {
534                         am_writeword (dev, hdraddr + 2, RMD_OWN);
535                         printk (KERN_WARNING "%s: memory squeeze, dropping packet.\n", dev->name);
536                         priv->stats.rx_dropped ++;
537                         break;
538                 }
539         } while (1);
540 }
541
542 /*
543  * Update stats for the transmitted packet
544  */
545 static void
546 am79c961_tx(struct net_device *dev, struct dev_priv *priv)
547 {
548         do {
549                 short len;
550                 u_int hdraddr;
551                 u_int status;
552
553                 hdraddr = priv->txhdr + (priv->txtail << 3);
554                 status = am_readword (dev, hdraddr + 2);
555                 if (status & TMD_OWN)
556                         break;
557
558                 priv->txtail ++;
559                 if (priv->txtail >= TX_BUFFERS)
560                         priv->txtail = 0;
561
562                 if (status & TMD_ERR) {
563                         u_int status2;
564
565                         priv->stats.tx_errors ++;
566
567                         status2 = am_readword (dev, hdraddr + 6);
568
569                         /*
570                          * Clear the error byte
571                          */
572                         am_writeword (dev, hdraddr + 6, 0);
573
574                         if (status2 & TST_RTRY)
575                                 priv->stats.collisions += 16;
576                         if (status2 & TST_LCOL)
577                                 priv->stats.tx_window_errors ++;
578                         if (status2 & TST_LCAR)
579                                 priv->stats.tx_carrier_errors ++;
580                         if (status2 & TST_UFLO)
581                                 priv->stats.tx_fifo_errors ++;
582                         continue;
583                 }
584                 priv->stats.tx_packets ++;
585                 len = am_readword (dev, hdraddr + 4);
586                 priv->stats.tx_bytes += -len;
587         } while (priv->txtail != priv->txhead);
588
589         netif_wake_queue(dev);
590 }
591
592 static irqreturn_t
593 am79c961_interrupt(int irq, void *dev_id, struct pt_regs *regs)
594 {
595         struct net_device *dev = (struct net_device *)dev_id;
596         struct dev_priv *priv = netdev_priv(dev);
597         u_int status, n = 100;
598         int handled = 0;
599
600         do {
601                 status = read_rreg(dev->base_addr, CSR0);
602                 write_rreg(dev->base_addr, CSR0, status &
603                            (CSR0_IENA|CSR0_TINT|CSR0_RINT|
604                             CSR0_MERR|CSR0_MISS|CSR0_CERR|CSR0_BABL));
605
606                 if (status & CSR0_RINT) {
607                         handled = 1;
608                         am79c961_rx(dev, priv);
609                 }
610                 if (status & CSR0_TINT) {
611                         handled = 1;
612                         am79c961_tx(dev, priv);
613                 }
614                 if (status & CSR0_MISS) {
615                         handled = 1;
616                         priv->stats.rx_dropped ++;
617                 }
618                 if (status & CSR0_CERR) {
619                         handled = 1;
620                         mod_timer(&priv->timer, jiffies);
621         } while (--n && status & (CSR0_RINT | CSR0_TINT));
622
623         return IRQ_RETVAL(handled);
624 }
625
626 /*
627  * Initialise the chip.  Note that we always expect
628  * to be entered with interrupts enabled.
629  */
630 static int
631 am79c961_hw_init(struct net_device *dev)
632 {
633         struct dev_priv *priv = netdev_priv(dev);
634
635         spin_lock_irq(&priv->chip_lock);
636         write_rreg (dev->base_addr, CSR0, CSR0_STOP);
637         write_rreg (dev->base_addr, CSR3, CSR3_MASKALL);
638         spin_unlock_irq(&priv->chip_lock);
639
640         am79c961_ramtest(dev, 0x66);
641         am79c961_ramtest(dev, 0x99);
642
643         return 0;
644 }
645
646 static void __init am79c961_banner(void)
647 {
648         static unsigned version_printed;
649
650         if (net_debug && version_printed++ == 0)
651                 printk(KERN_INFO "%s", version);
652 }
653
654 static int __init am79c961_init(void)
655 {
656         struct net_device *dev;
657         struct dev_priv *priv;
658         int i, ret;
659
660         dev = alloc_etherdev(sizeof(struct dev_priv));
661         ret = -ENOMEM;
662         if (!dev)
663                 goto out;
664
665         priv = netdev_priv(dev);
666
667         /*
668          * Fixed address and IRQ lines here.
669          * The PNP initialisation should have been
670          * done by the ether bootp loader.
671          */
672         dev->base_addr = 0x220;
673         dev->irq = IRQ_EBSA110_ETHERNET;
674
675         ret = -ENODEV;
676         if (!request_region(dev->base_addr, 0x18, dev->name))
677                 goto nodev;
678
679         /*
680          * Reset the device.
681          */
682         inb(dev->base_addr + NET_RESET);
683         udelay(5);
684
685         /*
686          * Check the manufacturer part of the
687          * ether address.
688          */
689         if (inb(dev->base_addr) != 0x08 ||
690             inb(dev->base_addr + 2) != 0x00 ||
691             inb(dev->base_addr + 4) != 0x2b)
692                 goto release;
693
694         am79c961_banner();
695         printk(KERN_INFO "%s: ether address ", dev->name);
696
697         /* Retrive and print the ethernet address. */
698         for (i = 0; i < 6; i++) {
699                 dev->dev_addr[i] = inb(dev->base_addr + i * 2) & 0xff;
700                 printk (i == 5 ? "%02x\n" : "%02x:", dev->dev_addr[i]);
701         }
702
703         spin_lock_init(&priv->chip_lock);
704         init_timer(&priv->timer);
705         priv->timer.data = (unsigned long)dev;
706         priv->timer.function = am79c961_timer;
707
708         if (am79c961_hw_init(dev))
709                 goto release;
710
711         dev->open               = am79c961_open;
712         dev->stop               = am79c961_close;
713         dev->hard_start_xmit    = am79c961_sendpacket;
714         dev->get_stats          = am79c961_getstats;
715         dev->set_multicast_list = am79c961_setmulticastlist;
716         dev->tx_timeout         = am79c961_timeout;
717
718         ret = register_netdev(dev);
719         if (ret == 0)
720                 return 0;
721
722 release:
723         release_region(dev->base_addr, 0x18);
724 nodev:
725         free_netdev(dev);
726 out:
727         return ret;
728 }
729
730 __initcall(am79c961_init);