📄 sk_mca.c
字号:
/* net-3-driver for the SKNET MCA-based cardsThis is an extension to the Linux operating system, and is covered by thesame Gnu Public License that covers that work.Copyright 1999 by Alfred Arnold (alfred@ccac.rwth-aachen.de, aarnold@elsa.de)This driver is based both on the 3C523 driver and the SK_G16 driver.paper sources: 'PC Hardware: Aufbau, Funktionsweise, Programmierung' by Hans-Peter Messmer for the basic Microchannel stuff 'Linux Geraetetreiber' by Allesandro Rubini, Kalle Dalheimer for help on Ethernet driver programming 'Ethernet/IEEE 802.3 Family 1992 World Network Data Book/Handbook' by AMD for documentation on the AM7990 LANCE 'SKNET Personal Technisches Manual', Version 1.2 by Schneider&Koch for documentation on the Junior board 'SK-NET MC2+ Technical Manual", Version 1.1 by Schneider&Koch for documentation on the MC2 bord A big thank you to the S&K support for providing me so quickly with documentation! Also see http://www.syskonnect.com/ Missing things: -> set debug level via ioctl instead of compile-time switches -> I didn't follow the development of the 2.1.x kernels, so my assumptions about which things changed with which kernel version are probably nonsenseHistory: May 16th, 1999 startup May 22st, 1999 added private structure, methods begun building data structures in RAM May 23nd, 1999 can receive frames, send frames May 24th, 1999 modularized intialization of LANCE loadable as module still Tx problem :-( May 26th, 1999 MC2 works support for multiple devices display media type for MC2+ May 28th, 1999 fixed problem in GetLANCE leaving interrupts turned off increase TX queue to 4 packets to improve send performance May 29th, 1999 a few corrections in statistics, caught rcvr overruns reinitialization of LANCE/board in critical situations MCA info implemented implemented LANCE multicast filter Jun 6th, 1999 additions for Linux 2.2 Dec 25th, 1999 unfortunately there seem to be newer MC2+ boards that react on IRQ 3/5/9/10 instead of 3/5/10/11, so we have to autoprobe in questionable cases... Dec 28th, 1999 integrated patches from David Weinehall & Bill Wendling for 2.3 kernels (isa_...functions). Things are defined in a way that it still works with 2.0.x 8-) Dec 30th, 1999 added handling of the remaining interrupt conditions. That should cure the spurious hangs. Jan 30th, 2000 newer kernels automatically probe more than one board, so the 'startslot' as a variable is also needed here June 1st, 2000 added changes for recent 2.3 kernels *************************************************************************/#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/ioport.h>#include <linux/malloc.h>#include <linux/interrupt.h>#include <linux/delay.h>#include <linux/time.h>#include <linux/mca.h>#include <asm/processor.h>#include <asm/bitops.h>#include <asm/io.h>#include <linux/module.h>#include <linux/version.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#define _SK_MCA_DRIVER_#include "sk_mca.h"/* ------------------------------------------------------------------------ * global static data - not more since we can handle multiple boards and * have to pack all state info into the device struct! * ------------------------------------------------------------------------ */static char *MediaNames[Media_Count] = { "10Base2", "10BaseT", "10Base5", "Unknown" };static unsigned char poly[] = { 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0};/* ------------------------------------------------------------------------ * private subfunctions * ------------------------------------------------------------------------ *//* dump parts of shared memory - only needed during debugging */#ifdef DEBUGstatic void dumpmem(struct SKMCA_NETDEV *dev, u32 start, u32 len){ int z; for (z = 0; z < len; z++) { if ((z & 15) == 0) printk("%04x:", z); printk(" %02x", SKMCA_READB(dev->mem_start + start + z)); if ((z & 15) == 15) printk("\n"); }}/* print exact time - ditto */static void PrTime(void){ struct timeval tv; do_gettimeofday(&tv); printk("%9d:%06d: ", tv.tv_sec, tv.tv_usec);}#endif/* deduce resources out of POS registers */static void getaddrs(int slot, int junior, int *base, int *irq, skmca_medium * medium){ u_char pos0, pos1, pos2; if (junior) { pos0 = mca_read_stored_pos(slot, 2); *base = ((pos0 & 0x0e) << 13) + 0xc0000; *irq = ((pos0 & 0x10) >> 4) + 10; *medium = Media_Unknown; } else { /* reset POS 104 Bits 0+1 so the shared memory region goes to the configured area between 640K and 1M. Afterwards, enable the MC2. I really don't know what rode SK to do this... */ mca_write_pos(slot, 4, mca_read_stored_pos(slot, 4) & 0xfc); mca_write_pos(slot, 2, mca_read_stored_pos(slot, 2) | 0x01); pos1 = mca_read_stored_pos(slot, 3); pos2 = mca_read_stored_pos(slot, 4); *base = ((pos1 & 0x07) << 14) + 0xc0000; switch (pos2 & 0x0c) { case 0: *irq = 3; break; case 4: *irq = 5; break; case 8: *irq = -10; break; case 12: *irq = -11; break; } *medium = (pos2 >> 6) & 3; }}/* check for both cards: When the MC2 is turned off, it was configured for more than 15MB RAM, is disabled and won't get detected using the standard probe. We therefore have to scan the slots manually :-( */static int dofind(int *junior, int firstslot){ int slot; unsigned int id; for (slot = firstslot; slot < MCA_MAX_SLOT_NR; slot++) { id = mca_read_stored_pos(slot, 0) + (((unsigned int) mca_read_stored_pos(slot, 1)) << 8); *junior = 0; if (id == SKNET_MCA_ID) return slot; *junior = 1; if (id == SKNET_JUNIOR_MCA_ID) return slot; } return MCA_NOTFOUND;}/* reset the whole board */static void ResetBoard(struct SKMCA_NETDEV *dev){ skmca_priv *priv = (skmca_priv *) dev->priv; SKMCA_WRITEB(CTRL_RESET_ON, priv->ctrladdr); udelay(10); SKMCA_WRITEB(CTRL_RESET_OFF, priv->ctrladdr);}/* wait for LANCE interface to become not busy */static int WaitLANCE(struct SKMCA_NETDEV *dev){ skmca_priv *priv = (skmca_priv *) dev->priv; int t = 0; while ((SKMCA_READB(priv->ctrladdr) & STAT_IO_BUSY) == STAT_IO_BUSY) { udelay(1); if (++t > 1000) { printk("%s: LANCE access timeout", dev->name); return 0; } } return 1;}/* set LANCE register - must be atomic */static void SetLANCE(struct SKMCA_NETDEV *dev, u16 addr, u16 value){ skmca_priv *priv = (skmca_priv *) dev->priv; unsigned long flags; /* disable interrupts */ save_flags(flags); cli(); /* wait until no transfer is pending */ WaitLANCE(dev); /* transfer register address to RAP */ SKMCA_WRITEB(CTRL_RESET_OFF | CTRL_RW_WRITE | CTRL_ADR_RAP, priv->ctrladdr); SKMCA_WRITEW(addr, priv->ioregaddr); SKMCA_WRITEB(IOCMD_GO, priv->cmdaddr); udelay(1); WaitLANCE(dev); /* transfer data to register */ SKMCA_WRITEB(CTRL_RESET_OFF | CTRL_RW_WRITE | CTRL_ADR_DATA, priv->ctrladdr); SKMCA_WRITEW(value, priv->ioregaddr); SKMCA_WRITEB(IOCMD_GO, priv->cmdaddr); udelay(1); WaitLANCE(dev); /* reenable interrupts */ restore_flags(flags);}/* get LANCE register */static u16 GetLANCE(struct SKMCA_NETDEV *dev, u16 addr){ skmca_priv *priv = (skmca_priv *) dev->priv; unsigned long flags; unsigned int res; /* disable interrupts */ save_flags(flags); cli(); /* wait until no transfer is pending */ WaitLANCE(dev); /* transfer register address to RAP */ SKMCA_WRITEB(CTRL_RESET_OFF | CTRL_RW_WRITE | CTRL_ADR_RAP, priv->ctrladdr); SKMCA_WRITEW(addr, priv->ioregaddr); SKMCA_WRITEB(IOCMD_GO, priv->cmdaddr); udelay(1); WaitLANCE(dev); /* transfer data from register */ SKMCA_WRITEB(CTRL_RESET_OFF | CTRL_RW_READ | CTRL_ADR_DATA, priv->ctrladdr); SKMCA_WRITEB(IOCMD_GO, priv->cmdaddr); udelay(1); WaitLANCE(dev); res = SKMCA_READW(priv->ioregaddr); /* reenable interrupts */ restore_flags(flags); return res;}/* build up descriptors in shared RAM */static void InitDscrs(struct SKMCA_NETDEV *dev){ u32 bufaddr; /* Set up Tx descriptors. The board has only 16K RAM so bits 16..23 are always 0. */ bufaddr = RAM_DATABASE; { LANCE_TxDescr descr; int z; for (z = 0; z < TXCOUNT; z++) { descr.LowAddr = bufaddr; descr.Flags = 0; descr.Len = 0xf000; descr.Status = 0; SKMCA_TOIO(dev->mem_start + RAM_TXBASE + (z * sizeof(LANCE_TxDescr)), &descr, sizeof(LANCE_TxDescr)); SKMCA_SETIO(dev->mem_start + bufaddr, 0, RAM_BUFSIZE); bufaddr += RAM_BUFSIZE; } } /* do the same for the Rx descriptors */ { LANCE_RxDescr descr; int z; for (z = 0; z < RXCOUNT; z++) { descr.LowAddr = bufaddr; descr.Flags = RXDSCR_FLAGS_OWN; descr.MaxLen = -RAM_BUFSIZE; descr.Len = 0; SKMCA_TOIO(dev->mem_start + RAM_RXBASE + (z * sizeof(LANCE_RxDescr)), &descr, sizeof(LANCE_RxDescr)); SKMCA_SETIO(dev->mem_start + bufaddr, 0, RAM_BUFSIZE); bufaddr += RAM_BUFSIZE; } }}/* calculate the hash bit position for a given multicast address taken more or less directly from the AMD datasheet... */static void UpdateCRC(unsigned char *CRC, int bit){ int j; /* shift CRC one bit */ memmove(CRC + 1, CRC, 32 * sizeof(unsigned char)); CRC[0] = 0; /* if bit XOR controlbit = 1, set CRC = CRC XOR polynomial */ if (bit ^ CRC[32]) for (j = 0; j < 32; j++) CRC[j] ^= poly[j];}static unsigned int GetHash(char *address){ unsigned char CRC[33]; int i, byte, hashcode; /* a multicast address has bit 0 in the first byte set */ if ((address[0] & 1) == 0) return -1; /* initialize CRC */ memset(CRC, 1, sizeof(CRC)); /* loop through address bits */ for (byte = 0; byte < 6; byte++) for (i = 0; i < 8; i++) UpdateCRC(CRC, (address[byte] >> i) & 1); /* hashcode is the 6 least significant bits of the CRC */ hashcode = 0; for (i = 0; i < 6; i++) hashcode = (hashcode << 1) + CRC[i]; return hashcode;}/* feed ready-built initialization block into LANCE */static void InitLANCE(struct SKMCA_NETDEV *dev){ skmca_priv *priv = (skmca_priv *) dev->priv; /* build up descriptors. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -