2003-05-03 10:16:56 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001-2003, Shunsuke Akiyama <akiyama@FreeBSD.org>.
|
2005-08-10 03:54:37 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999, 2000 Bill Paul <wpaul@ee.columbia.edu>.
|
2003-05-03 10:16:56 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 THE AUTHOR OR CONTRIBUTORS 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.
|
2003-11-13 19:54:37 +00:00
|
|
|
*/
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997, 1998, 1999, 2000
|
|
|
|
* Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
|
2003-05-03 10:16:56 +00:00
|
|
|
*
|
2003-11-13 19:54:37 +00:00
|
|
|
* 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.
|
2003-05-03 10:16:56 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-05-03 10:16:56 +00:00
|
|
|
/*
|
|
|
|
* RealTek RTL8150 USB to fast ethernet controller driver.
|
|
|
|
* Datasheet is available from
|
|
|
|
* ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2003-05-03 10:16:56 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
2005-06-10 16:49:24 +00:00
|
|
|
#include <net/if_types.h>
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#include <sys/bus.h>
|
2003-07-16 02:20:14 +00:00
|
|
|
#include <machine/bus.h>
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
#include <dev/usb/usbdi_util.h>
|
|
|
|
#include <dev/usb/usbdivar.h>
|
2004-06-27 12:41:44 +00:00
|
|
|
#include "usbdevs.h"
|
2003-05-03 10:16:56 +00:00
|
|
|
#include <dev/usb/usb_ethersubr.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
|
|
|
#include <dev/usb/if_ruereg.h>
|
|
|
|
|
2005-10-22 05:06:55 +00:00
|
|
|
/* "device miibus" required. See GENERIC if you get errors here. */
|
2003-05-03 10:16:56 +00:00
|
|
|
#include "miibus_if.h"
|
|
|
|
|
|
|
|
#ifdef USB_DEBUG
|
2006-09-06 23:44:25 +00:00
|
|
|
static int ruedebug = 0;
|
2003-05-03 10:16:56 +00:00
|
|
|
SYSCTL_NODE(_hw_usb, OID_AUTO, rue, CTLFLAG_RW, 0, "USB rue");
|
|
|
|
SYSCTL_INT(_hw_usb_rue, OID_AUTO, debug, CTLFLAG_RW,
|
|
|
|
&ruedebug, 0, "rue debug level");
|
|
|
|
|
|
|
|
#define DPRINTFN(n, x) do { \
|
|
|
|
if (ruedebug > (n)) \
|
2007-06-20 05:11:37 +00:00
|
|
|
printf x; \
|
2003-05-03 10:16:56 +00:00
|
|
|
} while (0);
|
|
|
|
#else
|
|
|
|
#define DPRINTFN(n, x)
|
|
|
|
#endif
|
|
|
|
#define DPRINTF(x) DPRINTFN(0, x)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Various supported device vendors/products.
|
|
|
|
*/
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static struct rue_type rue_devs[] = {
|
2003-05-03 10:16:56 +00:00
|
|
|
{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUAKTX },
|
|
|
|
{ USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_USBKR100 },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
2007-06-18 22:25:46 +00:00
|
|
|
static device_probe_t rue_match;
|
|
|
|
static device_attach_t rue_attach;
|
|
|
|
static device_detach_t rue_detach;
|
|
|
|
static device_shutdown_t rue_shutdown;
|
|
|
|
static miibus_readreg_t rue_miibus_readreg;
|
|
|
|
static miibus_writereg_t rue_miibus_writereg;
|
|
|
|
static miibus_statchg_t rue_miibus_statchg;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int rue_encap(struct rue_softc *, struct mbuf *, int);
|
2003-05-03 10:16:56 +00:00
|
|
|
#ifdef RUE_INTR_PIPE
|
2006-09-06 23:44:25 +00:00
|
|
|
static void rue_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
|
2003-05-03 10:16:56 +00:00
|
|
|
#endif
|
2006-09-06 23:44:25 +00:00
|
|
|
static void rue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
|
|
|
|
static void rue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
|
|
|
|
static void rue_tick(void *);
|
|
|
|
static void rue_rxstart(struct ifnet *);
|
|
|
|
static void rue_start(struct ifnet *);
|
|
|
|
static int rue_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static void rue_init(void *);
|
|
|
|
static void rue_stop(struct rue_softc *);
|
|
|
|
static void rue_watchdog(struct ifnet *);
|
|
|
|
static int rue_ifmedia_upd(struct ifnet *);
|
|
|
|
static void rue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
|
|
|
|
|
|
|
|
static void rue_setmulti(struct rue_softc *);
|
|
|
|
static void rue_reset(struct rue_softc *);
|
|
|
|
|
|
|
|
static int rue_read_mem(struct rue_softc *, u_int16_t, void *, u_int16_t);
|
|
|
|
static int rue_write_mem(struct rue_softc *, u_int16_t, void *, u_int16_t);
|
|
|
|
static int rue_csr_read_1(struct rue_softc *, int);
|
|
|
|
static int rue_csr_write_1(struct rue_softc *, int, u_int8_t);
|
|
|
|
static int rue_csr_read_2(struct rue_softc *, int);
|
|
|
|
static int rue_csr_write_2(struct rue_softc *, int, u_int16_t);
|
|
|
|
static int rue_csr_write_4(struct rue_softc *, int, u_int32_t);
|
|
|
|
|
|
|
|
static device_method_t rue_methods[] = {
|
2003-05-03 10:16:56 +00:00
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, rue_match),
|
|
|
|
DEVMETHOD(device_attach, rue_attach),
|
|
|
|
DEVMETHOD(device_detach, rue_detach),
|
|
|
|
DEVMETHOD(device_shutdown, rue_shutdown),
|
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
|
|
|
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
|
|
|
|
|
|
|
/* MII interface */
|
|
|
|
DEVMETHOD(miibus_readreg, rue_miibus_readreg),
|
|
|
|
DEVMETHOD(miibus_writereg, rue_miibus_writereg),
|
|
|
|
DEVMETHOD(miibus_statchg, rue_miibus_statchg),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static driver_t rue_driver = {
|
2003-05-03 10:16:56 +00:00
|
|
|
"rue",
|
|
|
|
rue_methods,
|
|
|
|
sizeof(struct rue_softc)
|
|
|
|
};
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static devclass_t rue_devclass;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
DRIVER_MODULE(rue, uhub, rue_driver, rue_devclass, usbd_driver_load, 0);
|
|
|
|
DRIVER_MODULE(miibus, rue, miibus_driver, miibus_devclass, 0, 0);
|
|
|
|
MODULE_DEPEND(rue, usb, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(rue, ether, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(rue, miibus, 1, 1, 1);
|
|
|
|
|
|
|
|
#define RUE_SETBIT(sc, reg, x) \
|
|
|
|
rue_csr_write_1(sc, reg, rue_csr_read_1(sc, reg) | (x))
|
|
|
|
|
|
|
|
#define RUE_CLRBIT(sc, reg, x) \
|
|
|
|
rue_csr_write_1(sc, reg, rue_csr_read_1(sc, reg) & ~(x))
|
|
|
|
|
|
|
|
#define RUE_SETBIT_2(sc, reg, x) \
|
|
|
|
rue_csr_write_2(sc, reg, rue_csr_read_2(sc, reg) | (x))
|
|
|
|
|
|
|
|
#define RUE_CLRBIT_2(sc, reg, x) \
|
|
|
|
rue_csr_write_2(sc, reg, rue_csr_read_2(sc, reg) & ~(x))
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_read_mem(struct rue_softc *sc, u_int16_t addr, void *buf, u_int16_t len)
|
|
|
|
{
|
|
|
|
usb_device_request_t req;
|
|
|
|
usbd_status err;
|
|
|
|
|
|
|
|
if (sc->rue_dying)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
|
|
|
req.bmRequestType = UT_READ_VENDOR_DEVICE;
|
|
|
|
req.bRequest = UR_SET_ADDRESS;
|
|
|
|
USETW(req.wValue, addr);
|
|
|
|
USETW(req.wIndex, 0);
|
|
|
|
USETW(req.wLength, len);
|
|
|
|
|
|
|
|
err = usbd_do_request(sc->rue_udev, &req, buf);
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "control pipe read failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_write_mem(struct rue_softc *sc, u_int16_t addr, void *buf, u_int16_t len)
|
|
|
|
{
|
|
|
|
usb_device_request_t req;
|
|
|
|
usbd_status err;
|
|
|
|
|
|
|
|
if (sc->rue_dying)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
|
|
|
req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
|
|
|
|
req.bRequest = UR_SET_ADDRESS;
|
|
|
|
USETW(req.wValue, addr);
|
|
|
|
USETW(req.wIndex, 0);
|
|
|
|
USETW(req.wLength, len);
|
|
|
|
|
|
|
|
err = usbd_do_request(sc->rue_udev, &req, buf);
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "control pipe write failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_csr_read_1(struct rue_softc *sc, int reg)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
u_int8_t val = 0;
|
|
|
|
|
|
|
|
err = rue_read_mem(sc, reg, &val, 1);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (val);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_csr_read_2(struct rue_softc *sc, int reg)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
u_int16_t val = 0;
|
|
|
|
uWord w;
|
|
|
|
|
|
|
|
USETW(w, val);
|
|
|
|
err = rue_read_mem(sc, reg, &w, 2);
|
|
|
|
val = UGETW(w);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (val);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_csr_write_1(struct rue_softc *sc, int reg, u_int8_t val)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = rue_write_mem(sc, reg, &val, 1);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_csr_write_2(struct rue_softc *sc, int reg, u_int16_t val)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
uWord w;
|
|
|
|
|
|
|
|
USETW(w, val);
|
|
|
|
err = rue_write_mem(sc, reg, &w, 2);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_csr_write_4(struct rue_softc *sc, int reg, u_int32_t val)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
uDWord dw;
|
|
|
|
|
|
|
|
USETDW(dw, val);
|
|
|
|
err = rue_write_mem(sc, reg, &dw, 4);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
|
|
|
rue_miibus_readreg(device_t dev, int phy, int reg)
|
2003-05-03 10:16:56 +00:00
|
|
|
{
|
2007-06-17 18:46:26 +00:00
|
|
|
struct rue_softc *sc = device_get_softc(dev);
|
2003-05-03 10:16:56 +00:00
|
|
|
int rval;
|
|
|
|
int ruereg;
|
|
|
|
|
|
|
|
if (phy != 0) /* RTL8150 supports PHY == 0, only */
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
switch (reg) {
|
|
|
|
case MII_BMCR:
|
|
|
|
ruereg = RUE_BMCR;
|
|
|
|
break;
|
|
|
|
case MII_BMSR:
|
|
|
|
ruereg = RUE_BMSR;
|
|
|
|
break;
|
|
|
|
case MII_ANAR:
|
|
|
|
ruereg = RUE_ANAR;
|
|
|
|
break;
|
|
|
|
case MII_ANER:
|
|
|
|
ruereg = RUE_AER;
|
|
|
|
break;
|
|
|
|
case MII_ANLPAR:
|
|
|
|
ruereg = RUE_ANLP;
|
|
|
|
break;
|
|
|
|
case MII_PHYIDR1:
|
|
|
|
case MII_PHYIDR2:
|
|
|
|
return (0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (RUE_REG_MIN <= reg && reg <= RUE_REG_MAX) {
|
|
|
|
rval = rue_csr_read_1(sc, reg);
|
|
|
|
return (rval);
|
|
|
|
}
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "bad phy register\n");
|
2003-05-03 10:16:56 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
rval = rue_csr_read_2(sc, ruereg);
|
|
|
|
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
|
|
|
rue_miibus_writereg(device_t dev, int phy, int reg, int data)
|
2003-05-03 10:16:56 +00:00
|
|
|
{
|
2007-06-17 18:46:26 +00:00
|
|
|
struct rue_softc *sc = device_get_softc(dev);
|
2003-05-03 10:16:56 +00:00
|
|
|
int ruereg;
|
|
|
|
|
|
|
|
if (phy != 0) /* RTL8150 supports PHY == 0, only */
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
switch (reg) {
|
|
|
|
case MII_BMCR:
|
|
|
|
ruereg = RUE_BMCR;
|
|
|
|
break;
|
|
|
|
case MII_BMSR:
|
|
|
|
ruereg = RUE_BMSR;
|
|
|
|
break;
|
|
|
|
case MII_ANAR:
|
|
|
|
ruereg = RUE_ANAR;
|
|
|
|
break;
|
|
|
|
case MII_ANER:
|
|
|
|
ruereg = RUE_AER;
|
|
|
|
break;
|
|
|
|
case MII_ANLPAR:
|
|
|
|
ruereg = RUE_ANLP;
|
|
|
|
break;
|
|
|
|
case MII_PHYIDR1:
|
|
|
|
case MII_PHYIDR2:
|
|
|
|
return (0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (RUE_REG_MIN <= reg && reg <= RUE_REG_MAX) {
|
|
|
|
rue_csr_write_1(sc, reg, data);
|
|
|
|
return (0);
|
|
|
|
}
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "bad phy register\n");
|
2003-05-03 10:16:56 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
rue_csr_write_2(sc, ruereg, data);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
|
|
|
rue_miibus_statchg(device_t dev)
|
2003-05-03 10:16:56 +00:00
|
|
|
{
|
2005-03-25 20:19:18 +00:00
|
|
|
/*
|
|
|
|
* When the code below is enabled the card starts doing weird
|
|
|
|
* things after link going from UP to DOWN and back UP.
|
|
|
|
*
|
|
|
|
* Looks like some of register writes below messes up PHY
|
|
|
|
* interface.
|
|
|
|
*
|
|
|
|
* No visible regressions were found after commenting this code
|
|
|
|
* out, so that disable it for good.
|
|
|
|
*/
|
|
|
|
#if 0
|
2007-06-17 18:46:26 +00:00
|
|
|
struct rue_softc *sc = device_get_softc(dev);
|
2003-05-03 10:16:56 +00:00
|
|
|
struct mii_data *mii = GET_MII(sc);
|
|
|
|
int bmcr;
|
|
|
|
|
|
|
|
RUE_CLRBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
|
|
|
|
|
|
|
|
bmcr = rue_csr_read_2(sc, RUE_BMCR);
|
|
|
|
|
|
|
|
if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX)
|
|
|
|
bmcr |= RUE_BMCR_SPD_SET;
|
|
|
|
else
|
|
|
|
bmcr &= ~RUE_BMCR_SPD_SET;
|
|
|
|
|
|
|
|
if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
|
|
|
|
bmcr |= RUE_BMCR_DUPLEX;
|
|
|
|
else
|
|
|
|
bmcr &= ~RUE_BMCR_DUPLEX;
|
|
|
|
|
|
|
|
rue_csr_write_2(sc, RUE_BMCR, bmcr);
|
|
|
|
|
|
|
|
RUE_SETBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
|
2005-03-25 20:19:18 +00:00
|
|
|
#endif
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Program the 64-bit multicast hash filter.
|
|
|
|
*/
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_setmulti(struct rue_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int h = 0;
|
|
|
|
u_int32_t hashes[2] = { 0, 0 };
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
u_int32_t rxcfg;
|
|
|
|
int mcnt = 0;
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rue_ifp;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
rxcfg = rue_csr_read_2(sc, RUE_RCR);
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
|
|
|
|
rxcfg |= (RUE_RCR_AAM | RUE_RCR_AAP);
|
|
|
|
rxcfg &= ~RUE_RCR_AM;
|
|
|
|
rue_csr_write_2(sc, RUE_RCR, rxcfg);
|
|
|
|
rue_csr_write_4(sc, RUE_MAR0, 0xFFFFFFFF);
|
|
|
|
rue_csr_write_4(sc, RUE_MAR4, 0xFFFFFFFF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first, zot all the existing hash bits */
|
|
|
|
rue_csr_write_4(sc, RUE_MAR0, 0);
|
|
|
|
rue_csr_write_4(sc, RUE_MAR4, 0);
|
|
|
|
|
|
|
|
/* now program new ones */
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_LOCK(ifp);
|
2003-10-04 21:41:01 +00:00
|
|
|
TAILQ_FOREACH (ifma, &ifp->if_multiaddrs, ifma_link)
|
|
|
|
{
|
2003-05-03 10:16:56 +00:00
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
2004-06-09 14:34:04 +00:00
|
|
|
h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
|
|
|
|
ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
|
2003-05-03 10:16:56 +00:00
|
|
|
if (h < 32)
|
|
|
|
hashes[0] |= (1 << h);
|
|
|
|
else
|
|
|
|
hashes[1] |= (1 << (h - 32));
|
|
|
|
mcnt++;
|
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_UNLOCK(ifp);
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
if (mcnt)
|
|
|
|
rxcfg |= RUE_RCR_AM;
|
|
|
|
else
|
|
|
|
rxcfg &= ~RUE_RCR_AM;
|
|
|
|
|
|
|
|
rxcfg &= ~(RUE_RCR_AAM | RUE_RCR_AAP);
|
|
|
|
|
|
|
|
rue_csr_write_2(sc, RUE_RCR, rxcfg);
|
|
|
|
rue_csr_write_4(sc, RUE_MAR0, hashes[0]);
|
|
|
|
rue_csr_write_4(sc, RUE_MAR4, hashes[1]);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_reset(struct rue_softc *sc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rue_csr_write_1(sc, RUE_CR, RUE_CR_SOFT_RST);
|
|
|
|
|
|
|
|
for (i = 0; i < RUE_TIMEOUT; i++) {
|
|
|
|
DELAY(500);
|
|
|
|
if (!(rue_csr_read_1(sc, RUE_CR) & RUE_CR_SOFT_RST))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == RUE_TIMEOUT)
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "reset never completed!\n");
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
DELAY(10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe for a RTL8150 chip.
|
|
|
|
*/
|
|
|
|
|
2007-06-13 05:37:59 +00:00
|
|
|
static int
|
|
|
|
rue_match(device_t self)
|
2003-05-03 10:16:56 +00:00
|
|
|
{
|
2007-06-17 16:24:49 +00:00
|
|
|
struct usb_attach_arg *uaa = device_get_ivars(self);
|
2003-05-03 10:16:56 +00:00
|
|
|
struct rue_type *t;
|
|
|
|
|
|
|
|
if (uaa->iface == NULL)
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
|
|
|
|
t = rue_devs;
|
|
|
|
while (t->rue_vid) {
|
|
|
|
if (uaa->vendor == t->rue_vid &&
|
|
|
|
uaa->product == t->rue_did) {
|
|
|
|
return (UMATCH_VENDOR_PRODUCT);
|
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the interface. Allocate softc structures, do ifmedia
|
|
|
|
* setup and ethernet/BPF attach.
|
|
|
|
*/
|
|
|
|
|
2007-06-13 05:37:59 +00:00
|
|
|
static int
|
|
|
|
rue_attach(device_t self)
|
2003-05-03 10:16:56 +00:00
|
|
|
{
|
2007-06-17 18:46:26 +00:00
|
|
|
struct rue_softc *sc = device_get_softc(self);
|
|
|
|
struct usb_attach_arg *uaa = device_get_ivars(self);
|
2003-05-03 10:16:56 +00:00
|
|
|
u_char eaddr[ETHER_ADDR_LEN];
|
|
|
|
struct ifnet *ifp;
|
|
|
|
usbd_interface_handle iface;
|
|
|
|
usbd_status err;
|
|
|
|
usb_interface_descriptor_t *id;
|
|
|
|
usb_endpoint_descriptor_t *ed;
|
|
|
|
int i;
|
|
|
|
struct rue_type *t;
|
|
|
|
|
2005-03-25 00:44:21 +00:00
|
|
|
sc->rue_dev = self;
|
2003-05-03 10:16:56 +00:00
|
|
|
sc->rue_udev = uaa->device;
|
|
|
|
|
|
|
|
if (usbd_set_config_no(sc->rue_udev, RUE_CONFIG_NO, 0)) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "getting interface handle failed\n");
|
2003-05-03 10:16:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = usbd_device2interface_handle(uaa->device, RUE_IFACE_IDX, &iface);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "getting interface handle failed\n");
|
2003-05-03 10:16:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->rue_iface = iface;
|
|
|
|
|
|
|
|
t = rue_devs;
|
|
|
|
while (t->rue_vid) {
|
|
|
|
if (uaa->vendor == t->rue_vid &&
|
|
|
|
uaa->product == t->rue_did) {
|
|
|
|
sc->rue_info = t;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
|
|
|
|
id = usbd_get_interface_descriptor(sc->rue_iface);
|
|
|
|
|
|
|
|
/* Find endpoints */
|
|
|
|
for (i = 0; i < id->bNumEndpoints; i++) {
|
|
|
|
ed = usbd_interface2endpoint_descriptor(iface, i);
|
|
|
|
if (ed == NULL) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "couldn't get ep %d\n", i);
|
2003-05-03 10:16:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
|
|
|
|
UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
|
|
|
|
sc->rue_ed[RUE_ENDPT_RX] = ed->bEndpointAddress;
|
|
|
|
} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
|
|
|
|
UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
|
|
|
|
sc->rue_ed[RUE_ENDPT_TX] = ed->bEndpointAddress;
|
|
|
|
} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
|
|
|
|
UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
|
|
|
|
sc->rue_ed[RUE_ENDPT_INTR] = ed->bEndpointAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mtx_init(&sc->rue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
|
|
|
|
MTX_DEF | MTX_RECURSE);
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
|
|
|
/* Reset the adapter */
|
|
|
|
rue_reset(sc);
|
|
|
|
|
|
|
|
/* Get station address from the EEPROM */
|
|
|
|
err = rue_read_mem(sc, RUE_EEPROM_IDR0,
|
|
|
|
(caddr_t)&eaddr, ETHER_ADDR_LEN);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "couldn't get station address\n");
|
2003-05-03 10:16:56 +00:00
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rue_ifp = if_alloc(IFT_ETHER);
|
|
|
|
if (ifp == NULL) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "can not if_alloc()\n");
|
2005-06-10 16:49:24 +00:00
|
|
|
goto error1;
|
|
|
|
}
|
2003-05-03 10:16:56 +00:00
|
|
|
ifp->if_softc = sc;
|
2007-06-11 06:01:05 +00:00
|
|
|
if_initname(ifp, "rue", device_get_unit(sc->rue_dev));
|
2003-05-03 10:16:56 +00:00
|
|
|
ifp->if_mtu = ETHERMTU;
|
2004-08-11 03:38:55 +00:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
|
|
|
|
IFF_NEEDSGIANT;
|
2003-05-03 10:16:56 +00:00
|
|
|
ifp->if_ioctl = rue_ioctl;
|
|
|
|
ifp->if_start = rue_start;
|
|
|
|
ifp->if_watchdog = rue_watchdog;
|
|
|
|
ifp->if_init = rue_init;
|
|
|
|
ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
|
|
|
|
/* MII setup */
|
|
|
|
if (mii_phy_probe(self, &sc->rue_miibus,
|
|
|
|
rue_ifmedia_upd, rue_ifmedia_sts)) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "MII without any PHY!\n");
|
2005-06-10 16:49:24 +00:00
|
|
|
goto error2;
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 12:35:25 +00:00
|
|
|
sc->rue_qdat.ifp = ifp;
|
|
|
|
sc->rue_qdat.if_rxstart = rue_rxstart;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
/* Call MI attach routine */
|
|
|
|
ether_ifattach(ifp, eaddr);
|
|
|
|
callout_handle_init(&sc->rue_stat_ch);
|
|
|
|
usb_register_netisr();
|
|
|
|
sc->rue_dying = 0;
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
2007-06-12 15:37:19 +00:00
|
|
|
return 0;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
error2:
|
|
|
|
if_free(ifp);
|
2003-05-03 10:16:56 +00:00
|
|
|
error1:
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
mtx_destroy(&sc->rue_mtx);
|
|
|
|
error:
|
2007-06-12 15:37:19 +00:00
|
|
|
return ENXIO;
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
|
|
|
rue_detach(device_t dev)
|
2003-05-03 10:16:56 +00:00
|
|
|
{
|
|
|
|
struct rue_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
RUE_LOCK(sc);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rue_ifp;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
sc->rue_dying = 1;
|
|
|
|
untimeout(rue_tick, sc, sc->rue_stat_ch);
|
|
|
|
ether_ifdetach(ifp);
|
2005-09-16 09:16:46 +00:00
|
|
|
if_free(ifp);
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
if (sc->rue_ep[RUE_ENDPT_TX] != NULL)
|
|
|
|
usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_TX]);
|
|
|
|
if (sc->rue_ep[RUE_ENDPT_RX] != NULL)
|
|
|
|
usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_RX]);
|
|
|
|
#ifdef RUE_INTR_PIPE
|
|
|
|
if (sc->rue_ep[RUE_ENDPT_INTR] != NULL)
|
|
|
|
usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_INTR]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
mtx_destroy(&sc->rue_mtx);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RUE_INTR_PIPE
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
|
|
|
|
{
|
|
|
|
struct rue_softc *sc = priv;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct rue_intrpkt *p;
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rue_ifp;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
|
|
|
if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "usb error on intr: %s\n",
|
|
|
|
usbd_errstr(status));
|
2003-05-03 10:16:56 +00:00
|
|
|
if (status == USBD_STALLED)
|
|
|
|
usbd_clear_endpoint_stall(sc->rue_ep[RUE_ENDPT_INTR]);
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
usbd_get_xfer_status(xfer, NULL, (void **)&p, NULL, NULL);
|
|
|
|
|
|
|
|
ifp->if_ierrors += p->rue_rxlost_cnt;
|
|
|
|
ifp->if_ierrors += p->rue_crcerr_cnt;
|
|
|
|
ifp->if_collisions += p->rue_col_cnt;
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_rxstart(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct rue_softc *sc;
|
2005-03-25 12:42:30 +00:00
|
|
|
struct ue_chain *c;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
RUE_LOCK(sc);
|
2005-03-25 12:42:30 +00:00
|
|
|
c = &sc->rue_cdata.ue_rx_chain[sc->rue_cdata.ue_rx_prod];
|
2003-05-03 10:16:56 +00:00
|
|
|
|
2005-03-25 12:42:30 +00:00
|
|
|
c->ue_mbuf = usb_ether_newbuf();
|
|
|
|
if (c->ue_mbuf == NULL) {
|
|
|
|
printf("%s: no memory for rx list "
|
2006-09-07 00:06:42 +00:00
|
|
|
"-- packet dropped!\n", device_get_nameunit(sc->rue_dev));
|
2003-05-03 10:16:56 +00:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup new transfer. */
|
2005-03-25 12:42:30 +00:00
|
|
|
usbd_setup_xfer(c->ue_xfer, sc->rue_ep[RUE_ENDPT_RX],
|
|
|
|
c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK,
|
2003-05-03 10:16:56 +00:00
|
|
|
USBD_NO_TIMEOUT, rue_rxeof);
|
2005-03-25 12:42:30 +00:00
|
|
|
usbd_transfer(c->ue_xfer);
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A frame has been uploaded: pass the resulting mbuf chain up to
|
|
|
|
* the higher level protocols.
|
|
|
|
*/
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
|
|
|
|
{
|
2005-03-25 12:42:30 +00:00
|
|
|
struct ue_chain *c = priv;
|
|
|
|
struct rue_softc *sc = c->ue_sc;
|
2003-05-03 10:16:56 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int total_len = 0;
|
|
|
|
struct rue_rxpkt r;
|
|
|
|
|
|
|
|
if (sc->rue_dying)
|
|
|
|
return;
|
|
|
|
RUE_LOCK(sc);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rue_ifp;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
|
|
|
if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (usbd_ratecheck(&sc->rue_rx_notice))
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "usb error on rx: %s\n",
|
|
|
|
usbd_errstr(status));
|
2003-05-03 10:16:56 +00:00
|
|
|
if (status == USBD_STALLED)
|
|
|
|
usbd_clear_endpoint_stall(sc->rue_ep[RUE_ENDPT_RX]);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
|
|
|
|
|
|
|
|
if (total_len <= ETHER_CRC_LEN) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2005-03-25 12:42:30 +00:00
|
|
|
m = c->ue_mbuf;
|
2003-05-03 10:16:56 +00:00
|
|
|
bcopy(mtod(m, char *) + total_len - 4, (char *)&r, sizeof (r));
|
|
|
|
|
|
|
|
/* Check recieve packet was valid or not */
|
|
|
|
if ((r.rue_rxstat & RUE_RXSTAT_VALID) == 0) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No errors; receive the packet. */
|
|
|
|
total_len -= ETHER_CRC_LEN;
|
|
|
|
|
|
|
|
ifp->if_ipackets++;
|
2005-06-10 16:49:24 +00:00
|
|
|
m->m_pkthdr.rcvif = (void *)&sc->rue_qdat;
|
2003-05-03 10:16:56 +00:00
|
|
|
m->m_pkthdr.len = m->m_len = total_len;
|
|
|
|
|
|
|
|
/* Put the packet on the special USB input queue. */
|
|
|
|
usb_ether_input(m);
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
|
|
|
|
done:
|
|
|
|
/* Setup new transfer. */
|
|
|
|
usbd_setup_xfer(xfer, sc->rue_ep[RUE_ENDPT_RX],
|
2005-03-25 12:42:30 +00:00
|
|
|
c, mtod(c->ue_mbuf, char *), UE_BUFSZ,
|
2003-05-03 10:16:56 +00:00
|
|
|
USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, rue_rxeof);
|
|
|
|
usbd_transfer(xfer);
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A frame was downloaded to the chip. It's safe for us to clean up
|
|
|
|
* the list buffers.
|
|
|
|
*/
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
|
|
|
|
{
|
2005-03-25 12:42:30 +00:00
|
|
|
struct ue_chain *c = priv;
|
|
|
|
struct rue_softc *sc = c->ue_sc;
|
2003-05-03 10:16:56 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
usbd_status err;
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rue_ifp;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
|
|
|
if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "usb error on tx: %s\n",
|
|
|
|
usbd_errstr(status));
|
2003-05-03 10:16:56 +00:00
|
|
|
if (status == USBD_STALLED)
|
|
|
|
usbd_clear_endpoint_stall(sc->rue_ep[RUE_ENDPT_TX]);
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_timer = 0;
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2005-03-25 12:42:30 +00:00
|
|
|
usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &err);
|
2003-05-03 10:16:56 +00:00
|
|
|
|
2005-03-25 12:42:30 +00:00
|
|
|
if (c->ue_mbuf != NULL) {
|
|
|
|
c->ue_mbuf->m_pkthdr.rcvif = ifp;
|
|
|
|
usb_tx_done(c->ue_mbuf);
|
|
|
|
c->ue_mbuf = NULL;
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
else
|
|
|
|
ifp->if_opackets++;
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_tick(void *xsc)
|
|
|
|
{
|
|
|
|
struct rue_softc *sc = xsc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct mii_data *mii;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rue_ifp;
|
2003-05-03 10:16:56 +00:00
|
|
|
mii = GET_MII(sc);
|
|
|
|
if (mii == NULL) {
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mii_tick(mii);
|
|
|
|
if (!sc->rue_link && mii->mii_media_status & IFM_ACTIVE &&
|
|
|
|
IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
|
|
|
|
sc->rue_link++;
|
|
|
|
if (ifp->if_snd.ifq_head != NULL)
|
|
|
|
rue_start(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->rue_stat_ch = timeout(rue_tick, sc, hz);
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_encap(struct rue_softc *sc, struct mbuf *m, int idx)
|
|
|
|
{
|
|
|
|
int total_len;
|
2005-03-25 12:42:30 +00:00
|
|
|
struct ue_chain *c;
|
2003-05-03 10:16:56 +00:00
|
|
|
usbd_status err;
|
|
|
|
|
2005-03-25 12:42:30 +00:00
|
|
|
c = &sc->rue_cdata.ue_tx_chain[idx];
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the mbuf data into a contiguous buffer
|
|
|
|
*/
|
2005-03-25 12:42:30 +00:00
|
|
|
m_copydata(m, 0, m->m_pkthdr.len, c->ue_buf);
|
|
|
|
c->ue_mbuf = m;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
total_len = m->m_pkthdr.len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is an undocumented behavior.
|
|
|
|
* RTL8150 chip doesn't send frame length smaller than
|
|
|
|
* RUE_MIN_FRAMELEN (60) byte packet.
|
|
|
|
*/
|
|
|
|
if (total_len < RUE_MIN_FRAMELEN)
|
|
|
|
total_len = RUE_MIN_FRAMELEN;
|
|
|
|
|
2005-03-25 12:42:30 +00:00
|
|
|
usbd_setup_xfer(c->ue_xfer, sc->rue_ep[RUE_ENDPT_TX],
|
|
|
|
c, c->ue_buf, total_len, USBD_FORCE_SHORT_XFER,
|
2003-05-03 10:16:56 +00:00
|
|
|
10000, rue_txeof);
|
|
|
|
|
|
|
|
/* Transmit */
|
2005-03-25 12:42:30 +00:00
|
|
|
err = usbd_transfer(c->ue_xfer);
|
2003-05-03 10:16:56 +00:00
|
|
|
if (err != USBD_IN_PROGRESS) {
|
|
|
|
rue_stop(sc);
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
|
2005-03-25 12:42:30 +00:00
|
|
|
sc->rue_cdata.ue_tx_cnt++;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct rue_softc *sc = ifp->if_softc;
|
|
|
|
struct mbuf *m_head = NULL;
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
|
|
|
if (!sc->rue_link) {
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m_head);
|
|
|
|
if (m_head == NULL) {
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rue_encap(sc, m_head, 0)) {
|
|
|
|
IF_PREPEND(&ifp->if_snd, m_head);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there's a BPF listener, bounce a copy of this frame
|
|
|
|
* to him.
|
|
|
|
*/
|
|
|
|
BPF_MTAP(ifp, m_head);
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a timeout in case the chip goes out to lunch.
|
|
|
|
*/
|
|
|
|
ifp->if_timer = 5;
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_init(void *xsc)
|
|
|
|
{
|
|
|
|
struct rue_softc *sc = xsc;
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->rue_ifp;
|
2003-05-03 10:16:56 +00:00
|
|
|
struct mii_data *mii = GET_MII(sc);
|
2005-03-25 12:42:30 +00:00
|
|
|
struct ue_chain *c;
|
2003-05-03 10:16:56 +00:00
|
|
|
usbd_status err;
|
|
|
|
int i;
|
|
|
|
int rxcfg;
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel pending I/O and free all RX/TX buffers.
|
|
|
|
*/
|
|
|
|
rue_reset(sc);
|
|
|
|
|
|
|
|
/* Set MAC address */
|
2005-11-11 16:04:59 +00:00
|
|
|
rue_write_mem(sc, RUE_IDR0, IF_LLADDR(sc->rue_ifp),
|
2005-06-10 16:49:24 +00:00
|
|
|
ETHER_ADDR_LEN);
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
/* Init TX ring. */
|
2005-03-25 12:42:30 +00:00
|
|
|
if (usb_ether_tx_list_init(sc, &sc->rue_cdata,
|
2005-03-25 12:50:57 +00:00
|
|
|
sc->rue_udev) == ENOBUFS) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "tx list init failed\n");
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init RX ring. */
|
2005-03-25 12:42:30 +00:00
|
|
|
if (usb_ether_rx_list_init(sc, &sc->rue_cdata,
|
2005-03-25 12:50:57 +00:00
|
|
|
sc->rue_udev) == ENOBUFS) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "rx list init failed\n");
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RUE_INTR_PIPE
|
2005-03-25 12:42:30 +00:00
|
|
|
sc->rue_cdata.ue_ibuf = malloc(RUE_INTR_PKTLEN, M_USBDEV, M_NOWAIT);
|
2003-05-03 10:16:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the initial TX and RX configuration.
|
|
|
|
*/
|
|
|
|
rue_csr_write_1(sc, RUE_TCR, RUE_TCR_CONFIG);
|
|
|
|
|
|
|
|
rxcfg = RUE_RCR_CONFIG;
|
|
|
|
|
|
|
|
/* Set capture broadcast bit to capture broadcast frames. */
|
|
|
|
if (ifp->if_flags & IFF_BROADCAST)
|
|
|
|
rxcfg |= RUE_RCR_AB;
|
|
|
|
else
|
|
|
|
rxcfg &= ~RUE_RCR_AB;
|
|
|
|
|
|
|
|
/* If we want promiscuous mode, set the allframes bit. */
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
rxcfg |= RUE_RCR_AAP;
|
|
|
|
else
|
|
|
|
rxcfg &= ~RUE_RCR_AAP;
|
|
|
|
|
|
|
|
rue_csr_write_2(sc, RUE_RCR, rxcfg);
|
|
|
|
|
|
|
|
/* Load the multicast filter. */
|
|
|
|
rue_setmulti(sc);
|
|
|
|
|
|
|
|
/* Enable RX and TX */
|
|
|
|
rue_csr_write_1(sc, RUE_CR, (RUE_CR_TE | RUE_CR_RE | RUE_CR_EP3CLREN));
|
|
|
|
|
|
|
|
mii_mediachg(mii);
|
|
|
|
|
|
|
|
/* Open RX and TX pipes. */
|
|
|
|
err = usbd_open_pipe(sc->rue_iface, sc->rue_ed[RUE_ENDPT_RX],
|
|
|
|
USBD_EXCLUSIVE_USE, &sc->rue_ep[RUE_ENDPT_RX]);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "open rx pipe failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
err = usbd_open_pipe(sc->rue_iface, sc->rue_ed[RUE_ENDPT_TX],
|
|
|
|
USBD_EXCLUSIVE_USE, &sc->rue_ep[RUE_ENDPT_TX]);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "open tx pipe failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RUE_INTR_PIPE
|
|
|
|
err = usbd_open_pipe_intr(sc->rue_iface, sc->rue_ed[RUE_ENDPT_INTR],
|
|
|
|
USBD_SHORT_XFER_OK,
|
|
|
|
&sc->rue_ep[RUE_ENDPT_INTR], sc,
|
2005-03-25 12:42:30 +00:00
|
|
|
sc->rue_cdata.ue_ibuf, RUE_INTR_PKTLEN,
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_intr, RUE_INTR_INTERVAL);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "open intr pipe failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Start up the receive pipe. */
|
2005-03-25 12:42:30 +00:00
|
|
|
for (i = 0; i < UE_RX_LIST_CNT; i++) {
|
|
|
|
c = &sc->rue_cdata.ue_rx_chain[i];
|
|
|
|
usbd_setup_xfer(c->ue_xfer, sc->rue_ep[RUE_ENDPT_RX],
|
|
|
|
c, mtod(c->ue_mbuf, char *), UE_BUFSZ,
|
2003-05-03 10:16:56 +00:00
|
|
|
USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, rue_rxeof);
|
2005-03-25 12:42:30 +00:00
|
|
|
usbd_transfer(c->ue_xfer);
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
sc->rue_stat_ch = timeout(rue_tick, sc, hz);
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set media options.
|
|
|
|
*/
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_ifmedia_upd(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct rue_softc *sc = ifp->if_softc;
|
|
|
|
struct mii_data *mii = GET_MII(sc);
|
|
|
|
|
|
|
|
sc->rue_link = 0;
|
|
|
|
if (mii->mii_instance) {
|
|
|
|
struct mii_softc *miisc;
|
|
|
|
LIST_FOREACH (miisc, &mii->mii_phys, mii_list)
|
|
|
|
mii_phy_reset(miisc);
|
|
|
|
}
|
|
|
|
mii_mediachg(mii);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report current media status.
|
|
|
|
*/
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
|
|
|
|
{
|
|
|
|
struct rue_softc *sc = ifp->if_softc;
|
|
|
|
struct mii_data *mii = GET_MII(sc);
|
|
|
|
|
|
|
|
mii_pollstat(mii);
|
|
|
|
ifmr->ifm_active = mii->mii_media_active;
|
|
|
|
ifmr->ifm_status = mii->mii_media_status;
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static int
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
|
|
|
{
|
|
|
|
struct rue_softc *sc = ifp->if_softc;
|
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
struct mii_data *mii;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
|
2003-05-03 10:16:56 +00:00
|
|
|
ifp->if_flags & IFF_PROMISC &&
|
|
|
|
!(sc->rue_if_flags & IFF_PROMISC)) {
|
|
|
|
RUE_SETBIT_2(sc, RUE_RCR,
|
|
|
|
(RUE_RCR_AAM | RUE_RCR_AAP));
|
|
|
|
rue_setmulti(sc);
|
2005-08-09 10:20:02 +00:00
|
|
|
} else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
|
2003-05-03 10:16:56 +00:00
|
|
|
!(ifp->if_flags & IFF_PROMISC) &&
|
|
|
|
sc->rue_if_flags & IFF_PROMISC) {
|
|
|
|
RUE_CLRBIT_2(sc, RUE_RCR,
|
|
|
|
(RUE_RCR_AAM | RUE_RCR_AAP));
|
|
|
|
rue_setmulti(sc);
|
2005-08-09 10:20:02 +00:00
|
|
|
} else if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_init(sc);
|
|
|
|
} else {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_stop(sc);
|
|
|
|
}
|
|
|
|
sc->rue_if_flags = ifp->if_flags;
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
rue_setmulti(sc);
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
mii = GET_MII(sc);
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = ether_ioctl(ifp, command, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_watchdog(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct rue_softc *sc = ifp->if_softc;
|
2005-03-25 12:42:30 +00:00
|
|
|
struct ue_chain *c;
|
2003-05-03 10:16:56 +00:00
|
|
|
usbd_status stat;
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
|
|
|
ifp->if_oerrors++;
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "watchdog timeout\n");
|
2003-05-03 10:16:56 +00:00
|
|
|
|
2005-03-25 12:42:30 +00:00
|
|
|
c = &sc->rue_cdata.ue_tx_chain[0];
|
|
|
|
usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
|
|
|
|
rue_txeof(c->ue_xfer, c, stat);
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
if (ifp->if_snd.ifq_head != NULL)
|
|
|
|
rue_start(ifp);
|
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the adapter and free any mbufs allocated to the
|
|
|
|
* RX and TX lists.
|
|
|
|
*/
|
|
|
|
|
2006-09-06 23:44:25 +00:00
|
|
|
static void
|
2003-05-03 10:16:56 +00:00
|
|
|
rue_stop(struct rue_softc *sc)
|
|
|
|
{
|
|
|
|
usbd_status err;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rue_ifp;
|
2003-05-03 10:16:56 +00:00
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
|
|
|
rue_csr_write_1(sc, RUE_CR, 0x00);
|
|
|
|
rue_reset(sc);
|
|
|
|
|
|
|
|
untimeout(rue_tick, sc, sc->rue_stat_ch);
|
|
|
|
|
|
|
|
/* Stop transfers. */
|
|
|
|
if (sc->rue_ep[RUE_ENDPT_RX] != NULL) {
|
|
|
|
err = usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_RX]);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "abort rx pipe failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
err = usbd_close_pipe(sc->rue_ep[RUE_ENDPT_RX]);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "close rx pipe failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
sc->rue_ep[RUE_ENDPT_RX] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->rue_ep[RUE_ENDPT_TX] != NULL) {
|
|
|
|
err = usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_TX]);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "abort tx pipe failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
err = usbd_close_pipe(sc->rue_ep[RUE_ENDPT_TX]);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "close tx pipe failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
sc->rue_ep[RUE_ENDPT_TX] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RUE_INTR_PIPE
|
|
|
|
if (sc->rue_ep[RUE_ENDPT_INTR] != NULL) {
|
|
|
|
err = usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_INTR]);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "abort intr pipe failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
err = usbd_close_pipe(sc->rue_ep[RUE_ENDPT_INTR]);
|
|
|
|
if (err) {
|
2007-06-11 06:01:05 +00:00
|
|
|
device_printf(sc->rue_dev, "close intr pipe failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|
|
|
|
sc->rue_ep[RUE_ENDPT_INTR] = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Free RX resources. */
|
2005-03-25 12:42:30 +00:00
|
|
|
usb_ether_rx_list_free(&sc->rue_cdata);
|
2003-05-03 10:16:56 +00:00
|
|
|
/* Free TX resources. */
|
2005-03-25 12:42:30 +00:00
|
|
|
usb_ether_tx_list_free(&sc->rue_cdata);
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
#ifdef RUE_INTR_PIPE
|
2005-03-25 12:42:30 +00:00
|
|
|
free(sc->rue_cdata.ue_ibuf, M_USBDEV);
|
|
|
|
sc->rue_cdata.ue_ibuf = NULL;
|
2003-05-03 10:16:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sc->rue_link = 0;
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
|
2003-05-03 10:16:56 +00:00
|
|
|
|
|
|
|
RUE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop all chip I/O so that the kernel's probe routines don't
|
|
|
|
* get confused by errant DMAs when rebooting.
|
|
|
|
*/
|
|
|
|
|
2007-06-18 22:25:46 +00:00
|
|
|
static int
|
2006-09-06 23:44:25 +00:00
|
|
|
rue_shutdown(device_t dev)
|
2003-05-03 10:16:56 +00:00
|
|
|
{
|
|
|
|
struct rue_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
sc->rue_dying++;
|
|
|
|
RUE_LOCK(sc);
|
|
|
|
rue_reset(sc);
|
|
|
|
rue_stop(sc);
|
|
|
|
RUE_UNLOCK(sc);
|
2007-06-18 22:25:46 +00:00
|
|
|
|
|
|
|
return (0);
|
2003-05-03 10:16:56 +00:00
|
|
|
}
|