/* ---------------------------------------------------------------------------- Linux PCMCIA ethernet adapter driver for the New Media Ethernet LAN. nmclan_cs.c,v 0.16 1995/07/01 06:42:17 rpao Exp rpao
The Ethernet LAN uses the Advanced Micro Devices (AMD) Am79C940 Media Access Controller for Ethernet (MACE). It is essentially the Am2150 PCMCIA Ethernet card contained in the Am2150 Demo Kit.
Written by Roger C. Pao <rpao@paonet.org> Copyright 1995 Roger C. Pao Linux 2.5 cleanups Copyright Red Hat 2003
This software may be used and distributed according to the terms of the GNU General Public License.
Ported to Linux 1.3.* network driver environment by Matti Aarnio <mea@utu.fi>
References
Am2150 Technical Reference Manual, Revision 1.0, August 17, 1993 Am79C940 (MACE) Data Sheet, 1994 Am79C90 (C-LANCE) Data Sheet, 1994 Linux PCMCIA Programmer's Guide v1.17 /usr/src/linux/net/inet/dev.c, Linux kernel 1.2.8
Eric Mears, New Media Corporation Tom Pollard, New Media Corporation Dean Siasoyco, New Media Corporation Ken Lesniak, Silicon Graphics, Inc. <lesniak@boston.sgi.com> Donald Becker <becker@scyld.com> David Hinds <dahinds@users.sourceforge.net>
The Linux client driver is based on the 3c589_cs.c client driver by David Hinds.
The Linux network driver outline is based on the 3c589_cs.c driver, the 8390.c driver, and the example skeleton.c kernel code, which are by Donald Becker.
The Am2150 network driver hardware interface code is based on the OS/9000 driver for the New Media Ethernet LAN by Eric Mears.
Special thanks for testing and help in debugging this driver goes to Ken Lesniak.
------------------------------------------------------------------------------- Driver Notes and Issues -------------------------------------------------------------------------------
1. Developed on a Dell 320SLi PCMCIA Card Services 2.6.2 Linux dell 1.2.10 #1 Thu Jun 29 20:23:41 PDT 1995 i386
2. rc.pcmcia may require loading pcmcia_core with io_speed=300: 'insmod pcmcia_core.o io_speed=300'. This will avoid problems with fast systems which causes rx_framecnt to return random values.
3. If hot extraction does not work for you, use 'ifconfig eth0 down' before extraction.
4. There is a bad slow-down problem in this driver.
5. Future: Multicast processing. In the meantime, do _not_ compile your kernel with multicast ip enabled.
------------------------------------------------------------------------------- History ------------------------------------------------------------------------------- Log: nmclan_cs.c,v * 2.5.75-ac1 2003/07/11 Alan Cox <alan@lxorguk.ukuu.org.uk> * Fixed hang on card eject as we probe it * Cleaned up to use new style locking. * * Revision 0.16 1995/07/01 06:42:17 rpao * Bug fix: nmclan_reset() called CardServices incorrectly. * * Revision 0.15 1995/05/24 08:09:47 rpao * Re-implement MULTI_TX dev->tbusy handling. * * Revision 0.14 1995/05/23 03:19:30 rpao * Added, in nmclan_config(), "tuple.Attributes = 0;". * Modified MACE ID check to ignore chip revision level. * Avoid tx_free_frames race condition between _start_xmit and _interrupt. * * Revision 0.13 1995/05/18 05:56:34 rpao * Statistics changes. * Bug fix: nmclan_reset did not enable TX and RX: call restore_multicast_list. * Bug fix: mace_interrupt checks ~MACE_IMR_DEFAULT. Fixes driver lockup. * * Revision 0.12 1995/05/14 00:12:23 rpao * Statistics overhaul. *
95/05/13 rpao V0.10a Bug fix: MACE statistics counters used wrong I/O ports. Bug fix: mace_interrupt() needed to allow statistics to be processed without RX or TX interrupts pending. 95/05/11 rpao V0.10 Multiple transmit request processing. Modified statistics to use MACE counters where possible. 95/05/10 rpao V0.09 Bug fix: Must use IO_DATA_PATH_WIDTH_AUTO. *Released 95/05/10 rpao V0.08 Bug fix: Make all non-exported functions private by using static keyword. Bug fix: Test IntrCnt _before_ reading MACE_IR. 95/05/10 rpao V0.07 Statistics. 95/05/09 rpao V0.06 Fix rx_framecnt problem by addition of PCIC wait states.
/* Loop Control Defines */ #define MACE_MAX_IR_ITERATIONS 10 #define MACE_MAX_RX_ITERATIONS 12 /* TBD: Dean brought this up, and I assumed the hardware would handle it:
If MACE_MAX_RX_ITERATIONS is > 1, rx_framecnt may still be non-zero when the isr exits. We may not get another interrupt to process the remaining packets for some time.
*/
/* The Am2150 has a Xilinx XC3042 field programmable gate array (FPGA) which manages the interface between the MACE and the PCMCIA bus. It also includes buffer management for the 32K x 8 SRAM to control up to four transmit and 12 receive frames at a time.
*/ #define AM2150_MAX_TX_FRAMES 4 #define AM2150_MAX_RX_FRAMES 12
/* ---------------------------------------------------------------------------- Parameters These are the parameters that can be set during loading with 'insmod'.
---------------------------------------------------------------------------- */
MODULE_DESCRIPTION("New Media PCMCIA ethernet driver");
MODULE_LICENSE("GPL");
#define INT_MODULE_PARM(n, v) staticint n = v; module_param(n, int, 0)
/* ---------------------------------------------------------------------------- mace_read Reads a MACE register. This is bank independent; however, the caller must ensure that this call is not interruptable. We are assuming that during normal operation, the MACE is always in bank 0.
---------------------------------------------------------------------------- */ staticint mace_read(mace_private *lp, unsignedint ioaddr, int reg)
{ int data = 0xFF; unsignedlong flags;
switch (reg >> 4) { case 0: /* register 0-15 */
data = inb(ioaddr + AM2150_MACE_BASE + reg); break; case 1: /* register 16-31 */
spin_lock_irqsave(&lp->bank_lock, flags);
MACEBANK(1);
data = inb(ioaddr + AM2150_MACE_BASE + (reg & 0x0F));
MACEBANK(0);
spin_unlock_irqrestore(&lp->bank_lock, flags); break;
} return data & 0xFF;
} /* mace_read */
/* ---------------------------------------------------------------------------- mace_write Writes to a MACE register. This is bank independent; however, the caller must ensure that this call is not interruptable. We are assuming that during normal operation, the MACE is always in bank 0.
---------------------------------------------------------------------------- */ staticvoid mace_write(mace_private *lp, unsignedint ioaddr, int reg, int data)
{ unsignedlong flags;
/* ---------------------------------------------------------------------------- mace_init Resets the MACE chip.
---------------------------------------------------------------------------- */ staticint mace_init(mace_private *lp, unsignedint ioaddr, constchar *enet_addr)
{ int i; int ct = 0;
/* MACE Software reset */
mace_write(lp, ioaddr, MACE_BIUCC, 1); while (mace_read(lp, ioaddr, MACE_BIUCC) & 0x01) { /* Wait for reset bit to be cleared automatically after <= 200ns */; if(++ct > 500)
{
pr_err("reset failed, card removed?\n"); return -1;
}
udelay(1);
}
mace_write(lp, ioaddr, MACE_BIUCC, 0);
/* The Am2150 requires that the MACE FIFOs operate in burst mode. */
mace_write(lp, ioaddr, MACE_FIFOCC, 0x0F);
mace_write(lp,ioaddr, MACE_RCVFC, 0); /* Disable Auto Strip Receive */
mace_write(lp, ioaddr, MACE_IMR, 0xFF); /* Disable all interrupts until _open */
/* * Bit 2-1 PORTSEL[1-0] Port Select. * 00 AUI/10Base-2 * 01 10Base-T * 10 DAI Port (reserved in Am2150) * 11 GPSI * For this card, only the first two are valid. * So, PLSCC should be set to * 0x00 for 10Base-2 * 0x02 for 10Base-T * Or just set ASEL in PHYCC below!
*/ switch (if_port) { case 1:
mace_write(lp, ioaddr, MACE_PLSCC, 0x02); break; case 2:
mace_write(lp, ioaddr, MACE_PLSCC, 0x00); break; default:
mace_write(lp, ioaddr, MACE_PHYCC, /* ASEL */ 4); /* ASEL Auto Select. When set, the PORTSEL[1-0] bits are overridden, and the MACE device will automatically select the operating media
interface port. */ break;
}
mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_PHYADDR); /* Poll ADDRCHG bit */
ct = 0; while (mace_read(lp, ioaddr, MACE_IAC) & MACE_IAC_ADDRCHG)
{ if(++ ct > 500)
{
pr_err("ADDRCHG timeout, card removed?\n"); return -1;
}
} /* Set PADR register */ for (i = 0; i < ETH_ALEN; i++)
mace_write(lp, ioaddr, MACE_PADR, enet_addr[i]);
/* MAC Configuration Control Register should be written last */ /* Let set_multicast_list set this. */ /* mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV); */
mace_write(lp, ioaddr, MACE_MACCC, 0x00); return 0;
} /* mace_init */
link->io_lines = 5;
ret = pcmcia_request_io(link); if (ret) goto failed;
ret = pcmcia_request_irq(link, mace_interrupt); if (ret) goto failed;
ret = pcmcia_enable_device(link); if (ret) goto failed;
/* Read the ethernet address from the CIS. */
len = pcmcia_get_tuple(link, 0x80, &buf); if (!buf || len < ETH_ALEN) {
kfree(buf); goto failed;
}
eth_hw_addr_set(dev, buf);
kfree(buf);
/* Verify configuration by reading the MACE ID. */
{ char sig[2];
sig[0] = mace_read(lp, ioaddr, MACE_CHIPIDL);
sig[1] = mace_read(lp, ioaddr, MACE_CHIPIDH); if ((sig[0] == 0x40) && ((sig[1] & 0x0F) == 0x09)) {
dev_dbg(&link->dev, "nmclan_cs configured: mace id=%x %x\n",
sig[0], sig[1]);
} else {
pr_notice("mace id not found: %x %x should be 0x40 0x?9\n",
sig[0], sig[1]); goto failed;
}
}
if (link->open) {
nmclan_reset(dev);
netif_device_attach(dev);
}
return 0;
}
/* ---------------------------------------------------------------------------- nmclan_reset Reset and restore all of the Xilinx and MACE registers.
---------------------------------------------------------------------------- */ staticvoid nmclan_reset(struct net_device *dev)
{
mace_private *lp = netdev_priv(dev);
/* Save original COR value */
pcmcia_read_config_byte(link, CISREG_COR, &OrigCorValue);
/* Reset Xilinx */
dev_dbg(&link->dev, "nmclan_reset: OrigCorValue=0x%x, resetting...\n",
OrigCorValue);
pcmcia_write_config_byte(link, CISREG_COR, COR_SOFT_RESET); /* Need to wait for 20 ms for PCMCIA to finish reset. */
/* Restore original COR configuration index */
pcmcia_write_config_byte(link, CISREG_COR,
(COR_LEVEL_REQ | (OrigCorValue & COR_CONFIG_MASK))); /* Xilinx is now completely reset along with the MACE chip. */
lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
#endif/* #if RESET_XILINX */
/* Xilinx is now completely reset along with the MACE chip. */
lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
/* Reinitialize the MACE chip for operation. */
mace_init(lp, dev->base_addr, dev->dev_addr);
mace_write(lp, dev->base_addr, MACE_IMR, MACE_IMR_DEFAULT);
/* Restore the multicast list and enable TX and RX. */
restore_multicast_list(dev);
} /* nmclan_reset */
/* ---------------------------------------------------------------------------- mace_config [Someone tell me what this is supposed to do? Is if_port a defined standard? If so, there should be defines to indicate 1=10Base-T, 2=10Base-2, etc. including limited automatic detection.]
---------------------------------------------------------------------------- */ staticint mace_config(struct net_device *dev, struct ifmap *map)
{ if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) { if (map->port <= 2) {
WRITE_ONCE(dev->if_port, map->port);
netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
} else return -EINVAL;
} return 0;
} /* mace_config */
/* ---------------------------------------------------------------------------- mace_start_xmit This routine begins the packet transmit function. When completed, it will generate a transmit interrupt.
According to /usr/src/linux/net/inet/dev.c, if _start_xmit returns 0, the "packet is now solely the responsibility of the driver." If _start_xmit returns non-zero, the "transmission failed, put skb back into a list."
---------------------------------------------------------------------------- */
{ /* This block must not be interrupted by another transmit request! mace_tx_timeout will take care of timer-based retransmissions from the upper layers. The interrupt handler is guaranteed never to service a transmit interrupt while we are in here.
*/
/* WARNING: Write the _exact_ number of bytes written in the header! */ /* Put out the word header [must be an outw()] . . . */
outw(skb->len, ioaddr + AM2150_XMT); /* . . . and the packet [may be any combination of outw() and outb()] */
outsw(ioaddr + AM2150_XMT, skb->data, skb->len >> 1); if (skb->len & 1) { /* Odd byte transfer */
outb(skb->data[skb->len-1], ioaddr + AM2150_XMT);
}
if (
(xmtfs = inb(ioaddr + AM2150_MACE_BASE + MACE_XMTFS)) &
MACE_XMTFS_XMTSV /* Transmit Status Valid */
) {
lp->mace_stats.xmtsv++;
if (xmtfs & ~MACE_XMTFS_XMTSV) { if (xmtfs & MACE_XMTFS_UFLO) { /* Underflow. Indicates that the Transmit FIFO emptied before
the end of frame was reached. */
lp->mace_stats.uflo++;
} if (xmtfs & MACE_XMTFS_LCOL) { /* Late Collision */
lp->mace_stats.lcol++;
} if (xmtfs & MACE_XMTFS_MORE) { /* MORE than one retry was needed */
lp->mace_stats.more++;
} if (xmtfs & MACE_XMTFS_ONE) { /* Exactly ONE retry occurred */
lp->mace_stats.one++;
} if (xmtfs & MACE_XMTFS_DEFER) { /* Transmission was defered */
lp->mace_stats.defer++;
} if (xmtfs & MACE_XMTFS_LCAR) { /* Loss of carrier */
lp->mace_stats.lcar++;
} if (xmtfs & MACE_XMTFS_RTRY) { /* Retry error: transmit aborted after 16 attempts */
lp->mace_stats.rtry++;
}
} /* if (xmtfs & ~MACE_XMTFS_XMTSV) */
} /* if (xmtfs & MACE_XMTFS_XMTSV) */
dev->stats.tx_packets++;
lp->tx_free_frames++;
netif_wake_queue(dev);
} /* if (status & MACE_IR_XMTINT) */
if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) { if (status & MACE_IR_JAB) { /* Jabber Error. Excessive transmit duration (20-150ms). */
lp->mace_stats.jab++;
} if (status & MACE_IR_BABL) { /* Babble Error. >1518 bytes transmitted. */
lp->mace_stats.babl++;
} if (status & MACE_IR_CERR) { /* Collision Error. CERR indicates the absence of the Signal Quality Error Test message after a packet
transmission. */
lp->mace_stats.cerr++;
} if (status & MACE_IR_RCVCCO) { /* Receive Collision Count Overflow; */
lp->mace_stats.rcvcco++;
} if (status & MACE_IR_RNTPCO) { /* Runt Packet Count Overflow */
lp->mace_stats.rntpco++;
} if (status & MACE_IR_MPCO) { /* Missed Packet Count Overflow */
lp->mace_stats.mpco++;
}
} /* if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) */
} while ((status & ~MACE_IMR_DEFAULT) && (--IntrCnt));
/* ---------------------------------------------------------------------------- update_stats Update statistics. We change to register window 1, so this should be run single-threaded if the device is active. This is expected to be a rare operation, and it's simpler for the rest of the driver to assume that window 0 is always valid rather than use a special window-state variable.
oflo & uflo should _never_ occur since it would mean the Xilinx was not able to transfer data between the MACE FIFO and the card's SRAM fast enough. If this happens, something is seriously wrong with the hardware.
---------------------------------------------------------------------------- */ staticvoid update_stats(unsignedint ioaddr, struct net_device *dev)
{
mace_private *lp = netdev_priv(dev);
lp->mace_stats.rcvcc += mace_read(lp, ioaddr, MACE_RCVCC);
lp->mace_stats.rntpc += mace_read(lp, ioaddr, MACE_RNTPC);
lp->mace_stats.mpc += mace_read(lp, ioaddr, MACE_MPC); /* At this point, mace_stats is fully updated for this call.
We may now update the netdev stats. */
/* The MACE has no equivalent for netdev stats field which are commented
out. */
/* dev->stats.multicast; */
dev->stats.collisions =
lp->mace_stats.rcvcco * 256 + lp->mace_stats.rcvcc; /* Collision: The MACE may retry sending a packet 15 times before giving up. The retry count is in XMTRC. Does each retry constitute a collision?
If so, why doesn't the RCVCC record these collisions? */
pr_debug("%s: updating the statistics.\n", dev->name);
pr_linux_stats(&dev->stats);
pr_mace_stats(&lp->mace_stats);
return &dev->stats;
} /* net_device_stats */
/* ---------------------------------------------------------------------------- updateCRC Modified from Am79C90 data sheet.
---------------------------------------------------------------------------- */
#ifdef BROKEN_MULTICAST
staticvoid updateCRC(int *CRC, int bit)
{ staticconstint 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
}; /* CRC polynomial. poly[n] = coefficient of the x**n term of the
CRC generator polynomial. */
int j;
/* shift CRC and control bit (CRC[32]) */ for (j = 32; j > 0; j--)
CRC[j] = CRC[j-1];
CRC[0] = 0;
/* If bit XOR(control bit) = 1, set CRC = CRC XOR polynomial. */ if (bit ^ CRC[32]) for (j = 0; j < 32; j++)
CRC[j] ^= poly[j];
} /* updateCRC */
/* ---------------------------------------------------------------------------- BuildLAF Build logical address filter. Modified from Am79C90 data sheet.
Input ladrf: logical address filter (contents initialized to 0) adr: ethernet address
---------------------------------------------------------------------------- */ staticvoid BuildLAF(int *ladrf, int *adr)
{ int CRC[33]={1}; /* CRC register, 1 word/bit + extra control bit */
int i, byte; /* temporary array indices */ int hashcode; /* the output object */
CRC[32]=0;
for (byte = 0; byte < 6; byte++) for (i = 0; i < 8; i++)
updateCRC(CRC, (adr[byte] >> i) & 1);
hashcode = 0; for (i = 0; i < 6; i++)
hashcode = (hashcode << 1) + CRC[i];
#ifdef PCMCIA_DEBUG if (0)
printk(KERN_DEBUG " adr =%pM\n", adr);
printk(KERN_DEBUG " hashcode = %d(decimal), ladrf[0:63] =", hashcode); for (i = 0; i < 8; i++)
pr_cont(" %02X", ladrf[i]);
pr_cont("\n"); #endif
} /* BuildLAF */
/* ---------------------------------------------------------------------------- restore_multicast_list Restores the multicast filter for MACE chip to the last set_multicast_list() call.
Input multicast_num_addrs multicast_ladrf[]
---------------------------------------------------------------------------- */ staticvoid restore_multicast_list(struct net_device *dev)
{
mace_private *lp = netdev_priv(dev); int num_addrs = lp->multicast_num_addrs; int *ladrf = lp->multicast_ladrf; unsignedint ioaddr = dev->base_addr; int i;
pr_debug("%s: restoring Rx mode to %d addresses.\n",
dev->name, num_addrs);
if (num_addrs > 0) {
pr_debug("Attempt to restore multicast list detected.\n");
mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_LOGADDR); /* Poll ADDRCHG bit */ while (mace_read(lp, ioaddr, MACE_IAC) & MACE_IAC_ADDRCHG)
; /* Set LADRF register */ for (i = 0; i < MACE_LADRF_LEN; i++)
mace_write(lp, ioaddr, MACE_LADRF, ladrf[i]);
/* ---------------------------------------------------------------------------- set_multicast_list Set or clear the multicast filter for this adaptor.
Input num_addrs == -1 Promiscuous mode, receive all packets num_addrs == 0 Normal mode, clear multicast list num_addrs > 0 Multicast mode, receive normal and MC packets, and do best-effort filtering. Output multicast_num_addrs multicast_ladrf[]
---------------------------------------------------------------------------- */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.