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