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,
8 alfred.arnold@lancom.de)
10 This driver is based both on the SK_MCA driver, which is itself based on the
11 SK_G16 and 3C523 driver.
14 'PC Hardware: Aufbau, Funktionsweise, Programmierung' by
15 Hans-Peter Messmer for the basic Microchannel stuff
17 'Linux Geraetetreiber' by Allesandro Rubini, Kalle Dalheimer
18 for help on Ethernet driver programming
20 'DP83934CVUL-20/25 MHz SONIC-T Ethernet Controller Datasheet' by National
21 Semiconductor for info on the MAC chip
23 'LAN Technical Reference Ethernet Adapter Interface Version 1 Release 1.0
24 Document Number SC30-3661-00' by IBM for info on the adapter itself
26 Also see http://www.natsemi.com/
28 special acknowledgements to:
29 - Bob Eager for helping me out with documentation from IBM
30 - Jim Shorney for his endless patience with me while I was using
31 him as a beta tester to trace down the address filter bug ;-)
35 -> set debug level via ioctl instead of compile-time switches
36 -> I didn't follow the development of the 2.1.x kernels, so my
37 assumptions about which things changed with which kernel version
42 startup from SK_MCA driver
44 finally got docs about the card. A big thank you to Bob Eager!
48 recv queue done, tcpdump works
50 transmission part works
52 added usage of the isa_functions for Linux 2.3 . Things should
53 still work with 2.0.x....
55 in Linux 2.2.13, the version.h file mysteriously didn't get
56 included. Added a workaround for this. Futhermore, it now
57 not only compiles as a modules ;-)
59 newer kernels automatically probe more than one board, so the
60 'startslot' as a variable is also needed here
62 the interrupt mask register is not set 'hard' instead of individually
63 setting registers, since this seems to set bits that shouldn't be
66 reset interrupt status immediately after CAM load
67 add a recovery delay after releasing the chip's reset line
69 finally found the bug in the address filter setup - damned signed
72 corrected version codes, added support for the latest 2.3 changes
74 cleaned up for the 2.5 tree <alan@redhat.com>
76 *************************************************************************/
78 #include <linux/kernel.h>
79 #include <linux/string.h>
80 #include <linux/errno.h>
81 #include <linux/ioport.h>
82 #include <linux/slab.h>
83 #include <linux/interrupt.h>
84 #include <linux/delay.h>
85 #include <linux/time.h>
86 #include <linux/mca-legacy.h>
87 #include <linux/module.h>
88 #include <linux/netdevice.h>
89 #include <linux/etherdevice.h>
90 #include <linux/skbuff.h>
92 #include <asm/processor.h>
93 #include <asm/bitops.h>
96 #define _IBM_LANA_DRIVER_
101 /* ------------------------------------------------------------------------
102 * global static data - not more since we can handle multiple boards and
103 * have to pack all state info into the device struct!
104 * ------------------------------------------------------------------------ */
106 static char *MediaNames[Media_Count] = {
107 "10BaseT", "10Base5", "Unknown", "10Base2"
110 /* ------------------------------------------------------------------------
111 * private subfunctions
112 * ------------------------------------------------------------------------ */
115 /* dump all registers */
117 static void dumpregs(struct net_device *dev)
121 for (z = 0; z < 160; z += 2) {
123 printk("REGS: %04x:", z);
124 printk(" %04x", inw(dev->base_addr + z));
130 /* dump parts of shared memory - only needed during debugging */
132 static void dumpmem(struct net_device *dev, u32 start, u32 len)
136 printk("Address %04x:\n", start);
137 for (z = 0; z < len; z++) {
140 printk(" %02x", isa_readb(dev->mem_start + start + z));
148 /* print exact time - ditto */
150 static void PrTime(void)
154 do_gettimeofday(&tv);
155 printk("%9d:%06d: ", (int) tv.tv_sec, (int) tv.tv_usec);
159 /* deduce resources out of POS registers */
161 static void getaddrs(int slot, int *base, int *memlen, int *iobase,
162 int *irq, ibmlana_medium * medium)
166 pos0 = mca_read_stored_pos(slot, 2);
167 pos1 = mca_read_stored_pos(slot, 3);
169 *base = 0xc0000 + ((pos1 & 0xf0) << 9);
170 *memlen = (pos1 & 0x01) ? 0x8000 : 0x4000;
171 *iobase = (pos0 & 0xe0) << 7;
172 switch (pos0 & 0x06) {
186 *medium = (pos0 & 0x18) >> 3;
189 /* wait on register value with mask and timeout */
191 static int wait_timeout(struct net_device *dev, int regoffs, u16 mask,
192 u16 value, int timeout)
194 unsigned long fin = jiffies + timeout;
196 while (time_before(jiffies,fin))
197 if ((inw(dev->base_addr + regoffs) & mask) == value)
204 /* reset the whole board */
206 static void ResetBoard(struct net_device *dev)
208 unsigned char bcmval;
210 /* read original board control value */
212 bcmval = inb(dev->base_addr + BCMREG);
214 /* set reset bit for a while */
216 bcmval |= BCMREG_RESET;
217 outb(bcmval, dev->base_addr + BCMREG);
219 bcmval &= ~BCMREG_RESET;
220 outb(bcmval, dev->base_addr + BCMREG);
222 /* switch over to RAM again */
224 bcmval |= BCMREG_RAMEN | BCMREG_RAMWIN;
225 outb(bcmval, dev->base_addr + BCMREG);
228 /* calculate RAM layout & set up descriptors in RAM */
230 static void InitDscrs(struct net_device *dev)
232 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
233 u32 addr, baddr, raddr;
241 isa_memset_io(dev->mem_start, 0xaa,
242 dev->mem_start - dev->mem_start);
244 /* setup n TX descriptors - independent of RAM size */
246 priv->tdastart = addr = 0;
247 priv->txbufstart = baddr = sizeof(tda_t) * TXBUFCNT;
248 for (z = 0; z < TXBUFCNT; z++) {
256 if (z == TXBUFCNT - 1)
257 tda.link = priv->tdastart;
259 tda.link = addr + sizeof(tda_t);
261 isa_memcpy_toio(dev->mem_start + addr, &tda, sizeof(tda_t));
262 addr += sizeof(tda_t);
266 /* calculate how many receive buffers fit into remaining memory */
268 priv->rxbufcnt = (dev->mem_end - dev->mem_start - baddr) / (sizeof(rra_t) + sizeof(rda_t) + PKTSIZE);
270 /* calculate receive addresses */
272 priv->rrastart = raddr = priv->txbufstart + (TXBUFCNT * PKTSIZE);
273 priv->rdastart = addr = priv->rrastart + (priv->rxbufcnt * sizeof(rra_t));
274 priv->rxbufstart = baddr = priv->rdastart + (priv->rxbufcnt * sizeof(rda_t));
276 for (z = 0; z < priv->rxbufcnt; z++) {
279 rra.cntlo = PKTSIZE >> 1;
281 isa_memcpy_toio(dev->mem_start + raddr, &rra, sizeof(rra_t));
288 if (z < priv->rxbufcnt - 1)
289 rda.link = addr + sizeof(rda_t);
293 isa_memcpy_toio(dev->mem_start + addr, &rda, sizeof(rda_t));
296 raddr += sizeof(rra_t);
297 addr += sizeof(rda_t);
300 /* initialize current pointers */
302 priv->nextrxdescr = 0;
303 priv->lastrxdescr = priv->rxbufcnt - 1;
304 priv->nexttxdescr = 0;
305 priv->currtxdescr = 0;
307 memset(priv->txused, 0, sizeof(priv->txused));
310 /* set up Rx + Tx descriptors in SONIC */
312 static int InitSONIC(struct net_device *dev)
314 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
316 /* set up start & end of resource area */
319 outw(priv->rrastart, dev->base_addr + SONIC_RSA);
320 outw(priv->rrastart + (priv->rxbufcnt * sizeof(rra_t)), dev->base_addr + SONIC_REA);
321 outw(priv->rrastart, dev->base_addr + SONIC_RRP);
322 outw(priv->rrastart, dev->base_addr + SONIC_RWP);
324 /* set EOBC so that only one packet goes into one buffer */
326 outw((PKTSIZE - 4) >> 1, dev->base_addr + SONIC_EOBC);
328 /* let SONIC read the first RRA descriptor */
330 outw(CMDREG_RRRA, dev->base_addr + SONIC_CMDREG);
331 if (!wait_timeout(dev, SONIC_CMDREG, CMDREG_RRRA, 0, 2)) {
332 printk(KERN_ERR "%s: SONIC did not respond on RRRA command - giving up.", dev->name);
336 /* point SONIC to the first RDA */
338 outw(0, dev->base_addr + SONIC_URDA);
339 outw(priv->rdastart, dev->base_addr + SONIC_CRDA);
341 /* set upper half of TDA address */
343 outw(0, dev->base_addr + SONIC_UTDA);
348 /* stop SONIC so we can reinitialize it */
350 static void StopSONIC(struct net_device *dev)
352 /* disable interrupts */
354 outb(inb(dev->base_addr + BCMREG) & (~BCMREG_IEN), dev->base_addr + BCMREG);
355 outb(0, dev->base_addr + SONIC_IMREG);
357 /* reset the SONIC */
359 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
361 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
364 /* initialize card and SONIC for proper operation */
366 static void putcam(camentry_t * cams, int *camcnt, char *addr)
368 camentry_t *pcam = cams + (*camcnt);
369 u8 *uaddr = (u8 *) addr;
371 pcam->index = *camcnt;
372 pcam->addr0 = (((u16) uaddr[1]) << 8) | uaddr[0];
373 pcam->addr1 = (((u16) uaddr[3]) << 8) | uaddr[2];
374 pcam->addr2 = (((u16) uaddr[5]) << 8) | uaddr[4];
378 static void InitBoard(struct net_device *dev)
383 struct dev_mc_list *mcptr;
386 /* reset the SONIC */
388 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
391 /* clear all spurious interrupts */
393 outw(inw(dev->base_addr + SONIC_ISREG), dev->base_addr + SONIC_ISREG);
395 /* set up the SONIC's bus interface - constant for this adapter -
396 must be done while the SONIC is in reset */
398 outw(DCREG_USR1 | DCREG_USR0 | DCREG_WC1 | DCREG_DW32, dev->base_addr + SONIC_DCREG);
399 outw(0, dev->base_addr + SONIC_DCREG2);
401 /* remove reset form the SONIC */
403 outw(0, dev->base_addr + SONIC_CMDREG);
406 /* data sheet requires URRA to be programmed before setting up the CAM contents */
408 outw(0, dev->base_addr + SONIC_URRA);
410 /* program the CAM entry 0 to the device address */
413 putcam(cams, &camcnt, dev->dev_addr);
415 /* start putting the multicast addresses into the CAM list. Stop if
418 for (mcptr = dev->mc_list; mcptr != NULL; mcptr = mcptr->next) {
419 putcam(cams, &camcnt, mcptr->dmi_addr);
424 /* calculate CAM mask */
426 cammask = (1 << camcnt) - 1;
428 /* feed CDA into SONIC, initialize RCR value (always get broadcasts) */
430 isa_memcpy_toio(dev->mem_start, cams, sizeof(camentry_t) * camcnt);
431 isa_memcpy_toio(dev->mem_start + (sizeof(camentry_t) * camcnt), &cammask, sizeof(cammask));
434 printk("CAM setup:\n");
435 dumpmem(dev, 0, sizeof(camentry_t) * camcnt + sizeof(cammask));
438 outw(0, dev->base_addr + SONIC_CAMPTR);
439 outw(camcnt, dev->base_addr + SONIC_CAMCNT);
440 outw(CMDREG_LCAM, dev->base_addr + SONIC_CMDREG);
441 if (!wait_timeout(dev, SONIC_CMDREG, CMDREG_LCAM, 0, 2)) {
442 printk(KERN_ERR "%s:SONIC did not respond on LCAM command - giving up.", dev->name);
445 /* clear interrupt condition */
447 outw(ISREG_LCD, dev->base_addr + SONIC_ISREG);
450 printk("Loading CAM done, address pointers %04x:%04x\n",
451 inw(dev->base_addr + SONIC_URRA),
452 inw(dev->base_addr + SONIC_CAMPTR));
456 printk("\n-->CAM: PTR %04x CNT %04x\n",
457 inw(dev->base_addr + SONIC_CAMPTR),
458 inw(dev->base_addr + SONIC_CAMCNT));
459 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
460 for (z = 0; z < camcnt; z++) {
461 outw(z, dev->base_addr + SONIC_CAMEPTR);
462 printk("Entry %d: %04x %04x %04x\n", z,
463 inw(dev->base_addr + SONIC_CAMADDR0),
464 inw(dev->base_addr + SONIC_CAMADDR1),
465 inw(dev->base_addr + SONIC_CAMADDR2));
467 outw(0, dev->base_addr + SONIC_CMDREG);
472 rcrval = RCREG_BRD | RCREG_LB_NONE;
474 /* if still multicast addresses left or ALLMULTI is set, set the multicast
477 if ((dev->flags & IFF_ALLMULTI) || (mcptr != NULL))
480 /* promiscous mode ? */
482 if (dev->flags & IFF_PROMISC)
485 /* program receive mode */
487 outw(rcrval, dev->base_addr + SONIC_RCREG);
489 printk("\nRCRVAL: %04x\n", rcrval);
492 /* set up descriptors in shared memory + feed them into SONIC registers */
498 /* reset all pending interrupts */
500 outw(0xffff, dev->base_addr + SONIC_ISREG);
502 /* enable transmitter + receiver interrupts */
504 outw(CMDREG_RXEN, dev->base_addr + SONIC_CMDREG);
505 outw(IMREG_PRXEN | IMREG_RBEEN | IMREG_PTXEN | IMREG_TXEREN, dev->base_addr + SONIC_IMREG);
507 /* turn on card interrupts */
509 outb(inb(dev->base_addr + BCMREG) | BCMREG_IEN, dev->base_addr + BCMREG);
512 printk("Register dump after initialization:\n");
517 /* start transmission of a descriptor */
519 static void StartTx(struct net_device *dev, int descr)
521 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
524 addr = priv->tdastart + (descr * sizeof(tda_t));
526 /* put descriptor address into SONIC */
528 outw(addr, dev->base_addr + SONIC_CTDA);
530 /* trigger transmitter */
532 priv->currtxdescr = descr;
533 outw(CMDREG_TXP, dev->base_addr + SONIC_CMDREG);
536 /* ------------------------------------------------------------------------
537 * interrupt handler(s)
538 * ------------------------------------------------------------------------ */
540 /* receive buffer area exhausted */
542 static void irqrbe_handler(struct net_device *dev)
544 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
546 /* point the SONIC back to the RRA start */
548 outw(priv->rrastart, dev->base_addr + SONIC_RRP);
549 outw(priv->rrastart, dev->base_addr + SONIC_RWP);
552 /* receive interrupt */
554 static void irqrx_handler(struct net_device *dev)
556 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
558 u32 rdaaddr, lrdaaddr;
563 /* read descriptor that was next to be filled by SONIC */
565 rdaaddr = priv->rdastart + (priv->nextrxdescr * sizeof(rda_t));
566 lrdaaddr = priv->rdastart + (priv->lastrxdescr * sizeof(rda_t));
567 isa_memcpy_fromio(&rda, dev->mem_start + rdaaddr, sizeof(rda_t));
569 /* iron out upper word halves of fields we use - SONIC will duplicate
570 bits 0..15 to 16..31 */
572 rda.status &= 0xffff;
573 rda.length &= 0xffff;
574 rda.startlo &= 0xffff;
576 /* stop if the SONIC still owns it, i.e. there is no data for us */
583 else if (rda.status & RCREG_PRX) {
588 skb = dev_alloc_skb(rda.length + 2);
590 priv->stat.rx_dropped++;
594 isa_memcpy_fromio(skb_put(skb, rda.length),
596 rda.startlo, rda.length);
598 /* set up skb fields */
601 skb->protocol = eth_type_trans(skb, dev);
602 skb->ip_summed = CHECKSUM_NONE;
605 dev->last_rx = jiffies;
606 priv->stat.rx_packets++;
607 priv->stat.rx_bytes += rda.length;
609 /* pass to the upper layers */
614 /* otherwise check error status bits and increase statistics */
617 priv->stat.rx_errors++;
618 if (rda.status & RCREG_FAER)
619 priv->stat.rx_frame_errors++;
620 if (rda.status & RCREG_CRCR)
621 priv->stat.rx_crc_errors++;
624 /* descriptor processed, will become new last descriptor in queue */
628 isa_memcpy_toio(dev->mem_start + rdaaddr, &rda,
631 /* set up link and EOL = 0 in currently last descriptor. Only write
632 the link field since the SONIC may currently already access the
635 isa_memcpy_toio(dev->mem_start + lrdaaddr + 20, &rdaaddr, 4);
637 /* advance indices */
639 priv->lastrxdescr = priv->nextrxdescr;
640 if ((++priv->nextrxdescr) >= priv->rxbufcnt)
641 priv->nextrxdescr = 0;
645 /* transmit interrupt */
647 static void irqtx_handler(struct net_device *dev)
649 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
652 /* fetch descriptor (we forgot the size ;-) */
653 isa_memcpy_fromio(&tda, dev->mem_start + priv->tdastart + (priv->currtxdescr * sizeof(tda_t)), sizeof(tda_t));
655 /* update statistics */
656 priv->stat.tx_packets++;
657 priv->stat.tx_bytes += tda.length;
659 /* update our pointers */
660 priv->txused[priv->currtxdescr] = 0;
663 /* if there are more descriptors present in RAM, start them */
664 if (priv->txusedcnt > 0)
665 StartTx(dev, (priv->currtxdescr + 1) % TXBUFCNT);
667 /* tell the upper layer we can go on transmitting */
668 netif_wake_queue(dev);
671 static void irqtxerr_handler(struct net_device *dev)
673 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
676 /* fetch descriptor to check status */
677 isa_memcpy_fromio(&tda, dev->mem_start + priv->tdastart + (priv->currtxdescr * sizeof(tda_t)), sizeof(tda_t));
679 /* update statistics */
680 priv->stat.tx_errors++;
681 if (tda.status & (TCREG_NCRS | TCREG_CRSL))
682 priv->stat.tx_carrier_errors++;
683 if (tda.status & TCREG_EXC)
684 priv->stat.tx_aborted_errors++;
685 if (tda.status & TCREG_OWC)
686 priv->stat.tx_window_errors++;
687 if (tda.status & TCREG_FU)
688 priv->stat.tx_fifo_errors++;
690 /* update our pointers */
691 priv->txused[priv->currtxdescr] = 0;
694 /* if there are more descriptors present in RAM, start them */
695 if (priv->txusedcnt > 0)
696 StartTx(dev, (priv->currtxdescr + 1) % TXBUFCNT);
698 /* tell the upper layer we can go on transmitting */
699 netif_wake_queue(dev);
702 /* general interrupt entry */
704 static irqreturn_t irq_handler(int irq, void *device, struct pt_regs *regs)
706 struct net_device *dev = (struct net_device *) device;
709 /* in case we're not meant... */
710 if (!(inb(dev->base_addr + BCMREG) & BCMREG_IPEND))
713 /* loop through the interrupt bits until everything is clear */
715 ival = inw(dev->base_addr + SONIC_ISREG);
717 if (ival & ISREG_RBE) {
719 outw(ISREG_RBE, dev->base_addr + SONIC_ISREG);
721 if (ival & ISREG_PKTRX) {
723 outw(ISREG_PKTRX, dev->base_addr + SONIC_ISREG);
725 if (ival & ISREG_TXDN) {
727 outw(ISREG_TXDN, dev->base_addr + SONIC_ISREG);
729 if (ival & ISREG_TXER) {
730 irqtxerr_handler(dev);
731 outw(ISREG_TXER, dev->base_addr + SONIC_ISREG);
738 /* ------------------------------------------------------------------------
740 * ------------------------------------------------------------------------ */
744 static int ibmlana_getinfo(char *buf, int slot, void *d)
747 struct net_device *dev = (struct net_device *) d;
750 /* can't say anything about an uninitialized device... */
754 if (dev->priv == NULL)
756 priv = (ibmlana_priv *) dev->priv;
760 len += sprintf(buf + len, "IRQ: %d\n", priv->realirq);
761 len += sprintf(buf + len, "I/O: %#lx\n", dev->base_addr);
762 len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start, dev->mem_end - 1);
763 len += sprintf(buf + len, "Transceiver: %s\n", MediaNames[priv->medium]);
764 len += sprintf(buf + len, "Device: %s\n", dev->name);
765 len += sprintf(buf + len, "MAC address:");
766 for (i = 0; i < 6; i++)
767 len += sprintf(buf + len, " %02x", dev->dev_addr[i]);
774 /* open driver. Means also initialization and start of LANCE */
776 static int ibmlana_open(struct net_device *dev)
779 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
781 /* register resources - only necessary for IRQ */
783 result = request_irq(priv->realirq, irq_handler, SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
785 printk(KERN_ERR "%s: failed to register irq %d\n", dev->name, dev->irq);
788 dev->irq = priv->realirq;
790 /* set up the card and SONIC */
793 /* initialize operational flags */
794 netif_start_queue(dev);
798 /* close driver. Shut down board and free allocated resources */
800 static int ibmlana_close(struct net_device *dev)
804 /* release resources */
806 free_irq(dev->irq, dev);
811 /* transmit a block. */
813 static int ibmlana_tx(struct sk_buff *skb, struct net_device *dev)
815 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
816 int retval = 0, tmplen, addr;
821 /* find out if there are free slots for a frame to transmit. If not,
822 the upper layer is in deep desperation and we simply ignore the frame. */
824 if (priv->txusedcnt >= TXBUFCNT) {
826 priv->stat.tx_dropped++;
830 /* copy the frame data into the next free transmit buffer - fillup missing */
834 baddr = priv->txbufstart + (priv->nexttxdescr * PKTSIZE);
835 isa_memcpy_toio(dev->mem_start + baddr, skb->data, skb->len);
837 /* copy filler into RAM - in case we're filling up...
838 we're filling a bit more than necessary, but that doesn't harm
839 since the buffer is far larger...
840 Sorry Linus for the filler string but I couldn't resist ;-) */
842 if (tmplen > skb->len) {
843 char *fill = "NetBSD is a nice OS too! ";
844 unsigned int destoffs = skb->len, l = strlen(fill);
846 while (destoffs < tmplen) {
847 isa_memcpy_toio(dev->mem_start + baddr + destoffs, fill, l);
852 /* set up the new frame descriptor */
853 addr = priv->tdastart + (priv->nexttxdescr * sizeof(tda_t));
854 isa_memcpy_fromio(&tda, dev->mem_start + addr, sizeof(tda_t));
855 tda.length = tda.fraglength = tmplen;
856 isa_memcpy_toio(dev->mem_start + addr, &tda, sizeof(tda_t));
858 /* if there were no active descriptors, trigger the SONIC */
859 spin_lock_irqsave(&priv->lock, flags);
862 priv->txused[priv->nexttxdescr] = 1;
864 /* are all transmission slots used up ? */
865 if (priv->txusedcnt >= TXBUFCNT)
866 netif_stop_queue(dev);
868 if (priv->txusedcnt == 1)
869 StartTx(dev, priv->nexttxdescr);
870 priv->nexttxdescr = (priv->nexttxdescr + 1) % TXBUFCNT;
872 spin_unlock_irqrestore(&priv->lock, flags);
878 /* return pointer to Ethernet statistics */
880 static struct net_device_stats *ibmlana_stats(struct net_device *dev)
882 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
886 /* we don't support runtime reconfiguration, since am MCA card can
887 be unambigously identified by its POS registers. */
889 static int ibmlana_config(struct net_device *dev, struct ifmap *map)
894 /* switch receiver mode. */
896 static void ibmlana_set_multicast_list(struct net_device *dev)
898 /* first stop the SONIC... */
900 /* ...then reinit it with the new flags */
904 /* ------------------------------------------------------------------------
906 * ------------------------------------------------------------------------ */
908 static int startslot; /* counts through slots when probing multiple devices */
910 static int ibmlana_probe(struct net_device *dev)
912 int force_detect = 0;
914 int base = 0, irq = 0, iobase = 0, memlen = 0;
916 ibmlana_medium medium;
918 SET_MODULE_OWNER(dev);
920 /* can't work without an MCA bus ;-) */
924 /* start address of 1 --> forced detection */
925 if (dev->mem_start == 1)
928 base = dev->mem_start;
931 for (slot = startslot; (slot = mca_find_adapter(IBM_LANA_ID, slot)) != -1; slot++) {
932 /* deduce card addresses */
933 getaddrs(slot, &base, &memlen, &iobase, &irq, &medium);
935 /* slot already in use ? */
936 if (mca_is_adapter_used(slot))
938 /* were we looking for something different ? */
939 if (dev->irq && dev->irq != irq)
941 if (dev->mem_start && dev->mem_start != base)
943 /* found something that matches */
947 /* nothing found ? */
949 return (base != 0 || irq != 0) ? -ENXIO : -ENODEV;
951 /* announce success */
952 printk(KERN_INFO "%s: IBM LAN Adapter/A found in slot %d\n", dev->name, slot + 1);
954 /* try to obtain I/O range */
955 if (!request_region(iobase, IBM_LANA_IORANGE, dev->name)) {
956 printk(KERN_ERR "%s: cannot allocate I/O range at %#x!\n", dev->name, iobase);
957 startslot = slot + 1;
961 /* make procfs entries */
962 mca_set_adapter_name(slot, "IBM LAN Adapter/A");
963 mca_set_adapter_procfn(slot, (MCA_ProcFn) ibmlana_getinfo, dev);
965 mca_mark_as_used(slot);
967 /* allocate structure */
971 priv->medium = medium;
972 spin_lock_init(&priv->lock);
974 /* set base + irq for this device (irq not allocated so far) */
977 dev->mem_start = base;
978 dev->mem_end = base + memlen;
979 dev->base_addr = iobase;
983 dev->open = ibmlana_open;
984 dev->stop = ibmlana_close;
985 dev->set_config = ibmlana_config;
986 dev->hard_start_xmit = ibmlana_tx;
987 dev->do_ioctl = NULL;
988 dev->get_stats = ibmlana_stats;
989 dev->set_multicast_list = ibmlana_set_multicast_list;
990 dev->flags |= IFF_MULTICAST;
992 /* copy out MAC address */
994 for (z = 0; z < sizeof(dev->dev_addr); z++)
995 dev->dev_addr[z] = inb(dev->base_addr + MACADDRPROM + z);
999 printk(KERN_INFO "%s: IRQ %d, I/O %#lx, memory %#lx-%#lx, "
1000 "MAC address %02x:%02x:%02x:%02x:%02x:%02x.\n",
1001 dev->name, priv->realirq, dev->base_addr,
1002 dev->mem_start, dev->mem_end - 1,
1003 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1004 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1005 printk(KERN_INFO "%s: %s medium\n", dev->name, MediaNames[priv->medium]);
1011 /* next probe will start at next slot */
1013 startslot = slot + 1;
1018 /* ------------------------------------------------------------------------
1019 * modularization support
1020 * ------------------------------------------------------------------------ */
1026 static struct net_device *moddevs[DEVMAX];
1030 MODULE_PARM(irq, "i");
1031 MODULE_PARM(io, "i");
1032 MODULE_PARM_DESC(irq, "IBM LAN/A IRQ number");
1033 MODULE_PARM_DESC(io, "IBM LAN/A I/O base address");
1034 MODULE_LICENSE("GPL");
1036 int init_module(void)
1041 for (z = 0; z < DEVMAX; z++) {
1042 struct net_device *dev = alloc_etherdev(sizeof(ibmlana_priv));
1046 dev->base_addr = io;
1047 if (ibmlana_probe(dev)) {
1051 if (register_netdev(dev)) {
1052 ibmlana_priv *priv = dev->priv;
1053 release_region(dev->base_addr, IBM_LANA_IORANGE);
1054 mca_mark_as_unused(priv->slot);
1055 mca_set_adapter_name(priv->slot, "");
1056 mca_set_adapter_procfn(priv->slot, NULL, NULL);
1062 return (z > 0) ? 0 : -EIO;
1065 void cleanup_module(void)
1068 for (z = 0; z < DEVMAX; z++) {
1069 struct net_device *dev = moddevs[z];
1071 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
1072 unregister_netdev(dev);
1073 /*DeinitBoard(dev); */
1074 release_region(dev->base_addr, IBM_LANA_IORANGE);
1075 mca_mark_as_unused(priv->slot);
1076 mca_set_adapter_name(priv->slot, "");
1077 mca_set_adapter_procfn(priv->slot, NULL, NULL);