/* sun3lance.c: Ethernet driver for SUN3 Lance chip */ /*
Sun3 Lance ethernet driver, by Sam Creasey (sammy@users.qual.net). This driver is a part of the linux kernel, and is thus distributed under the GNU General Public License.
The values used in LANCE_OBIO and LANCE_IRQ seem to be empirically true for the correct IRQ and address of the lance registers. They have not been widely tested, however. What we probably need is a "proper" way to search for a device in the sun3's prom, but, alas, linux has no such thing.
This driver is largely based on atarilance.c, by Roman Hodek. Other sources of inspiration were the NetBSD sun3 am7990 driver, and the linux sparc lance driver (sunlance.c).
There are more assumptions made throughout this driver, it almost certainly still needs work, but it does work at least for RARP/BOOTP and mounting the root NFS filesystem.
*/
staticconstchar version[] = "sun3lance.c: v1.2 1/12/2001 Sam Creasey (sammy@sammy.net)\n";
/* Definitions for packet buffer access: */ #define PKT_BUF_SZ 1544
/* Get the address of a packet buffer corresponding to a given buffer head */ #define PKTBUF_ADDR(head) (void *)((unsignedlong)(MEM) | (head)->base)
/* The LANCE Rx and Tx ring descriptors. */ struct lance_rx_head { unsignedshort base; /* Low word of base addr */ volatileunsignedchar flag; unsignedchar base_hi; /* High word of base addr (unused) */ short buf_length; /* This length is 2s complement! */ volatileshort msg_length; /* This length is "normal". */
};
struct lance_tx_head { unsignedshort base; /* Low word of base addr */ volatileunsignedchar flag; unsignedchar base_hi; /* High word of base addr (unused) */ short length; /* Length is 2s complement! */ volatileshort misc;
};
/* The LANCE initialization block, described in databook. */ struct lance_init_block { unsignedshort mode; /* Pre-set mode */ unsignedchar hwaddr[6]; /* Physical ethernet address */ unsignedint filter[2]; /* Multicast filter (unused). */ /* Receive and transmit ring base, along with length bits. */ unsignedshort rdra; unsignedshort rlen; unsignedshort tdra; unsignedshort tlen; unsignedshort pad[4]; /* is thie needed? */
};
/* The whole layout of the Lance shared memory */ struct lance_memory { struct lance_init_block init; struct lance_tx_head tx_head[TX_RING_SIZE]; struct lance_rx_head rx_head[RX_RING_SIZE]; char rx_data[RX_RING_SIZE][PKT_BUF_SZ]; char tx_data[TX_RING_SIZE][PKT_BUF_SZ];
};
/* The driver's private device structure */
struct lance_private { volatileunsignedshort *iobase; struct lance_memory *mem; int new_rx, new_tx; /* The next free ring entry */ int old_tx, old_rx; /* ring entry to be processed */ /* These two must be longs for set_bit() */ long tx_full; long lock;
};
if (!MACH_IS_SUN3 && !MACH_IS_SUN3X) return ERR_PTR(-ENODEV);
/* check that this machine has an onboard lance */ switch(idprom->id_machtype) { case SM_SUN3|SM_3_50: case SM_SUN3|SM_3_60: case SM_SUN3X|SM_3_80: /* these machines have lance */ break;
default: return ERR_PTR(-ENODEV);
}
if (found) return ERR_PTR(-ENODEV);
dev = alloc_etherdev(sizeof(struct lance_private)); if (!dev) return ERR_PTR(-ENOMEM);
if (!lance_probe(dev)) goto out;
err = register_netdev(dev); if (err) goto out1;
found = 1; return dev;
/* Transmitter timeout, serious problems. */ if (netif_queue_stopped(dev)) { int tickssofar = jiffies - dev_trans_start(dev); if (tickssofar < HZ/5) return NETDEV_TX_BUSY;
DPRINTK( 1, ( "%s: transmit timed out, status %04x, resetting.\n",
dev->name, DREG ));
DREG = CSR0_STOP; /* * Always set BSWP after a STOP as STOP puts it back into * little endian mode.
*/
REGA(CSR3) = CSR3_BSWP;
dev->stats.tx_errors++;
if(lance_debug >= 2) { int i;
printk("Ring data: old_tx %d new_tx %d%s new_rx %d\n",
lp->old_tx, lp->new_tx,
lp->tx_full ? " (full)" : "",
lp->new_rx ); for( i = 0 ; i < RX_RING_SIZE; i++ )
printk( "rx #%d: base=%04x blen=%04x mlen=%04x\n",
i, MEM->rx_head[i].base,
-MEM->rx_head[i].buf_length,
MEM->rx_head[i].msg_length); for( i = 0 ; i < TX_RING_SIZE; i++ )
printk("tx #%d: base=%04x len=%04x misc=%04x\n",
i, MEM->tx_head[i].base,
-MEM->tx_head[i].length,
MEM->tx_head[i].misc );
}
/* Fill in a Tx ring entry */ #if 0 if (lance_debug >= 2) {
printk( "%s: TX pkt %d type 0x%04x" " from %s to %s" " data at 0x%08x len %d\n",
dev->name, lp->new_tx, ((u_short *)skb->data)[6],
DEV_ADDR(&skb->data[6]), DEV_ADDR(skb->data),
(int)skb->data, (int)skb->len );
} #endif /* We're not prepared for the int until the last flags are set/reset.
* And the int may happen already after setting the OWN_CHIP... */
local_irq_save(flags);
/* Mask to ring buffer boundary. */
entry = lp->new_tx;
head = &(MEM->tx_head[entry]);
/* Caution: the write order is important here, set the "ownership" bits * last.
*/
/* the sun3's lance needs it's buffer padded to the minimum
size */
len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
/* get packet, toss into skbuff */ staticint lance_rx( struct net_device *dev )
{ struct lance_private *lp = netdev_priv(dev); int entry = lp->new_rx;
/* If we own the next entry, it's a new packet. Send it up. */ while( (MEM->rx_head[entry].flag & RMD1_OWN) == RMD1_OWN_HOST ) { struct lance_rx_head *head = &(MEM->rx_head[entry]); int status = head->flag;
if (status != (RMD1_ENP|RMD1_STP)) { /* There was an error. */ /* There is a tricky error noted by John Murphy, <murf@perftech.com> to Russ Nelson: Even with full-sized buffers it's possible for a jabber packet to use two
buffers, with only the last correctly noting the error. */ if (status & RMD1_ENP) /* Only count a general error at the */
dev->stats.rx_errors++; /* end of a packet.*/ if (status & RMD1_FRAM) dev->stats.rx_frame_errors++; if (status & RMD1_OFLO) dev->stats.rx_over_errors++; if (status & RMD1_CRC) dev->stats.rx_crc_errors++; if (status & RMD1_BUFF) dev->stats.rx_fifo_errors++;
head->flag &= (RMD1_ENP|RMD1_STP);
} else { /* Malloc up new buffer, compatible with net-3. */ // short pkt_len = head->msg_length;// & 0xfff; short pkt_len = (head->msg_length & 0xfff) - 4; struct sk_buff *skb;
/* From lance.c (Donald Becker): */ /* We should check that at least two ring entries are free.
If not, we should free one and mark stats->rx_dropped++. */
DPRINTK( 2, ( "%s: Shutting down ethercard, status was %2.2x.\n",
dev->name, DREG ));
/* We stop the LANCE here -- it occasionally polls
memory if we don't. */
DREG = CSR0_STOP; return 0;
}
/* Set or clear the multicast filter for this adaptor. 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.
*/
/* completely untested on a sun3 */ staticvoid set_multicast_list( struct net_device *dev )
{ struct lance_private *lp = netdev_priv(dev);
if(netif_queue_stopped(dev)) /* Only possible if board is already started */ return;
/* We take the simple way out and always enable promiscuous mode. */
DREG = CSR0_STOP; /* Temporarily stop the lance. */
if (dev->flags & IFF_PROMISC) { /* Log any net taps. */
DPRINTK( 3, ( "%s: Promiscuous mode enabled.\n", dev->name ));
REGA( CSR15 ) = 0x8000; /* Set promiscuous mode */
} else { short multicast_table[4]; int num_addrs = netdev_mc_count(dev); int i; /* We don't use the multicast table, but rely on upper-layer
* filtering. */
memset( multicast_table, (num_addrs == 0) ? 0 : -1, sizeof(multicast_table) ); for( i = 0; i < 4; i++ )
REGA( CSR8+i ) = multicast_table[i];
REGA( CSR15 ) = 0; /* Unset promiscuous mode */
}
/* * Always set BSWP after a STOP as STOP puts it back into * little endian mode.
*/
REGA( CSR3 ) = CSR3_BSWP;
/* Resume normal operation and reset AREG to CSR0 */
REGA( CSR0 ) = CSR0_IDON | CSR0_INEA | CSR0_STRT;
}
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.