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 Bill Paul's FreeBSD driver for the CATC USB-...



details:   https://anonhg.NetBSD.org/src/rev/c00bebd206c4
branches:  trunk
changeset: 480681:c00bebd206c4
user:      augustss <augustss%NetBSD.org@localhost>
date:      Mon Jan 17 17:12:20 2000 +0000

description:
Add Bill Paul's FreeBSD driver for the CATC USB-EL1201A chip.

XXX The driver is untested since I don't have any hardware with this chip.

diffstat:

 sys/dev/usb/if_cue.c    |  1475 +++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/if_cuereg.h |   196 ++++++
 2 files changed, 1671 insertions(+), 0 deletions(-)

diffs (truncated from 1679 to 300 lines):

diff -r 48cb1920f382 -r c00bebd206c4 sys/dev/usb/if_cue.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/if_cue.c      Mon Jan 17 17:12:20 2000 +0000
@@ -0,0 +1,1475 @@
+/*     $NetBSD: if_cue.c,v 1.1 2000/01/17 17:12:20 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_cue.c,v 1.4 2000/01/16 22:45:06 wpaul Exp $
+ */
+
+/*
+ * CATC USB-EL1201A USB to ethernet driver. Used in the CATC Netmate
+ * adapters and others.
+ *
+ * Written by Bill Paul <wpaul%ee.columbia.edu@localhost>
+ * Electrical Engineering Department
+ * Columbia University, New York City
+ */
+
+/*
+ * The CATC USB-EL1201A provides USB ethernet support at 10Mbps. The
+ * RX filter uses a 512-bit multicast hash table, single perfect entry
+ * for the station address, and promiscuous mode. Unlike the ADMtek
+ * and KLSI chips, the CATC ASIC supports read and write combining
+ * mode where multiple packets can be transfered using a single bulk
+ * transaction, which helps performance a great deal.
+ */
+
+/*
+ * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
+ */
+
+/*
+ * TODO:
+ * proper cleanup on errors
+ */
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include "opt_inet.h"
+#include "opt_ns.h"
+#include "bpfilter.h"
+#include "rnd.h"
+#endif
+
+#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>
+
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+
+#include <sys/device.h>
+
+#endif
+
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/if_dl.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
+
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#ifdef INET
+#include <netinet/in.h> 
+#include <netinet/if_inarp.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+#endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
+
+#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_cuereg.h>
+
+#ifdef CUE_DEBUG
+#define DPRINTF(x)     if (cuedebug) logprintf x
+#define DPRINTFN(n,x)  if (cuedebug >= (n)) logprintf x
+int    cuedebug = 0;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n,x)
+#endif
+
+/*
+ * Various supported device vendors/products.
+ */
+static struct cue_type cue_devs[] = {
+       { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE },
+       { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 },
+       /*{ USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U111 },*/
+       { 0, 0 }
+};
+
+USB_DECLARE_DRIVER(cue);
+
+static int cue_tx_list_init    __P((struct cue_softc *));
+static int cue_rx_list_init    __P((struct cue_softc *));
+static int cue_newbuf          __P((struct cue_softc *, struct cue_chain *,
+                                   struct mbuf *));
+static int cue_send            __P((struct cue_softc *, struct mbuf *, int));
+static void cue_rxeof          __P((usbd_xfer_handle,
+                                   usbd_private_handle, usbd_status));
+static void cue_txeof          __P((usbd_xfer_handle,
+                                   usbd_private_handle, usbd_status));
+static void cue_tick           __P((void *));
+static void cue_start          __P((struct ifnet *));
+static int cue_ioctl           __P((struct ifnet *, u_long, caddr_t));
+static void cue_init           __P((void *));
+static void cue_stop           __P((struct cue_softc *));
+static void cue_watchdog               __P((struct ifnet *));
+
+static void cue_setmulti       __P((struct cue_softc *));
+static u_int32_t cue_crc       __P((caddr_t));
+static void cue_reset          __P((struct cue_softc *));
+
+static int csr_read_1          __P((struct cue_softc *, int));
+static int csr_write_1         __P((struct cue_softc *, int, int));
+static int csr_read_2          __P((struct cue_softc *, int));
+#ifdef notdef
+static int csr_write_2         __P((struct cue_softc *, int, int));
+#endif
+static int cue_mem             __P((struct cue_softc *, int,
+                                   int, void *, int));
+static int cue_getmac          __P((struct cue_softc *, void *));
+
+#ifdef __FreeBSD__
+#ifndef lint
+static const char rcsid[] =
+  "$FreeBSD: src/sys/dev/usb/if_cue.c,v 1.4 2000/01/16 22:45:06 wpaul Exp $";
+#endif
+
+static void cue_rxstart                __P((struct ifnet *));
+static void cue_shutdown               __P((device_t));
+
+static struct usb_qdat cue_qdat;
+
+static device_method_t cue_methods[] = {
+       /* Device interface */
+       DEVMETHOD(device_probe,         cue_match),
+       DEVMETHOD(device_attach,        cue_attach),
+       DEVMETHOD(device_detach,        cue_detach),
+       DEVMETHOD(device_shutdown,      cue_shutdown),
+
+       { 0, 0 }
+};
+
+static driver_t cue_driver = {
+       "cue",
+       cue_methods,
+       sizeof(struct cue_softc)
+};
+
+static devclass_t cue_devclass;
+
+DRIVER_MODULE(if_cue, uhub, cue_driver, cue_devclass, usbd_driver_load, 0);
+
+#endif /* defined(__FreeBSD__) */
+
+#define CUE_SETBIT(sc, reg, x)                         \
+       csr_write_1(sc, reg, csr_read_1(sc, reg) | (x))
+
+#define CUE_CLRBIT(sc, reg, x)                         \
+       csr_write_1(sc, reg, csr_read_1(sc, reg) & ~(x))
+
+static int
+csr_read_1(sc, reg)
+       struct cue_softc        *sc;
+       int                     reg;
+{
+       usb_device_request_t    req;
+       usbd_status             err;
+       u_int8_t                val = 0;
+       int                     s;
+
+       s = splusb();
+
+       req.bmRequestType = UT_READ_VENDOR_DEVICE;
+       req.bRequest = CUE_CMD_READREG;
+       USETW(req.wValue, 0);
+       USETW(req.wIndex, reg);
+       USETW(req.wLength, 1);
+
+       err = usbd_do_request(sc->cue_udev, &req, &val);
+
+       splx(s);
+
+       if (err)
+               return (0);
+
+       return (val);
+}
+
+static int
+csr_read_2(sc, reg)
+       struct cue_softc        *sc;
+       int                     reg;
+{
+       usb_device_request_t    req;
+       usbd_status             err;
+       u_int16_t               val = 0;
+       int                     s;
+
+       s = splusb();
+
+       req.bmRequestType = UT_READ_VENDOR_DEVICE;
+       req.bRequest = CUE_CMD_READREG;
+       USETW(req.wValue, 0);
+       USETW(req.wIndex, reg);
+       USETW(req.wLength, 2);
+
+       err = usbd_do_request(sc->cue_udev, &req, &val);
+
+       splx(s);
+
+       if (err)
+               return (0);
+
+       return (val);
+}
+
+static int
+csr_write_1(sc, reg, val)
+       struct cue_softc        *sc;
+       int                     reg, val;
+{
+       usb_device_request_t    req;
+       usbd_status             err;
+       int                     s;
+
+       s = splusb();
+
+       req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+       req.bRequest = CUE_CMD_WRITEREG;
+       USETW(req.wValue, val);
+       USETW(req.wIndex, reg);
+       USETW(req.wLength, 0);
+
+       err = usbd_do_request(sc->cue_udev, &req, NULL);
+
+       splx(s);
+
+       if (err)
+               return (-1);
+



Home | Main Index | Thread Index | Old Index