2 net-3-driver for the IBM LAN Adapter/A
4 This is an extension to the Linux operating system, and is covered by the
5 same GNU General Public License that covers that work.
7 Copyright 1999 by Alfred Arnold (alfred@ccac.rwth-aachen.de, aarnold@elsa.de)
9 This driver is based both on the SK_MCA driver, which is itself based on the
10 SK_G16 and 3C523 driver.
13 'PC Hardware: Aufbau, Funktionsweise, Programmierung' by
14 Hans-Peter Messmer for the basic Microchannel stuff
16 'Linux Geraetetreiber' by Allesandro Rubini, Kalle Dalheimer
17 for help on Ethernet driver programming
19 'DP83934CVUL-20/25 MHz SONIC-T Ethernet Controller Datasheet' by National
20 Semiconductor for info on the MAC chip
22 'LAN Technical Reference Ethernet Adapter Interface Version 1 Release 1.0
23 Document Number SC30-3661-00' by IBM for info on the adapter itself
25 Also see http://www.natsemi.com/
27 special acknowledgements to:
28 - Bob Eager for helping me out with documentation from IBM
29 - Jim Shorney for his endless patience with me while I was using
30 him as a beta tester to trace down the address filter bug ;-)
34 -> set debug level via ioctl instead of compile-time switches
35 -> I didn't follow the development of the 2.1.x kernels, so my
36 assumptions about which things changed with which kernel version
41 startup from SK_MCA driver
43 finally got docs about the card. A big thank you to Bob Eager!
47 recv queue done, tcpdump works
49 transmission part works
51 added usage of the isa_functions for Linux 2.3 . Things should
52 still work with 2.0.x....
54 in Linux 2.2.13, the version.h file mysteriously didn't get
55 included. Added a workaround for this. Futhermore, it now
56 not only compiles as a modules ;-)
58 newer kernels automatically probe more than one board, so the
59 'startslot' as a variable is also needed here
61 the interrupt mask register is not set 'hard' instead of individually
62 setting registers, since this seems to set bits that shouldn't be
65 reset interrupt status immediately after CAM load
66 add a recovery delay after releasing the chip's reset line
68 finally found the bug in the address filter setup - damned signed
71 corrected version codes, added support for the latest 2.3 changes
73 cleaned up for the 2.5 tree <alan@redhat.com>
75 *************************************************************************/
77 #include <linux/kernel.h>
78 #include <linux/string.h>
79 #include <linux/errno.h>
80 #include <linux/ioport.h>
81 #include <linux/slab.h>
82 #include <linux/interrupt.h>
83 #include <linux/delay.h>
84 #include <linux/time.h>
85 #include <linux/mca-legacy.h>
86 #include <linux/module.h>
87 #include <linux/netdevice.h>
88 #include <linux/etherdevice.h>
89 #include <linux/skbuff.h>
91 #include <asm/processor.h>
92 #include <asm/bitops.h>
95 #define _IBM_LANA_DRIVER_
100 /* ------------------------------------------------------------------------
101 * global static data - not more since we can handle multiple boards and
102 * have to pack all state info into the device struct!
103 * ------------------------------------------------------------------------ */
105 static char *MediaNames[Media_Count] = {
106 "10BaseT", "10Base5", "Unknown", "10Base2"
109 /* ------------------------------------------------------------------------
110 * private subfunctions
111 * ------------------------------------------------------------------------ */
114 /* dump all registers */
116 static void dumpregs(struct net_device *dev)
120 for (z = 0; z < 160; z += 2) {
122 printk("REGS: %04x:", z);
123 printk(" %04x", inw(dev->base_addr + z));
129 /* dump parts of shared memory - only needed during debugging */
131 static void dumpmem(struct net_device *dev, u32 start, u32 len)
135 printk("Address %04x:\n", start);
136 for (z = 0; z < len; z++) {
139 printk(" %02x", isa_readb(dev->mem_start + start + z));
147 /* print exact time - ditto */
149 static void PrTime(void)
153 do_gettimeofday(&tv);
154 printk("%9d:%06d: ", (int) tv.tv_sec, (int) tv.tv_usec);
158 /* deduce resources out of POS registers */
160 static void getaddrs(int slot, int *base, int *memlen, int *iobase,
161 int *irq, ibmlana_medium * medium)
165 pos0 = mca_read_stored_pos(slot, 2);
166 pos1 = mca_read_stored_pos(slot, 3);
168 *base = 0xc0000 + ((pos1 & 0xf0) << 9);
169 *memlen = (pos1 & 0x01) ? 0x8000 : 0x4000;
170 *iobase = (pos0 & 0xe0) << 7;
171 switch (pos0 & 0x06) {
185 *medium = (pos0 & 0x18) >> 3;
188 /* wait on register value with mask and timeout */
190 static int wait_timeout(struct net_device *dev, int regoffs, u16 mask,
191 u16 value, int timeout)
193 unsigned long fin = jiffies + timeout;
195 while (time_before(jiffies,fin))
196 if ((inw(dev->base_addr + regoffs) & mask) == value)
203 /* reset the whole board */
205 static void ResetBoard(struct net_device *dev)
207 unsigned char bcmval;
209 /* read original board control value */
211 bcmval = inb(dev->base_addr + BCMREG);
213 /* set reset bit for a while */
215 bcmval |= BCMREG_RESET;
216 outb(bcmval, dev->base_addr + BCMREG);
218 bcmval &= ~BCMREG_RESET;
219 outb(bcmval, dev->base_addr + BCMREG);
221 /* switch over to RAM again */
223 bcmval |= BCMREG_RAMEN | BCMREG_RAMWIN;
224 outb(bcmval, dev->base_addr + BCMREG);
227 /* calculate RAM layout & set up descriptors in RAM */
229 static void InitDscrs(struct net_device *dev)
231 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
232 u32 addr, baddr, raddr;
240 isa_memset_io(dev->mem_start, 0xaa,
241 dev->mem_start - dev->mem_start);
243 /* setup n TX descriptors - independent of RAM size */
245 priv->tdastart = addr = 0;
246 priv->txbufstart = baddr = sizeof(tda_t) * TXBUFCNT;
247 for (z = 0; z < TXBUFCNT; z++) {
255 if (z == TXBUFCNT - 1)
256 tda.link = priv->tdastart;
258 tda.link = addr + sizeof(tda_t);
260 isa_memcpy_toio(dev->mem_start + addr, &tda, sizeof(tda_t));
261 addr += sizeof(tda_t);
265 /* calculate how many receive buffers fit into remaining memory */
267 priv->rxbufcnt = (dev->mem_end - dev->mem_start - baddr) / (sizeof(rra_t) + sizeof(rda_t) + PKTSIZE);
269 /* calculate receive addresses */
271 priv->rrastart = raddr = priv->txbufstart + (TXBUFCNT * PKTSIZE);
272 priv->rdastart = addr = priv->rrastart + (priv->rxbufcnt * sizeof(rra_t));
273 priv->rxbufstart = baddr = priv->rdastart + (priv->rxbufcnt * sizeof(rda_t));
275 for (z = 0; z < priv->rxbufcnt; z++) {
278 rra.cntlo = PKTSIZE >> 1;
280 isa_memcpy_toio(dev->mem_start + raddr, &rra, sizeof(rra_t));
287 if (z < priv->rxbufcnt - 1)
288 rda.link = addr + sizeof(rda_t);
292 isa_memcpy_toio(dev->mem_start + addr, &rda, sizeof(rda_t));
295 raddr += sizeof(rra_t);
296 addr += sizeof(rda_t);
299 /* initialize current pointers */
301 priv->nextrxdescr = 0;
302 priv->lastrxdescr = priv->rxbufcnt - 1;
303 priv->nexttxdescr = 0;
304 priv->currtxdescr = 0;
306 memset(priv->txused, 0, sizeof(priv->txused));
309 /* set up Rx + Tx descriptors in SONIC */
311 static int InitSONIC(struct net_device *dev)
313 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
315 /* set up start & end of resource area */
318 outw(priv->rrastart, dev->base_addr + SONIC_RSA);
319 outw(priv->rrastart + (priv->rxbufcnt * sizeof(rra_t)), dev->base_addr + SONIC_REA);
320 outw(priv->rrastart, dev->base_addr + SONIC_RRP);
321 outw(priv->rrastart, dev->base_addr + SONIC_RWP);
323 /* set EOBC so that only one packet goes into one buffer */
325 outw((PKTSIZE - 4) >> 1, dev->base_addr + SONIC_EOBC);
327 /* let SONIC read the first RRA descriptor */
329 outw(CMDREG_RRRA, dev->base_addr + SONIC_CMDREG);
330 if (!wait_timeout(dev, SONIC_CMDREG, CMDREG_RRRA, 0, 2)) {
331 printk(KERN_ERR "%s: SONIC did not respond on RRRA command - giving up.", dev->name);
335 /* point SONIC to the first RDA */
337 outw(0, dev->base_addr + SONIC_URDA);
338 outw(priv->rdastart, dev->base_addr + SONIC_CRDA);
340 /* set upper half of TDA address */
342 outw(0, dev->base_addr + SONIC_UTDA);
347 /* stop SONIC so we can reinitialize it */
349 static void StopSONIC(struct net_device *dev)
351 /* disable interrupts */
353 outb(inb(dev->base_addr + BCMREG) & (~BCMREG_IEN), dev->base_addr + BCMREG);
354 outb(0, dev->base_addr + SONIC_IMREG);
356 /* reset the SONIC */
358 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
360 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
363 /* initialize card and SONIC for proper operation */
365 static void putcam(camentry_t * cams, int *camcnt, char *addr)
367 camentry_t *pcam = cams + (*camcnt);
368 u8 *uaddr = (u8 *) addr;
370 pcam->index = *camcnt;
371 pcam->addr0 = (((u16) uaddr[1]) << 8) | uaddr[0];
372 pcam->addr1 = (((u16) uaddr[3]) << 8) | uaddr[2];
373 pcam->addr2 = (((u16) uaddr[5]) << 8) | uaddr[4];
377 static void InitBoard(struct net_device *dev)
382 struct dev_mc_list *mcptr;
385 /* reset the SONIC */
387 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
390 /* clear all spurious interrupts */
392 outw(inw(dev->base_addr + SONIC_ISREG), dev->base_addr + SONIC_ISREG);
394 /* set up the SONIC's bus interface - constant for this adapter -
395 must be done while the SONIC is in reset */
397 outw(DCREG_USR1 | DCREG_USR0 | DCREG_WC1 | DCREG_DW32, dev->base_addr + SONIC_DCREG);
398 outw(0, dev->base_addr + SONIC_DCREG2);
400 /* remove reset form the SONIC */
402 outw(0, dev->base_addr + SONIC_CMDREG);
405 /* data sheet requires URRA to be programmed before setting up the CAM contents */
407 outw(0, dev->base_addr + SONIC_URRA);
409 /* program the CAM entry 0 to the device address */
412 putcam(cams, &camcnt, dev->dev_addr);
414 /* start putting the multicast addresses into the CAM list. Stop if
417 for (mcptr = dev->mc_list; mcptr != NULL; mcptr = mcptr->next) {
418 putcam(cams, &camcnt, mcptr->dmi_addr);
423 /* calculate CAM mask */
425 cammask = (1 << camcnt) - 1;
427 /* feed CDA into SONIC, initialize RCR value (always get broadcasts) */
429 isa_memcpy_toio(dev->mem_start, cams, sizeof(camentry_t) * camcnt);
430 isa_memcpy_toio(dev->mem_start + (sizeof(camentry_t) * camcnt), &cammask, sizeof(cammask));
433 printk("CAM setup:\n");
434 dumpmem(dev, 0, sizeof(camentry_t) * camcnt + sizeof(cammask));
437 outw(0, dev->base_addr + SONIC_CAMPTR);
438 outw(camcnt, dev->base_addr + SONIC_CAMCNT);
439 outw(CMDREG_LCAM, dev->base_addr + SONIC_CMDREG);
440 if (!wait_timeout(dev, SONIC_CMDREG, CMDREG_LCAM, 0, 2)) {
441 printk(KERN_ERR "%s:SONIC did not respond on LCAM command - giving up.", dev->name);
444 /* clear interrupt condition */
446 outw(ISREG_LCD, dev->base_addr + SONIC_ISREG);
449 printk("Loading CAM done, address pointers %04x:%04x\n",
450 inw(dev->base_addr + SONIC_URRA),
451 inw(dev->base_addr + SONIC_CAMPTR));
455 printk("\n-->CAM: PTR %04x CNT %04x\n",
456 inw(dev->base_addr + SONIC_CAMPTR),
457 inw(dev->base_addr + SONIC_CAMCNT));
458 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
459 for (z = 0; z < camcnt; z++) {
460 outw(z, dev->base_addr + SONIC_CAMEPTR);
461 printk("Entry %d: %04x %04x %04x\n", z,
462 inw(dev->base_addr + SONIC_CAMADDR0),
463 inw(dev->base_addr + SONIC_CAMADDR1),
464 inw(dev->base_addr + SONIC_CAMADDR2));
466 outw(0, dev->base_addr + SONIC_CMDREG);
471 rcrval = RCREG_BRD | RCREG_LB_NONE;
473 /* if still multicast addresses left or ALLMULTI is set, set the multicast
476 if ((dev->flags & IFF_ALLMULTI) || (mcptr != NULL))
479 /* promiscous mode ? */
481 if (dev->flags & IFF_PROMISC)
484 /* program receive mode */
486 outw(rcrval, dev->base_addr + SONIC_RCREG);
488 printk("\nRCRVAL: %04x\n", rcrval);
491 /* set up descriptors in shared memory + feed them into SONIC registers */
497 /* reset all pending interrupts */
499 outw(0xffff, dev->base_addr + SONIC_ISREG);
501 /* enable transmitter + receiver interrupts */
503 outw(CMDREG_RXEN, dev->base_addr + SONIC_CMDREG);
504 outw(IMREG_PRXEN | IMREG_RBEEN | IMREG_PTXEN | IMREG_TXEREN, dev->base_addr + SONIC_IMREG);
506 /* turn on card interrupts */
508 outb(inb(dev->base_addr + BCMREG) | BCMREG_IEN, dev->base_addr + BCMREG);
511 printk("Register dump after initialization:\n");
516 /* start transmission of a descriptor */
518 static void StartTx(struct net_device *dev, int descr)
520 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
523 addr = priv->tdastart + (descr * sizeof(tda_t));
525 /* put descriptor address into SONIC */
527 outw(addr, dev->base_addr + SONIC_CTDA);
529 /* trigger transmitter */
531 priv->currtxdescr = descr;
532 outw(CMDREG_TXP, dev->base_addr + SONIC_CMDREG);
535 /* ------------------------------------------------------------------------
536 * interrupt handler(s)
537 * ------------------------------------------------------------------------ */
539 /* receive buffer area exhausted */
541 static void irqrbe_handler(struct net_device *dev)
543 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
545 /* point the SONIC back to the RRA start */
547 outw(priv->rrastart, dev->base_addr + SONIC_RRP);
548 outw(priv->rrastart, dev->base_addr + SONIC_RWP);
551 /* receive interrupt */
553 static void irqrx_handler(struct net_device *dev)
555 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
557 u32 rdaaddr, lrdaaddr;
562 /* read descriptor that was next to be filled by SONIC */
564 rdaaddr = priv->rdastart + (priv->nextrxdescr * sizeof(rda_t));
565 lrdaaddr = priv->rdastart + (priv->lastrxdescr * sizeof(rda_t));
566 isa_memcpy_fromio(&rda, dev->mem_start + rdaaddr, sizeof(rda_t));
568 /* iron out upper word halves of fields we use - SONIC will duplicate
569 bits 0..15 to 16..31 */
571 rda.status &= 0xffff;
572 rda.length &= 0xffff;
573 rda.startlo &= 0xffff;
575 /* stop if the SONIC still owns it, i.e. there is no data for us */
582 else if (rda.status & RCREG_PRX) {
587 skb = dev_alloc_skb(rda.length + 2);
589 priv->stat.rx_dropped++;
593 isa_memcpy_fromio(skb_put(skb, rda.length),
595 rda.startlo, rda.length);
597 /* set up skb fields */
600 skb->protocol = eth_type_trans(skb, dev);
601 skb->ip_summed = CHECKSUM_NONE;
604 dev->last_rx = jiffies;
605 priv->stat.rx_packets++;
606 priv->stat.rx_bytes += rda.length;
608 /* pass to the upper layers */
613 /* otherwise check error status bits and increase statistics */
616 priv->stat.rx_errors++;
617 if (rda.status & RCREG_FAER)
618 priv->stat.rx_frame_errors++;
619 if (rda.status & RCREG_CRCR)
620 priv->stat.rx_crc_errors++;
623 /* descriptor processed, will become new last descriptor in queue */
627 isa_memcpy_toio(dev->mem_start + rdaaddr, &rda,
630 /* set up link and EOL = 0 in currently last descriptor. Only write
631 the link field since the SONIC may currently already access the
634 isa_memcpy_toio(dev->mem_start + lrdaaddr + 20, &rdaaddr, 4);
636 /* advance indices */
638 priv->lastrxdescr = priv->nextrxdescr;
639 if ((++priv->nextrxdescr) >= priv->rxbufcnt)
640 priv->nextrxdescr = 0;
644 /* transmit interrupt */
646 static void irqtx_handler(struct net_device *dev)
648 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
651 /* fetch descriptor (we forgot the size ;-) */
652 isa_memcpy_fromio(&tda, dev->mem_start + priv->tdastart + (priv->currtxdescr * sizeof(tda_t)), sizeof(tda_t));
654 /* update statistics */
655 priv->stat.tx_packets++;
656 priv->stat.tx_bytes += tda.length;
658 /* update our pointers */
659 priv->txused[priv->currtxdescr] = 0;
662 /* if there are more descriptors present in RAM, start them */
663 if (priv->txusedcnt > 0)
664 StartTx(dev, (priv->currtxdescr + 1) % TXBUFCNT);
666 /* tell the upper layer we can go on transmitting */
667 netif_wake_queue(dev);
670 static void irqtxerr_handler(struct net_device *dev)
672 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
675 /* fetch descriptor to check status */
676 isa_memcpy_fromio(&tda, dev->mem_start + priv->tdastart + (priv->currtxdescr * sizeof(tda_t)), sizeof(tda_t));
678 /* update statistics */
679 priv->stat.tx_errors++;
680 if (tda.status & (TCREG_NCRS | TCREG_CRSL))
681 priv->stat.tx_carrier_errors++;
682 if (tda.status & TCREG_EXC)
683 priv->stat.tx_aborted_errors++;
684 if (tda.status & TCREG_OWC)
685 priv->stat.tx_window_errors++;
686 if (tda.status & TCREG_FU)
687 priv->stat.tx_fifo_errors++;
689 /* update our pointers */
690 priv->txused[priv->currtxdescr] = 0;
693 /* if there are more descriptors present in RAM, start them */
694 if (priv->txusedcnt > 0)
695 StartTx(dev, (priv->currtxdescr + 1) % TXBUFCNT);
697 /* tell the upper layer we can go on transmitting */
698 netif_wake_queue(dev);
701 /* general interrupt entry */
703 static irqreturn_t irq_handler(int irq, void *device, struct pt_regs *regs)
705 struct net_device *dev = (struct net_device *) device;
708 /* in case we're not meant... */
709 if (!(inb(dev->base_addr + BCMREG) & BCMREG_IPEND))
712 /* loop through the interrupt bits until everything is clear */
714 ival = inw(dev->base_addr + SONIC_ISREG);
716 if (ival & ISREG_RBE) {
718 outw(ISREG_RBE, dev->base_addr + SONIC_ISREG);
720 if (ival & ISREG_PKTRX) {
722 outw(ISREG_PKTRX, dev->base_addr + SONIC_ISREG);
724 if (ival & ISREG_TXDN) {
726 outw(ISREG_TXDN, dev->base_addr + SONIC_ISREG);
728 if (ival & ISREG_TXER) {
729 irqtxerr_handler(dev);
730 outw(ISREG_TXER, dev->base_addr + SONIC_ISREG);
737 /* ------------------------------------------------------------------------
739 * ------------------------------------------------------------------------ */
743 static int ibmlana_getinfo(char *buf, int slot, void *d)
746 struct net_device *dev = (struct net_device *) d;
749 /* can't say anything about an uninitialized device... */
753 if (dev->priv == NULL)
755 priv = (ibmlana_priv *) dev->priv;
759 len += sprintf(buf + len, "IRQ: %d\n", priv->realirq);
760 len += sprintf(buf + len, "I/O: %#lx\n", dev->base_addr);
761 len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start, dev->mem_end - 1);
762 len += sprintf(buf + len, "Transceiver: %s\n", MediaNames[priv->medium]);
763 len += sprintf(buf + len, "Device: %s\n", dev->name);
764 len += sprintf(buf + len, "MAC address:");
765 for (i = 0; i < 6; i++)
766 len += sprintf(buf + len, " %02x", dev->dev_addr[i]);
773 /* open driver. Means also initialization and start of LANCE */
775 static int ibmlana_open(struct net_device *dev)
778 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
780 /* register resources - only necessary for IRQ */
782 result = request_irq(priv->realirq, irq_handler, SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
784 printk(KERN_ERR "%s: failed to register irq %d\n", dev->name, dev->irq);
787 dev->irq = priv->realirq;
789 /* set up the card and SONIC */
792 /* initialize operational flags */
793 netif_start_queue(dev);
797 /* close driver. Shut down board and free allocated resources */
799 static int ibmlana_close(struct net_device *dev)
803 /* release resources */
805 free_irq(dev->irq, dev);
810 /* transmit a block. */
812 static int ibmlana_tx(struct sk_buff *skb, struct net_device *dev)
814 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
815 int retval = 0, tmplen, addr;
820 /* find out if there are free slots for a frame to transmit. If not,
821 the upper layer is in deep desperation and we simply ignore the frame. */
823 if (priv->txusedcnt >= TXBUFCNT) {
825 priv->stat.tx_dropped++;
829 /* copy the frame data into the next free transmit buffer - fillup missing */
833 baddr = priv->txbufstart + (priv->nexttxdescr * PKTSIZE);
834 isa_memcpy_toio(dev->mem_start + baddr, skb->data, skb->len);
836 /* copy filler into RAM - in case we're filling up...
837 we're filling a bit more than necessary, but that doesn't harm
838 since the buffer is far larger...
839 Sorry Linus for the filler string but I couldn't resist ;-) */
841 if (tmplen > skb->len) {
842 char *fill = "NetBSD is a nice OS too! ";
843 unsigned int destoffs = skb->len, l = strlen(fill);
845 while (destoffs < tmplen) {
846 isa_memcpy_toio(dev->mem_start + baddr + destoffs, fill, l);
851 /* set up the new frame descriptor */
852 addr = priv->tdastart + (priv->nexttxdescr * sizeof(tda_t));
853 isa_memcpy_fromio(&tda, dev->mem_start + addr, sizeof(tda_t));
854 tda.length = tda.fraglength = tmplen;
855 isa_memcpy_toio(dev->mem_start + addr, &tda, sizeof(tda_t));
857 /* if there were no active descriptors, trigger the SONIC */
858 spin_lock_irqsave(&priv->lock, flags);
861 priv->txused[priv->nexttxdescr] = 1;
863 /* are all transmission slots used up ? */
864 if (priv->txusedcnt >= TXBUFCNT)
865 netif_stop_queue(dev);
867 if (priv->txusedcnt == 1)
868 StartTx(dev, priv->nexttxdescr);
869 priv->nexttxdescr = (priv->nexttxdescr + 1) % TXBUFCNT;
871 spin_unlock_irqrestore(&priv->lock, flags);
877 /* return pointer to Ethernet statistics */
879 static struct net_device_stats *ibmlana_stats(struct net_device *dev)
881 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
885 /* we don't support runtime reconfiguration, since am MCA card can
886 be unambigously identified by its POS registers. */
888 static int ibmlana_config(struct net_device *dev, struct ifmap *map)
893 /* switch receiver mode. */
895 static void ibmlana_set_multicast_list(struct net_device *dev)
897 /* first stop the SONIC... */
899 /* ...then reinit it with the new flags */
903 /* ------------------------------------------------------------------------
905 * ------------------------------------------------------------------------ */
907 static int startslot; /* counts through slots when probing multiple devices */
909 static int ibmlana_probe(struct net_device *dev)
911 int force_detect = 0;
913 int base = 0, irq = 0, iobase = 0, memlen = 0;
915 ibmlana_medium medium;
917 SET_MODULE_OWNER(dev);
919 /* can't work without an MCA bus ;-) */
923 /* start address of 1 --> forced detection */
924 if (dev->mem_start == 1)
927 base = dev->mem_start;
930 for (slot = startslot; (slot = mca_find_adapter(IBM_LANA_ID, slot)) != -1; slot++) {
931 /* deduce card addresses */
932 getaddrs(slot, &base, &memlen, &iobase, &irq, &medium);
934 /* slot already in use ? */
935 if (mca_is_adapter_used(slot))
937 /* were we looking for something different ? */
938 if (dev->irq && dev->irq != irq)
940 if (dev->mem_start && dev->mem_start != base)
942 /* found something that matches */
946 /* nothing found ? */
948 return (base != 0 || irq != 0) ? -ENXIO : -ENODEV;
950 /* announce success */
951 printk(KERN_INFO "%s: IBM LAN Adapter/A found in slot %d\n", dev->name, slot + 1);
953 /* try to obtain I/O range */
954 if (!request_region(iobase, IBM_LANA_IORANGE, dev->name)) {
955 printk(KERN_ERR "%s: cannot allocate I/O range at %#x!\n", dev->name, iobase);
956 startslot = slot + 1;
960 /* make procfs entries */
961 mca_set_adapter_name(slot, "IBM LAN Adapter/A");
962 mca_set_adapter_procfn(slot, (MCA_ProcFn) ibmlana_getinfo, dev);
964 mca_mark_as_used(slot);
966 /* allocate structure */
970 priv->medium = medium;
971 spin_lock_init(&priv->lock);
973 /* set base + irq for this device (irq not allocated so far) */
976 dev->mem_start = base;
977 dev->mem_end = base + memlen;
978 dev->base_addr = iobase;
982 dev->open = ibmlana_open;
983 dev->stop = ibmlana_close;
984 dev->set_config = ibmlana_config;
985 dev->hard_start_xmit = ibmlana_tx;
986 dev->do_ioctl = NULL;
987 dev->get_stats = ibmlana_stats;
988 dev->set_multicast_list = ibmlana_set_multicast_list;
989 dev->flags |= IFF_MULTICAST;
991 /* copy out MAC address */
993 for (z = 0; z < sizeof(dev->dev_addr); z++)
994 dev->dev_addr[z] = inb(dev->base_addr + MACADDRPROM + z);
998 printk(KERN_INFO "%s: IRQ %d, I/O %#lx, memory %#lx-%#lx, "
999 "MAC address %02x:%02x:%02x:%02x:%02x:%02x.\n",
1000 dev->name, priv->realirq, dev->base_addr,
1001 dev->mem_start, dev->mem_end - 1,
1002 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1003 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1004 printk(KERN_INFO "%s: %s medium\n", dev->name, MediaNames[priv->medium]);
1010 /* next probe will start at next slot */
1012 startslot = slot + 1;
1017 /* ------------------------------------------------------------------------
1018 * modularization support
1019 * ------------------------------------------------------------------------ */
1025 static struct net_device *moddevs[DEVMAX];
1029 MODULE_PARM(irq, "i");
1030 MODULE_PARM(io, "i");
1031 MODULE_PARM_DESC(irq, "IBM LAN/A IRQ number");
1032 MODULE_PARM_DESC(io, "IBM LAN/A I/O base address");
1033 MODULE_LICENSE("GPL");
1035 int init_module(void)
1040 for (z = 0; z < DEVMAX; z++) {
1041 struct net_device *dev = alloc_etherdev(sizeof(ibmlana_priv));
1045 dev->base_addr = io;
1046 if (ibmlana_probe(dev)) {
1050 if (register_netdev(dev)) {
1051 ibmlana_priv *priv = dev->priv;
1052 release_region(dev->base_addr, IBM_LANA_IORANGE);
1053 mca_mark_as_unused(priv->slot);
1054 mca_set_adapter_name(priv->slot, "");
1055 mca_set_adapter_procfn(priv->slot, NULL, NULL);
1061 return (z > 0) ? 0 : -EIO;
1064 void cleanup_module(void)
1067 for (z = 0; z < DEVMAX; z++) {
1068 struct net_device *dev = moddevs[z];
1070 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
1071 unregister_netdev(dev);
1072 /*DeinitBoard(dev); */
1073 release_region(dev->base_addr, IBM_LANA_IORANGE);
1074 mca_mark_as_unused(priv->slot);
1075 mca_set_adapter_name(priv->slot, "");
1076 mca_set_adapter_procfn(priv->slot, NULL, NULL);