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