Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb Add initial version of a driver for the ADMtek A...



details:   https://anonhg.NetBSD.org/src/rev/e9a145d802fe
branches:  trunk
changeset: 480596:e9a145d802fe
user:      augustss <augustss%NetBSD.org@localhost>
date:      Sun Jan 16 13:45:56 2000 +0000

description:
Add initial version of a driver for the ADMtek AN986 Pegasus USB to
Ethernet chip.
Written by Bill Paul, <wpaul%ee.columbia.edu@localhost>, for FreeBSD.
Massaged by Lennart Augustsson.
XXX Needs a thread to avoid a the gruesome USBD_NO_TSLEEP hack.

diffstat:

 sys/dev/usb/if_aue.c    |  1845 +++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/if_auereg.h |   265 ++++++
 2 files changed, 2110 insertions(+), 0 deletions(-)

diffs (truncated from 2118 to 300 lines):

diff -r 9b1f48e819a1 -r e9a145d802fe sys/dev/usb/if_aue.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/if_aue.c      Sun Jan 16 13:45:56 2000 +0000
@@ -0,0 +1,1845 @@
+/*     $NetBSD: if_aue.c,v 1.1 2000/01/16 13:45:56 augustss Exp $      */
+/*
+ * Copyright (c) 1997, 1998, 1999, 2000
+ *     Bill Paul <wpaul%ee.columbia.edu@localhost>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $
+ */
+
+/*
+ * ADMtek AN986 Pegasus USB to ethernet driver. Datasheet is available
+ * from http://www.admtek.com.tw.
+ *
+ * Written by Bill Paul <wpaul%ee.columbia.edu@localhost>
+ * Electrical Engineering Department
+ * Columbia University, New York City
+ */
+
+/*
+ * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet
+ * support: the control endpoint for reading/writing registers, burst
+ * read endpoint for packet reception, burst write for packet transmission
+ * and one for "interrupts." The chip uses the same RX filter scheme
+ * as the other ADMtek ethernet parts: one perfect filter entry for the
+ * the station address and a 64-bit multicast hash table. The chip supports
+ * both MII and HomePNA attachments.
+ *
+ * Since the maximum data transfer speed of USB is supposed to be 12Mbps,
+ * you're never really going to get 100Mbps speeds from this device. I
+ * think the idea is to allow the device to connect to 10 or 100Mbps
+ * networks, not necessarily to provide 100Mbps performance. Also, since
+ * the controller uses an external PHY chip, it's possible that board
+ * designers might simply choose a 10Mbps PHY.
+ *
+ * Registers are accessed using usbd_do_request(). Packet transfers are
+ * done using usbd_transfer() and friends.
+ */
+
+/*
+ * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
+ */
+
+/*
+ * TODO:
+ * better error messages from rxstat
+ * split out if_auevar.h
+ * add thread to avoid register reads from interrupt context
+ * more error checks
+ * investigate short rx problem
+ */
+
+#include "opt_inet.h"
+#include "opt_ns.h"
+#include "bpfilter.h"
+#include "rnd.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/sockio.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+
+#if defined(__FreeBSD__)
+
+#include <net/ethernet.h>
+#include <machine/clock.h>     /* for DELAY */
+#include <sys/bus.h>
+/* "controller miibus0" required.  See GENERIC if you get errors here. */
+#include "miibus_if.h"
+
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+
+#include <sys/device.h>
+
+#endif
+
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <net/if_ether.h>
+
+#define bpf_mtap(ifp, m) bpf_tap((ifp)->if_bpf, mtod((m), caddr_t), (m)->m_len)
+
+#endif
+
+#if defined(__FreeBSD__) || NBPFILTER > 0
+#include <net/bpf.h>
+#endif
+
+#ifdef INET
+#include <netinet/in.h> 
+#include <netinet/if_inarp.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include <dev/usb/usbdevs.h>
+
+#ifdef __FreeBSD__
+#include <dev/usb/usb_ethersubr.h>
+#endif
+
+#include <dev/usb/if_auereg.h>
+
+#define AUE_DEBUG
+
+#ifdef AUE_DEBUG
+#define DPRINTF(x)     if (auedebug) logprintf x
+#define DPRINTFN(n,x)  if (auedebug >= (n)) logprintf x
+int    auedebug = 1;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n,x)
+#endif
+
+int aue_cutoff = AUE_CUTOFF;
+#undef AUE_CUTOFF
+#define AUE_CUTOFF aue_cutoff
+
+/*
+ * Various supported device vendors/types and their names.
+ */
+static struct aue_type aue_devs[] = {
+       { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100 },
+       { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX },
+       { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX },
+       { USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS },
+       { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX },
+       { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA },
+       { USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB },
+       { 0, 0 }
+};
+
+USB_DECLARE_DRIVER(aue);
+
+static int aue_tx_list_init    __P((struct aue_softc *));
+static int aue_rx_list_init    __P((struct aue_softc *));
+static int aue_newbuf          __P((struct aue_softc *, struct aue_chain *,
+                                   struct mbuf *));
+static int aue_send            __P((struct aue_softc *, struct mbuf *, int));
+static void aue_intr           __P((usbd_xfer_handle,
+                                   usbd_private_handle, usbd_status));
+static void aue_rxeof          __P((usbd_xfer_handle,
+                                   usbd_private_handle, usbd_status));
+static void aue_txeof          __P((usbd_xfer_handle,
+                                   usbd_private_handle, usbd_status));
+static void aue_tick           __P((void *));
+static void aue_start          __P((struct ifnet *));
+static int aue_ioctl           __P((struct ifnet *, u_long, caddr_t));
+static void aue_init           __P((void *));
+static void aue_stop           __P((struct aue_softc *));
+static void aue_watchdog       __P((struct ifnet *));
+#ifdef __FreeBSD__
+static void aue_shutdown       __P((device_ptr_t));
+#endif
+static int aue_ifmedia_upd     __P((struct ifnet *));
+static void aue_ifmedia_sts    __P((struct ifnet *, struct ifmediareq *));
+
+static int aue_eeprom_getword  __P((struct aue_softc *, int));
+static void aue_read_mac       __P((struct aue_softc *, u_char *));
+static int aue_miibus_readreg  __P((device_ptr_t, int, int));
+#if defined(__FreeBSD__)
+static int aue_miibus_writereg __P((device_ptr_t, int, int, int));
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+static void aue_miibus_writereg        __P((device_ptr_t, int, int, int));
+#endif
+static void aue_miibus_statchg __P((device_ptr_t));
+
+static void aue_setmulti       __P((struct aue_softc *));
+static u_int32_t aue_crc       __P((caddr_t));
+static void aue_reset          __P((struct aue_softc *));
+
+static int csr_read_1          __P((struct aue_softc *, int));
+static int csr_write_1         __P((struct aue_softc *, int, int));
+static int csr_read_2          __P((struct aue_softc *, int));
+static int csr_write_2         __P((struct aue_softc *, int, int));
+
+#if defined(__FreeBSD__)
+#if !defined(lint)
+static const char rcsid[] =
+  "$FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $";
+#endif
+
+static void aue_rxstart                __P((struct ifnet *));
+
+static struct usb_qdat aue_qdat;
+
+static device_method_t aue_methods[] = {
+       /* Device interface */
+       DEVMETHOD(device_probe,         aue_match),
+       DEVMETHOD(device_attach,        aue_attach),
+       DEVMETHOD(device_detach,        aue_detach),
+       DEVMETHOD(device_shutdown,      aue_shutdown),
+
+       /* bus interface */
+       DEVMETHOD(bus_print_child,      bus_generic_print_child),
+       DEVMETHOD(bus_driver_added,     bus_generic_driver_added),
+
+       /* MII interface */
+       DEVMETHOD(miibus_readreg,       aue_miibus_readreg),
+       DEVMETHOD(miibus_writereg,      aue_miibus_writereg),
+       DEVMETHOD(miibus_statchg,       aue_miibus_statchg),
+
+       { 0, 0 }
+};
+
+static driver_t aue_driver = {
+       "aue",
+       aue_methods,
+       sizeof(struct aue_softc)
+};
+
+static devclass_t aue_devclass;
+
+DRIVER_MODULE(if_aue, uhub, aue_driver, aue_devclass, usbd_driver_load, 0);
+DRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0);
+
+#endif /* __FreeBSD__ */
+
+#define AUE_DO_REQUEST(dev, req, data) usbd_do_request_flags(dev, req, data, USBD_NO_TSLEEP, NULL)
+
+#define AUE_SETBIT(sc, reg, x)                         \
+       csr_write_1(sc, reg, csr_read_1(sc, reg) | (x))
+
+#define AUE_CLRBIT(sc, reg, x)                         \
+       csr_write_1(sc, reg, csr_read_1(sc, reg) & ~(x))
+
+static int
+csr_read_1(sc, reg)
+       struct aue_softc        *sc;
+       int                     reg;
+{
+       usb_device_request_t    req;
+       usbd_status             err;
+       uByte                   val = 0;
+       int                     s;
+
+       req.bmRequestType = UT_READ_VENDOR_DEVICE;
+       req.bRequest = AUE_UR_READREG;
+       USETW(req.wValue, 0);
+       USETW(req.wIndex, reg);
+       USETW(req.wLength, 1);
+
+       s = splusb();
+       err = AUE_DO_REQUEST(sc->aue_udev, &req, &val);
+       splx(s);
+
+       if (err)
+               return (0);
+
+       return (val);
+}
+
+static int
+csr_read_2(sc, reg)
+       struct aue_softc        *sc;



Home | Main Index | Thread Index | Old Index