2 net-3-driver for the SKNET MCA-based cards
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 3C523 driver and the SK_G16 driver.
12 'PC Hardware: Aufbau, Funktionsweise, Programmierung' by
13 Hans-Peter Messmer for the basic Microchannel stuff
15 'Linux Geraetetreiber' by Allesandro Rubini, Kalle Dalheimer
16 for help on Ethernet driver programming
18 'Ethernet/IEEE 802.3 Family 1992 World Network Data Book/Handbook' by AMD
19 for documentation on the AM7990 LANCE
21 'SKNET Personal Technisches Manual', Version 1.2 by Schneider&Koch
22 for documentation on the Junior board
24 'SK-NET MC2+ Technical Manual", Version 1.1 by Schneider&Koch for
25 documentation on the MC2 bord
27 A big thank you to the S&K support for providing me so quickly with
30 Also see http://www.syskonnect.com/
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
43 added private structure, methods
44 begun building data structures in RAM
46 can receive frames, send frames
48 modularized initialization of LANCE
53 support for multiple devices
54 display media type for MC2+
56 fixed problem in GetLANCE leaving interrupts turned off
57 increase TX queue to 4 packets to improve send performance
59 a few corrections in statistics, caught rcvr overruns
60 reinitialization of LANCE/board in critical situations
62 implemented LANCE multicast filter
64 additions for Linux 2.2
66 unfortunately there seem to be newer MC2+ boards that react
67 on IRQ 3/5/9/10 instead of 3/5/10/11, so we have to autoprobe
68 in questionable cases...
70 integrated patches from David Weinehall & Bill Wendling for 2.3
71 kernels (isa_...functions). Things are defined in a way that
72 it still works with 2.0.x 8-)
74 added handling of the remaining interrupt conditions. That
75 should cure the spurious hangs.
77 newer kernels automatically probe more than one board, so the
78 'startslot' as a variable is also needed here
80 added changes for recent 2.3 kernels
82 *************************************************************************/
84 #include <linux/kernel.h>
85 #include <linux/string.h>
86 #include <linux/errno.h>
87 #include <linux/ioport.h>
88 #include <linux/slab.h>
89 #include <linux/interrupt.h>
90 #include <linux/delay.h>
91 #include <linux/time.h>
92 #include <linux/mca-legacy.h>
93 #include <linux/init.h>
94 #include <linux/module.h>
95 #include <linux/version.h>
96 #include <linux/netdevice.h>
97 #include <linux/etherdevice.h>
98 #include <linux/skbuff.h>
100 #include <asm/processor.h>
101 #include <asm/bitops.h>
104 #define _SK_MCA_DRIVER_
107 /* ------------------------------------------------------------------------
108 * global static data - not more since we can handle multiple boards and
109 * have to pack all state info into the device struct!
110 * ------------------------------------------------------------------------ */
112 static char *MediaNames[Media_Count] =
113 { "10Base2", "10BaseT", "10Base5", "Unknown" };
115 static unsigned char poly[] =
116 { 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0,
117 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0
120 /* ------------------------------------------------------------------------
121 * private subfunctions
122 * ------------------------------------------------------------------------ */
124 /* dump parts of shared memory - only needed during debugging */
127 static void dumpmem(struct net_device *dev, u32 start, u32 len)
131 for (z = 0; z < len; z++) {
134 printk(" %02x", SKMCA_READB(dev->mem_start + start + z));
140 /* print exact time - ditto */
142 static void PrTime(void)
146 do_gettimeofday(&tv);
147 printk("%9d:%06d: ", tv.tv_sec, tv.tv_usec);
151 /* deduce resources out of POS registers */
153 static void __init getaddrs(int slot, int junior, int *base, int *irq,
154 skmca_medium * medium)
156 u_char pos0, pos1, pos2;
159 pos0 = mca_read_stored_pos(slot, 2);
160 *base = ((pos0 & 0x0e) << 13) + 0xc0000;
161 *irq = ((pos0 & 0x10) >> 4) + 10;
162 *medium = Media_Unknown;
164 /* reset POS 104 Bits 0+1 so the shared memory region goes to the
165 configured area between 640K and 1M. Afterwards, enable the MC2.
166 I really don't know what rode SK to do this... */
168 mca_write_pos(slot, 4,
169 mca_read_stored_pos(slot, 4) & 0xfc);
170 mca_write_pos(slot, 2,
171 mca_read_stored_pos(slot, 2) | 0x01);
173 pos1 = mca_read_stored_pos(slot, 3);
174 pos2 = mca_read_stored_pos(slot, 4);
175 *base = ((pos1 & 0x07) << 14) + 0xc0000;
176 switch (pos2 & 0x0c) {
190 *medium = (pos2 >> 6) & 3;
194 /* check for both cards:
195 When the MC2 is turned off, it was configured for more than 15MB RAM,
196 is disabled and won't get detected using the standard probe. We
197 therefore have to scan the slots manually :-( */
199 static int __init dofind(int *junior, int firstslot)
204 for (slot = firstslot; slot < MCA_MAX_SLOT_NR; slot++) {
205 id = mca_read_stored_pos(slot, 0)
206 + (((unsigned int) mca_read_stored_pos(slot, 1)) << 8);
209 if (id == SKNET_MCA_ID)
212 if (id == SKNET_JUNIOR_MCA_ID)
218 /* reset the whole board */
220 static void ResetBoard(struct net_device *dev)
222 skmca_priv *priv = (skmca_priv *) dev->priv;
224 SKMCA_WRITEB(CTRL_RESET_ON, priv->ctrladdr);
226 SKMCA_WRITEB(CTRL_RESET_OFF, priv->ctrladdr);
229 /* wait for LANCE interface to become not busy */
231 static int WaitLANCE(struct net_device *dev)
233 skmca_priv *priv = (skmca_priv *) dev->priv;
236 while ((SKMCA_READB(priv->ctrladdr) & STAT_IO_BUSY) ==
240 printk("%s: LANCE access timeout", dev->name);
248 /* set LANCE register - must be atomic */
250 static void SetLANCE(struct net_device *dev, u16 addr, u16 value)
252 skmca_priv *priv = (skmca_priv *) dev->priv;
255 /* disable interrupts */
257 spin_lock_irqsave(&priv->lock, flags);
259 /* wait until no transfer is pending */
263 /* transfer register address to RAP */
265 SKMCA_WRITEB(CTRL_RESET_OFF | CTRL_RW_WRITE | CTRL_ADR_RAP,
267 SKMCA_WRITEW(addr, priv->ioregaddr);
268 SKMCA_WRITEB(IOCMD_GO, priv->cmdaddr);
272 /* transfer data to register */
274 SKMCA_WRITEB(CTRL_RESET_OFF | CTRL_RW_WRITE | CTRL_ADR_DATA,
276 SKMCA_WRITEW(value, priv->ioregaddr);
277 SKMCA_WRITEB(IOCMD_GO, priv->cmdaddr);
281 /* reenable interrupts */
283 spin_unlock_irqrestore(&priv->lock, flags);
286 /* get LANCE register */
288 static u16 GetLANCE(struct net_device *dev, u16 addr)
290 skmca_priv *priv = (skmca_priv *) dev->priv;
294 /* disable interrupts */
296 spin_lock_irqsave(&priv->lock, flags);
298 /* wait until no transfer is pending */
302 /* transfer register address to RAP */
304 SKMCA_WRITEB(CTRL_RESET_OFF | CTRL_RW_WRITE | CTRL_ADR_RAP,
306 SKMCA_WRITEW(addr, priv->ioregaddr);
307 SKMCA_WRITEB(IOCMD_GO, priv->cmdaddr);
311 /* transfer data from register */
313 SKMCA_WRITEB(CTRL_RESET_OFF | CTRL_RW_READ | CTRL_ADR_DATA,
315 SKMCA_WRITEB(IOCMD_GO, priv->cmdaddr);
318 res = SKMCA_READW(priv->ioregaddr);
320 /* reenable interrupts */
322 spin_unlock_irqrestore(&priv->lock, flags);
327 /* build up descriptors in shared RAM */
329 static void InitDscrs(struct net_device *dev)
333 /* Set up Tx descriptors. The board has only 16K RAM so bits 16..23
336 bufaddr = RAM_DATABASE;
341 for (z = 0; z < TXCOUNT; z++) {
342 descr.LowAddr = bufaddr;
346 SKMCA_TOIO(dev->mem_start + RAM_TXBASE +
347 (z * sizeof(LANCE_TxDescr)), &descr,
348 sizeof(LANCE_TxDescr));
349 SKMCA_SETIO(dev->mem_start + bufaddr, 0,
351 bufaddr += RAM_BUFSIZE;
355 /* do the same for the Rx descriptors */
361 for (z = 0; z < RXCOUNT; z++) {
362 descr.LowAddr = bufaddr;
363 descr.Flags = RXDSCR_FLAGS_OWN;
364 descr.MaxLen = -RAM_BUFSIZE;
366 SKMCA_TOIO(dev->mem_start + RAM_RXBASE +
367 (z * sizeof(LANCE_RxDescr)), &descr,
368 sizeof(LANCE_RxDescr));
369 SKMCA_SETIO(dev->mem_start + bufaddr, 0,
371 bufaddr += RAM_BUFSIZE;
376 /* calculate the hash bit position for a given multicast address
377 taken more or less directly from the AMD datasheet... */
379 static void UpdateCRC(unsigned char *CRC, int bit)
383 /* shift CRC one bit */
385 memmove(CRC + 1, CRC, 32 * sizeof(unsigned char));
388 /* if bit XOR controlbit = 1, set CRC = CRC XOR polynomial */
391 for (j = 0; j < 32; j++)
395 static unsigned int GetHash(char *address)
397 unsigned char CRC[33];
398 int i, byte, hashcode;
400 /* a multicast address has bit 0 in the first byte set */
402 if ((address[0] & 1) == 0)
407 memset(CRC, 1, sizeof(CRC));
409 /* loop through address bits */
411 for (byte = 0; byte < 6; byte++)
412 for (i = 0; i < 8; i++)
413 UpdateCRC(CRC, (address[byte] >> i) & 1);
415 /* hashcode is the 6 least significant bits of the CRC */
418 for (i = 0; i < 6; i++)
419 hashcode = (hashcode << 1) + CRC[i];
423 /* feed ready-built initialization block into LANCE */
425 static void InitLANCE(struct net_device *dev)
427 skmca_priv *priv = (skmca_priv *) dev->priv;
429 /* build up descriptors. */
433 /* next RX descriptor to be read is the first one. Since the LANCE
434 will start from the beginning after initialization, we have to
435 reset out pointers too. */
439 /* no TX descriptors active */
441 priv->nexttxput = priv->nexttxdone = priv->txbusy = 0;
443 /* set up the LANCE bus control register - constant for SKnet boards */
445 SetLANCE(dev, LANCE_CSR3,
446 CSR3_BSWAP_OFF | CSR3_ALE_LOW | CSR3_BCON_HOLD);
448 /* write address of initialization block into LANCE */
450 SetLANCE(dev, LANCE_CSR1, RAM_INITBASE & 0xffff);
451 SetLANCE(dev, LANCE_CSR2, (RAM_INITBASE >> 16) & 0xff);
453 /* we don't get ready until the LANCE has read the init block */
455 netif_stop_queue(dev);
457 /* let LANCE read the initialization block. LANCE is ready
458 when we receive the corresponding interrupt. */
460 SetLANCE(dev, LANCE_CSR0, CSR0_INEA | CSR0_INIT);
463 /* stop the LANCE so we can reinitialize it */
465 static void StopLANCE(struct net_device *dev)
467 /* can't take frames any more */
469 netif_stop_queue(dev);
471 /* disable interrupts, stop it */
473 SetLANCE(dev, LANCE_CSR0, CSR0_STOP);
476 /* initialize card and LANCE for proper operation */
478 static void InitBoard(struct net_device *dev)
480 LANCE_InitBlock block;
482 /* Lay out the shared RAM - first we create the init block for the LANCE.
483 We do not overwrite it later because we need it again when we switch
484 promiscous mode on/off. */
487 if (dev->flags & IFF_PROMISC)
488 block.Mode |= LANCE_INIT_PROM;
489 memcpy(block.PAdr, dev->dev_addr, 6);
490 memset(block.LAdrF, 0, sizeof(block.LAdrF));
491 block.RdrP = (RAM_RXBASE & 0xffffff) | (LRXCOUNT << 29);
492 block.TdrP = (RAM_TXBASE & 0xffffff) | (LTXCOUNT << 29);
494 SKMCA_TOIO(dev->mem_start + RAM_INITBASE, &block, sizeof(block));
496 /* initialize LANCE. Implicitly sets up other structures in RAM. */
501 /* deinitialize card and LANCE */
503 static void DeinitBoard(struct net_device *dev)
514 /* probe for device's irq */
516 static int __init ProbeIRQ(struct net_device *dev)
518 unsigned long imaskval, njiffies, irq;
521 /* enable all interrupts */
523 imaskval = probe_irq_on();
525 /* initialize the board. Wait for interrupt 'Initialization done'. */
530 njiffies = jiffies + HZ;
532 csr0val = GetLANCE(dev, LANCE_CSR0);
534 while (((csr0val & CSR0_IDON) == 0) && (jiffies != njiffies));
536 /* turn of interrupts again */
538 irq = probe_irq_off(imaskval);
540 /* if we found something, ack the interrupt */
543 SetLANCE(dev, LANCE_CSR0, csr0val | CSR0_IDON);
545 /* back to idle state */
552 /* ------------------------------------------------------------------------
553 * interrupt handler(s)
554 * ------------------------------------------------------------------------ */
556 /* LANCE has read initialization block -> start it */
558 static u16 irqstart_handler(struct net_device *dev, u16 oldcsr0)
560 /* now we're ready to transmit */
562 netif_wake_queue(dev);
564 /* reset IDON bit, start LANCE */
566 SetLANCE(dev, LANCE_CSR0, oldcsr0 | CSR0_IDON | CSR0_STRT);
567 return GetLANCE(dev, LANCE_CSR0);
570 /* did we lose blocks due to a FIFO overrun ? */
572 static u16 irqmiss_handler(struct net_device *dev, u16 oldcsr0)
574 skmca_priv *priv = (skmca_priv *) dev->priv;
576 /* update statistics */
578 priv->stat.rx_fifo_errors++;
582 SetLANCE(dev, LANCE_CSR0, oldcsr0 | CSR0_MISS);
583 return GetLANCE(dev, LANCE_CSR0);
586 /* receive interrupt */
588 static u16 irqrx_handler(struct net_device *dev, u16 oldcsr0)
590 skmca_priv *priv = (skmca_priv *) dev->priv;
592 unsigned int descraddr;
594 /* run through queue until we reach a descriptor we do not own */
596 descraddr = RAM_RXBASE + (priv->nextrx * sizeof(LANCE_RxDescr));
598 /* read descriptor */
599 SKMCA_FROMIO(&descr, dev->mem_start + descraddr,
600 sizeof(LANCE_RxDescr));
602 /* if we reach a descriptor we do not own, we're done */
603 if ((descr.Flags & RXDSCR_FLAGS_OWN) != 0)
608 printk("Receive packet on descr %d len %d\n", priv->nextrx,
612 /* erroneous packet ? */
613 if ((descr.Flags & RXDSCR_FLAGS_ERR) != 0) {
614 priv->stat.rx_errors++;
615 if ((descr.Flags & RXDSCR_FLAGS_CRC) != 0)
616 priv->stat.rx_crc_errors++;
617 else if ((descr.Flags & RXDSCR_FLAGS_CRC) != 0)
618 priv->stat.rx_frame_errors++;
619 else if ((descr.Flags & RXDSCR_FLAGS_OFLO) != 0)
620 priv->stat.rx_fifo_errors++;
627 skb = dev_alloc_skb(descr.Len + 2);
629 priv->stat.rx_dropped++;
631 SKMCA_FROMIO(skb_put(skb, descr.Len),
633 descr.LowAddr, descr.Len);
635 skb->protocol = eth_type_trans(skb, dev);
636 skb->ip_summed = CHECKSUM_NONE;
637 priv->stat.rx_packets++;
638 priv->stat.rx_bytes += descr.Len;
640 dev->last_rx = jiffies;
644 /* give descriptor back to LANCE */
646 descr.Flags |= RXDSCR_FLAGS_OWN;
648 /* update descriptor in shared RAM */
649 SKMCA_TOIO(dev->mem_start + descraddr, &descr,
650 sizeof(LANCE_RxDescr));
652 /* go to next descriptor */
654 descraddr += sizeof(LANCE_RxDescr);
655 if (priv->nextrx >= RXCOUNT) {
657 descraddr = RAM_RXBASE;
663 SetLANCE(dev, LANCE_CSR0, oldcsr0 | CSR0_RINT);
664 return GetLANCE(dev, LANCE_CSR0);
667 /* transmit interrupt */
669 static u16 irqtx_handler(struct net_device *dev, u16 oldcsr0)
671 skmca_priv *priv = (skmca_priv *) dev->priv;
673 unsigned int descraddr;
675 /* check descriptors at most until no busy one is left */
678 RAM_TXBASE + (priv->nexttxdone * sizeof(LANCE_TxDescr));
679 while (priv->txbusy > 0) {
680 /* read descriptor */
681 SKMCA_FROMIO(&descr, dev->mem_start + descraddr,
682 sizeof(LANCE_TxDescr));
684 /* if the LANCE still owns this one, we've worked out all sent packets */
685 if ((descr.Flags & TXDSCR_FLAGS_OWN) != 0)
690 printk("Send packet done on descr %d\n", priv->nexttxdone);
693 /* update statistics */
694 if ((descr.Flags & TXDSCR_FLAGS_ERR) == 0) {
695 priv->stat.tx_packets++;
696 priv->stat.tx_bytes++;
698 priv->stat.tx_errors++;
699 if ((descr.Status & TXDSCR_STATUS_UFLO) != 0) {
700 priv->stat.tx_fifo_errors++;
704 if ((descr.Status & TXDSCR_STATUS_LCOL) !=
705 0) priv->stat.tx_window_errors++;
706 else if ((descr.Status & TXDSCR_STATUS_LCAR) != 0)
707 priv->stat.tx_carrier_errors++;
708 else if ((descr.Status & TXDSCR_STATUS_RTRY) != 0)
709 priv->stat.tx_aborted_errors++;
712 /* go to next descriptor */
714 descraddr += sizeof(LANCE_TxDescr);
715 if (priv->nexttxdone >= TXCOUNT) {
716 priv->nexttxdone = 0;
717 descraddr = RAM_TXBASE;
722 /* reset TX interrupt bit */
724 SetLANCE(dev, LANCE_CSR0, oldcsr0 | CSR0_TINT);
725 oldcsr0 = GetLANCE(dev, LANCE_CSR0);
727 /* at least one descriptor is freed. Therefore we can accept
729 /* inform upper layers we're in business again */
731 netif_wake_queue(dev);
736 /* general interrupt entry */
738 static irqreturn_t irq_handler(int irq, void *device, struct pt_regs *regs)
740 struct net_device *dev = (struct net_device *) device;
743 /* read CSR0 to get interrupt cause */
745 csr0val = GetLANCE(dev, LANCE_CSR0);
747 /* in case we're not meant... */
749 if ((csr0val & CSR0_INTR) == 0)
753 set_bit(LINK_STATE_RXSEM, &dev->state);
756 /* loop through the interrupt bits until everything is clear */
759 if ((csr0val & CSR0_IDON) != 0)
760 csr0val = irqstart_handler(dev, csr0val);
761 if ((csr0val & CSR0_RINT) != 0)
762 csr0val = irqrx_handler(dev, csr0val);
763 if ((csr0val & CSR0_MISS) != 0)
764 csr0val = irqmiss_handler(dev, csr0val);
765 if ((csr0val & CSR0_TINT) != 0)
766 csr0val = irqtx_handler(dev, csr0val);
767 if ((csr0val & CSR0_MERR) != 0) {
768 SetLANCE(dev, LANCE_CSR0, csr0val | CSR0_MERR);
769 csr0val = GetLANCE(dev, LANCE_CSR0);
771 if ((csr0val & CSR0_BABL) != 0) {
772 SetLANCE(dev, LANCE_CSR0, csr0val | CSR0_BABL);
773 csr0val = GetLANCE(dev, LANCE_CSR0);
776 while ((csr0val & CSR0_INTR) != 0);
779 clear_bit(LINK_STATE_RXSEM, &dev->state);
784 /* ------------------------------------------------------------------------
786 * ------------------------------------------------------------------------ */
790 static int skmca_getinfo(char *buf, int slot, void *d)
793 struct net_device *dev = (struct net_device *) d;
796 /* can't say anything about an uninitialized device... */
800 if (dev->priv == NULL)
802 priv = (skmca_priv *) dev->priv;
806 len += sprintf(buf + len, "IRQ: %d\n", priv->realirq);
807 len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start,
810 sprintf(buf + len, "Transceiver: %s\n",
811 MediaNames[priv->medium]);
812 len += sprintf(buf + len, "Device: %s\n", dev->name);
813 len += sprintf(buf + len, "MAC address:");
814 for (i = 0; i < 6; i++)
815 len += sprintf(buf + len, " %02x", dev->dev_addr[i]);
822 /* open driver. Means also initialization and start of LANCE */
824 static int skmca_open(struct net_device *dev)
827 skmca_priv *priv = (skmca_priv *) dev->priv;
829 /* register resources - only necessary for IRQ */
831 request_irq(priv->realirq, irq_handler,
832 SA_SHIRQ | SA_SAMPLE_RANDOM, "sk_mca", dev);
834 printk("%s: failed to register irq %d\n", dev->name,
838 dev->irq = priv->realirq;
840 /* set up the card and LANCE */
846 netif_start_queue(dev);
851 /* close driver. Shut down board and free allocated resources */
853 static int skmca_close(struct net_device *dev)
858 /* release resources */
860 free_irq(dev->irq, dev);
866 /* transmit a block. */
868 static int skmca_tx(struct sk_buff *skb, struct net_device *dev)
870 skmca_priv *priv = (skmca_priv *) dev->priv;
872 unsigned int address;
873 int tmplen, retval = 0;
876 /* if we get called with a NULL descriptor, the Ethernet layer thinks
877 our card is stuck an we should reset it. We'll do this completely: */
882 return 0; /* don't try to free the block here ;-) */
885 /* is there space in the Tx queue ? If no, the upper layer gave us a
886 packet in spite of us not being ready and is really in trouble.
887 We'll do the dropping for him: */
888 if (priv->txbusy >= TXCOUNT) {
889 priv->stat.tx_dropped++;
894 /* get TX descriptor */
895 address = RAM_TXBASE + (priv->nexttxput * sizeof(LANCE_TxDescr));
896 SKMCA_FROMIO(&descr, dev->mem_start + address,
897 sizeof(LANCE_TxDescr));
899 /* enter packet length as 2s complement - assure minimum length */
903 descr.Len = 65536 - tmplen;
905 /* copy filler into RAM - in case we're filling up...
906 we're filling a bit more than necessary, but that doesn't harm
907 since the buffer is far larger... */
908 if (tmplen > skb->len) {
909 char *fill = "NetBSD is a nice OS too! ";
910 unsigned int destoffs = 0, l = strlen(fill);
912 while (destoffs < tmplen) {
913 SKMCA_TOIO(dev->mem_start + descr.LowAddr +
919 /* do the real data copying */
920 SKMCA_TOIO(dev->mem_start + descr.LowAddr, skb->data, skb->len);
922 /* hand descriptor over to LANCE - this is the first and last chunk */
924 TXDSCR_FLAGS_OWN | TXDSCR_FLAGS_STP | TXDSCR_FLAGS_ENP;
928 printk("Send packet on descr %d len %d\n", priv->nexttxput,
932 /* one more descriptor busy */
934 spin_lock_irqsave(&priv->lock, flags);
937 if (priv->nexttxput >= TXCOUNT)
941 /* are we saturated ? */
943 if (priv->txbusy >= TXCOUNT)
944 netif_stop_queue(dev);
946 /* write descriptor back to RAM */
947 SKMCA_TOIO(dev->mem_start + address, &descr,
948 sizeof(LANCE_TxDescr));
950 /* if no descriptors were active, give the LANCE a hint to read it
953 if (priv->txbusy == 0)
954 SetLANCE(dev, LANCE_CSR0, CSR0_INEA | CSR0_TDMD);
956 spin_unlock_irqrestore(&priv->lock, flags);
965 /* return pointer to Ethernet statistics */
967 static struct net_device_stats *skmca_stats(struct net_device *dev)
969 skmca_priv *priv = (skmca_priv *) dev->priv;
971 return &(priv->stat);
974 /* we don't support runtime reconfiguration, since an MCA card can
975 be unambigously identified by its POS registers. */
977 static int skmca_config(struct net_device *dev, struct ifmap *map)
982 /* switch receiver mode. We use the LANCE's multicast filter to prefilter
983 multicast addresses. */
985 static void skmca_set_multicast_list(struct net_device *dev)
987 LANCE_InitBlock block;
989 /* first stop the LANCE... */
992 /* ...then modify the initialization block... */
993 SKMCA_FROMIO(&block, dev->mem_start + RAM_INITBASE, sizeof(block));
994 if (dev->flags & IFF_PROMISC)
995 block.Mode |= LANCE_INIT_PROM;
997 block.Mode &= ~LANCE_INIT_PROM;
999 if (dev->flags & IFF_ALLMULTI) { /* get all multicasts */
1000 memset(block.LAdrF, 0xff, sizeof(block.LAdrF));
1001 } else { /* get selected/no multicasts */
1003 struct dev_mc_list *mptr;
1006 memset(block.LAdrF, 0, sizeof(block.LAdrF));
1007 for (mptr = dev->mc_list; mptr != NULL; mptr = mptr->next) {
1008 code = GetHash(mptr->dmi_addr);
1009 block.LAdrF[(code >> 3) & 7] |= 1 << (code & 7);
1013 SKMCA_TOIO(dev->mem_start + RAM_INITBASE, &block, sizeof(block));
1015 /* ...then reinit LANCE with the correct flags */
1019 /* ------------------------------------------------------------------------
1021 * ------------------------------------------------------------------------ */
1023 static int startslot; /* counts through slots when probing multiple devices */
1025 static void cleanup_card(struct net_device *dev)
1027 skmca_priv *priv = dev->priv;
1030 free_irq(dev->irq, dev);
1031 mca_mark_as_unused(priv->slot);
1032 mca_set_adapter_procfn(priv->slot, NULL, NULL);
1035 struct net_device * __init skmca_probe(int unit)
1037 struct net_device *dev;
1038 int force_detect = 0;
1039 int junior, slot, i;
1040 int base = 0, irq = 0;
1042 skmca_medium medium;
1045 /* can't work without an MCA bus ;-) */
1048 return ERR_PTR(-ENODEV);
1050 dev = alloc_etherdev(sizeof(skmca_priv));
1052 return ERR_PTR(-ENOMEM);
1055 sprintf(dev->name, "eth%d", unit);
1056 netdev_boot_setup_check(dev);
1059 SET_MODULE_OWNER(dev);
1061 /* start address of 1 --> forced detection */
1063 if (dev->mem_start == 1)
1066 /* search through slots */
1068 base = dev->mem_start;
1069 irq = dev->base_addr;
1070 for (slot = startslot; (slot = dofind(&junior, slot)) != -1; slot++) {
1071 /* deduce card addresses */
1073 getaddrs(slot, junior, &base, &irq, &medium);
1075 /* slot already in use ? */
1077 if (mca_is_adapter_used(slot))
1080 /* were we looking for something different ? */
1082 if (dev->irq && dev->irq != irq)
1084 if (dev->mem_start && dev->mem_start != base)
1087 /* found something that matches */
1092 /* nothing found ? */
1096 return (base || irq) ? ERR_PTR(-ENXIO) : ERR_PTR(-ENODEV);
1099 /* make procfs entries */
1102 mca_set_adapter_name(slot,
1103 "SKNET junior MC2 Ethernet Adapter");
1105 mca_set_adapter_name(slot, "SKNET MC2+ Ethernet Adapter");
1106 mca_set_adapter_procfn(slot, (MCA_ProcFn) skmca_getinfo, dev);
1108 mca_mark_as_used(slot);
1110 /* announce success */
1111 printk("%s: SKNet %s adapter found in slot %d\n", dev->name,
1112 junior ? "Junior MC2" : "MC2+", slot + 1);
1114 /* allocate structure */
1117 priv->macbase = base + 0x3fc0;
1118 priv->ioregaddr = base + 0x3ff0;
1119 priv->ctrladdr = base + 0x3ff2;
1120 priv->cmdaddr = base + 0x3ff3;
1121 priv->medium = medium;
1122 memset(&priv->stat, 0, sizeof(struct net_device_stats));
1123 spin_lock_init(&priv->lock);
1125 /* set base + irq for this device (irq not allocated so far) */
1127 dev->mem_start = base;
1128 dev->mem_end = base + 0x4000;
1135 ("%s: ambigous POS bit combination, must probe for IRQ...\n",
1137 nirq = ProbeIRQ(dev);
1139 printk("%s: IRQ probe failed, assuming IRQ %d",
1140 dev->name, priv->realirq = -irq);
1142 priv->realirq = nirq;
1144 priv->realirq = irq;
1147 dev->open = skmca_open;
1148 dev->stop = skmca_close;
1149 dev->set_config = skmca_config;
1150 dev->hard_start_xmit = skmca_tx;
1151 dev->do_ioctl = NULL;
1152 dev->get_stats = skmca_stats;
1153 dev->set_multicast_list = skmca_set_multicast_list;
1154 dev->flags |= IFF_MULTICAST;
1156 /* copy out MAC address */
1157 for (i = 0; i < 6; i++)
1158 dev->dev_addr[i] = SKMCA_READB(priv->macbase + (i << 1));
1161 printk("%s: IRQ %d, memory %#lx-%#lx, "
1162 "MAC address %02x:%02x:%02x:%02x:%02x:%02x.\n",
1163 dev->name, priv->realirq, dev->mem_start, dev->mem_end - 1,
1164 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1165 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1166 printk("%s: %s medium\n", dev->name, MediaNames[priv->medium]);
1172 startslot = slot + 1;
1174 err = register_netdev(dev);
1183 /* ------------------------------------------------------------------------
1184 * modularization support
1185 * ------------------------------------------------------------------------ */
1188 MODULE_LICENSE("GPL");
1192 static struct net_device *moddevs[DEVMAX];
1194 int init_module(void)
1199 for (z = 0; z < DEVMAX; z++) {
1200 struct net_device *dev = skmca_probe(-1);
1210 void cleanup_module(void)
1214 for (z = 0; z < DEVMAX; z++) {
1215 struct net_device *dev = moddevs[z];
1217 unregister_netdev(dev);