Linux-2.6.12-rc2
[GitHub/mt8127/android_kernel_alcatel_ttab.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 #include <linux/bitops.h>
32
33 #include <asm/system.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__(
57 "str%?h %1, [%2] @ NET_RAP\n\t"
58 "str%?h %0, [%2, #-4] @ NET_RDP"
59 :
60 : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464));
61 }
62
63 static inline unsigned short read_rreg(u_long base_addr, u_int reg)
64 {
65 unsigned short v;
66 __asm__(
67 "str%?h %1, [%2] @ NET_RAP\n\t"
68 "ldr%?h %0, [%2, #-4] @ NET_RDP"
69 : "=r" (v)
70 : "r" (reg), "r" (ISAIO_BASE + 0x0464));
71 return v;
72 }
73
74 static inline void write_ireg(u_long base, u_int reg, u_int val)
75 {
76 __asm__(
77 "str%?h %1, [%2] @ NET_RAP\n\t"
78 "str%?h %0, [%2, #8] @ NET_IDP"
79 :
80 : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464));
81 }
82
83 static inline unsigned short read_ireg(u_long base_addr, u_int reg)
84 {
85 u_short v;
86 __asm__(
87 "str%?h %1, [%2] @ NAT_RAP\n\t"
88 "str%?h %0, [%2, #8] @ NET_IDP\n\t"
89 : "=r" (v)
90 : "r" (reg), "r" (ISAIO_BASE + 0x0464));
91 return v;
92 }
93
94 #define am_writeword(dev,off,val) __raw_writew(val, ISAMEM_BASE + ((off) << 1))
95 #define am_readword(dev,off) __raw_readw(ISAMEM_BASE + ((off) << 1))
96
97 static inline void
98 am_writebuffer(struct net_device *dev, u_int offset, unsigned char *buf, unsigned int length)
99 {
100 offset = ISAMEM_BASE + (offset << 1);
101 length = (length + 1) & ~1;
102 if ((int)buf & 2) {
103 __asm__ __volatile__("str%?h %2, [%0], #4"
104 : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8)));
105 buf += 2;
106 length -= 2;
107 }
108 while (length > 8) {
109 unsigned int tmp, tmp2;
110 __asm__ __volatile__(
111 "ldm%?ia %1!, {%2, %3}\n\t"
112 "str%?h %2, [%0], #4\n\t"
113 "mov%? %2, %2, lsr #16\n\t"
114 "str%?h %2, [%0], #4\n\t"
115 "str%?h %3, [%0], #4\n\t"
116 "mov%? %3, %3, lsr #16\n\t"
117 "str%?h %3, [%0], #4"
118 : "=&r" (offset), "=&r" (buf), "=r" (tmp), "=r" (tmp2)
119 : "0" (offset), "1" (buf));
120 length -= 8;
121 }
122 while (length > 0) {
123 __asm__ __volatile__("str%?h %2, [%0], #4"
124 : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8)));
125 buf += 2;
126 length -= 2;
127 }
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 = ISAMEM_BASE + (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\n\t"
139 "str%?b %2, [%1], #1\n\t"
140 "mov%? %2, %2, lsr #8\n\t"
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\n\t"
149 "ldr%?h %3, [%0], #4\n\t"
150 "orr%? %2, %2, %3, lsl #16\n\t"
151 "ldr%?h %3, [%0], #4\n\t"
152 "ldr%?h %4, [%0], #4\n\t"
153 "orr%? %3, %3, %4, lsl #16\n\t"
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\n\t"
163 "str%?b %2, [%1], #1\n\t"
164 "mov%? %2, %2, lsr #8\n\t"
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 compatible
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 = netdev_priv(dev);
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, CSR4, CSR4_APAD_XMIT|CSR4_MFCOM|CSR4_RCVCCOM|CSR4_TXSTRTM|CSR4_JABM);
274 write_rreg (dev->base_addr, CSR0, CSR0_IENA|CSR0_STRT);
275 }
276
277 static void am79c961_timer(unsigned long data)
278 {
279 struct net_device *dev = (struct net_device *)data;
280 struct dev_priv *priv = netdev_priv(dev);
281 unsigned int lnkstat, carrier;
282
283 lnkstat = read_ireg(dev->base_addr, ISALED0) & ISALED0_LNKST;
284 carrier = netif_carrier_ok(dev);
285
286 if (lnkstat && !carrier)
287 netif_carrier_on(dev);
288 else if (!lnkstat && carrier)
289 netif_carrier_off(dev);
290
291 mod_timer(&priv->timer, jiffies + 5*HZ);
292 }
293
294 /*
295 * Open/initialize the board.
296 */
297 static int
298 am79c961_open(struct net_device *dev)
299 {
300 struct dev_priv *priv = netdev_priv(dev);
301 int ret;
302
303 memset (&priv->stats, 0, sizeof (priv->stats));
304
305 ret = request_irq(dev->irq, am79c961_interrupt, 0, dev->name, dev);
306 if (ret)
307 return ret;
308
309 am79c961_init_for_open(dev);
310
311 netif_carrier_off(dev);
312
313 priv->timer.expires = jiffies;
314 add_timer(&priv->timer);
315
316 netif_start_queue(dev);
317
318 return 0;
319 }
320
321 /*
322 * The inverse routine to am79c961_open().
323 */
324 static int
325 am79c961_close(struct net_device *dev)
326 {
327 struct dev_priv *priv = netdev_priv(dev);
328 unsigned long flags;
329
330 del_timer_sync(&priv->timer);
331
332 netif_stop_queue(dev);
333 netif_carrier_off(dev);
334
335 spin_lock_irqsave(priv->chip_lock, flags);
336 write_rreg (dev->base_addr, CSR0, CSR0_STOP);
337 write_rreg (dev->base_addr, CSR3, CSR3_MASKALL);
338 spin_unlock_irqrestore(priv->chip_lock, flags);
339
340 free_irq (dev->irq, dev);
341
342 return 0;
343 }
344
345 /*
346 * Get the current statistics.
347 */
348 static struct net_device_stats *am79c961_getstats (struct net_device *dev)
349 {
350 struct dev_priv *priv = netdev_priv(dev);
351 return &priv->stats;
352 }
353
354 static void am79c961_mc_hash(struct dev_mc_list *dmi, unsigned short *hash)
355 {
356 if (dmi->dmi_addrlen == ETH_ALEN && dmi->dmi_addr[0] & 0x01) {
357 int idx, bit;
358 u32 crc;
359
360 crc = ether_crc_le(ETH_ALEN, dmi->dmi_addr);
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 adapter.
371 */
372 static void am79c961_setmulticastlist (struct net_device *dev)
373 {
374 struct dev_priv *priv = netdev_priv(dev);
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 = netdev_priv(dev);
454 unsigned int hdraddr, bufaddr;
455 unsigned int head;
456 unsigned long flags;
457
458 head = priv->txhead;
459 hdraddr = priv->txhdr + (head << 3);
460 bufaddr = priv->txbuffer[head];
461 head += 1;
462 if (head >= TX_BUFFERS)
463 head = 0;
464
465 am_writebuffer (dev, bufaddr, skb->data, skb->len);
466 am_writeword (dev, hdraddr + 4, -skb->len);
467 am_writeword (dev, hdraddr + 2, TMD_OWN|TMD_STP|TMD_ENP);
468 priv->txhead = head;
469
470 spin_lock_irqsave(priv->chip_lock, flags);
471 write_rreg (dev->base_addr, CSR0, CSR0_TDMD|CSR0_IENA);
472 dev->trans_start = jiffies;
473 spin_unlock_irqrestore(priv->chip_lock, flags);
474
475 /*
476 * If the next packet is owned by the ethernet device,
477 * then the tx ring is full and we can't add another
478 * packet.
479 */
480 if (am_readword(dev, priv->txhdr + (priv->txhead << 3) + 2) & TMD_OWN)
481 netif_stop_queue(dev);
482
483 dev_kfree_skb(skb);
484
485 return 0;
486 }
487
488 /*
489 * If we have a good packet(s), get it/them out of the buffers.
490 */
491 static void
492 am79c961_rx(struct net_device *dev, struct dev_priv *priv)
493 {
494 do {
495 struct sk_buff *skb;
496 u_int hdraddr;
497 u_int pktaddr;
498 u_int status;
499 int len;
500
501 hdraddr = priv->rxhdr + (priv->rxtail << 3);
502 pktaddr = priv->rxbuffer[priv->rxtail];
503
504 status = am_readword (dev, hdraddr + 2);
505 if (status & RMD_OWN) /* do we own it? */
506 break;
507
508 priv->rxtail ++;
509 if (priv->rxtail >= RX_BUFFERS)
510 priv->rxtail = 0;
511
512 if ((status & (RMD_ERR|RMD_STP|RMD_ENP)) != (RMD_STP|RMD_ENP)) {
513 am_writeword (dev, hdraddr + 2, RMD_OWN);
514 priv->stats.rx_errors ++;
515 if (status & RMD_ERR) {
516 if (status & RMD_FRAM)
517 priv->stats.rx_frame_errors ++;
518 if (status & RMD_CRC)
519 priv->stats.rx_crc_errors ++;
520 } else if (status & RMD_STP)
521 priv->stats.rx_length_errors ++;
522 continue;
523 }
524
525 len = am_readword(dev, hdraddr + 6);
526 skb = dev_alloc_skb(len + 2);
527
528 if (skb) {
529 skb->dev = dev;
530 skb_reserve(skb, 2);
531
532 am_readbuffer(dev, pktaddr, skb_put(skb, len), len);
533 am_writeword(dev, hdraddr + 2, RMD_OWN);
534 skb->protocol = eth_type_trans(skb, dev);
535 netif_rx(skb);
536 dev->last_rx = jiffies;
537 priv->stats.rx_bytes += len;
538 priv->stats.rx_packets ++;
539 } else {
540 am_writeword (dev, hdraddr + 2, RMD_OWN);
541 printk (KERN_WARNING "%s: memory squeeze, dropping packet.\n", dev->name);
542 priv->stats.rx_dropped ++;
543 break;
544 }
545 } while (1);
546 }
547
548 /*
549 * Update stats for the transmitted packet
550 */
551 static void
552 am79c961_tx(struct net_device *dev, struct dev_priv *priv)
553 {
554 do {
555 short len;
556 u_int hdraddr;
557 u_int status;
558
559 hdraddr = priv->txhdr + (priv->txtail << 3);
560 status = am_readword (dev, hdraddr + 2);
561 if (status & TMD_OWN)
562 break;
563
564 priv->txtail ++;
565 if (priv->txtail >= TX_BUFFERS)
566 priv->txtail = 0;
567
568 if (status & TMD_ERR) {
569 u_int status2;
570
571 priv->stats.tx_errors ++;
572
573 status2 = am_readword (dev, hdraddr + 6);
574
575 /*
576 * Clear the error byte
577 */
578 am_writeword (dev, hdraddr + 6, 0);
579
580 if (status2 & TST_RTRY)
581 priv->stats.collisions += 16;
582 if (status2 & TST_LCOL)
583 priv->stats.tx_window_errors ++;
584 if (status2 & TST_LCAR)
585 priv->stats.tx_carrier_errors ++;
586 if (status2 & TST_UFLO)
587 priv->stats.tx_fifo_errors ++;
588 continue;
589 }
590 priv->stats.tx_packets ++;
591 len = am_readword (dev, hdraddr + 4);
592 priv->stats.tx_bytes += -len;
593 } while (priv->txtail != priv->txhead);
594
595 netif_wake_queue(dev);
596 }
597
598 static irqreturn_t
599 am79c961_interrupt(int irq, void *dev_id, struct pt_regs *regs)
600 {
601 struct net_device *dev = (struct net_device *)dev_id;
602 struct dev_priv *priv = netdev_priv(dev);
603 u_int status, n = 100;
604 int handled = 0;
605
606 do {
607 status = read_rreg(dev->base_addr, CSR0);
608 write_rreg(dev->base_addr, CSR0, status &
609 (CSR0_IENA|CSR0_TINT|CSR0_RINT|
610 CSR0_MERR|CSR0_MISS|CSR0_CERR|CSR0_BABL));
611
612 if (status & CSR0_RINT) {
613 handled = 1;
614 am79c961_rx(dev, priv);
615 }
616 if (status & CSR0_TINT) {
617 handled = 1;
618 am79c961_tx(dev, priv);
619 }
620 if (status & CSR0_MISS) {
621 handled = 1;
622 priv->stats.rx_dropped ++;
623 }
624 if (status & CSR0_CERR) {
625 handled = 1;
626 mod_timer(&priv->timer, jiffies);
627 }
628 } while (--n && status & (CSR0_RINT | CSR0_TINT));
629
630 return IRQ_RETVAL(handled);
631 }
632
633 #ifdef CONFIG_NET_POLL_CONTROLLER
634 static void am79c961_poll_controller(struct net_device *dev)
635 {
636 unsigned long flags;
637 local_irq_save(flags);
638 am79c961_interrupt(dev->irq, dev, NULL);
639 local_irq_restore(flags);
640 }
641 #endif
642
643 /*
644 * Initialise the chip. Note that we always expect
645 * to be entered with interrupts enabled.
646 */
647 static int
648 am79c961_hw_init(struct net_device *dev)
649 {
650 struct dev_priv *priv = netdev_priv(dev);
651
652 spin_lock_irq(&priv->chip_lock);
653 write_rreg (dev->base_addr, CSR0, CSR0_STOP);
654 write_rreg (dev->base_addr, CSR3, CSR3_MASKALL);
655 spin_unlock_irq(&priv->chip_lock);
656
657 am79c961_ramtest(dev, 0x66);
658 am79c961_ramtest(dev, 0x99);
659
660 return 0;
661 }
662
663 static void __init am79c961_banner(void)
664 {
665 static unsigned version_printed;
666
667 if (net_debug && version_printed++ == 0)
668 printk(KERN_INFO "%s", version);
669 }
670
671 static int __init am79c961_init(void)
672 {
673 struct net_device *dev;
674 struct dev_priv *priv;
675 int i, ret;
676
677 dev = alloc_etherdev(sizeof(struct dev_priv));
678 ret = -ENOMEM;
679 if (!dev)
680 goto out;
681
682 priv = netdev_priv(dev);
683
684 /*
685 * Fixed address and IRQ lines here.
686 * The PNP initialisation should have been
687 * done by the ether bootp loader.
688 */
689 dev->base_addr = 0x220;
690 dev->irq = IRQ_EBSA110_ETHERNET;
691
692 ret = -ENODEV;
693 if (!request_region(dev->base_addr, 0x18, dev->name))
694 goto nodev;
695
696 /*
697 * Reset the device.
698 */
699 inb(dev->base_addr + NET_RESET);
700 udelay(5);
701
702 /*
703 * Check the manufacturer part of the
704 * ether address.
705 */
706 if (inb(dev->base_addr) != 0x08 ||
707 inb(dev->base_addr + 2) != 0x00 ||
708 inb(dev->base_addr + 4) != 0x2b)
709 goto release;
710
711 am79c961_banner();
712 printk(KERN_INFO "%s: ether address ", dev->name);
713
714 /* Retrive and print the ethernet address. */
715 for (i = 0; i < 6; i++) {
716 dev->dev_addr[i] = inb(dev->base_addr + i * 2) & 0xff;
717 printk (i == 5 ? "%02x\n" : "%02x:", dev->dev_addr[i]);
718 }
719
720 spin_lock_init(&priv->chip_lock);
721 init_timer(&priv->timer);
722 priv->timer.data = (unsigned long)dev;
723 priv->timer.function = am79c961_timer;
724
725 if (am79c961_hw_init(dev))
726 goto release;
727
728 dev->open = am79c961_open;
729 dev->stop = am79c961_close;
730 dev->hard_start_xmit = am79c961_sendpacket;
731 dev->get_stats = am79c961_getstats;
732 dev->set_multicast_list = am79c961_setmulticastlist;
733 dev->tx_timeout = am79c961_timeout;
734 #ifdef CONFIG_NET_POLL_CONTROLLER
735 dev->poll_controller = am79c961_poll_controller;
736 #endif
737
738 ret = register_netdev(dev);
739 if (ret == 0)
740 return 0;
741
742 release:
743 release_region(dev->base_addr, 0x18);
744 nodev:
745 free_netdev(dev);
746 out:
747 return ret;
748 }
749
750 __initcall(am79c961_init);