/* We do not process more than these number of bytes during one *interrupt.(Ofcoursewereceivecompletepackets,sothisisnot *anexactvalue). *Somethingbetween2000..22000;firstvaluegivesbestinterruptlatency, *thesecondenablestheusageofthecompleteon-chipbuffer.Weusethe *highvalueastheinitialvalue.
*/ staticunsigned maxrx_bytes = 22000;
int card_type; int probe_port; int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */ int mohawk; /* a CE3 type card */ int dingo; /* a CEM56 type card */ int new_mii; /* has full 10baseT/100baseT MII */ int modem; /* is a multi function card (i.e with a modem) */ void __iomem *dingo_ccr; /* only used for CEM56 cards */ unsigned last_ptr_value; /* last packets transmitted value */ constchar *manf_str; struct work_struct tx_timeout_task;
};
/*====== Functions used for debugging =================================*/ #if0/* reading regs may change system status */ staticvoid
PrintRegisters(struct net_device *dev)
{ unsignedint ioaddr = dev->base_addr;
if (pc_debug > 1) { int i, page;
printk(KERN_DEBUG pr_fmt("Register common: ")); for (i = 0; i < 8; i++)
pr_cont(" %2.2x", GetByte(i));
pr_cont("\n"); for (page = 0; page <= 8; page++) {
printk(KERN_DEBUG pr_fmt("Register page %2x: "), page);
SelectPage(page); for (i = 8; i < 16; i++)
pr_cont(" %2.2x", GetByte(i));
pr_cont("\n");
} for (page=0x40 ; page <= 0x5f; page++) { if (page == 0x43 || (page >= 0x46 && page <= 0x4f) ||
(page >= 0x51 && page <=0x5e)) continue;
printk(KERN_DEBUG pr_fmt("Register page %2x: "), page);
SelectPage(page); for (i = 8; i < 16; i++)
pr_cont(" %2.2x", GetByte(i));
pr_cont("\n");
}
}
} #endif/* 0 */
/*============== MII Management functions ===============*/
/* Is this a valid card */ if (link->has_manf_id == 0) {
pr_notice("manfid not found in CIS\n"); goto failure;
}
switch (link->manf_id) { case MANFID_XIRCOM:
local->manf_str = "Xircom"; break; case MANFID_ACCTON:
local->manf_str = "Accton"; break; case MANFID_COMPAQ: case MANFID_COMPAQ2:
local->manf_str = "Compaq"; break; case MANFID_INTEL:
local->manf_str = "Intel"; break; case MANFID_TOSHIBA:
local->manf_str = "Toshiba"; break; default:
pr_notice("Unknown Card Manufacturer ID: 0x%04x\n",
(unsigned)link->manf_id); goto failure;
}
dev_dbg(&link->dev, "found %s card\n", local->manf_str);
if (!set_card_type(link)) {
pr_notice("this card is not supported\n"); goto failure;
}
/* get the ethernet address from the CIS */
err = pcmcia_get_mac_from_cis(link, dev);
/* not found: try to get the node-id from tuple 0x89 */ if (err) {
len = pcmcia_get_tuple(link, 0x89, &buf); /* data layout looks like tuple 0x22 */ if (buf && len == 8) { if (*buf == CISTPL_FUNCE_LAN_NODE_ID)
dev_addr_mod(dev, 2, &buf[2], 4); else
err = -1;
}
kfree(buf);
}
if (err)
err = pcmcia_loop_tuple(link, CISTPL_FUNCE, pcmcia_get_mac_ce, dev);
if (err) {
pr_notice("node-id not found in CIS\n"); goto failure;
}
if (local->modem) { int pass;
link->config_flags |= CONF_AUTO_SET_IO;
if (local->dingo) { /* Take the Modem IO port from the CIS and scan for a free
* Ethernet port */ if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL)) goto port_found;
} else { /* We do 2 passes here: The first one uses the regular mapping and *thesecondtriesagain,therebyconsideringthatthe32portsare *mirroredevery32bytes.Actuallyweuseamirroredportfor *theMakoif(onthefirstpass)theCORbit5isset.
*/ for (pass=0; pass < 2; pass++) if (!pcmcia_loop_config(link, xirc2ps_config_check,
&pass)) goto port_found; /* if special option: *trytoconfigureasEthernetonly.
* .... */
}
pr_notice("no ports available\n");
} else {
link->io_lines = 10;
link->resource[0]->end = 16;
link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
link->resource[0]->start = ioaddr; if (!(err = pcmcia_request_io(link))) goto port_found;
}
link->resource[0]->start = 0; /* let CS decide */ if ((err = pcmcia_request_io(link))) goto config_error;
}
port_found:
/**************** *Nowallocateaninterruptline.Notethatthisdoesnot *actuallyassignahandlertotheinterrupt.
*/ if ((err=pcmcia_request_irq(link, xirc2ps_interrupt))) goto config_error;
link->config_flags |= CONF_ENABLE_IRQ; if (do_sound)
link->config_flags |= CONF_ENABLE_SPKR;
if ((err = pcmcia_enable_device(link))) goto config_error;
if (local->dingo) { /* Reset the modem's BAR to the correct value *ThisisnecessarybecauseintheRequestConfigurationcall, *thebaseaddressoftheethernetport(BasePort1)iswritten *totheBARregistersofthemodem.
*/
err = pcmcia_write_config_byte(link, CISREG_IOBASE_0, (u8)
link->resource[1]->start & 0xff); if (err) goto config_error;
/* There is no config entry for the Ethernet part which *isat0x0800.Soweallocateawindowintotheattribute *memoryandwritedirecttotheCISregisters
*/
link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM |
WIN_ENABLE;
link->resource[2]->start = link->resource[2]->end = 0; if ((err = pcmcia_request_window(link, link->resource[2], 0))) goto config_error;
/* Setup the CCRs; there are no infos in the CIS about the Ethernet *part.
*/
writeb(0x47, local->dingo_ccr + CISREG_COR);
ioaddr = link->resource[0]->start;
writeb(ioaddr & 0xff , local->dingo_ccr + CISREG_IOBASE_0);
writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
/* The if_port symbol can be set when the module is loaded */
local->probe_port=0; if (!if_port) {
local->probe_port = dev->if_port = 1;
} elseif ((if_port >= 1 && if_port <= 2) ||
(local->mohawk && if_port==4))
dev->if_port = if_port; else
pr_notice("invalid if_port requested\n");
/* we can now register the device with the net subsystem */
dev->irq = link->irq;
dev->base_addr = link->resource[0]->start;
if (local->dingo)
do_reset(dev, 1); /* a kludge to make the cem56 work */
SET_NETDEV_DEV(dev, &link->dev);
if ((err=register_netdev(dev))) {
pr_notice("register_netdev() failed\n"); goto config_error;
}
/* give some infos about the hardware */
netdev_info(dev, "%s: port %#3lx, irq %d, hwaddr %pM\n",
local->manf_str, (u_long)dev->base_addr, (int)dev->irq,
dev->dev_addr);
if (!netif_device_present(dev)) return IRQ_HANDLED;
ioaddr = dev->base_addr; if (lp->mohawk) { /* must disable the interrupt */
PutByte(XIRCREG_CR, 0);
}
pr_debug("%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
saved_page = GetByte(XIRCREG_PR); /* Read the ISR to see whats the cause for the interrupt. *ThisalsoclearstheinterruptflagsonCE2cards
*/
int_status = GetByte(XIRCREG_ISR);
bytes_rcvd = 0;
loop_entry: if (int_status == 0xff) { /* card may be ejected */
pr_debug("%s: interrupt %d for dead card\n", dev->name, irq); goto leave;
}
eth_status = GetByte(XIRCREG_ESR);
/***** receive section ******/
SelectPage(0); while (eth_status & FullPktRcvd) {
rsr = GetByte(XIRCREG0_RSR); if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) { /* too many bytes received during this int, drop the rest of the
* packets */
dev->stats.rx_dropped++;
pr_debug("%s: RX drop, too much done\n", dev->name);
} elseif (rsr & PktRxOk) { struct sk_buff *skb;
/* 1 extra so we can use insw */
skb = netdev_alloc_skb(dev, pktlen + 3); if (!skb) {
dev->stats.rx_dropped++;
} else { /* okay get the packet */
skb_reserve(skb, 2); if (lp->silicon == 0 ) { /* work around a hardware bug */ unsigned rhsa; /* receive start address */
SelectPage(5);
rhsa = GetWord(XIRCREG5_RHSA0);
SelectPage(0);
rhsa += 3; /* skip control infos */ if (rhsa >= 0x8000)
rhsa = 0; if (rhsa + pktlen > 0x8000) { unsigned i;
u_char *buf = skb_put(skb, pktlen); for (i=0; i < pktlen ; i++, rhsa++) {
buf[i] = GetByte(XIRCREG_EDP); if (rhsa == 0x8000) {
rhsa = 0;
i--;
}
}
} else {
insw(ioaddr+XIRCREG_EDP,
skb_put(skb, pktlen), (pktlen+1)>>1);
}
} #if0 elseif (lp->mohawk) { /* To use this 32 bit access we should use *amanualoptimizedloop *Alsothewordsareswapped,wecangetmore *performancebyusing32bitaccessandswapping *thewordsinaregister.Willneedthisforcardbus * *Note:don'tforgettochangetheALLOC_SKBto..+3
*/ unsigned i;
u_long *p = skb_put(skb, pktlen); register u_long a; unsignedint edpreg = ioaddr+XIRCREG_EDP-2; for (i=0; i < len ; i += 4, p++) {
a = inl(edpreg);
__asm__("rorl $16,%0\n\t"
:"=q" (a)
: "0" (a));
*p = a;
}
} #endif else {
insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
(pktlen+1)>>1);
}
skb->protocol = eth_type_trans(skb, dev);
netif_rx(skb);
dev->stats.rx_packets++;
dev->stats.rx_bytes += pktlen; if (!(rsr & PhyPkt))
dev->stats.multicast++;
}
} else { /* bad packet */
pr_debug("rsr=%#02x\n", rsr);
} if (rsr & PktTooLong) {
dev->stats.rx_frame_errors++;
pr_debug("%s: Packet too long\n", dev->name);
} if (rsr & CRCErr) {
dev->stats.rx_crc_errors++;
pr_debug("%s: CRC error\n", dev->name);
} if (rsr & AlignErr) {
dev->stats.rx_fifo_errors++; /* okay ? */
pr_debug("%s: Alignment error\n", dev->name);
}
/* get the new ethernet status */
eth_status = GetByte(XIRCREG_ESR);
} if (rx_status & 0x10) { /* Receive overrun */
dev->stats.rx_over_errors++;
PutByte(XIRCREG_CR, ClearRxOvrun);
pr_debug("receive overrun cleared\n");
}
/***** transmit section ******/ if (int_status & PktTxed) { unsigned n, nn;
n = lp->last_ptr_value;
nn = GetByte(XIRCREG0_PTR);
lp->last_ptr_value = nn; if (nn < n) /* rollover */
dev->stats.tx_packets += 256 - n; elseif (n == nn) { /* happens sometimes - don't know why */
pr_debug("PTR not changed?\n");
} else
dev->stats.tx_packets += lp->last_ptr_value - n;
netif_wake_queue(dev);
} if (tx_status & 0x0002) { /* Excessive collisions */
pr_debug("tx restarted due to excessive collisions\n");
PutByte(XIRCREG_CR, RestartTx); /* restart transmitter process */
} if (tx_status & 0x0040)
dev->stats.tx_aborted_errors++;
/* recalculate our work chunk so that we limit the duration of this *ISRtoabout1/10ofasecond. *Calculateonlyifwereceivedareasonableamountofbytes.
*/ if (bytes_rcvd > 1000) {
u_long duration = jiffies - start_ticks;
if (duration >= HZ/10) { /* if more than about 1/10 second */
maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration; if (maxrx_bytes < 2000)
maxrx_bytes = 2000; elseif (maxrx_bytes > 22000)
maxrx_bytes = 22000;
pr_debug("set maxrx=%u (rcvd=%u ticks=%lu)\n",
maxrx_bytes, bytes_rcvd, duration);
} elseif (!duration && maxrx_bytes < 22000) { /* now much faster */
maxrx_bytes += 2000; if (maxrx_bytes > 22000)
maxrx_bytes = 22000;
pr_debug("set maxrx=%u\n", maxrx_bytes);
}
}
leave: if (lockup_hack) { if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0) goto loop_entry;
}
SelectPage(saved_page);
PutByte(XIRCREG_CR, EnableIntr); /* re-enable interrupts */ /* Instead of dropping packets during a receive, we could *forceaninterruptwiththiscommand: *PutByte(XIRCREG_CR,EnableIntr|ForceIntr);
*/ return IRQ_HANDLED;
} /* xirc2ps_interrupt */
switch(cmd) { case SIOCGMIIPHY: /* Get the address of the PHY in use. */
data->phy_id = 0; /* we have only this address */
fallthrough; case SIOCGMIIREG: /* Read the specified MII register. */
data->val_out = mii_rd(ioaddr, data->phy_id & 0x1f,
data->reg_num & 0x1f); break; case SIOCSMIIREG: /* Write the specified MII register */
mii_wr(ioaddr, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in, 16); break; default: return -EOPNOTSUPP;
} return0;
}
SelectPage(4);
udelay(1);
PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
msleep(40); /* wait 40 msec */ if (local->mohawk)
PutByte(XIRCREG4_GPR1, 1); /* set bit 0: power up */ else
PutByte(XIRCREG4_GPR1, 1 | 4); /* set bit 0: power up, bit 2: AIC */
msleep(20); /* wait 20 msec */
}
if (local->probe_port) { if (!local->mohawk) {
SelectPage(4);
PutByte(XIRCREG4_GPR0, 4);
local->probe_port = 0;
}
} elseif (dev->if_port == 2) { /* enable 10Base2 */
SelectPage(0x42);
PutByte(XIRCREG42_SWC1, 0xC0);
} else { /* enable 10BaseT */
SelectPage(0x42);
PutByte(XIRCREG42_SWC1, 0x80);
}
msleep(40); /* wait 40 msec to let it complete */
#if0
{
SelectPage(0);
value = GetByte(XIRCREG_ESR); /* read the ESR */
pr_debug("%s: ESR is: %#02x\n", dev->name, value);
} #endif
/* setup the ECR */
SelectPage(1);
PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */
PutByte(XIRCREG1_IMR1, 1 ); /* and Set TxUnderrunDetect */
value = GetByte(XIRCREG1_ECR); #if0 if (local->mohawk)
value |= DisableLinkPulse;
PutByte(XIRCREG1_ECR, value); #endif
pr_debug("%s: ECR is: %#02x\n", dev->name, value);
if (local->silicon != 1) { /* set the local memory dividing line. *Thecommentsinthesamplecodesaythatthisisonly *settablewiththescipperversion2whichisrevision0. *AlwaysforCE3cards
*/
SelectPage(2);
PutWord(XIRCREG2_RBS, 0x2000);
}
if (full && local->mohawk && init_mii(dev)) { if (dev->if_port == 4 || local->dingo || local->new_mii) {
netdev_info(dev, "MII selected\n");
SelectPage(2);
PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
msleep(20);
} else {
netdev_info(dev, "MII detected; using 10mbs\n");
SelectPage(0x42); if (dev->if_port == 2) /* enable 10Base2 */
PutByte(XIRCREG42_SWC1, 0xC0); else/* enable 10BaseT */
PutByte(XIRCREG42_SWC1, 0x80);
msleep(40); /* wait 40 msec to let it complete */
} if (full_duplex)
PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR) | FullDuplex);
} else { /* No MII */
SelectPage(0);
value = GetByte(XIRCREG_ESR); /* read the ESR */
dev->if_port = (value & MediaSelect) ? 1 : 2;
}
/* configure the LEDs */
SelectPage(2); if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */
PutByte(XIRCREG2_LED, 0x3b); else/* Coax: Not-Collision and Activity */
PutByte(XIRCREG2_LED, 0x3a);
if (local->dingo)
PutByte(0x0b, 0x04); /* 100 Mbit LED */
/* enable receiver and put the mac online */ if (full) {
set_multicast_list(dev);
SelectPage(0x40);
PutByte(XIRCREG40_CMD0, EnableRecv | Online);
}
/* setup Ethernet IMR and enable interrupts */
SelectPage(1);
PutByte(XIRCREG1_IMR0, 0xff);
udelay(1);
SelectPage(0);
PutByte(XIRCREG_CR, EnableIntr); if (local->modem && !local->dingo) { /* do some magic */ if (!(GetByte(0x10) & 0x01))
PutByte(0x10, 0x11); /* unmask master-int bit */
}
if (full)
netdev_info(dev, "media %s, silicon revision %d\n",
if_names[dev->if_port], local->silicon); /* We should switch back to page 0 to avoid a bug in revision 0 *whereregswithoffsetbelow8can'tbereadafteranaccess
* to the MAC registers */
SelectPage(0);
}
if (local->probe_port)
control = 0x1000; /* auto neg */ elseif (dev->if_port == 4)
control = 0x2000; /* no auto neg, 100mbs mode */ else
control = 0x0000; /* no auto neg, 10mbs mode */
mii_wr(ioaddr, 0, 0, control, 16);
udelay(100);
control = mii_rd(ioaddr, 0, 0);
if (control & 0x0400) {
netdev_notice(dev, "can't take PHY out of isolation mode\n");
local->probe_port = 0; return0;
}
if (local->probe_port) { /* according to the DP83840A specs the auto negotiation process *maytakeupto3.5sec,soweusethisalsoforourML6692 *Fixme:Bettertouseatimerhere!
*/ for (i=0; i < 35; i++) {
msleep(100); /* wait 100 msec */
status = mii_rd(ioaddr, 0, 1); if ((status & 0x0020) && (status & 0x0004)) break;
}
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.