Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/sommerfeld_i386mp_1]: src/sys/arch/i386/stand/lib/netif add ne2000 stand...
details: https://anonhg.NetBSD.org/src/rev/e71c341d6d31
branches: sommerfeld_i386mp_1
changeset: 482441:e71c341d6d31
user: yamt <yamt%NetBSD.org@localhost>
date: Thu Nov 01 09:37:18 2001 +0000
description:
add ne2000 standalone driver.
diffstat:
sys/arch/i386/stand/lib/netif/dp8390.c | 368 +++++++++++++++++++++++++++++++++
sys/arch/i386/stand/lib/netif/dp8390.h | 33 ++
sys/arch/i386/stand/lib/netif/ne.h | 4 +
3 files changed, 405 insertions(+), 0 deletions(-)
diffs (truncated from 417 to 300 lines):
diff -r 26cf6fd1a159 -r e71c341d6d31 sys/arch/i386/stand/lib/netif/dp8390.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/stand/lib/netif/dp8390.c Thu Nov 01 09:37:18 2001 +0000
@@ -0,0 +1,368 @@
+/* $NetBSD: dp8390.c,v 1.3.2.2 2001/11/01 09:37:18 yamt Exp $ */
+
+/*
+ * Polling driver for National Semiconductor DS8390/WD83C690 based
+ * ethernet adapters.
+ *
+ * Copyright (c) 1998 Matthias Drochner. All rights reserved.
+ *
+ * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
+ *
+ * Copyright (C) 1993, David Greenman. This software may be used, modified,
+ * copied, distributed, and sold, in both source and binary form provided that
+ * the above copyright and these terms are retained. Under no circumstances is
+ * the author responsible for the proper functioning of this software, nor does
+ * the author assume any responsibility for damages incurred with its use.
+ */
+
+#include <sys/types.h>
+#include <machine/pio.h>
+
+#include <lib/libsa/stand.h>
+#include <libi386.h>
+
+#include <dev/ic/dp8390reg.h>
+#include "dp8390.h"
+#ifdef SUPPORT_NE2000
+#include "ne.h"
+#endif
+
+#include "etherdrv.h"
+
+int dp8390_iobase, dp8390_membase, dp8390_memsize;
+#if defined(SUPPORT_WD80X3) && defined(SUPPORT_SMC_ULTRA)
+int dp8390_is790;
+#endif
+u_int8_t dp8390_cr_proto;
+u_int8_t dp8390_dcr_reg;
+
+#define WE_IOBASE dp8390_iobase
+
+static u_short rec_page_start;
+static u_short rec_page_stop;
+static u_short next_packet;
+
+extern u_char eth_myaddr[6];
+
+#ifndef _STANDALONE
+static caddr_t vmembase;
+extern caddr_t mapmem __P((int, int));
+extern void unmapmem __P((caddr_t, int));
+extern int mapio __P((void));
+
+static void bbcopy(src, dst, len)
+caddr_t src, dst;
+int len;
+{
+ char *s = (char *)src, *d = (char *)dst;
+
+ while(len--)
+ *d++ = *s++;
+}
+#endif
+
+static void dp8390_read __P((int, char *, u_short));
+
+#define NIC_GET(reg) inb(WE_IOBASE + reg)
+#define NIC_PUT(reg, val) outb(WE_IOBASE + reg, val)
+
+static void
+dp8390_init()
+{
+ int i;
+
+ /*
+ * Initialize the NIC in the exact order outlined in the NS manual.
+ * This init procedure is "mandatory"...don't change what or when
+ * things happen.
+ */
+
+ /* Set interface for page 0, remote DMA complete, stopped. */
+ NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STP);
+
+ if (dp8390_dcr_reg & ED_DCR_LS) {
+ NIC_PUT(ED_P0_DCR, dp8390_dcr_reg);
+ } else {
+ /*
+ * Set FIFO threshold to 8, No auto-init Remote DMA, byte
+ * order=80x86, byte-wide DMA xfers,
+ */
+ NIC_PUT(ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
+ }
+
+ /* Clear remote byte count registers. */
+ NIC_PUT(ED_P0_RBCR0, 0);
+ NIC_PUT(ED_P0_RBCR1, 0);
+
+ /* Tell RCR to do nothing for now. */
+ NIC_PUT(ED_P0_RCR, ED_RCR_MON);
+
+ /* Place NIC in internal loopback mode. */
+ NIC_PUT(ED_P0_TCR, ED_TCR_LB0);
+
+ /* Set lower bits of byte addressable framing to 0. */
+ if (dp8390_is790)
+ NIC_PUT(0x09, 0);
+
+ /* Initialize receive buffer ring. */
+ NIC_PUT(ED_P0_BNRY, rec_page_start);
+ NIC_PUT(ED_P0_PSTART, rec_page_start);
+ NIC_PUT(ED_P0_PSTOP, rec_page_stop);
+
+ /*
+ * Clear all interrupts. A '1' in each bit position clears the
+ * corresponding flag.
+ */
+ NIC_PUT(ED_P0_ISR, 0xff);
+
+ /*
+ * Disable all interrupts.
+ */
+ NIC_PUT(ED_P0_IMR, 0);
+
+ /* Program command register for page 1. */
+ NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_1 | ED_CR_STP);
+
+ /* Copy out our station address. */
+ for (i = 0; i < 6; ++i)
+ NIC_PUT(ED_P1_PAR0 + i, eth_myaddr[i]);
+
+ /*
+ * Set current page pointer to one page after the boundary pointer, as
+ * recommended in the National manual.
+ */
+ next_packet = rec_page_start + 1;
+ NIC_PUT(ED_P1_CURR, next_packet);
+
+ /* Program command register for page 0. */
+ NIC_PUT(ED_P1_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STP);
+
+ /* directed and broadcast */
+ NIC_PUT(ED_P0_RCR, ED_RCR_AB);
+
+ /* Take interface out of loopback. */
+ NIC_PUT(ED_P0_TCR, 0);
+
+ /* Fire up the interface. */
+ NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STA);
+}
+
+int
+dp8390_config()
+{
+#ifndef _STANDALONE
+ if (mapio()) {
+ printf("no IO access\n");
+ return(-1);
+ }
+ vmembase = mapmem(dp8390_membase, dp8390_memsize);
+ if (!vmembase) {
+ printf("no memory access\n");
+ return(-1);
+ }
+#endif
+
+ rec_page_start = TX_PAGE_START + ED_TXBUF_SIZE;
+ rec_page_stop = TX_PAGE_START + (dp8390_memsize >> ED_PAGE_SHIFT);
+
+ dp8390_init();
+
+ return(0);
+}
+
+void
+dp8390_stop()
+{
+ int n = 5000;
+
+ /* Stop everything on the interface, and select page 0 registers. */
+ NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STP);
+
+ /*
+ * Wait for interface to enter stopped state, but limit # of checks to
+ * 'n' (about 5ms). It shouldn't even take 5us on modern DS8390's, but
+ * just in case it's an old one.
+ */
+ while (((NIC_GET(ED_P0_ISR) & ED_ISR_RST) == 0) && --n);
+
+#ifndef _STANDALONE
+ unmapmem(vmembase, dp8390_memsize);
+#endif
+}
+
+int
+EtherSend(pkt, len)
+char *pkt;
+int len;
+{
+#ifdef SUPPORT_NE2000
+ ne2000_writemem(pkt, dp8390_membase, len);
+#else
+#ifdef _STANDALONE
+ vpbcopy(pkt, (void *)dp8390_membase, len);
+#else
+ bbcopy(pkt, vmembase, len);
+#endif
+#endif
+
+ /* Set TX buffer start page. */
+ NIC_PUT(ED_P0_TPSR, TX_PAGE_START);
+
+ /* Set TX length. */
+ NIC_PUT(ED_P0_TBCR0, len < 60 ? 60 : len);
+ NIC_PUT(ED_P0_TBCR1, len >> 8);
+
+ /* Set page 0, remote DMA complete, transmit packet, and *start*. */
+ NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_TXP | ED_CR_STA);
+
+ return(len);
+}
+
+static void
+dp8390_read(buf, dest, len)
+ int buf;
+ char *dest;
+ u_short len;
+{
+ u_short tmp_amount;
+
+ /* Does copy wrap to lower addr in ring buffer? */
+ if (buf + len > dp8390_membase + dp8390_memsize) {
+ tmp_amount = dp8390_membase + dp8390_memsize - buf;
+
+ /* Copy amount up to end of NIC memory. */
+#ifdef SUPPORT_NE2000
+ ne2000_readmem(buf, dest, tmp_amount);
+#else
+#ifdef _STANDALONE
+ pvbcopy((void *)buf, dest, tmp_amount);
+#else
+ bbcopy(vmembase + buf - dp8390_membase, dest, tmp_amount);
+#endif
+#endif
+
+ len -= tmp_amount;
+ buf = RX_BUFBASE + (rec_page_start << ED_PAGE_SHIFT);
+ dest += tmp_amount;
+ }
+#ifdef SUPPORT_NE2000
+ ne2000_readmem(buf, dest, len);
+#else
+#ifdef _STANDALONE
+ pvbcopy((void *)buf, dest, len);
+#else
+ bbcopy(vmembase + buf - dp8390_membase, dest, len);
+#endif
+#endif
+}
+
+int
+EtherReceive(pkt, maxlen)
+char *pkt;
+int maxlen;
+{
+ struct dp8390_ring packet_hdr;
+ int packet_ptr;
+ u_short len;
+ u_char boundary, current;
+#ifdef DP8390_OLDCHIPS
+ u_char nlen;
+#endif
+
+ if (!(NIC_GET(ED_P0_RSR) & ED_RSR_PRX))
+ return(0); /* XXX error handling */
+
+ /* Set NIC to page 1 registers to get 'current' pointer. */
+ NIC_PUT(ED_P0_CR, dp8390_cr_proto | ED_CR_PAGE_1 | ED_CR_STA);
+
+ /*
+ * 'sc->next_packet' is the logical beginning of the ring-buffer - i.e.
+ * it points to where new data has been buffered. The 'CURR' (current)
+ * register points to the logical end of the ring-buffer - i.e. it
+ * points to where additional new data will be added. We loop here
+ * until the logical beginning equals the logical end (or in other
+ * words, until the ring-buffer is empty).
+ */
+ current = NIC_GET(ED_P1_CURR);
+
+ /* Set NIC to page 0 registers to update boundary register. */
+ NIC_PUT(ED_P1_CR, dp8390_cr_proto | ED_CR_PAGE_0 | ED_CR_STA);
+
+ if (next_packet == current)
+ return(0);
+
+ /* Get pointer to this buffer's header structure. */
+ packet_ptr = RX_BUFBASE + (next_packet << ED_PAGE_SHIFT);
+
Home |
Main Index |
Thread Index |
Old Index