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 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 intialization 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 small fixes (David Weinehall)
68 *************************************************************************/
70 #include <linux/module.h>
71 #include <linux/version.h>
73 #include <linux/kernel.h>
74 #include <linux/version.h>
75 #include <linux/sched.h>
76 #include <linux/string.h>
77 #include <linux/errno.h>
78 #include <linux/ioport.h>
79 #include <linux/malloc.h>
80 #include <linux/interrupt.h>
81 #include <linux/delay.h>
82 #include <linux/time.h>
83 #include <linux/mca.h>
84 #include <asm/processor.h>
85 #include <asm/bitops.h>
88 #include <linux/netdevice.h>
89 #include <linux/etherdevice.h>
90 #include <linux/skbuff.h>
92 #define _SK_MCA_DRIVER_
95 /* ------------------------------------------------------------------------
96 * global static data - not more since we can handle multiple boards and
97 * have to pack all state info into the device struct!
98 * ------------------------------------------------------------------------ */
100 static char *MediaNames
[Media_Count
]=
101 {"10Base2", "10BaseT", "10Base5", "Unknown"};
103 static unsigned char poly
[] =
104 {1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0,
105 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0};
107 /* ------------------------------------------------------------------------
108 * private subfunctions
109 * ------------------------------------------------------------------------ */
111 /* dump parts of shared memory - only needed during debugging */
114 static void dumpmem(struct net_device
*dev
, u32 start
, u32 len
)
118 for (z
= 0; z
< len
; z
++)
122 printk(" %02x", readb(dev
->mem_start
+ start
+ z
));
128 /* print exact time - ditto */
130 static void PrTime(void)
134 do_gettimeofday(&tv
);
135 printk("%9d:%06d: ", tv
.tv_sec
, tv
.tv_usec
);
139 /* deduce resources out of POS registers */
141 static void getaddrs(int slot
, int junior
, int *base
, int *irq
,
142 skmca_medium
*medium
)
144 u_char pos0
, pos1
, pos2
;
148 pos0
= mca_read_stored_pos(slot
, 2);
149 *base
= ((pos0
& 0x0e) << 13) + 0xc0000;
150 *irq
= ((pos0
& 0x10) >> 4) + 10;
151 *medium
= Media_Unknown
;
155 /* reset POS 104 Bits 0+1 so the shared memory region goes to the
156 configured area between 640K and 1M. Afterwards, enable the MC2.
157 I really don't know what rode SK to do this... */
159 mca_write_pos(slot
, 4, mca_read_stored_pos(slot
, 4) & 0xfc);
160 mca_write_pos(slot
, 2, mca_read_stored_pos(slot
, 2) | 0x01);
162 pos1
= mca_read_stored_pos(slot
, 3);
163 pos2
= mca_read_stored_pos(slot
, 4);
164 *base
= ((pos1
& 0x07) << 14) + 0xc0000;
167 case 0: *irq
= 3; break;
168 case 4: *irq
= 5; break;
169 case 8: *irq
= 10; break;
170 case 12: *irq
= 11; break;
172 *medium
= (pos2
>> 6) & 3;
176 /* check for both cards:
177 When the MC2 is turned off, it was configured for more than 15MB RAM,
178 is disabled and won't get detected using the standard probe. We
179 therefore have to scan the slots manually :-( */
181 static int dofind(int *junior
, int firstslot
)
186 for (slot
= firstslot
; slot
< MCA_MAX_SLOT_NR
; slot
++)
188 id
= mca_read_stored_pos(slot
, 0)
189 + (((unsigned int) mca_read_stored_pos(slot
, 1)) << 8);
192 if (id
== SKNET_MCA_ID
)
195 if (id
== SKNET_JUNIOR_MCA_ID
)
201 /* reset the whole board */
203 static void ResetBoard(struct net_device
*dev
)
205 skmca_priv
*priv
= (skmca_priv
*) dev
->priv
;
207 writeb(CTRL_RESET_ON
, priv
->ctrladdr
);
209 writeb(CTRL_RESET_OFF
, priv
->ctrladdr
);
212 /* set LANCE register - must be atomic */
214 static void SetLANCE(struct net_device
*dev
, u16 addr
, u16 value
)
216 skmca_priv
*priv
= (skmca_priv
*) dev
->priv
;
219 /* disable interrupts */
224 /* wait until no transfer is pending */
226 while ((readb(priv
->ctrladdr
) & STAT_IO_BUSY
) == STAT_IO_BUSY
);
228 /* transfer register address to RAP */
230 writeb(CTRL_RESET_OFF
| CTRL_RW_WRITE
| CTRL_ADR_RAP
, priv
->ctrladdr
);
231 writew(addr
, priv
->ioregaddr
);
232 writeb(IOCMD_GO
, priv
->cmdaddr
);
234 while ((readb(priv
->ctrladdr
) & STAT_IO_BUSY
) == STAT_IO_BUSY
);
236 /* transfer data to register */
238 writeb(CTRL_RESET_OFF
| CTRL_RW_WRITE
| CTRL_ADR_DATA
, priv
->ctrladdr
);
239 writew(value
, priv
->ioregaddr
);
240 writeb(IOCMD_GO
, priv
->cmdaddr
);
242 while ((readb(priv
->ctrladdr
) & STAT_IO_BUSY
) == STAT_IO_BUSY
);
244 /* reenable interrupts */
246 restore_flags(flags
);
249 /* get LANCE register */
251 static u16
GetLANCE(struct net_device
*dev
, u16 addr
)
253 skmca_priv
*priv
= (skmca_priv
*) dev
->priv
;
257 /* disable interrupts */
262 /* wait until no transfer is pending */
264 while ((readb(priv
->ctrladdr
) & STAT_IO_BUSY
) == STAT_IO_BUSY
);
266 /* transfer register address to RAP */
268 writeb(CTRL_RESET_OFF
| CTRL_RW_WRITE
| CTRL_ADR_RAP
, priv
->ctrladdr
);
269 writew(addr
, priv
->ioregaddr
);
270 writeb(IOCMD_GO
, priv
->cmdaddr
);
272 while ((readb(priv
->ctrladdr
) & STAT_IO_BUSY
) == STAT_IO_BUSY
);
274 /* transfer data from register */
276 writeb(CTRL_RESET_OFF
| CTRL_RW_READ
| CTRL_ADR_DATA
, priv
->ctrladdr
);
277 writeb(IOCMD_GO
, priv
->cmdaddr
);
279 while ((readb(priv
->ctrladdr
) & STAT_IO_BUSY
) == STAT_IO_BUSY
);
280 res
= readw(priv
->ioregaddr
);
282 /* reenable interrupts */
284 restore_flags(flags
);
289 /* build up descriptors in shared RAM */
291 static void InitDscrs(struct net_device
*dev
)
295 /* Set up Tx descriptors. The board has only 16K RAM so bits 16..23
298 bufaddr
= RAM_DATABASE
;
303 for (z
= 0; z
< TXCOUNT
; z
++)
305 descr
.LowAddr
= bufaddr
;
309 memcpy_toio(dev
->mem_start
+ RAM_TXBASE
+ (z
* sizeof(LANCE_TxDescr
)),
310 &descr
, sizeof(LANCE_TxDescr
));
311 memset_io(dev
->mem_start
+ bufaddr
, 0, RAM_BUFSIZE
);
312 bufaddr
+= RAM_BUFSIZE
;
316 /* do the same for the Rx descriptors */
322 for (z
= 0; z
< RXCOUNT
; z
++)
324 descr
.LowAddr
= bufaddr
;
325 descr
.Flags
= RXDSCR_FLAGS_OWN
;
326 descr
.MaxLen
= -RAM_BUFSIZE
;
328 memcpy_toio(dev
->mem_start
+ RAM_RXBASE
+ (z
* sizeof(LANCE_RxDescr
)),
329 &descr
, sizeof(LANCE_RxDescr
));
330 memset_io(dev
->mem_start
+ bufaddr
, 0, RAM_BUFSIZE
);
331 bufaddr
+= RAM_BUFSIZE
;
336 /* calculate the hash bit position for a given multicast address
337 taken more or less directly from the AMD datasheet... */
339 static void UpdateCRC(unsigned char *CRC
, int bit
)
343 /* shift CRC one bit */
345 memmove(CRC
+ 1, CRC
, 32 * sizeof(unsigned char));
348 /* if bit XOR controlbit = 1, set CRC = CRC XOR polynomial */
351 for (j
= 0; j
< 32; j
++)
355 static unsigned int GetHash(char *address
)
357 unsigned char CRC
[33];
358 int i
, byte
, hashcode
;
360 /* a multicast address has bit 0 in the first byte set */
362 if ((address
[0] & 1) == 0)
367 memset(CRC
, 1, sizeof(CRC
));
369 /* loop through address bits */
371 for (byte
= 0; byte
< 6; byte
++)
372 for (i
= 0; i
< 8; i
++)
373 UpdateCRC(CRC
, (address
[byte
] >> i
) & 1);
375 /* hashcode is the 6 least significant bits of the CRC */
378 for (i
= 0; i
< 6; i
++)
379 hashcode
= (hashcode
<< 1) + CRC
[i
];
383 /* feed ready-built initialization block into LANCE */
385 static void InitLANCE(struct net_device
*dev
)
387 skmca_priv
*priv
= (skmca_priv
*) dev
->priv
;
389 /* build up descriptors. */
393 /* next RX descriptor to be read is the first one. Since the LANCE
394 will start from the beginning after initialization, we have to
395 reset out pointers too. */
399 /* no TX descriptors active */
401 priv
->nexttxput
= priv
->nexttxdone
= priv
->txbusy
= 0;
403 /* set up the LANCE bus control register - constant for SKnet boards */
405 SetLANCE(dev
, LANCE_CSR3
, CSR3_BSWAP_OFF
| CSR3_ALE_LOW
| CSR3_BCON_HOLD
);
407 /* write address of initialization block into LANCE */
409 SetLANCE(dev
, LANCE_CSR1
, RAM_INITBASE
& 0xffff);
410 SetLANCE(dev
, LANCE_CSR2
, (RAM_INITBASE
>> 16) & 0xff);
412 /* we don't get ready until the LANCE has read the init block */
416 /* let LANCE read the initialization block. LANCE is ready
417 when we receive the corresponding interrupt. */
419 SetLANCE(dev
, LANCE_CSR0
, CSR0_INEA
| CSR0_INIT
);
422 /* stop the LANCE so we can reinitialize it */
424 static void StopLANCE(struct net_device
*dev
)
426 /* can't take frames any more */
430 /* disable interrupts, stop it */
432 SetLANCE(dev
, LANCE_CSR0
, CSR0_STOP
);
435 /* initialize card and LANCE for proper operation */
437 static void InitBoard(struct net_device
*dev
)
439 LANCE_InitBlock block
;
441 /* Lay out the shared RAM - first we create the init block for the LANCE.
442 We do not overwrite it later because we need it again when we switch
443 promiscous mode on/off. */
446 if (dev
->flags
& IFF_PROMISC
)
447 block
.Mode
|= LANCE_INIT_PROM
;
448 memcpy(block
.PAdr
, dev
->dev_addr
, 6);
449 memset(block
.LAdrF
, 0, sizeof(block
.LAdrF
));
450 block
.RdrP
= (RAM_RXBASE
& 0xffffff) | (LRXCOUNT
<< 29);
451 block
.TdrP
= (RAM_TXBASE
& 0xffffff) | (LTXCOUNT
<< 29);
453 memcpy_toio(dev
->mem_start
+ RAM_INITBASE
, &block
, sizeof(block
));
455 /* initialize LANCE. Implicitly sets up other structures in RAM. */
460 /* deinitialize card and LANCE */
462 static void DeinitBoard(struct net_device
*dev
)
473 /* ------------------------------------------------------------------------
474 * interrupt handler(s)
475 * ------------------------------------------------------------------------ */
477 /* LANCE has read initializazion block -> start it */
479 static u16
irqstart_handler(struct net_device
*dev
, u16 oldcsr0
)
481 /* now we're ready to transmit */
485 /* reset IDON bit, start LANCE */
487 SetLANCE(dev
, LANCE_CSR0
, oldcsr0
| CSR0_IDON
| CSR0_STRT
);
488 return GetLANCE(dev
, LANCE_CSR0
);
491 /* receive interrupt */
493 static u16
irqrx_handler(struct net_device
*dev
, u16 oldcsr0
)
495 skmca_priv
*priv
= (skmca_priv
*) dev
->priv
;
497 unsigned int descraddr
;
499 /* did we loose blocks due to a FIFO overrun ? */
501 if (oldcsr0
& CSR0_MISS
)
502 priv
->stat
.rx_fifo_errors
++;
504 /* run through queue until we reach a descriptor we do not own */
506 descraddr
= RAM_RXBASE
+ (priv
->nextrx
* sizeof(LANCE_RxDescr
));
509 /* read descriptor */
510 memcpy_fromio(&descr
, dev
->mem_start
+ descraddr
, sizeof(LANCE_RxDescr
));
512 /* if we reach a descriptor we do not own, we're done */
513 if ((descr
.Flags
& RXDSCR_FLAGS_OWN
) != 0)
517 PrTime(); printk("Receive packet on descr %d len %d\n", priv
->nextrx
, descr
.Len
);
520 /* erroneous packet ? */
521 if ((descr
.Flags
& RXDSCR_FLAGS_ERR
) != 0)
523 priv
->stat
.rx_errors
++;
524 if ((descr
.Flags
& RXDSCR_FLAGS_CRC
) != 0)
525 priv
->stat
.rx_crc_errors
++;
526 else if ((descr
.Flags
& RXDSCR_FLAGS_CRC
) != 0)
527 priv
->stat
.rx_frame_errors
++;
528 else if ((descr
.Flags
& RXDSCR_FLAGS_OFLO
) != 0)
529 priv
->stat
.rx_fifo_errors
++;
537 skb
= dev_alloc_skb(descr
.Len
+ 2);
539 priv
->stat
.rx_dropped
++;
542 memcpy_fromio(skb_put(skb
, descr
.Len
),
543 dev
->mem_start
+ descr
.LowAddr
, descr
.Len
);
545 skb
->protocol
= eth_type_trans(skb
, dev
);
546 skb
->ip_summed
= CHECKSUM_NONE
;
547 priv
->stat
.rx_packets
++;
548 #if LINUX_VERSION_CODE >= 0x020119 /* byte counters for >= 2.1.25 */
549 priv
->stat
.rx_bytes
+= descr
.Len
;
555 /* give descriptor back to LANCE */
557 descr
.Flags
|= RXDSCR_FLAGS_OWN
;
559 /* update descriptor in shared RAM */
560 memcpy_toio(dev
->mem_start
+ descraddr
, &descr
, sizeof(LANCE_RxDescr
));
562 /* go to next descriptor */
563 priv
->nextrx
++; descraddr
+= sizeof(LANCE_RxDescr
);
564 if (priv
->nextrx
>= RXCOUNT
)
567 descraddr
= RAM_RXBASE
;
573 SetLANCE(dev
, LANCE_CSR0
, oldcsr0
| CSR0_RINT
);
574 return GetLANCE(dev
, LANCE_CSR0
);
577 /* transmit interrupt */
579 static u16
irqtx_handler(struct net_device
*dev
, u16 oldcsr0
)
581 skmca_priv
*priv
= (skmca_priv
*) dev
->priv
;
583 unsigned int descraddr
;
585 /* check descriptors at most until no busy one is left */
587 descraddr
= RAM_TXBASE
+ (priv
->nexttxdone
* sizeof(LANCE_TxDescr
));
588 while (priv
->txbusy
> 0)
590 /* read descriptor */
591 memcpy_fromio(&descr
, dev
->mem_start
+ descraddr
, sizeof(LANCE_TxDescr
));
593 /* if the LANCE still owns this one, we've worked out all sent packets */
594 if ((descr
.Flags
& TXDSCR_FLAGS_OWN
) != 0)
598 PrTime(); printk("Send packet done on descr %d\n", priv
->nexttxdone
);
601 /* update statistics */
602 if ((descr
.Flags
& TXDSCR_FLAGS_ERR
) == 0)
604 priv
->stat
.tx_packets
++;
605 #if LINUX_VERSION_CODE >= 0x020119 /* byte counters for >= 2.1.25 */
606 priv
->stat
.tx_bytes
++;
611 priv
->stat
.tx_errors
++;
612 if ((descr
.Status
& TXDSCR_STATUS_UFLO
) != 0)
614 priv
->stat
.tx_fifo_errors
++;
617 else if ((descr
.Status
& TXDSCR_STATUS_LCOL
) != 0)
618 priv
->stat
.tx_window_errors
++;
619 else if ((descr
.Status
& TXDSCR_STATUS_LCAR
) != 0)
620 priv
->stat
.tx_carrier_errors
++;
621 else if ((descr
.Status
& TXDSCR_STATUS_RTRY
) != 0)
622 priv
->stat
.tx_aborted_errors
++;
625 /* go to next descriptor */
627 descraddr
+= sizeof(LANCE_TxDescr
);
628 if (priv
->nexttxdone
>= TXCOUNT
)
630 priv
->nexttxdone
= 0;
631 descraddr
= RAM_TXBASE
;
636 /* reset TX interrupt bit */
638 SetLANCE(dev
, LANCE_CSR0
, oldcsr0
| CSR0_TINT
);
639 oldcsr0
= GetLANCE(dev
, LANCE_CSR0
);
641 /* at least one descriptor is freed. Therefore we can accept
646 /* inform upper layers we're in business again */
653 /* general interrupt entry */
655 static void irq_handler(int irq
, void *device
, struct pt_regs
*regs
)
657 struct net_device
*dev
= (struct net_device
*) device
;
660 /* read CSR0 to get interrupt cause */
662 csr0val
= GetLANCE(dev
, LANCE_CSR0
);
664 /* in case we're not meant... */
666 if ((csr0val
& CSR0_INTR
) == 0)
671 /* loop through the interrupt bits until everything is clear */
675 if ((csr0val
& CSR0_IDON
) != 0)
676 csr0val
= irqstart_handler(dev
, csr0val
);
677 if ((csr0val
& CSR0_RINT
) != 0)
678 csr0val
= irqrx_handler(dev
, csr0val
);
679 if ((csr0val
& CSR0_TINT
) != 0)
680 csr0val
= irqtx_handler(dev
, csr0val
);
682 while ((csr0val
& CSR0_INTR
) != 0);
687 /* ------------------------------------------------------------------------
689 * ------------------------------------------------------------------------ */
693 static int skmca_getinfo(char *buf
, int slot
, void *d
)
696 struct net_device
*dev
= (struct net_device
*) d
;
699 /* can't say anything about an uninitialized device... */
703 if (dev
->priv
== NULL
)
705 priv
= (skmca_priv
*) dev
->priv
;
709 len
+= sprintf(buf
+ len
, "IRQ: %d\n", priv
->realirq
);
710 len
+= sprintf(buf
+ len
, "Memory: %#lx-%#lx\n", dev
->mem_start
,
712 len
+= sprintf(buf
+ len
, "Transceiver: %s\n", MediaNames
[priv
->medium
]);
713 len
+= sprintf(buf
+ len
, "Device: %s\n", dev
->name
);
714 len
+= sprintf(buf
+ len
, "MAC address:");
715 for (i
= 0; i
< 6; i
++ )
716 len
+= sprintf( buf
+len
, " %02x", dev
->dev_addr
[i
] );
723 /* open driver. Means also initialization and start of LANCE */
725 static int skmca_open(struct net_device
*dev
)
728 skmca_priv
*priv
= (skmca_priv
*) dev
->priv
;
730 /* register resources - only necessary for IRQ */
731 result
= request_irq(priv
->realirq
, irq_handler
, SA_SHIRQ
| SA_SAMPLE_RANDOM
,
735 printk("%s: failed to register irq %d\n", dev
->name
, dev
->irq
);
738 dev
->irq
= priv
->realirq
;
740 /* set up the card and LANCE */
750 /* close driver. Shut down board and free allocated resources */
752 static int skmca_close(struct net_device
*dev
)
757 /* release resources */
759 free_irq(dev
->irq
, dev
);
769 /* transmit a block. */
771 static int skmca_tx(struct sk_buff
*skb
, struct net_device
*dev
)
773 skmca_priv
*priv
= (skmca_priv
*) dev
->priv
;
775 unsigned int address
;
776 int tmplen
, retval
= 0;
779 /* if we get called with a NULL descriptor, the Ethernet layer thinks
780 our card is stuck an we should reset it. We'll do this completely: */
786 return 0; /* don't try to free the block here ;-) */
789 /* is there space in the Tx queue ? If no, the upper layer gave us a
790 packet in spite of us not being ready and is really in trouble.
791 We'll do the dropping for him: */
792 if (priv
->txbusy
>= TXCOUNT
)
794 priv
->stat
.tx_dropped
++;
799 /* get TX descriptor */
800 address
= RAM_TXBASE
+ (priv
->nexttxput
* sizeof(LANCE_TxDescr
));
801 memcpy_fromio(&descr
, dev
->mem_start
+ address
, sizeof(LANCE_TxDescr
));
803 /* enter packet length as 2s complement - assure minimum length */
807 descr
.Len
= 65536 - tmplen
;
809 /* copy filler into RAM - in case we're filling up...
810 we're filling a bit more than necessary, but that doesn't harm
811 since the buffer is far larger... */
812 if (tmplen
> skb
->len
)
814 char *fill
= "NetBSD is a nice OS too! ";
815 unsigned int destoffs
= 0, l
= strlen(fill
);
817 while (destoffs
< tmplen
)
819 memcpy_toio(dev
->mem_start
+ descr
.LowAddr
+ destoffs
, fill
, l
);
824 /* do the real data copying */
825 memcpy_toio(dev
->mem_start
+ descr
.LowAddr
, skb
->data
, skb
->len
);
827 /* hand descriptor over to LANCE - this is the first and last chunk */
828 descr
.Flags
= TXDSCR_FLAGS_OWN
| TXDSCR_FLAGS_STP
| TXDSCR_FLAGS_ENP
;
831 PrTime(); printk("Send packet on descr %d len %d\n", priv
->nexttxput
, skb
->len
);
834 /* one more descriptor busy */
838 if (priv
->nexttxput
>= TXCOUNT
)
841 dev
->tbusy
= (priv
->txbusy
>= TXCOUNT
);
843 /* write descriptor back to RAM */
844 memcpy_toio(dev
->mem_start
+ address
, &descr
, sizeof(LANCE_TxDescr
));
846 /* if no descriptors were active, give the LANCE a hint to read it
849 if (priv
->txbusy
== 0)
850 SetLANCE(dev
, LANCE_CSR0
, CSR0_INEA
| CSR0_TDMD
);
852 restore_flags(flags
);
856 /* When did that change exactly ? */
858 #if LINUX_VERSION_CODE >= 0x020200
861 dev_kfree_skb(skb
, FREE_WRITE
);
866 /* return pointer to Ethernet statistics */
868 static struct enet_statistics
*skmca_stats(struct net_device
*dev
)
870 skmca_priv
*priv
= (skmca_priv
*) dev
->priv
;
872 return &(priv
->stat
);
875 /* we don't support runtime reconfiguration, since an MCA card can
876 be unambigously identified by its POS registers. */
878 static int skmca_config(struct net_device
*dev
, struct ifmap
*map
)
883 /* switch receiver mode. We use the LANCE's multicast filter to prefilter
884 multicast addresses. */
886 static void skmca_set_multicast_list(struct net_device
*dev
)
888 LANCE_InitBlock block
;
890 /* first stop the LANCE... */
893 /* ...then modify the initialization block... */
894 memcpy_fromio(&block
, dev
->mem_start
+ RAM_INITBASE
, sizeof(block
));
895 if (dev
->flags
& IFF_PROMISC
)
896 block
.Mode
|= LANCE_INIT_PROM
;
898 block
.Mode
&= ~LANCE_INIT_PROM
;
900 if (dev
->flags
& IFF_ALLMULTI
) /* get all multicasts */
902 memset(block
.LAdrF
, 8, 0xff);
904 else /* get selected/no multicasts */
906 struct dev_mc_list
*mptr
;
909 memset(block
.LAdrF
, 8, 0x00);
910 for (mptr
= dev
->mc_list
; mptr
!= NULL
; mptr
= mptr
->next
)
912 code
= GetHash(mptr
->dmi_addr
);
913 block
.LAdrF
[(code
>> 3) & 7] |= 1 << (code
& 7);
917 memcpy_toio(dev
->mem_start
+ RAM_INITBASE
, &block
, sizeof(block
));
919 /* ...then reinit LANCE with the correct flags */
923 /* ------------------------------------------------------------------------
925 * ------------------------------------------------------------------------ */
928 static int startslot
; /* counts through slots when probing multiple devices */
930 #define startslot 0 /* otherwise a dummy, since there is only eth0 in-kern*/
933 int skmca_probe(struct net_device
*dev
)
935 int force_detect
= 0;
937 int base
= 0, irq
= 0;
941 /* can't work without an MCA bus ;-) */
946 /* start address of 1 --> forced detection */
948 if (dev
->mem_start
== 1)
951 /* search through slots */
955 base
= dev
->mem_start
;
958 slot
= dofind(&junior
, startslot
);
962 /* deduce card addresses */
964 getaddrs(slot
, junior
, &base
, &irq
, &medium
);
966 #if LINUX_VERSION_CODE >= 0x020200
967 /* slot already in use ? */
969 if (mca_is_adapter_used(slot
))
971 slot
= dofind(&junior
, slot
+ 1);
976 /* were we looking for something different ? */
978 if ((dev
->irq
!= 0) || (dev
->mem_start
!= 0))
980 if ((dev
->irq
!= 0) && (dev
->irq
!= irq
))
982 slot
= dofind(&junior
, slot
+ 1);
985 if ((dev
->mem_start
!= 0) && (dev
->mem_start
!= base
))
987 slot
= dofind(&junior
, slot
+ 1);
992 /* found something that matches */
997 /* nothing found ? */
1000 return ((base
!= 0) || (irq
!= 0)) ? ENXIO
: ENODEV
;
1002 /* make procfs entries */
1005 mca_set_adapter_name(slot
, "SKNET junior MC2 Ethernet Adapter");
1007 mca_set_adapter_name(slot
, "SKNET MC2+ Ethernet Adapter");
1008 mca_set_adapter_procfn(slot
, (MCA_ProcFn
) skmca_getinfo
, dev
);
1010 #if LINUX_VERSION_CODE >= 0x020200
1011 mca_mark_as_used(slot
);
1014 /* announce success */
1015 printk("%s: SKNet %s adapter found in slot %d\n", dev
->name
,
1016 junior
? "Junior MC2" : "MC2+", slot
+ 1);
1018 /* allocate structure */
1019 priv
= dev
->priv
= (skmca_priv
*) kmalloc(sizeof(skmca_priv
), GFP_KERNEL
);
1021 priv
->macbase
= base
+ 0x3fc0;
1022 priv
->ioregaddr
= base
+ 0x3ff0;
1023 priv
->ctrladdr
= base
+ 0x3ff2;
1024 priv
->cmdaddr
= base
+ 0x3ff3;
1025 priv
->realirq
= irq
;
1026 priv
->medium
= medium
;
1027 memset(&(priv
->stat
), 0, sizeof(struct enet_statistics
));
1029 /* set base + irq for this device (irq not allocated so far) */
1031 dev
->mem_start
= base
;
1032 dev
->mem_end
= base
+ 0x4000;
1035 dev
->open
= skmca_open
;
1036 dev
->stop
= skmca_close
;
1037 dev
->set_config
= skmca_config
;
1038 dev
->hard_start_xmit
= skmca_tx
;
1039 dev
->do_ioctl
= NULL
;
1040 dev
->get_stats
= skmca_stats
;
1041 dev
->set_multicast_list
= skmca_set_multicast_list
;
1042 dev
->flags
|= IFF_MULTICAST
;
1050 /* copy out MAC address */
1051 for (i
= 0; i
< 6; i
++)
1052 dev
->dev_addr
[i
] = readb(priv
->macbase
+ (i
<< 1));
1055 printk("%s: IRQ %d, memory %#lx-%#lx, "
1056 "MAC address %02x:%02x:%02x:%02x:%02x:%02x.\n",
1057 dev
->name
, priv
->realirq
, dev
->mem_start
, dev
->mem_end
- 1,
1058 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
1059 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
1060 printk("%s: %s medium\n", dev
->name
, MediaNames
[priv
->medium
]);
1067 startslot
= slot
+ 1;
1073 /* ------------------------------------------------------------------------
1074 * modularization support
1075 * ------------------------------------------------------------------------ */
1081 static char NameSpace
[8 * DEVMAX
];
1082 static struct net_device moddevs
[DEVMAX
] =
1083 {{NameSpace
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
, skmca_probe
},
1084 {NameSpace
+ 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
, skmca_probe
},
1085 {NameSpace
+ 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
, skmca_probe
},
1086 {NameSpace
+ 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
, skmca_probe
},
1087 {NameSpace
+ 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
, skmca_probe
}};
1092 int init_module(void)
1097 for (z
= 0; z
< DEVMAX
; z
++)
1099 strcpy(moddevs
[z
].name
, " ");
1100 res
= register_netdev(moddevs
+ z
);
1102 return (z
> 0) ? 0 : -EIO
;
1108 void cleanup_module(void)
1110 struct net_device
*dev
;
1116 printk("cannot unload, module in use\n");
1120 for (z
= 0; z
< DEVMAX
; z
++)
1123 if (dev
->priv
!= NULL
)
1125 priv
= (skmca_priv
*) dev
->priv
;
1128 free_irq(dev
->irq
, dev
);
1130 unregister_netdev(dev
);
1131 #if LINUX_VERSION_CODE >= 0x020200
1132 mca_mark_as_unused(priv
->slot
);
1134 mca_set_adapter_procfn(priv
->slot
, NULL
, NULL
);
1135 kfree_s(dev
->priv
, sizeof(skmca_priv
));