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 *************************************************************************/
75 #include <linux/version.h>
76 #include <linux/kernel.h>
77 #include <linux/sched.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.h>
86 #include <asm/processor.h>
87 #include <asm/bitops.h>
90 #include <linux/module.h>
92 #include <linux/netdevice.h>
93 #include <linux/etherdevice.h>
94 #include <linux/skbuff.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" };
109 /* ------------------------------------------------------------------------
110 * private subfunctions
111 * ------------------------------------------------------------------------ */
114 /* dump all registers */
116 static void dumpregs(struct IBMLANA_NETDEV *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 IBMLANA_NETDEV *dev, u32 start, u32 len)
135 printk("Address %04x:\n", start);
136 for (z = 0; z < len; z++) {
139 printk(" %02x", IBMLANA_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 IBMLANA_NETDEV *dev, int regoffs, u16 mask,
191 u16 value, int timeout)
193 unsigned long fin = jiffies + timeout;
195 while (jiffies != fin)
196 if ((inw(dev->base_addr + regoffs) & mask) == value)
203 /* reset the whole board */
205 static void ResetBoard(struct IBMLANA_NETDEV *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 IBMLANA_NETDEV *dev)
231 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
232 u32 addr, baddr, raddr;
240 IBMLANA_SETIO(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 IBMLANA_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) /
268 (sizeof(rra_t) + sizeof(rda_t) + PKTSIZE);
270 /* calculate receive addresses */
272 priv->rrastart = raddr = priv->txbufstart + (TXBUFCNT * PKTSIZE);
273 priv->rdastart = addr =
274 priv->rrastart + (priv->rxbufcnt * sizeof(rra_t));
275 priv->rxbufstart = baddr =
276 priv->rdastart + (priv->rxbufcnt * sizeof(rda_t));
277 for (z = 0; z < priv->rxbufcnt; z++) {
280 rra.cntlo = PKTSIZE >> 1;
282 IBMLANA_TOIO(dev->mem_start + raddr, &rra, sizeof(rra_t));
289 if (z < priv->rxbufcnt - 1)
290 rda.link = addr + sizeof(rda_t);
294 IBMLANA_TOIO(dev->mem_start + addr, &rda, sizeof(rda_t));
297 raddr += sizeof(rra_t);
298 addr += sizeof(rda_t);
301 /* initialize current pointers */
303 priv->nextrxdescr = 0;
304 priv->lastrxdescr = priv->rxbufcnt - 1;
305 priv->nexttxdescr = 0;
306 priv->currtxdescr = 0;
308 memset(priv->txused, 0, sizeof(priv->txused));
311 /* set up Rx + Tx descriptors in SONIC */
313 static int InitSONIC(struct IBMLANA_NETDEV *dev)
315 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
317 /* set up start & end of resource area */
320 outw(priv->rrastart, dev->base_addr + SONIC_RSA);
321 outw(priv->rrastart + (priv->rxbufcnt * sizeof(rra_t)),
322 dev->base_addr + SONIC_REA);
323 outw(priv->rrastart, dev->base_addr + SONIC_RRP);
324 outw(priv->rrastart, dev->base_addr + SONIC_RWP);
326 /* set EOBC so that only one packet goes into one buffer */
328 outw((PKTSIZE - 4) >> 1, dev->base_addr + SONIC_EOBC);
330 /* let SONIC read the first RRA descriptor */
332 outw(CMDREG_RRRA, dev->base_addr + SONIC_CMDREG);
333 if (!wait_timeout(dev, SONIC_CMDREG, CMDREG_RRRA, 0, 2)) {
335 ("%s: SONIC did not respond on RRRA command - giving up.",
340 /* point SONIC to the first RDA */
342 outw(0, dev->base_addr + SONIC_URDA);
343 outw(priv->rdastart, dev->base_addr + SONIC_CRDA);
345 /* set upper half of TDA address */
347 outw(0, dev->base_addr + SONIC_UTDA);
352 /* stop SONIC so we can reinitialize it */
354 static void StopSONIC(struct IBMLANA_NETDEV *dev)
356 /* disable interrupts */
358 outb(inb(dev->base_addr + BCMREG) & (~BCMREG_IEN),
359 dev->base_addr + BCMREG);
360 outb(0, dev->base_addr + SONIC_IMREG);
362 /* reset the SONIC */
364 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
366 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
369 /* initialize card and SONIC for proper operation */
371 static void putcam(camentry_t * cams, int *camcnt, char *addr)
373 camentry_t *pcam = cams + (*camcnt);
374 u8 *uaddr = (u8 *) addr;
376 pcam->index = *camcnt;
377 pcam->addr0 = (((u16) uaddr[1]) << 8) | uaddr[0];
378 pcam->addr1 = (((u16) uaddr[3]) << 8) | uaddr[2];
379 pcam->addr2 = (((u16) uaddr[5]) << 8) | uaddr[4];
383 static void InitBoard(struct IBMLANA_NETDEV *dev)
388 struct dev_mc_list *mcptr;
391 /* reset the SONIC */
393 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
396 /* clear all spurious interrupts */
398 outw(inw(dev->base_addr + SONIC_ISREG),
399 dev->base_addr + SONIC_ISREG);
401 /* set up the SONIC's bus interface - constant for this adapter -
402 must be done while the SONIC is in reset */
404 outw(DCREG_USR1 | DCREG_USR0 | DCREG_WC1 | DCREG_DW32,
405 dev->base_addr + SONIC_DCREG);
406 outw(0, dev->base_addr + SONIC_DCREG2);
408 /* remove reset form the SONIC */
410 outw(0, dev->base_addr + SONIC_CMDREG);
413 /* data sheet requires URRA to be programmed before setting up the CAM contents */
415 outw(0, dev->base_addr + SONIC_URRA);
417 /* program the CAM entry 0 to the device address */
420 putcam(cams, &camcnt, dev->dev_addr);
422 /* start putting the multicast addresses into the CAM list. Stop if
425 for (mcptr = dev->mc_list; mcptr != NULL; mcptr = mcptr->next) {
426 putcam(cams, &camcnt, mcptr->dmi_addr);
431 /* calculate CAM mask */
433 cammask = (1 << camcnt) - 1;
435 /* feed CDA into SONIC, initialize RCR value (always get broadcasts) */
437 IBMLANA_TOIO(dev->mem_start, cams, sizeof(camentry_t) * camcnt);
438 IBMLANA_TOIO(dev->mem_start + (sizeof(camentry_t) * camcnt),
439 &cammask, sizeof(cammask));
442 printk("CAM setup:\n");
443 dumpmem(dev, 0, sizeof(camentry_t) * camcnt + sizeof(cammask));
446 outw(0, dev->base_addr + SONIC_CAMPTR);
447 outw(camcnt, dev->base_addr + SONIC_CAMCNT);
448 outw(CMDREG_LCAM, dev->base_addr + SONIC_CMDREG);
449 if (!wait_timeout(dev, SONIC_CMDREG, CMDREG_LCAM, 0, 2)) {
451 ("%s:SONIC did not respond on LCAM command - giving up.",
455 /* clear interrupt condition */
457 outw(ISREG_LCD, dev->base_addr + SONIC_ISREG);
460 printk("Loading CAM done, address pointers %04x:%04x\n",
461 inw(dev->base_addr + SONIC_URRA),
462 inw(dev->base_addr + SONIC_CAMPTR));
466 printk("\n-->CAM: PTR %04x CNT %04x\n",
467 inw(dev->base_addr + SONIC_CAMPTR),
468 inw(dev->base_addr + SONIC_CAMCNT));
469 outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG);
470 for (z = 0; z < camcnt; z++) {
471 outw(z, dev->base_addr + SONIC_CAMEPTR);
472 printk("Entry %d: %04x %04x %04x\n", z,
480 outw(0, dev->base_addr + SONIC_CMDREG);
485 rcrval = RCREG_BRD | RCREG_LB_NONE;
487 /* if still multicast addresses left or ALLMULTI is set, set the multicast
490 if ((dev->flags & IFF_ALLMULTI) || (mcptr != NULL))
493 /* promiscous mode ? */
495 if (dev->flags & IFF_PROMISC)
498 /* program receive mode */
500 outw(rcrval, dev->base_addr + SONIC_RCREG);
502 printk("\nRCRVAL: %04x\n", rcrval);
505 /* set up descriptors in shared memory + feed them into SONIC registers */
511 /* reset all pending interrupts */
513 outw(0xffff, dev->base_addr + SONIC_ISREG);
515 /* enable transmitter + receiver interrupts */
517 outw(CMDREG_RXEN, dev->base_addr + SONIC_CMDREG);
518 outw(IMREG_PRXEN | IMREG_RBEEN | IMREG_PTXEN | IMREG_TXEREN,
519 dev->base_addr + SONIC_IMREG);
521 /* turn on card interrupts */
523 outb(inb(dev->base_addr + BCMREG) | BCMREG_IEN,
524 dev->base_addr + BCMREG);
527 printk("Register dump after initialization:\n");
532 /* start transmission of a descriptor */
534 static void StartTx(struct IBMLANA_NETDEV *dev, int descr)
536 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
539 addr = priv->tdastart + (descr * sizeof(tda_t));
541 /* put descriptor address into SONIC */
543 outw(addr, dev->base_addr + SONIC_CTDA);
545 /* trigger transmitter */
547 priv->currtxdescr = descr;
548 outw(CMDREG_TXP, dev->base_addr + SONIC_CMDREG);
551 /* ------------------------------------------------------------------------
552 * interrupt handler(s)
553 * ------------------------------------------------------------------------ */
555 /* receive buffer area exhausted */
557 static void irqrbe_handler(struct IBMLANA_NETDEV *dev)
559 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
561 /* point the SONIC back to the RRA start */
563 outw(priv->rrastart, dev->base_addr + SONIC_RRP);
564 outw(priv->rrastart, dev->base_addr + SONIC_RWP);
567 /* receive interrupt */
569 static void irqrx_handler(struct IBMLANA_NETDEV *dev)
571 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
573 u32 rdaaddr, lrdaaddr;
578 /* read descriptor that was next to be filled by SONIC */
581 priv->rdastart + (priv->nextrxdescr * sizeof(rda_t));
583 priv->rdastart + (priv->lastrxdescr * sizeof(rda_t));
584 IBMLANA_FROMIO(&rda, dev->mem_start + rdaaddr,
587 /* iron out upper word halves of fields we use - SONIC will duplicate
588 bits 0..15 to 16..31 */
590 rda.status &= 0xffff;
591 rda.length &= 0xffff;
592 rda.startlo &= 0xffff;
594 /* stop if the SONIC still owns it, i.e. there is no data for us */
601 else if (rda.status & RCREG_PRX) {
606 skb = dev_alloc_skb(rda.length + 2);
608 priv->stat.rx_dropped++;
612 IBMLANA_FROMIO(skb_put(skb, rda.length),
614 rda.startlo, rda.length);
616 /* set up skb fields */
619 skb->protocol = eth_type_trans(skb, dev);
620 skb->ip_summed = CHECKSUM_NONE;
624 dev->last_rx = jiffies;
625 priv->stat.rx_packets++;
626 #if (LINUX_VERSION_CODE >= 0x20119) /* byte counters for kernel >= 2.1.25 */
627 priv->stat.rx_bytes += rda.length;
630 /* pass to the upper layers */
636 /* otherwise check error status bits and increase statistics */
639 priv->stat.rx_errors++;
641 if (rda.status & RCREG_FAER)
642 priv->stat.rx_frame_errors++;
644 if (rda.status & RCREG_CRCR)
645 priv->stat.rx_crc_errors++;
648 /* descriptor processed, will become new last descriptor in queue */
652 IBMLANA_TOIO(dev->mem_start + rdaaddr, &rda,
655 /* set up link and EOL = 0 in currently last descriptor. Only write
656 the link field since the SONIC may currently already access the
659 IBMLANA_TOIO(dev->mem_start + lrdaaddr + 20, &rdaaddr, 4);
661 /* advance indices */
663 priv->lastrxdescr = priv->nextrxdescr;
664 if ((++priv->nextrxdescr) >= priv->rxbufcnt)
665 priv->nextrxdescr = 0;
669 /* transmit interrupt */
671 static void irqtx_handler(struct IBMLANA_NETDEV *dev)
673 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
676 /* fetch descriptor (we forgot the size ;-) */
679 dev->mem_start + priv->tdastart +
680 (priv->currtxdescr * sizeof(tda_t)), sizeof(tda_t));
682 /* update statistics */
684 priv->stat.tx_packets++;
685 #if (LINUX_VERSION_CODE >= 0x020119)
686 priv->stat.tx_bytes += tda.length;
689 /* update our pointers */
691 priv->txused[priv->currtxdescr] = 0;
694 /* if there are more descriptors present in RAM, start them */
696 if (priv->txusedcnt > 0)
697 StartTx(dev, (priv->currtxdescr + 1) % TXBUFCNT);
699 /* tell the upper layer we can go on transmitting */
701 #if LINUX_VERSION_CODE >= 0x02032a
702 netif_wake_queue(dev);
709 static void irqtxerr_handler(struct IBMLANA_NETDEV *dev)
711 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
714 /* fetch descriptor to check status */
717 dev->mem_start + priv->tdastart +
718 (priv->currtxdescr * sizeof(tda_t)), sizeof(tda_t));
720 /* update statistics */
722 priv->stat.tx_errors++;
723 if (tda.status & (TCREG_NCRS | TCREG_CRSL))
724 priv->stat.tx_carrier_errors++;
725 if (tda.status & TCREG_EXC)
726 priv->stat.tx_aborted_errors++;
727 if (tda.status & TCREG_OWC)
728 priv->stat.tx_window_errors++;
729 if (tda.status & TCREG_FU)
730 priv->stat.tx_fifo_errors++;
732 /* update our pointers */
734 priv->txused[priv->currtxdescr] = 0;
737 /* if there are more descriptors present in RAM, start them */
739 if (priv->txusedcnt > 0)
740 StartTx(dev, (priv->currtxdescr + 1) % TXBUFCNT);
742 /* tell the upper layer we can go on transmitting */
744 #if LINUX_VERSION_CODE >= 0x02032a
745 netif_wake_queue(dev);
752 /* general interrupt entry */
754 static void irq_handler(int irq, void *device, struct pt_regs *regs)
756 struct IBMLANA_NETDEV *dev = (struct IBMLANA_NETDEV *) device;
759 /* in case we're not meant... */
761 if (!(inb(dev->base_addr + BCMREG) & BCMREG_IPEND))
764 #if (LINUX_VERSION_CODE >= 0x02032a)
766 set_bit(LINK_STATE_RXSEM, &dev->state);
772 /* loop through the interrupt bits until everything is clear */
775 ival = inw(dev->base_addr + SONIC_ISREG);
777 if (ival & ISREG_RBE) {
779 outw(ISREG_RBE, dev->base_addr + SONIC_ISREG);
782 if (ival & ISREG_PKTRX) {
784 outw(ISREG_PKTRX, dev->base_addr + SONIC_ISREG);
787 if (ival & ISREG_TXDN) {
789 outw(ISREG_TXDN, dev->base_addr + SONIC_ISREG);
792 if (ival & ISREG_TXER) {
793 irqtxerr_handler(dev);
794 outw(ISREG_TXER, dev->base_addr + SONIC_ISREG);
800 #if (LINUX_VERSION_CODE >= 0x02032a)
802 clear_bit(LINK_STATE_RXSEM, &dev->state);
809 /* ------------------------------------------------------------------------
811 * ------------------------------------------------------------------------ */
815 static int ibmlana_getinfo(char *buf, int slot, void *d)
818 struct IBMLANA_NETDEV *dev = (struct IBMLANA_NETDEV *) d;
821 /* can't say anything about an uninitialized device... */
825 if (dev->priv == NULL)
827 priv = (ibmlana_priv *) dev->priv;
831 len += sprintf(buf + len, "IRQ: %d\n", priv->realirq);
832 len += sprintf(buf + len, "I/O: %#lx\n", dev->base_addr);
833 len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start,
836 sprintf(buf + len, "Transceiver: %s\n",
837 MediaNames[priv->medium]);
838 len += sprintf(buf + len, "Device: %s\n", dev->name);
839 len += sprintf(buf + len, "MAC address:");
840 for (i = 0; i < 6; i++)
841 len += sprintf(buf + len, " %02x", dev->dev_addr[i]);
848 /* open driver. Means also initialization and start of LANCE */
850 static int ibmlana_open(struct IBMLANA_NETDEV *dev)
853 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
855 /* register resources - only necessary for IRQ */
858 request_irq(priv->realirq, irq_handler,
859 SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
861 printk("%s: failed to register irq %d\n", dev->name,
865 dev->irq = priv->realirq;
867 /* set up the card and SONIC */
871 /* initialize operational flags */
873 #if (LINUX_VERSION_CODE >= 0x02032a)
874 netif_start_queue(dev);
885 /* close driver. Shut down board and free allocated resources */
887 static int ibmlana_close(struct IBMLANA_NETDEV *dev)
891 /* release resources */
893 free_irq(dev->irq, dev);
896 #if (LINUX_VERSION_CODE < 0x02032a)
903 /* transmit a block. */
905 static int ibmlana_tx(struct sk_buff *skb, struct IBMLANA_NETDEV *dev)
907 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
908 int retval = 0, tmplen, addr;
913 /* if we get called with a NULL descriptor, the Ethernet layer thinks
914 our card is stuck an we should reset it. We'll do this completely: */
917 printk("%s: Resetting SONIC\n", dev->name);
920 return 0; /* don't try to free the block here ;-) */
923 /* find out if there are free slots for a frame to transmit. If not,
924 the upper layer is in deep desperation and we simply ignore the frame. */
926 if (priv->txusedcnt >= TXBUFCNT) {
928 priv->stat.tx_dropped++;
932 /* copy the frame data into the next free transmit buffer - fillup missing */
937 baddr = priv->txbufstart + (priv->nexttxdescr * PKTSIZE);
938 IBMLANA_TOIO(dev->mem_start + baddr, skb->data, skb->len);
940 /* copy filler into RAM - in case we're filling up...
941 we're filling a bit more than necessary, but that doesn't harm
942 since the buffer is far larger...
943 Sorry Linus for the filler string but I couldn't resist ;-) */
945 if (tmplen > skb->len) {
946 char *fill = "NetBSD is a nice OS too! ";
947 unsigned int destoffs = skb->len, l = strlen(fill);
949 while (destoffs < tmplen) {
950 IBMLANA_TOIO(dev->mem_start + baddr + destoffs,
956 /* set up the new frame descriptor */
958 addr = priv->tdastart + (priv->nexttxdescr * sizeof(tda_t));
959 IBMLANA_FROMIO(&tda, dev->mem_start + addr, sizeof(tda_t));
960 tda.length = tda.fraglength = tmplen;
961 IBMLANA_TOIO(dev->mem_start + addr, &tda, sizeof(tda_t));
963 /* if there were no active descriptors, trigger the SONIC */
969 priv->txused[priv->nexttxdescr] = 1;
971 /* are all transmission slots used up ? */
973 if (priv->txusedcnt >= TXBUFCNT)
974 #if (LINUX_VERSION_CODE >= 0x02032a)
975 netif_stop_queue(dev);
980 if (priv->txusedcnt == 1)
981 StartTx(dev, priv->nexttxdescr);
982 priv->nexttxdescr = (priv->nexttxdescr + 1) % TXBUFCNT;
984 restore_flags(flags);
988 /* When did that change exactly ? */
990 #if (LINUX_VERSION_CODE >= 0x20200)
993 dev_kfree_skb(skb, FREE_WRITE);
998 /* return pointer to Ethernet statistics */
1000 static struct net_device_stats *ibmlana_stats(struct IBMLANA_NETDEV *dev)
1002 ibmlana_priv *priv = (ibmlana_priv *) dev->priv;
1004 return &(priv->stat);
1007 /* we don't support runtime reconfiguration, since am MCA card can
1008 be unambigously identified by its POS registers. */
1010 static int ibmlana_config(struct IBMLANA_NETDEV *dev, struct ifmap *map)
1015 /* switch receiver mode. */
1017 static void ibmlana_set_multicast_list(struct IBMLANA_NETDEV *dev)
1019 /* first stop the SONIC... */
1023 /* ...then reinit it with the new flags */
1028 /* ------------------------------------------------------------------------
1030 * ------------------------------------------------------------------------ */
1032 static int startslot; /* counts through slots when probing multiple devices */
1034 int ibmlana_probe(struct IBMLANA_NETDEV *dev)
1036 int force_detect = 0;
1038 int base = 0, irq = 0, iobase = 0, memlen = 0;
1040 ibmlana_medium medium;
1042 #if (LINUX_VERSION_CODE >= 0x02032a)
1043 SET_MODULE_OWNER(dev);
1046 /* can't work without an MCA bus ;-) */
1051 /* start address of 1 --> forced detection */
1053 if (dev->mem_start == 1)
1056 /* search through slots */
1059 base = dev->mem_start;
1062 slot = mca_find_adapter(IBM_LANA_ID, startslot);
1064 while (slot != -1) {
1065 /* deduce card addresses */
1067 getaddrs(slot, &base, &memlen, &iobase, &irq, &medium);
1069 #if (LINUX_VERSION_CODE >= 0x20300)
1070 /* slot already in use ? */
1072 if (mca_is_adapter_used(slot)) {
1073 slot = mca_find_adapter(IBM_LANA_ID, slot + 1);
1078 /* were we looking for something different ? */
1080 if ((dev->irq != 0) || (dev->mem_start != 0)) {
1081 if ((dev->irq != 0) && (dev->irq != irq)) {
1083 mca_find_adapter(IBM_LANA_ID,
1087 if ((dev->mem_start != 0)
1088 && (dev->mem_start != base)) {
1090 mca_find_adapter(IBM_LANA_ID,
1096 /* found something that matches */
1101 /* nothing found ? */
1104 return ((base != 0) || (irq != 0)) ? -ENXIO : -ENODEV;
1106 /* announce success */
1107 printk("%s: IBM LAN Adapter/A found in slot %d\n", dev->name,
1110 /* try to obtain I/O range */
1111 if (!request_region(iobase, IBM_LANA_IORANGE, dev->name)) {
1112 printk("%s: cannot allocate I/O range at %#x!\n", dev->name, iobase);
1113 startslot = slot + 1;
1117 /* make procfs entries */
1119 mca_set_adapter_name(slot, "IBM LAN Adapter/A");
1120 mca_set_adapter_procfn(slot, (MCA_ProcFn) ibmlana_getinfo, dev);
1122 #if (LINUX_VERSION_CODE >= 0x20200)
1123 mca_mark_as_used(slot);
1126 /* allocate structure */
1129 (ibmlana_priv *) kmalloc(sizeof(ibmlana_priv), GFP_KERNEL);
1131 release_region(iobase, IBM_LANA_IORANGE);
1135 priv->realirq = irq;
1136 priv->medium = medium;
1137 memset(&(priv->stat), 0, sizeof(struct net_device_stats));
1139 /* set base + irq for this device (irq not allocated so far) */
1142 dev->mem_start = base;
1143 dev->mem_end = base + memlen;
1144 dev->base_addr = iobase;
1148 dev->open = ibmlana_open;
1149 dev->stop = ibmlana_close;
1150 dev->set_config = ibmlana_config;
1151 dev->hard_start_xmit = ibmlana_tx;
1152 dev->do_ioctl = NULL;
1153 dev->get_stats = ibmlana_stats;
1154 dev->set_multicast_list = ibmlana_set_multicast_list;
1155 dev->flags |= IFF_MULTICAST;
1161 /* copy out MAC address */
1163 for (z = 0; z < sizeof(dev->dev_addr); z++)
1164 dev->dev_addr[z] = inb(dev->base_addr + MACADDRPROM + z);
1168 printk("%s: IRQ %d, I/O %#lx, memory %#lx-%#lx, "
1169 "MAC address %02x:%02x:%02x:%02x:%02x:%02x.\n",
1170 dev->name, priv->realirq, dev->base_addr,
1171 dev->mem_start, dev->mem_end - 1,
1172 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1173 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1174 printk("%s: %s medium\n", dev->name, MediaNames[priv->medium]);
1180 /* next probe will start at next slot */
1182 startslot = slot + 1;
1187 /* ------------------------------------------------------------------------
1188 * modularization support
1189 * ------------------------------------------------------------------------ */
1195 static struct IBMLANA_NETDEV moddevs[DEVMAX];
1198 MODULE_PARM(irq, "i");
1199 MODULE_PARM(io, "i");
1200 MODULE_PARM_DESC(irq, "IBM LAN/A IRQ number");
1201 MODULE_PARM_DESC(io, "IBM LAN/A I/O base address");
1202 MODULE_LICENSE("GPL");
1204 int init_module(void)
1209 for (z = 0; z < DEVMAX; z++) {
1210 moddevs[z].init = ibmlana_probe;
1211 moddevs[z].irq = irq;
1212 moddevs[z].base_addr = io;
1213 res = register_netdev(moddevs + z);
1215 return (z > 0) ? 0 : -EIO;
1221 void cleanup_module(void)
1223 struct IBMLANA_NETDEV *dev;
1228 printk("cannot unload, module in use\n");
1232 for (z = 0; z < DEVMAX; z++) {
1234 if (dev->priv != NULL) {
1235 priv = (ibmlana_priv *) dev->priv;
1236 /*DeinitBoard(dev); */
1238 free_irq(dev->irq, dev);
1240 release_region(dev->base_addr, IBM_LANA_IORANGE);
1241 unregister_netdev(dev);
1242 #if (LINUX_VERSION_CODE >= 0x20200)
1243 mca_mark_as_unused(priv->slot);
1245 mca_set_adapter_name(priv->slot, "");
1246 mca_set_adapter_procfn(priv->slot, NULL, NULL);