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 Kawasaki ...



details:   https://anonhg.NetBSD.org/src/rev/9b83b860f7a6
branches:  trunk
changeset: 480626:9b83b860f7a6
user:      augustss <augustss%NetBSD.org@localhost>
date:      Mon Jan 17 01:38:43 2000 +0000

description:
Add Bill Paul's FreeBSD driver for the Kawasaki LSI KL5KUSB101B USB Ethernet
chip.

diffstat:

 sys/dev/usb/if_kue.c    |  1504 +++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/if_kuereg.h |   189 +++++
 sys/dev/usb/kue_fw.h    |   686 +++++++++++++++++++++
 3 files changed, 2379 insertions(+), 0 deletions(-)

diffs (truncated from 2391 to 300 lines):

diff -r 2047b392bbb0 -r 9b83b860f7a6 sys/dev/usb/if_kue.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/if_kue.c      Mon Jan 17 01:38:43 2000 +0000
@@ -0,0 +1,1504 @@
+/*     $NetBSD: if_kue.c,v 1.1 2000/01/17 01:38:43 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_kue.c,v 1.14 2000/01/14 01:36:15 wpaul Exp $
+ */
+
+/*
+ * Kawasaki LSI KL5KUSB101B USB to ethernet adapter driver.
+ *
+ * Written by Bill Paul <wpaul%ee.columbia.edu@localhost>
+ * Electrical Engineering Department
+ * Columbia University, New York City
+ */
+
+/*
+ * The KLSI USB to ethernet adapter chip contains an USB serial interface,
+ * ethernet MAC and embedded microcontroller (called the QT Engine).
+ * The chip must have firmware loaded into it before it will operate.
+ * Packets are passed between the chip and host via bulk transfers.
+ * There is an interrupt endpoint mentioned in the software spec, however
+ * it's currently unused. This device is 10Mbps half-duplex only, hence
+ * there is no media selection logic. The MAC supports a 128 entry
+ * multicast filter, though the exact size of the filter can depend
+ * on the firmware. Curiously, while the software spec describes various
+ * ethernet statistics counters, my sample adapter and firmware combination
+ * claims not to support any statistics counters at all.
+ *
+ * Note that once we load the firmware in the device, we have to be
+ * careful not to load it again: if you restart your computer but
+ * leave the adapter attached to the USB controller, it may remain
+ * powered on and retain its firmware. In this case, we don't need
+ * to load the firmware a second time.
+ *
+ * Special thanks to Rob Furr for providing an ADS Technologies
+ * adapter for development and testing. No monkeys were harmed during
+ * the development of this driver.
+ */
+
+/*
+ * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
+ */
+
+/*
+ * TODO:
+ * only use kue_do_request for downloading firmware.
+ * more DPRINTF
+ * 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>
+#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
+
+#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_kuereg.h>
+#include <dev/usb/kue_fw.h>
+
+#ifdef KUE_DEBUG
+#define DPRINTF(x)     if (kuedebug) logprintf x
+#define DPRINTFN(n,x)  if (kuedebug >= (n)) logprintf x
+int    kuedebug = 0;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n,x)
+#endif
+
+/*
+ * Various supported device vendors/products.
+ */
+static struct kue_type kue_devs[] = {
+       { USB_VENDOR_AOX, USB_PRODUCT_AOX_USB101 },
+       { USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BT },
+       { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC10T },
+       { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_EA101 },
+       { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET },
+       { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET2 },
+       { USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_E45 },
+       { USB_VENDOR_3COM, USB_PRODUCT_3COM_3C19250 },
+       { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_ETHER_USB_T },
+       { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650C },
+       { USB_VENDOR_SMC, USB_PRODUCT_SMC_2102USB },
+       { 0, 0 }
+};
+
+USB_DECLARE_DRIVER(kue);
+
+static int kue_tx_list_init    __P((struct kue_softc *));
+static int kue_rx_list_init    __P((struct kue_softc *));
+static int kue_newbuf          __P((struct kue_softc *, struct kue_chain *,
+                                   struct mbuf *));
+static int kue_send            __P((struct kue_softc *, struct mbuf *, int));
+static int kue_open_pipes      __P((struct kue_softc *));
+static void kue_rxeof          __P((usbd_xfer_handle,
+                                   usbd_private_handle, usbd_status));
+static void kue_txeof          __P((usbd_xfer_handle,
+                                   usbd_private_handle, usbd_status));
+static void kue_start          __P((struct ifnet *));
+static int kue_ioctl           __P((struct ifnet *, u_long, caddr_t));
+static void kue_init           __P((void *));
+static void kue_stop           __P((struct kue_softc *));
+static void kue_watchdog               __P((struct ifnet *));
+
+static void kue_setmulti       __P((struct kue_softc *));
+static void kue_reset          __P((struct kue_softc *));
+
+static usbd_status kue_do_request
+                               __P((usbd_device_handle,
+                                  usb_device_request_t *, void *, u_int16_t,
+                                  u_int32_t *));
+static usbd_status kue_ctl_l   __P((struct kue_softc *, int, u_int8_t,
+                                   u_int16_t, char *, u_int32_t, 
+                                   u_int32_t, u_int32_t *));
+#define kue_ctl(sc, rw, breq, val, data, len) \
+       kue_ctl_l(sc, rw, breq, val, data, len, 0, 0)
+static usbd_status kue_setword __P((struct kue_softc *, u_int8_t, u_int16_t));
+static int kue_load_fw         __P((struct kue_softc *));
+
+#if defined(__FreeBSD__)
+#ifndef lint
+static const char rcsid[] =
+  "$FreeBSD: src/sys/dev/usb/if_kue.c,v 1.14 2000/01/14 01:36:15 wpaul Exp $";
+#endif
+
+static void kue_rxstart                __P((struct ifnet *));
+static void kue_shutdown       __P((device_t));
+
+static struct usb_qdat kue_qdat;
+
+static device_method_t kue_methods[] = {
+       /* Device interface */
+       DEVMETHOD(device_probe,         kue_match),
+       DEVMETHOD(device_attach,        kue_attach),
+       DEVMETHOD(device_detach,        kue_detach),
+       DEVMETHOD(device_shutdown,      kue_shutdown),
+
+       { 0, 0 }
+};
+
+static driver_t kue_driver = {
+       "kue",
+       kue_methods,
+       sizeof(struct kue_softc)
+};
+
+static devclass_t kue_devclass;
+
+DRIVER_MODULE(if_kue, uhub, kue_driver, kue_devclass, usbd_driver_load, 0);
+
+#endif /* __FreeBSD__ */
+
+/*
+ * We have a custom do_request function which is almost like the
+ * regular do_request function, except it has a much longer timeout.
+ * Why? Because we need to make requests over the control endpoint
+ * to download the firmware to the device, which can take longer
+ * than the default timeout.
+ */
+static usbd_status
+kue_do_request(dev, req, data, flags, lenp)
+       usbd_device_handle      dev;
+       usb_device_request_t    *req;
+       void                    *data;
+       u_int16_t               flags;
+       u_int32_t               *lenp;
+{
+       usbd_xfer_handle        xfer;
+       usbd_status             err;
+
+       DPRINTFN(15,("kue_do_request: enter\n"));
+
+       xfer = usbd_alloc_xfer(dev);
+       /* XXX 20000 */
+       usbd_setup_default_xfer(xfer, dev, 0, 20000, req,
+           data, UGETW(req->wLength), flags, 0);
+       err = usbd_sync_transfer(xfer);
+       if (lenp != NULL)
+               usbd_get_xfer_status(xfer, NULL, NULL, lenp, NULL);
+       usbd_free_xfer(xfer);
+
+       return (err);
+}
+
+static usbd_status
+kue_setword(sc, breq, word)
+       struct kue_softc        *sc;
+       u_int8_t                breq;
+       u_int16_t               word;
+{
+       usb_device_request_t    req;
+       usbd_status             err;
+       int                     s;
+
+       DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__));
+
+       req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+       req.bRequest = breq;
+       USETW(req.wValue, word);
+       USETW(req.wIndex, 0);
+       USETW(req.wLength, 0);
+
+       s = splusb();
+       err = kue_do_request(sc->kue_udev, &req, NULL, sc->kue_xfer_flags, 0);
+       splx(s);
+
+       return (err);
+}
+
+static usbd_status
+kue_ctl_l(sc, rw, breq, val, data, len, flags, lenp)



Home | Main Index | Thread Index | Old Index