/* These inlines can be used if only CONFIG_HPLANCE is defined */ staticinlinevoid WRITERAP(struct lance_private *lp, __u16 value)
{ do {
out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
} while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
}
staticinline __u16 READRDP(struct lance_private *lp)
{
__u16 value; do {
value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
} while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0); return value;
}
#endif #endif/* IS_ENABLED(CONFIG_HPLANCE) */
/* debugging output macros, various flavours */ /* #define TEST_HITS */ #ifdef UNDEF #define PRINT_RINGS() \ do { \ int t; \ for (t = 0; t < RX_RING_SIZE; t++) { \
printk("R%d: @(%02X %04X) len %04X, mblen %04X, bits %02X\n", \
t, ib->brx_ring[t].rmd1_hadr, ib->brx_ring[t].rmd0, \
ib->brx_ring[t].length, \
ib->brx_ring[t].mblength, ib->brx_ring[t].rmd1_bits); \
} \ for (t = 0; t < TX_RING_SIZE; t++) { \
printk("T%d: @(%02X %04X) len %04X, misc %04X, bits %02X\n", \
t, ib->btx_ring[t].tmd1_hadr, ib->btx_ring[t].tmd0, \
ib->btx_ring[t].length, \
ib->btx_ring[t].misc, ib->btx_ring[t].tmd1_bits); \
} \
} while (0) #else #define PRINT_RINGS() #endif
/* Load the CSR registers. The LANCE has to be STOPped when we do this! */ staticvoid load_csrs(struct lance_private *lp)
{ volatilestruct lance_init_block *aib = lp->lance_init_block; int leptr;
/* #define to 0 or 1 appropriately */ #define DEBUG_IRING 0 /* Set up the Lance Rx and Tx rings and the init block */ staticvoid lance_init_ring(struct net_device *dev)
{ struct lance_private *lp = netdev_priv(dev); volatilestruct lance_init_block *ib = lp->init_block; volatilestruct lance_init_block *aib; /* for LANCE_ADDR computations */ int leptr; int i;
/* Copy the ethernet address to the lance init block *Noticethatwedoabyteswapifwe'rebigendian. *[Ithinkthisistherightcriterion;atleast,sunlance, *a2065andatarilancedothebyteswapandlance.c(PC)doesn't. *However,thedatasheetsaysthattheBSWAPbitdoesn'taffect *theinitblock,sosurelyitshouldbelowbytefirstfor *everybody?Um.] *Wecoulddefinetheib->physaddrasthree16bitvaluesand *use(addr[1]<<8)|addr[0]&co,butthisismoreefficient.
*/ #ifdef __BIG_ENDIAN
ib->phys_addr[0] = dev->dev_addr[1];
ib->phys_addr[1] = dev->dev_addr[0];
ib->phys_addr[2] = dev->dev_addr[3];
ib->phys_addr[3] = dev->dev_addr[2];
ib->phys_addr[4] = dev->dev_addr[5];
ib->phys_addr[5] = dev->dev_addr[4]; #else for (i = 0; i < 6; i++)
ib->phys_addr[i] = dev->dev_addr[i]; #endif
if (DEBUG_IRING)
printk("TX rings:\n");
lp->tx_full = 0; /* Setup the Tx ring entries */ for (i = 0; i < (1 << lp->lance_log_tx_bufs); i++) {
leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
ib->btx_ring[i].tmd0 = leptr;
ib->btx_ring[i].tmd1_hadr = leptr >> 16;
ib->btx_ring[i].tmd1_bits = 0;
ib->btx_ring[i].length = 0xf000; /* The ones required by tmd2 */
ib->btx_ring[i].misc = 0; if (DEBUG_IRING)
printk("%d: 0x%8.8x\n", i, leptr);
}
/* Setup the Rx ring entries */ if (DEBUG_IRING)
printk("RX rings:\n"); for (i = 0; i < (1 << lp->lance_log_rx_bufs); i++) {
leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
ib->brx_ring[i].rmd0 = leptr;
ib->brx_ring[i].rmd1_hadr = leptr >> 16;
ib->brx_ring[i].rmd1_bits = LE_R1_OWN; /* 0xf000 == bits that must be one (reserved, presumably) */
ib->brx_ring[i].length = -RX_BUFF_SIZE | 0xf000;
ib->brx_ring[i].mblength = 0; if (DEBUG_IRING)
printk("%d: 0x%8.8x\n", i, leptr);
}
/* LANCE must be STOPped before we do this, too... */ staticint init_restart_lance(struct lance_private *lp)
{ int i;
WRITERAP(lp, LE_CSR0);
WRITERDP(lp, LE_C0_INIT);
/* Need a hook here for sunlance ledma stuff */
/* Wait for the lance to complete initialization */ for (i = 0; (i < 100) && !(READRDP(lp) & (LE_C0_ERR | LE_C0_IDON)); i++)
barrier(); if ((i == 100) || (READRDP(lp) & LE_C0_ERR)) {
printk("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, READRDP(lp)); return -1;
}
/* Clear IDON by writing a "1", enable interrupts and start lance */
WRITERDP(lp, LE_C0_IDON);
WRITERDP(lp, LE_C0_INEA | LE_C0_STRT);
#ifdef TEST_HITS
printk("["); for (i = 0; i < RX_RING_SIZE; i++) { if (i == lp->rx_new)
printk("%s",
ib->brx_ring[i].rmd1_bits & LE_R1_OWN ? "_" : "X"); else
printk("%s",
ib->brx_ring[i].rmd1_bits & LE_R1_OWN ? "." : "1");
}
printk("]"); #endif #ifdef CONFIG_HP300
blinken_leds(0x40, 0); #endif
WRITERDP(lp, LE_C0_RINT | LE_C0_INEA); /* ack Rx int, reenable ints */ for (rd = &ib->brx_ring[lp->rx_new]; /* For each Rx ring we own... */
!((bits = rd->rmd1_bits) & LE_R1_OWN);
rd = &ib->brx_ring[lp->rx_new]) {
/* We got an incomplete frame? */ if ((bits & LE_R1_POK) != LE_R1_POK) {
dev->stats.rx_over_errors++;
dev->stats.rx_errors++; continue;
} elseif (bits & LE_R1_ERR) { /* Count only the end frame as a rx error, *notthebeginning
*/ if (bits & LE_R1_BUF)
dev->stats.rx_fifo_errors++; if (bits & LE_R1_CRC)
dev->stats.rx_crc_errors++; if (bits & LE_R1_OFL)
dev->stats.rx_over_errors++; if (bits & LE_R1_FRA)
dev->stats.rx_frame_errors++; if (bits & LE_R1_EOP)
dev->stats.rx_errors++;
} else { int len = (rd->mblength & 0xfff) - 4; struct sk_buff *skb = netdev_alloc_skb(dev, len + 2);
/* buffer errors and underflows turn off the transmitter */ /* Restart the adapter */ if (status & (LE_T3_BUF|LE_T3_UFL)) {
dev->stats.tx_fifo_errors++;
int lance_open(struct net_device *dev)
{ struct lance_private *lp = netdev_priv(dev); int res;
/* Install the Interrupt handler. Or we could shunt this out to specific drivers? */ if (request_irq(lp->irq, lance_interrupt, IRQF_SHARED, lp->name, dev)) return -EAGAIN;
res = lance_reset(dev);
spin_lock_init(&lp->devlock);
netif_start_queue(dev);
return res;
}
EXPORT_SYMBOL_GPL(lance_open);
int lance_close(struct net_device *dev)
{ struct lance_private *lp = netdev_priv(dev);
netif_stop_queue(dev);
/* Stop the LANCE */
WRITERAP(lp, LE_CSR0);
WRITERDP(lp, LE_C0_STOP);
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.