Home | History | Annotate | Line # | Download | only in usb
if_cue.c revision 1.48.10.4
      1  1.48.10.4     itohy /*	$NetBSD: if_cue.c,v 1.48.10.4 2007/06/18 13:41:26 itohy Exp $	*/
      2        1.1  augustss /*
      3        1.1  augustss  * Copyright (c) 1997, 1998, 1999, 2000
      4        1.1  augustss  *	Bill Paul <wpaul (at) ee.columbia.edu>.  All rights reserved.
      5        1.1  augustss  *
      6        1.1  augustss  * Redistribution and use in source and binary forms, with or without
      7        1.1  augustss  * modification, are permitted provided that the following conditions
      8        1.1  augustss  * are met:
      9        1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     10        1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     11        1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     13        1.1  augustss  *    documentation and/or other materials provided with the distribution.
     14        1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     15        1.1  augustss  *    must display the following acknowledgement:
     16        1.1  augustss  *	This product includes software developed by Bill Paul.
     17        1.1  augustss  * 4. Neither the name of the author nor the names of any co-contributors
     18        1.1  augustss  *    may be used to endorse or promote products derived from this software
     19        1.1  augustss  *    without specific prior written permission.
     20        1.1  augustss  *
     21        1.1  augustss  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
     22        1.1  augustss  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23        1.1  augustss  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24        1.1  augustss  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
     25        1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26        1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27        1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28        1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29        1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30        1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31        1.1  augustss  * THE POSSIBILITY OF SUCH DAMAGE.
     32        1.1  augustss  *
     33        1.1  augustss  * $FreeBSD: src/sys/dev/usb/if_cue.c,v 1.4 2000/01/16 22:45:06 wpaul Exp $
     34        1.1  augustss  */
     35        1.1  augustss 
     36        1.1  augustss /*
     37       1.15  augustss  * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate
     38        1.1  augustss  * adapters and others.
     39        1.1  augustss  *
     40        1.1  augustss  * Written by Bill Paul <wpaul (at) ee.columbia.edu>
     41        1.1  augustss  * Electrical Engineering Department
     42        1.1  augustss  * Columbia University, New York City
     43        1.1  augustss  */
     44        1.1  augustss 
     45        1.1  augustss /*
     46       1.15  augustss  * The CATC USB-EL1210A provides USB ethernet support at 10Mbps. The
     47        1.1  augustss  * RX filter uses a 512-bit multicast hash table, single perfect entry
     48        1.1  augustss  * for the station address, and promiscuous mode. Unlike the ADMtek
     49        1.1  augustss  * and KLSI chips, the CATC ASIC supports read and write combining
     50        1.1  augustss  * mode where multiple packets can be transfered using a single bulk
     51        1.1  augustss  * transaction, which helps performance a great deal.
     52        1.1  augustss  */
     53        1.1  augustss 
     54        1.1  augustss /*
     55        1.1  augustss  * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
     56        1.1  augustss  */
     57       1.36     lukem 
     58       1.36     lukem #include <sys/cdefs.h>
     59  1.48.10.4     itohy __KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.48.10.4 2007/06/18 13:41:26 itohy Exp $");
     60        1.1  augustss 
     61       1.18  augustss #if defined(__NetBSD__)
     62        1.1  augustss #include "opt_inet.h"
     63        1.1  augustss #include "bpfilter.h"
     64        1.1  augustss #include "rnd.h"
     65       1.18  augustss #elif defined(__OpenBSD__)
     66       1.18  augustss #include "bpfilter.h"
     67       1.18  augustss #endif /* defined(__OpenBSD__) */
     68        1.1  augustss 
     69        1.1  augustss #include <sys/param.h>
     70        1.1  augustss #include <sys/systm.h>
     71       1.18  augustss #if !defined(__OpenBSD__)
     72       1.14   thorpej #include <sys/callout.h>
     73       1.18  augustss #endif
     74        1.1  augustss #include <sys/sockio.h>
     75        1.1  augustss #include <sys/mbuf.h>
     76        1.1  augustss #include <sys/malloc.h>
     77        1.1  augustss #include <sys/kernel.h>
     78        1.1  augustss #include <sys/socket.h>
     79        1.1  augustss 
     80        1.1  augustss #include <sys/device.h>
     81        1.5  augustss #if NRND > 0
     82        1.5  augustss #include <sys/rnd.h>
     83        1.5  augustss #endif
     84        1.1  augustss 
     85        1.1  augustss #include <net/if.h>
     86       1.28  augustss #if defined(__NetBSD__)
     87        1.1  augustss #include <net/if_arp.h>
     88       1.18  augustss #endif
     89        1.1  augustss #include <net/if_dl.h>
     90        1.1  augustss 
     91        1.6   mycroft #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
     92        1.1  augustss 
     93       1.28  augustss #if NBPFILTER > 0
     94        1.1  augustss #include <net/bpf.h>
     95        1.1  augustss #endif
     96        1.1  augustss 
     97       1.18  augustss #if defined(__NetBSD__)
     98       1.18  augustss #include <net/if_ether.h>
     99        1.1  augustss #ifdef INET
    100       1.40  augustss #include <netinet/in.h>
    101        1.1  augustss #include <netinet/if_inarp.h>
    102        1.1  augustss #endif
    103       1.18  augustss #endif /* defined(__NetBSD__) */
    104       1.18  augustss 
    105       1.18  augustss #if defined(__OpenBSD__)
    106       1.18  augustss #ifdef INET
    107       1.18  augustss #include <netinet/in.h>
    108       1.18  augustss #include <netinet/in_systm.h>
    109       1.18  augustss #include <netinet/in_var.h>
    110       1.18  augustss #include <netinet/ip.h>
    111       1.18  augustss #include <netinet/if_ether.h>
    112       1.18  augustss #endif
    113       1.18  augustss #endif /* defined(__OpenBSD__) */
    114        1.1  augustss 
    115        1.1  augustss 
    116        1.1  augustss #include <dev/usb/usb.h>
    117        1.1  augustss #include <dev/usb/usbdi.h>
    118        1.1  augustss #include <dev/usb/usbdi_util.h>
    119        1.1  augustss #include <dev/usb/usbdevs.h>
    120  1.48.10.2     itohy #include <dev/usb/usb_ethersubr.h>
    121        1.1  augustss 
    122        1.1  augustss #include <dev/usb/if_cuereg.h>
    123        1.1  augustss 
    124        1.1  augustss #ifdef CUE_DEBUG
    125        1.1  augustss #define DPRINTF(x)	if (cuedebug) logprintf x
    126        1.1  augustss #define DPRINTFN(n,x)	if (cuedebug >= (n)) logprintf x
    127        1.1  augustss int	cuedebug = 0;
    128        1.1  augustss #else
    129        1.1  augustss #define DPRINTF(x)
    130        1.1  augustss #define DPRINTFN(n,x)
    131        1.1  augustss #endif
    132        1.1  augustss 
    133        1.1  augustss /*
    134        1.1  augustss  * Various supported device vendors/products.
    135        1.1  augustss  */
    136       1.37  augustss Static struct usb_devno cue_devs[] = {
    137        1.1  augustss 	{ USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE },
    138        1.1  augustss 	{ USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 },
    139       1.22  augustss 	{ USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK },
    140       1.15  augustss 	/* Belkin F5U111 adapter covered by NETMATE entry */
    141        1.1  augustss };
    142       1.38  augustss #define cue_lookup(v, p) (usb_lookup(cue_devs, v, p))
    143        1.1  augustss 
    144        1.1  augustss USB_DECLARE_DRIVER(cue);
    145        1.1  augustss 
    146       1.23  augustss Static int cue_open_pipes(struct cue_softc *);
    147       1.23  augustss Static int cue_send(struct cue_softc *, struct mbuf *, int);
    148       1.23  augustss Static void cue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
    149       1.23  augustss Static void cue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
    150       1.23  augustss Static void cue_tick(void *);
    151       1.30  augustss Static void cue_tick_task(void *);
    152       1.23  augustss Static void cue_start(struct ifnet *);
    153  1.48.10.3     itohy Static int cue_ioctl(struct ifnet *, u_long, usb_ioctlarg_t);
    154  1.48.10.2     itohy Static int cue_init(struct ifnet *);
    155  1.48.10.2     itohy Static void cue_stop(struct ifnet *, int);
    156       1.23  augustss Static void cue_watchdog(struct ifnet *);
    157       1.23  augustss 
    158       1.23  augustss Static void cue_setmulti(struct cue_softc *);
    159       1.42      yamt Static u_int32_t cue_crc(const char *);
    160       1.23  augustss Static void cue_reset(struct cue_softc *);
    161       1.23  augustss 
    162       1.23  augustss Static int cue_csr_read_1(struct cue_softc *, int);
    163       1.23  augustss Static int cue_csr_write_1(struct cue_softc *, int, int);
    164       1.23  augustss Static int cue_csr_read_2(struct cue_softc *, int);
    165       1.23  augustss #if 0
    166       1.23  augustss Static int cue_csr_write_2(struct cue_softc *, int, int);
    167       1.23  augustss #endif
    168       1.23  augustss Static int cue_mem(struct cue_softc *, int, int, void *, int);
    169       1.23  augustss Static int cue_getmac(struct cue_softc *, void *);
    170        1.1  augustss 
    171        1.1  augustss #define CUE_SETBIT(sc, reg, x)				\
    172       1.15  augustss 	cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) | (x))
    173        1.1  augustss 
    174        1.1  augustss #define CUE_CLRBIT(sc, reg, x)				\
    175       1.15  augustss 	cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x))
    176        1.8  augustss 
    177       1.17  augustss Static int
    178       1.23  augustss cue_csr_read_1(struct cue_softc	*sc, int reg)
    179        1.1  augustss {
    180        1.1  augustss 	usb_device_request_t	req;
    181        1.1  augustss 	usbd_status		err;
    182        1.1  augustss 	u_int8_t		val = 0;
    183        1.1  augustss 
    184       1.15  augustss 	if (sc->cue_dying)
    185       1.15  augustss 		return (0);
    186        1.1  augustss 
    187        1.1  augustss 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    188        1.1  augustss 	req.bRequest = CUE_CMD_READREG;
    189        1.1  augustss 	USETW(req.wValue, 0);
    190        1.1  augustss 	USETW(req.wIndex, reg);
    191        1.1  augustss 	USETW(req.wLength, 1);
    192        1.1  augustss 
    193       1.30  augustss 	err = usbd_do_request(sc->cue_udev, &req, &val);
    194        1.1  augustss 
    195       1.15  augustss 	if (err) {
    196       1.15  augustss 		DPRINTF(("%s: cue_csr_read_1: reg=0x%x err=%s\n",
    197       1.15  augustss 			 USBDEVNAME(sc->cue_dev), reg, usbd_errstr(err)));
    198        1.1  augustss 		return (0);
    199       1.15  augustss 	}
    200       1.15  augustss 
    201       1.40  augustss 	DPRINTFN(10,("%s: cue_csr_read_1 reg=0x%x val=0x%x\n",
    202       1.15  augustss 		     USBDEVNAME(sc->cue_dev), reg, val));
    203        1.1  augustss 
    204        1.1  augustss 	return (val);
    205        1.1  augustss }
    206        1.1  augustss 
    207       1.17  augustss Static int
    208       1.23  augustss cue_csr_read_2(struct cue_softc	*sc, int reg)
    209        1.1  augustss {
    210        1.1  augustss 	usb_device_request_t	req;
    211        1.1  augustss 	usbd_status		err;
    212       1.15  augustss 	uWord			val;
    213        1.1  augustss 
    214       1.15  augustss 	if (sc->cue_dying)
    215       1.15  augustss 		return (0);
    216        1.1  augustss 
    217        1.1  augustss 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    218        1.1  augustss 	req.bRequest = CUE_CMD_READREG;
    219        1.1  augustss 	USETW(req.wValue, 0);
    220        1.1  augustss 	USETW(req.wIndex, reg);
    221        1.1  augustss 	USETW(req.wLength, 2);
    222        1.1  augustss 
    223       1.30  augustss 	err = usbd_do_request(sc->cue_udev, &req, &val);
    224        1.1  augustss 
    225       1.40  augustss 	DPRINTFN(10,("%s: cue_csr_read_2 reg=0x%x val=0x%x\n",
    226       1.15  augustss 		     USBDEVNAME(sc->cue_dev), reg, UGETW(val)));
    227        1.1  augustss 
    228       1.15  augustss 	if (err) {
    229       1.15  augustss 		DPRINTF(("%s: cue_csr_read_2: reg=0x%x err=%s\n",
    230       1.15  augustss 			 USBDEVNAME(sc->cue_dev), reg, usbd_errstr(err)));
    231        1.1  augustss 		return (0);
    232       1.15  augustss 	}
    233        1.1  augustss 
    234       1.15  augustss 	return (UGETW(val));
    235        1.1  augustss }
    236        1.1  augustss 
    237       1.17  augustss Static int
    238       1.23  augustss cue_csr_write_1(struct cue_softc *sc, int reg, int val)
    239        1.1  augustss {
    240        1.1  augustss 	usb_device_request_t	req;
    241        1.1  augustss 	usbd_status		err;
    242        1.1  augustss 
    243       1.15  augustss 	if (sc->cue_dying)
    244       1.15  augustss 		return (0);
    245       1.15  augustss 
    246       1.40  augustss 	DPRINTFN(10,("%s: cue_csr_write_1 reg=0x%x val=0x%x\n",
    247       1.15  augustss 		     USBDEVNAME(sc->cue_dev), reg, val));
    248        1.1  augustss 
    249        1.1  augustss 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    250        1.1  augustss 	req.bRequest = CUE_CMD_WRITEREG;
    251        1.1  augustss 	USETW(req.wValue, val);
    252        1.1  augustss 	USETW(req.wIndex, reg);
    253        1.1  augustss 	USETW(req.wLength, 0);
    254        1.1  augustss 
    255       1.30  augustss 	err = usbd_do_request(sc->cue_udev, &req, NULL);
    256        1.1  augustss 
    257       1.15  augustss 	if (err) {
    258       1.15  augustss 		DPRINTF(("%s: cue_csr_write_1: reg=0x%x err=%s\n",
    259       1.15  augustss 			 USBDEVNAME(sc->cue_dev), reg, usbd_errstr(err)));
    260        1.1  augustss 		return (-1);
    261       1.15  augustss 	}
    262       1.15  augustss 
    263       1.40  augustss 	DPRINTFN(20,("%s: cue_csr_write_1, after reg=0x%x val=0x%x\n",
    264       1.15  augustss 		     USBDEVNAME(sc->cue_dev), reg, cue_csr_read_1(sc, reg)));
    265        1.1  augustss 
    266        1.1  augustss 	return (0);
    267        1.1  augustss }
    268        1.1  augustss 
    269       1.23  augustss #if 0
    270       1.17  augustss Static int
    271       1.23  augustss cue_csr_write_2(struct cue_softc *sc, int reg, int aval)
    272        1.1  augustss {
    273        1.1  augustss 	usb_device_request_t	req;
    274        1.1  augustss 	usbd_status		err;
    275       1.15  augustss 	uWord			val;
    276        1.1  augustss 	int			s;
    277        1.1  augustss 
    278       1.15  augustss 	if (sc->cue_dying)
    279       1.15  augustss 		return (0);
    280       1.15  augustss 
    281       1.40  augustss 	DPRINTFN(10,("%s: cue_csr_write_2 reg=0x%x val=0x%x\n",
    282       1.15  augustss 		     USBDEVNAME(sc->cue_dev), reg, aval));
    283        1.1  augustss 
    284       1.15  augustss 	USETW(val, aval);
    285        1.1  augustss 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    286        1.1  augustss 	req.bRequest = CUE_CMD_WRITEREG;
    287        1.1  augustss 	USETW(req.wValue, val);
    288        1.1  augustss 	USETW(req.wIndex, reg);
    289        1.1  augustss 	USETW(req.wLength, 0);
    290        1.1  augustss 
    291       1.30  augustss 	err = usbd_do_request(sc->cue_udev, &req, NULL);
    292        1.1  augustss 
    293       1.15  augustss 	if (err) {
    294       1.15  augustss 		DPRINTF(("%s: cue_csr_write_2: reg=0x%x err=%s\n",
    295       1.15  augustss 			 USBDEVNAME(sc->cue_dev), reg, usbd_errstr(err)));
    296        1.1  augustss 		return (-1);
    297       1.15  augustss 	}
    298        1.1  augustss 
    299        1.1  augustss 	return (0);
    300        1.1  augustss }
    301        1.1  augustss #endif
    302        1.1  augustss 
    303       1.17  augustss Static int
    304       1.23  augustss cue_mem(struct cue_softc *sc, int cmd, int addr, void *buf, int len)
    305        1.1  augustss {
    306        1.1  augustss 	usb_device_request_t	req;
    307        1.1  augustss 	usbd_status		err;
    308        1.1  augustss 
    309       1.15  augustss 	DPRINTFN(10,("%s: cue_mem cmd=0x%x addr=0x%x len=%d\n",
    310       1.15  augustss 		     USBDEVNAME(sc->cue_dev), cmd, addr, len));
    311        1.1  augustss 
    312        1.1  augustss 	if (cmd == CUE_CMD_READSRAM)
    313        1.1  augustss 		req.bmRequestType = UT_READ_VENDOR_DEVICE;
    314        1.1  augustss 	else
    315        1.1  augustss 		req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    316        1.1  augustss 	req.bRequest = cmd;
    317        1.1  augustss 	USETW(req.wValue, 0);
    318        1.1  augustss 	USETW(req.wIndex, addr);
    319        1.1  augustss 	USETW(req.wLength, len);
    320        1.1  augustss 
    321       1.30  augustss 	err = usbd_do_request(sc->cue_udev, &req, buf);
    322        1.1  augustss 
    323       1.15  augustss 	if (err) {
    324       1.15  augustss 		DPRINTF(("%s: cue_csr_mem: addr=0x%x err=%s\n",
    325       1.15  augustss 			 USBDEVNAME(sc->cue_dev), addr, usbd_errstr(err)));
    326        1.1  augustss 		return (-1);
    327       1.15  augustss 	}
    328        1.1  augustss 
    329        1.1  augustss 	return (0);
    330        1.1  augustss }
    331        1.1  augustss 
    332       1.17  augustss Static int
    333       1.23  augustss cue_getmac(struct cue_softc *sc, void *buf)
    334        1.1  augustss {
    335        1.1  augustss 	usb_device_request_t	req;
    336        1.1  augustss 	usbd_status		err;
    337        1.1  augustss 
    338       1.15  augustss 	DPRINTFN(10,("%s: cue_getmac\n", USBDEVNAME(sc->cue_dev)));
    339        1.1  augustss 
    340        1.1  augustss 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    341        1.1  augustss 	req.bRequest = CUE_CMD_GET_MACADDR;
    342        1.1  augustss 	USETW(req.wValue, 0);
    343        1.1  augustss 	USETW(req.wIndex, 0);
    344        1.1  augustss 	USETW(req.wLength, ETHER_ADDR_LEN);
    345        1.1  augustss 
    346       1.30  augustss 	err = usbd_do_request(sc->cue_udev, &req, buf);
    347        1.1  augustss 
    348        1.1  augustss 	if (err) {
    349       1.30  augustss 		printf("%s: read MAC address failed\n",USBDEVNAME(sc->cue_dev));
    350        1.1  augustss 		return (-1);
    351        1.1  augustss 	}
    352        1.1  augustss 
    353        1.1  augustss 	return (0);
    354        1.1  augustss }
    355        1.1  augustss 
    356        1.1  augustss #define CUE_POLY	0xEDB88320
    357        1.1  augustss #define CUE_BITS	9
    358        1.1  augustss 
    359       1.17  augustss Static u_int32_t
    360       1.42      yamt cue_crc(const char *addr)
    361        1.1  augustss {
    362        1.1  augustss 	u_int32_t		idx, bit, data, crc;
    363        1.1  augustss 
    364        1.1  augustss 	/* Compute CRC for the address value. */
    365        1.1  augustss 	crc = 0xFFFFFFFF; /* initial value */
    366        1.1  augustss 
    367        1.1  augustss 	for (idx = 0; idx < 6; idx++) {
    368        1.1  augustss 		for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
    369        1.1  augustss 			crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CUE_POLY : 0);
    370        1.1  augustss 	}
    371        1.1  augustss 
    372        1.1  augustss 	return (crc & ((1 << CUE_BITS) - 1));
    373        1.1  augustss }
    374        1.1  augustss 
    375       1.17  augustss Static void
    376       1.23  augustss cue_setmulti(struct cue_softc *sc)
    377        1.1  augustss {
    378        1.1  augustss 	struct ifnet		*ifp;
    379       1.15  augustss 	struct ether_multi	*enm;
    380       1.15  augustss 	struct ether_multistep	step;
    381       1.15  augustss 	u_int32_t		h, i;
    382        1.1  augustss 
    383        1.1  augustss 	ifp = GET_IFP(sc);
    384        1.1  augustss 
    385       1.40  augustss 	DPRINTFN(2,("%s: cue_setmulti if_flags=0x%x\n",
    386       1.15  augustss 		    USBDEVNAME(sc->cue_dev), ifp->if_flags));
    387       1.15  augustss 
    388       1.33     enami 	if (ifp->if_flags & IFF_PROMISC) {
    389       1.33     enami allmulti:
    390       1.33     enami 		ifp->if_flags |= IFF_ALLMULTI;
    391        1.1  augustss 		for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
    392        1.1  augustss 			sc->cue_mctab[i] = 0xFF;
    393       1.15  augustss 		cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
    394       1.15  augustss 		    &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
    395        1.1  augustss 		return;
    396        1.1  augustss 	}
    397        1.1  augustss 
    398        1.1  augustss 	/* first, zot all the existing hash bits */
    399        1.1  augustss 	for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
    400        1.1  augustss 		sc->cue_mctab[i] = 0;
    401        1.1  augustss 
    402        1.1  augustss 	/* now program new ones */
    403       1.18  augustss #if defined(__NetBSD__)
    404       1.15  augustss 	ETHER_FIRST_MULTI(step, &sc->cue_ec, enm);
    405       1.18  augustss #else
    406       1.18  augustss 	ETHER_FIRST_MULTI(step, &sc->arpcom, enm);
    407       1.18  augustss #endif
    408       1.15  augustss 	while (enm != NULL) {
    409       1.15  augustss 		if (memcmp(enm->enm_addrlo,
    410       1.33     enami 		    enm->enm_addrhi, ETHER_ADDR_LEN) != 0)
    411       1.33     enami 			goto allmulti;
    412       1.33     enami 
    413       1.15  augustss 		h = cue_crc(enm->enm_addrlo);
    414       1.40  augustss 		sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
    415       1.15  augustss 		ETHER_NEXT_MULTI(step, enm);
    416       1.15  augustss 	}
    417       1.33     enami 
    418       1.33     enami 	ifp->if_flags &= ~IFF_ALLMULTI;
    419        1.1  augustss 
    420        1.1  augustss 	/*
    421        1.1  augustss 	 * Also include the broadcast address in the filter
    422        1.1  augustss 	 * so we can receive broadcast frames.
    423        1.1  augustss 	 */
    424        1.1  augustss 	if (ifp->if_flags & IFF_BROADCAST) {
    425        1.1  augustss 		h = cue_crc(etherbroadcastaddr);
    426       1.40  augustss 		sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
    427        1.1  augustss 	}
    428        1.1  augustss 
    429        1.1  augustss 	cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
    430        1.1  augustss 	    &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
    431        1.1  augustss }
    432        1.1  augustss 
    433       1.17  augustss Static void
    434       1.23  augustss cue_reset(struct cue_softc *sc)
    435        1.1  augustss {
    436        1.1  augustss 	usb_device_request_t	req;
    437        1.1  augustss 	usbd_status		err;
    438        1.1  augustss 
    439       1.15  augustss 	DPRINTFN(2,("%s: cue_reset\n", USBDEVNAME(sc->cue_dev)));
    440       1.15  augustss 
    441       1.15  augustss 	if (sc->cue_dying)
    442       1.15  augustss 		return;
    443        1.1  augustss 
    444        1.1  augustss 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    445        1.1  augustss 	req.bRequest = CUE_CMD_RESET;
    446        1.1  augustss 	USETW(req.wValue, 0);
    447        1.1  augustss 	USETW(req.wIndex, 0);
    448        1.1  augustss 	USETW(req.wLength, 0);
    449       1.15  augustss 
    450       1.30  augustss 	err = usbd_do_request(sc->cue_udev, &req, NULL);
    451        1.1  augustss 
    452        1.1  augustss 	if (err)
    453        1.1  augustss 		printf("%s: reset failed\n", USBDEVNAME(sc->cue_dev));
    454        1.1  augustss 
    455        1.1  augustss 	/* Wait a little while for the chip to get its brains in order. */
    456       1.30  augustss 	usbd_delay_ms(sc->cue_udev, 1);
    457        1.1  augustss }
    458        1.1  augustss 
    459        1.1  augustss /*
    460        1.1  augustss  * Probe for a CATC chip.
    461        1.1  augustss  */
    462        1.1  augustss USB_MATCH(cue)
    463        1.1  augustss {
    464        1.1  augustss 	USB_MATCH_START(cue, uaa);
    465        1.1  augustss 
    466  1.48.10.4     itohy #ifndef USB_USE_IFATTACH
    467        1.1  augustss 	if (uaa->iface != NULL)
    468        1.1  augustss 		return (UMATCH_NONE);
    469  1.48.10.4     itohy #endif /* USB_USE_IFATTACH */
    470        1.1  augustss 
    471       1.37  augustss 	return (cue_lookup(uaa->vendor, uaa->product) != NULL ?
    472       1.37  augustss 		UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
    473        1.1  augustss }
    474        1.1  augustss 
    475        1.1  augustss /*
    476        1.1  augustss  * Attach the interface. Allocate softc structures, do ifmedia
    477        1.1  augustss  * setup and ethernet/BPF attach.
    478        1.1  augustss  */
    479        1.1  augustss USB_ATTACH(cue)
    480        1.1  augustss {
    481        1.1  augustss 	USB_ATTACH_START(cue, sc, uaa);
    482       1.43  augustss 	char			*devinfop;
    483        1.1  augustss 	int			s;
    484        1.1  augustss 	u_char			eaddr[ETHER_ADDR_LEN];
    485        1.1  augustss 	usbd_device_handle	dev = uaa->device;
    486        1.1  augustss 	usbd_interface_handle	iface;
    487        1.1  augustss 	usbd_status		err;
    488        1.1  augustss 	struct ifnet		*ifp;
    489        1.1  augustss 	usb_interface_descriptor_t	*id;
    490        1.1  augustss 	usb_endpoint_descriptor_t	*ed;
    491        1.1  augustss 	int			i;
    492        1.1  augustss 
    493        1.1  augustss 	DPRINTFN(5,(" : cue_attach: sc=%p, dev=%p", sc, dev));
    494        1.1  augustss 
    495       1.43  augustss 	devinfop = usbd_devinfo_alloc(dev, 0);
    496        1.1  augustss 	USB_ATTACH_SETUP;
    497       1.43  augustss 	printf("%s: %s\n", USBDEVNAME(sc->cue_dev), devinfop);
    498       1.43  augustss 	usbd_devinfo_free(devinfop);
    499        1.1  augustss 
    500       1.25  augustss 	err = usbd_set_config_no(dev, CUE_CONFIG_NO, 1);
    501        1.1  augustss 	if (err) {
    502        1.1  augustss 		printf("%s: setting config no failed\n",
    503        1.1  augustss 		    USBDEVNAME(sc->cue_dev));
    504        1.1  augustss 		USB_ATTACH_ERROR_RETURN;
    505        1.1  augustss 	}
    506        1.1  augustss 
    507        1.1  augustss 	sc->cue_udev = dev;
    508        1.1  augustss 	sc->cue_product = uaa->product;
    509        1.1  augustss 	sc->cue_vendor = uaa->vendor;
    510        1.1  augustss 
    511       1.32  augustss 	usb_init_task(&sc->cue_tick_task, cue_tick_task, sc);
    512       1.32  augustss 	usb_init_task(&sc->cue_stop_task, (void (*)(void *))cue_stop, sc);
    513       1.30  augustss 
    514        1.1  augustss 	err = usbd_device2interface_handle(dev, CUE_IFACE_IDX, &iface);
    515        1.1  augustss 	if (err) {
    516        1.1  augustss 		printf("%s: getting interface handle failed\n",
    517        1.1  augustss 		    USBDEVNAME(sc->cue_dev));
    518        1.1  augustss 		USB_ATTACH_ERROR_RETURN;
    519        1.1  augustss 	}
    520        1.1  augustss 
    521        1.1  augustss 	sc->cue_iface = iface;
    522        1.1  augustss 	id = usbd_get_interface_descriptor(iface);
    523        1.1  augustss 
    524        1.1  augustss 	/* Find endpoints. */
    525        1.1  augustss 	for (i = 0; i < id->bNumEndpoints; i++) {
    526        1.8  augustss 		ed = usbd_interface2endpoint_descriptor(iface, i);
    527        1.1  augustss 		if (ed == NULL) {
    528        1.1  augustss 			printf("%s: couldn't get ep %d\n",
    529        1.1  augustss 			    USBDEVNAME(sc->cue_dev), i);
    530        1.1  augustss 			USB_ATTACH_ERROR_RETURN;
    531        1.1  augustss 		}
    532        1.1  augustss 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    533       1.11  augustss 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    534        1.1  augustss 			sc->cue_ed[CUE_ENDPT_RX] = ed->bEndpointAddress;
    535        1.1  augustss 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
    536       1.11  augustss 			   UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    537        1.1  augustss 			sc->cue_ed[CUE_ENDPT_TX] = ed->bEndpointAddress;
    538        1.1  augustss 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    539       1.11  augustss 			   UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
    540        1.1  augustss 			sc->cue_ed[CUE_ENDPT_INTR] = ed->bEndpointAddress;
    541        1.1  augustss 		}
    542        1.1  augustss 	}
    543        1.1  augustss 
    544       1.15  augustss #if 0
    545        1.1  augustss 	/* Reset the adapter. */
    546        1.1  augustss 	cue_reset(sc);
    547        1.1  augustss #endif
    548        1.1  augustss 	/*
    549        1.1  augustss 	 * Get station address.
    550        1.1  augustss 	 */
    551        1.1  augustss 	cue_getmac(sc, &eaddr);
    552        1.1  augustss 
    553       1.35   thorpej 	s = splnet();
    554        1.1  augustss 
    555        1.1  augustss 	/*
    556        1.1  augustss 	 * A CATC chip was detected. Inform the world.
    557        1.1  augustss 	 */
    558        1.1  augustss 	printf("%s: Ethernet address %s\n", USBDEVNAME(sc->cue_dev),
    559        1.1  augustss 	    ether_sprintf(eaddr));
    560        1.1  augustss 
    561        1.1  augustss 	/* Initialize interface info.*/
    562        1.1  augustss 	ifp = GET_IFP(sc);
    563        1.1  augustss 	ifp->if_softc = sc;
    564        1.1  augustss 	ifp->if_mtu = ETHERMTU;
    565        1.1  augustss 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
    566        1.1  augustss 	ifp->if_ioctl = cue_ioctl;
    567        1.1  augustss 	ifp->if_start = cue_start;
    568  1.48.10.2     itohy 	ifp->if_init = cue_init;
    569  1.48.10.2     itohy 	ifp->if_stop = cue_stop;
    570        1.1  augustss 	ifp->if_watchdog = cue_watchdog;
    571       1.19  augustss #if defined(__OpenBSD__)
    572       1.20  augustss 	ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
    573       1.19  augustss #endif
    574        1.1  augustss 	strncpy(ifp->if_xname, USBDEVNAME(sc->cue_dev), IFNAMSIZ);
    575        1.1  augustss 
    576       1.27   thorpej 	IFQ_SET_READY(&ifp->if_snd);
    577       1.27   thorpej 
    578        1.1  augustss 	/* Attach the interface. */
    579        1.1  augustss 	if_attach(ifp);
    580       1.18  augustss 	Ether_ifattach(ifp, eaddr);
    581        1.5  augustss #if NRND > 0
    582        1.1  augustss 	rnd_attach_source(&sc->rnd_source, USBDEVNAME(sc->cue_dev),
    583        1.1  augustss 	    RND_TYPE_NET, 0);
    584        1.1  augustss #endif
    585        1.1  augustss 
    586       1.16  augustss 	usb_callout_init(sc->cue_stat_ch);
    587       1.16  augustss 
    588        1.7  augustss 	sc->cue_attached = 1;
    589        1.1  augustss 	splx(s);
    590        1.5  augustss 
    591        1.5  augustss 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->cue_udev,
    592       1.15  augustss 	    USBDEV(sc->cue_dev));
    593        1.5  augustss 
    594        1.1  augustss 	USB_ATTACH_SUCCESS_RETURN;
    595        1.1  augustss }
    596        1.1  augustss 
    597        1.1  augustss USB_DETACH(cue)
    598        1.1  augustss {
    599        1.1  augustss 	USB_DETACH_START(cue, sc);
    600        1.4  augustss 	struct ifnet		*ifp = GET_IFP(sc);
    601        1.1  augustss 	int			s;
    602        1.1  augustss 
    603       1.39  augustss 	DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev), __func__));
    604       1.15  augustss 
    605       1.30  augustss 	usb_uncallout(sc->cue_stat_ch, cue_tick, sc);
    606       1.32  augustss 	/*
    607       1.32  augustss 	 * Remove any pending task.  It cannot be executing because it run
    608       1.32  augustss 	 * in the same thread as detach.
    609       1.32  augustss 	 */
    610       1.32  augustss 	usb_rem_task(sc->cue_udev, &sc->cue_tick_task);
    611       1.34  augustss 	usb_rem_task(sc->cue_udev, &sc->cue_stop_task);
    612        1.7  augustss 
    613        1.7  augustss 	if (!sc->cue_attached) {
    614        1.7  augustss 		/* Detached before attached finished, so just bail out. */
    615        1.7  augustss 		return (0);
    616        1.7  augustss 	}
    617        1.7  augustss 
    618       1.30  augustss 	s = splusb();
    619       1.30  augustss 
    620        1.4  augustss 	if (ifp->if_flags & IFF_RUNNING)
    621  1.48.10.2     itohy 		cue_stop(ifp, 1);
    622        1.4  augustss 
    623        1.4  augustss #if defined(__NetBSD__)
    624        1.5  augustss #if NRND > 0
    625        1.5  augustss 	rnd_detach_source(&sc->rnd_source);
    626        1.4  augustss #endif
    627        1.4  augustss 	ether_ifdetach(ifp);
    628        1.4  augustss #endif /* __NetBSD__ */
    629        1.1  augustss 
    630        1.1  augustss 	if_detach(ifp);
    631        1.1  augustss 
    632        1.4  augustss #ifdef DIAGNOSTIC
    633        1.4  augustss 	if (sc->cue_ep[CUE_ENDPT_TX] != NULL ||
    634        1.4  augustss 	    sc->cue_ep[CUE_ENDPT_RX] != NULL ||
    635        1.4  augustss 	    sc->cue_ep[CUE_ENDPT_INTR] != NULL)
    636        1.4  augustss 		printf("%s: detach has active endpoints\n",
    637        1.4  augustss 		       USBDEVNAME(sc->cue_dev));
    638        1.4  augustss #endif
    639        1.1  augustss 
    640        1.7  augustss 	sc->cue_attached = 0;
    641        1.1  augustss 	splx(s);
    642        1.5  augustss 
    643        1.5  augustss 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->cue_udev,
    644       1.15  augustss 	    USBDEV(sc->cue_dev));
    645        1.1  augustss 
    646        1.1  augustss 	return (0);
    647        1.1  augustss }
    648        1.1  augustss 
    649        1.1  augustss int
    650       1.23  augustss cue_activate(device_ptr_t self, enum devact act)
    651        1.1  augustss {
    652        1.1  augustss 	struct cue_softc *sc = (struct cue_softc *)self;
    653        1.1  augustss 
    654       1.39  augustss 	DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev), __func__));
    655        1.1  augustss 
    656        1.1  augustss 	switch (act) {
    657        1.1  augustss 	case DVACT_ACTIVATE:
    658        1.1  augustss 		return (EOPNOTSUPP);
    659        1.1  augustss 		break;
    660        1.1  augustss 
    661        1.1  augustss 	case DVACT_DEACTIVATE:
    662        1.4  augustss 		/* Deactivate the interface. */
    663        1.4  augustss 		if_deactivate(&sc->cue_ec.ec_if);
    664        1.1  augustss 		sc->cue_dying = 1;
    665        1.1  augustss 		break;
    666        1.1  augustss 	}
    667        1.1  augustss 	return (0);
    668        1.1  augustss }
    669        1.1  augustss 
    670        1.1  augustss /*
    671        1.1  augustss  * A frame has been uploaded: pass the resulting mbuf chain up to
    672        1.1  augustss  * the higher level protocols.
    673        1.1  augustss  */
    674       1.17  augustss Static void
    675       1.23  augustss cue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
    676        1.1  augustss {
    677  1.48.10.2     itohy 	struct ue_chain		*c = priv;
    678  1.48.10.2     itohy 	struct cue_softc	*sc = (void *)c->ue_dev;
    679        1.1  augustss 	struct ifnet		*ifp = GET_IFP(sc);
    680        1.1  augustss 	struct mbuf		*m;
    681        1.1  augustss 	int			total_len = 0;
    682        1.1  augustss 	u_int16_t		len;
    683        1.1  augustss 	int			s;
    684        1.1  augustss 
    685        1.1  augustss 	DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->cue_dev),
    686       1.39  augustss 		     __func__, status));
    687        1.1  augustss 
    688        1.4  augustss 	if (sc->cue_dying)
    689        1.4  augustss 		return;
    690        1.4  augustss 
    691        1.1  augustss 	if (!(ifp->if_flags & IFF_RUNNING))
    692        1.1  augustss 		return;
    693        1.1  augustss 
    694  1.48.10.2     itohy 	usbd_unmap_buffer(xfer);
    695  1.48.10.2     itohy 
    696        1.1  augustss 	if (status != USBD_NORMAL_COMPLETION) {
    697        1.1  augustss 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
    698        1.1  augustss 			return;
    699       1.10  augustss 		sc->cue_rx_errs++;
    700       1.10  augustss 		if (usbd_ratecheck(&sc->cue_rx_notice)) {
    701       1.10  augustss 			printf("%s: %u usb errors on rx: %s\n",
    702       1.10  augustss 			    USBDEVNAME(sc->cue_dev), sc->cue_rx_errs,
    703       1.10  augustss 			    usbd_errstr(status));
    704       1.10  augustss 			sc->cue_rx_errs = 0;
    705       1.10  augustss 		}
    706        1.1  augustss 		if (status == USBD_STALLED)
    707       1.44  augustss 			usbd_clear_endpoint_stall_async(sc->cue_ep[CUE_ENDPT_RX]);
    708        1.1  augustss 		goto done;
    709        1.1  augustss 	}
    710        1.1  augustss 
    711  1.48.10.2     itohy #if 0
    712        1.1  augustss 	usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
    713  1.48.10.2     itohy 	/* XXX should check total_len ? */
    714  1.48.10.2     itohy #endif
    715        1.1  augustss 
    716  1.48.10.2     itohy 	m = c->ue_mbuf;
    717        1.1  augustss 	len = UGETW(mtod(m, u_int8_t *));
    718        1.1  augustss 
    719        1.1  augustss 	/* No errors; receive the packet. */
    720        1.1  augustss 	total_len = len;
    721        1.1  augustss 
    722        1.1  augustss 	if (len < sizeof(struct ether_header)) {
    723        1.1  augustss 		ifp->if_ierrors++;
    724        1.1  augustss 		goto done;
    725        1.1  augustss 	}
    726        1.1  augustss 
    727  1.48.10.2     itohy 	/*
    728  1.48.10.2     itohy 	 * Allocate new mbuf cluster for the next transfer.
    729  1.48.10.2     itohy 	 * If that failed, discard current packet and recycle the mbuf.
    730  1.48.10.2     itohy 	 */
    731  1.48.10.2     itohy 	if ((c->ue_mbuf = usb_ether_newbuf(NULL)) == NULL) {
    732  1.48.10.2     itohy 		printf("%s: no memory for rx list -- packet dropped!\n",
    733  1.48.10.2     itohy 		    USBDEVNAME(sc->cue_dev));
    734  1.48.10.2     itohy 		ifp->if_ierrors++;
    735  1.48.10.2     itohy 		c->ue_mbuf = usb_ether_newbuf(m);
    736  1.48.10.2     itohy 		goto done;
    737  1.48.10.2     itohy 	}
    738  1.48.10.2     itohy 
    739        1.1  augustss 	ifp->if_ipackets++;
    740        1.1  augustss 	m_adj(m, sizeof(u_int16_t));
    741        1.1  augustss 	m->m_pkthdr.len = m->m_len = total_len;
    742        1.1  augustss 
    743        1.1  augustss 	m->m_pkthdr.rcvif = ifp;
    744        1.1  augustss 
    745       1.35   thorpej 	s = splnet();
    746        1.1  augustss 
    747        1.9  augustss #if NBPFILTER > 0
    748        1.1  augustss 	/*
    749        1.1  augustss 	 * Handle BPF listeners. Let the BPF user see the packet, but
    750        1.1  augustss 	 * don't pass it up to the ether_input() layer unless it's
    751        1.1  augustss 	 * a broadcast packet, multicast packet, matches our ethernet
    752        1.1  augustss 	 * address or the interface is in promiscuous mode.
    753        1.1  augustss 	 */
    754       1.24   thorpej 	if (ifp->if_bpf)
    755       1.19  augustss 		BPF_MTAP(ifp, m);
    756        1.9  augustss #endif
    757        1.1  augustss 
    758        1.1  augustss 	DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->cue_dev),
    759       1.39  augustss 		    __func__, m->m_len));
    760       1.18  augustss 	IF_INPUT(ifp, m);
    761        1.1  augustss 	splx(s);
    762        1.1  augustss 
    763        1.1  augustss done:
    764        1.1  augustss 	/* Setup new transfer. */
    765  1.48.10.2     itohy 	(void)usbd_map_buffer_mbuf(c->ue_xfer, c->ue_mbuf);
    766  1.48.10.2     itohy 	usbd_setup_xfer(c->ue_xfer, sc->cue_ep[CUE_ENDPT_RX],
    767  1.48.10.2     itohy 	    c, NULL /* XXX buf */, CUE_BUFSZ, USBD_SHORT_XFER_OK | USBD_NO_COPY,
    768        1.1  augustss 	    USBD_NO_TIMEOUT, cue_rxeof);
    769  1.48.10.2     itohy 	usbd_transfer(c->ue_xfer);
    770        1.1  augustss 
    771        1.1  augustss 	DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->cue_dev),
    772       1.39  augustss 		    __func__));
    773        1.1  augustss }
    774        1.1  augustss 
    775        1.1  augustss /*
    776        1.1  augustss  * A frame was downloaded to the chip. It's safe for us to clean up
    777        1.1  augustss  * the list buffers.
    778        1.1  augustss  */
    779       1.17  augustss Static void
    780       1.48  christos cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv,
    781       1.46  christos     usbd_status status)
    782        1.1  augustss {
    783  1.48.10.2     itohy 	struct ue_chain		*c = priv;
    784  1.48.10.2     itohy 	struct cue_softc	*sc = (void *)c->ue_dev;
    785        1.1  augustss 	struct ifnet		*ifp = GET_IFP(sc);
    786        1.1  augustss 	int			s;
    787        1.1  augustss 
    788        1.4  augustss 	if (sc->cue_dying)
    789        1.4  augustss 		return;
    790        1.4  augustss 
    791  1.48.10.2     itohy 	usbd_unmap_buffer(xfer);
    792  1.48.10.2     itohy 
    793       1.35   thorpej 	s = splnet();
    794        1.1  augustss 
    795        1.1  augustss 	DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->cue_dev),
    796       1.39  augustss 		    __func__, status));
    797        1.1  augustss 
    798        1.1  augustss 	ifp->if_timer = 0;
    799        1.1  augustss 	ifp->if_flags &= ~IFF_OACTIVE;
    800        1.1  augustss 
    801        1.1  augustss 	if (status != USBD_NORMAL_COMPLETION) {
    802        1.1  augustss 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
    803        1.1  augustss 			splx(s);
    804        1.1  augustss 			return;
    805        1.1  augustss 		}
    806        1.1  augustss 		ifp->if_oerrors++;
    807        1.1  augustss 		printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->cue_dev),
    808        1.1  augustss 		    usbd_errstr(status));
    809        1.1  augustss 		if (status == USBD_STALLED)
    810       1.44  augustss 			usbd_clear_endpoint_stall_async(sc->cue_ep[CUE_ENDPT_TX]);
    811        1.1  augustss 		splx(s);
    812        1.1  augustss 		return;
    813        1.1  augustss 	}
    814        1.1  augustss 
    815        1.1  augustss 	ifp->if_opackets++;
    816        1.1  augustss 
    817  1.48.10.2     itohy 	m_freem(c->ue_mbuf);
    818  1.48.10.2     itohy 	c->ue_mbuf = NULL;
    819        1.1  augustss 
    820       1.27   thorpej 	if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
    821        1.1  augustss 		cue_start(ifp);
    822        1.1  augustss 
    823        1.1  augustss 	splx(s);
    824        1.1  augustss }
    825        1.1  augustss 
    826       1.17  augustss Static void
    827       1.23  augustss cue_tick(void *xsc)
    828        1.1  augustss {
    829        1.1  augustss 	struct cue_softc	*sc = xsc;
    830        1.1  augustss 
    831        1.4  augustss 	if (sc == NULL)
    832        1.4  augustss 		return;
    833        1.1  augustss 
    834        1.4  augustss 	if (sc->cue_dying)
    835        1.1  augustss 		return;
    836        1.4  augustss 
    837       1.39  augustss 	DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev), __func__));
    838       1.15  augustss 
    839       1.30  augustss 	/* Perform statistics update in process context. */
    840       1.47     joerg 	usb_add_task(sc->cue_udev, &sc->cue_tick_task, USB_TASKQ_DRIVER);
    841       1.30  augustss }
    842       1.30  augustss 
    843       1.30  augustss Static void
    844       1.30  augustss cue_tick_task(void *xsc)
    845       1.30  augustss {
    846       1.30  augustss 	struct cue_softc	*sc = xsc;
    847       1.30  augustss 	struct ifnet		*ifp;
    848       1.30  augustss 
    849       1.30  augustss 	if (sc->cue_dying)
    850       1.30  augustss 		return;
    851       1.30  augustss 
    852       1.39  augustss 	DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev), __func__));
    853        1.1  augustss 
    854        1.1  augustss 	ifp = GET_IFP(sc);
    855        1.1  augustss 
    856       1.15  augustss 	ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_SINGLECOLL);
    857       1.15  augustss 	ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_MULTICOLL);
    858       1.15  augustss 	ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_EXCESSCOLL);
    859        1.1  augustss 
    860       1.15  augustss 	if (cue_csr_read_2(sc, CUE_RX_FRAMEERR))
    861        1.1  augustss 		ifp->if_ierrors++;
    862        1.1  augustss }
    863        1.1  augustss 
    864       1.17  augustss Static int
    865       1.23  augustss cue_send(struct cue_softc *sc, struct mbuf *m, int idx)
    866        1.1  augustss {
    867        1.1  augustss 	int			total_len;
    868  1.48.10.2     itohy 	struct ue_chain		*c;
    869        1.1  augustss 	usbd_status		err;
    870  1.48.10.2     itohy 	int			ret;
    871        1.1  augustss 
    872        1.1  augustss 	c = &sc->cue_cdata.cue_tx_chain[idx];
    873        1.1  augustss 
    874  1.48.10.2     itohy 	/* Prepend two bytes at the beginning to hold the frame length. */
    875  1.48.10.2     itohy 	M_PREPEND(m, sizeof(u_int16_t), M_DONTWAIT);
    876  1.48.10.2     itohy 	if (m != NULL)
    877  1.48.10.2     itohy 		m = m_pullup(m, sizeof(u_int16_t));	/* just in case */
    878  1.48.10.2     itohy 	if (m == NULL) {
    879  1.48.10.2     itohy 		GET_IFP(sc)->if_oerrors++;
    880  1.48.10.2     itohy 		return (ENOBUFS);
    881  1.48.10.2     itohy 	}
    882        1.1  augustss 
    883  1.48.10.2     itohy 	total_len = m->m_pkthdr.len;
    884        1.1  augustss 
    885       1.15  augustss 	DPRINTFN(10,("%s: %s: total_len=%d\n",
    886       1.39  augustss 		     USBDEVNAME(sc->cue_dev), __func__, total_len));
    887       1.15  augustss 
    888        1.1  augustss 	/* The first two bytes are the frame length */
    889  1.48.10.2     itohy 	USETW(mtod(m, char *), m->m_pkthdr.len - sizeof(u_int16_t));
    890  1.48.10.2     itohy 
    891  1.48.10.2     itohy 	ret = usb_ether_map_tx_buffer_mbuf(c, m);
    892  1.48.10.2     itohy 	if (ret) {
    893  1.48.10.2     itohy 		m_freem(m);
    894  1.48.10.2     itohy 		return (ret);
    895  1.48.10.2     itohy 	}
    896        1.1  augustss 
    897       1.15  augustss 	/* XXX 10000 */
    898  1.48.10.2     itohy 	usbd_setup_xfer(c->ue_xfer, sc->cue_ep[CUE_ENDPT_TX],
    899  1.48.10.2     itohy 	    c, NULL /* XXX buf */, total_len, USBD_NO_COPY, 10000, cue_txeof);
    900        1.1  augustss 
    901        1.1  augustss 	/* Transmit */
    902  1.48.10.2     itohy 	err = usbd_transfer(c->ue_xfer);
    903        1.1  augustss 	if (err != USBD_IN_PROGRESS) {
    904  1.48.10.2     itohy 		c->ue_mbuf = NULL;
    905  1.48.10.2     itohy 		m_freem(m);
    906       1.21  augustss 		printf("%s: cue_send error=%s\n", USBDEVNAME(sc->cue_dev),
    907       1.21  augustss 		       usbd_errstr(err));
    908       1.31  augustss 		/* Stop the interface from process context. */
    909       1.47     joerg 		usb_add_task(sc->cue_udev, &sc->cue_stop_task,
    910       1.47     joerg 		    USB_TASKQ_DRIVER);
    911        1.1  augustss 		return (EIO);
    912        1.1  augustss 	}
    913        1.1  augustss 
    914        1.1  augustss 	sc->cue_cdata.cue_tx_cnt++;
    915        1.1  augustss 
    916        1.1  augustss 	return (0);
    917        1.1  augustss }
    918        1.1  augustss 
    919       1.17  augustss Static void
    920       1.23  augustss cue_start(struct ifnet *ifp)
    921        1.1  augustss {
    922        1.1  augustss 	struct cue_softc	*sc = ifp->if_softc;
    923        1.1  augustss 	struct mbuf		*m_head = NULL;
    924        1.1  augustss 
    925        1.4  augustss 	if (sc->cue_dying)
    926        1.4  augustss 		return;
    927        1.4  augustss 
    928       1.39  augustss 	DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev),__func__));
    929       1.15  augustss 
    930        1.1  augustss 	if (ifp->if_flags & IFF_OACTIVE)
    931        1.1  augustss 		return;
    932        1.1  augustss 
    933       1.27   thorpej 	IFQ_POLL(&ifp->if_snd, m_head);
    934        1.1  augustss 	if (m_head == NULL)
    935        1.1  augustss 		return;
    936        1.1  augustss 
    937       1.27   thorpej 	IFQ_DEQUEUE(&ifp->if_snd, m_head);
    938       1.27   thorpej 
    939        1.9  augustss #if NBPFILTER > 0
    940        1.1  augustss 	/*
    941        1.1  augustss 	 * If there's a BPF listener, bounce a copy of this frame
    942        1.1  augustss 	 * to him.
    943        1.1  augustss 	 */
    944        1.1  augustss 	if (ifp->if_bpf)
    945        1.6   mycroft 		BPF_MTAP(ifp, m_head);
    946        1.9  augustss #endif
    947        1.1  augustss 
    948  1.48.10.2     itohy 	if (cue_send(sc, m_head, 0)) {
    949  1.48.10.2     itohy 		ifp->if_flags |= IFF_OACTIVE;
    950  1.48.10.2     itohy 		return;
    951  1.48.10.2     itohy 	}
    952  1.48.10.2     itohy 
    953        1.1  augustss 	ifp->if_flags |= IFF_OACTIVE;
    954        1.1  augustss 
    955        1.1  augustss 	/*
    956        1.1  augustss 	 * Set a timeout in case the chip goes out to lunch.
    957        1.1  augustss 	 */
    958        1.1  augustss 	ifp->if_timer = 5;
    959        1.1  augustss }
    960        1.1  augustss 
    961  1.48.10.2     itohy Static int
    962  1.48.10.2     itohy cue_init(struct ifnet *ifp)
    963        1.1  augustss {
    964  1.48.10.2     itohy 	struct cue_softc	*sc = ifp->if_softc;
    965       1.15  augustss 	int			i, s, ctl;
    966        1.1  augustss 	u_char			*eaddr;
    967  1.48.10.2     itohy 	struct ue_chain		*c;
    968        1.1  augustss 
    969        1.4  augustss 	if (sc->cue_dying)
    970  1.48.10.2     itohy 		return (EIO);
    971        1.4  augustss 
    972       1.39  augustss 	DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev),__func__));
    973       1.15  augustss 
    974        1.1  augustss 	if (ifp->if_flags & IFF_RUNNING)
    975  1.48.10.2     itohy 		return (EIO);
    976        1.1  augustss 
    977       1.35   thorpej 	s = splnet();
    978        1.1  augustss 
    979        1.1  augustss 	/*
    980        1.1  augustss 	 * Cancel pending I/O and free all RX/TX buffers.
    981        1.1  augustss 	 */
    982       1.15  augustss #if 1
    983        1.1  augustss 	cue_reset(sc);
    984        1.1  augustss #endif
    985        1.1  augustss 
    986       1.15  augustss 	/* Set advanced operation modes. */
    987       1.15  augustss 	cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
    988       1.15  augustss 	    CUE_AOP_EMBED_RXLEN | 0x03); /* 1 wait state */
    989       1.15  augustss 
    990       1.28  augustss #if defined(__OpenBSD__)
    991        1.1  augustss 	eaddr = sc->arpcom.ac_enaddr;
    992       1.18  augustss #elif defined(__NetBSD__)
    993        1.1  augustss 	eaddr = LLADDR(ifp->if_sadl);
    994       1.28  augustss #endif
    995        1.1  augustss 	/* Set MAC address */
    996        1.1  augustss 	for (i = 0; i < ETHER_ADDR_LEN; i++)
    997       1.15  augustss 		cue_csr_write_1(sc, CUE_PAR0 - i, eaddr[i]);
    998        1.1  augustss 
    999        1.1  augustss 	/* Enable RX logic. */
   1000       1.15  augustss 	ctl = CUE_ETHCTL_RX_ON | CUE_ETHCTL_MCAST_ON;
   1001        1.1  augustss 	if (ifp->if_flags & IFF_PROMISC)
   1002       1.15  augustss 		ctl |= CUE_ETHCTL_PROMISC;
   1003       1.15  augustss 	cue_csr_write_1(sc, CUE_ETHCTL, ctl);
   1004        1.1  augustss 
   1005        1.1  augustss 	/* Load the multicast filter. */
   1006        1.1  augustss 	cue_setmulti(sc);
   1007        1.1  augustss 
   1008        1.1  augustss 	/*
   1009        1.1  augustss 	 * Set the number of RX and TX buffers that we want
   1010        1.1  augustss 	 * to reserve inside the ASIC.
   1011        1.1  augustss 	 */
   1012       1.15  augustss 	cue_csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
   1013       1.15  augustss 	cue_csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
   1014        1.1  augustss 
   1015        1.1  augustss 	/* Set advanced operation modes. */
   1016       1.15  augustss 	cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
   1017       1.15  augustss 	    CUE_AOP_EMBED_RXLEN | 0x01); /* 1 wait state */
   1018        1.1  augustss 
   1019        1.1  augustss 	/* Program the LED operation. */
   1020       1.15  augustss 	cue_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
   1021        1.1  augustss 
   1022        1.1  augustss 	if (sc->cue_ep[CUE_ENDPT_RX] == NULL) {
   1023       1.15  augustss 		if (cue_open_pipes(sc)) {
   1024       1.15  augustss 			splx(s);
   1025  1.48.10.2     itohy 			return (EIO);
   1026       1.15  augustss 		}
   1027       1.15  augustss 	}
   1028       1.15  augustss 
   1029  1.48.10.2     itohy 	/* Init TX ring. */
   1030  1.48.10.2     itohy 	if ((i = usb_ether_tx_list_init(USBDEV(sc->cue_dev),
   1031  1.48.10.2     itohy 	    sc->cue_cdata.cue_tx_chain, CUE_TX_LIST_CNT,
   1032  1.48.10.2     itohy 	    sc->cue_udev, sc->cue_ep[CUE_ENDPT_TX], NULL))) {
   1033  1.48.10.2     itohy 		printf("%s: tx list init failed\n", USBDEVNAME(sc->cue_dev));
   1034  1.48.10.2     itohy 		splx(s);
   1035  1.48.10.2     itohy 		return (i);
   1036  1.48.10.2     itohy 	}
   1037  1.48.10.2     itohy 
   1038  1.48.10.2     itohy 	/* Init RX ring. */
   1039  1.48.10.2     itohy 	if ((i = usb_ether_rx_list_init(USBDEV(sc->cue_dev),
   1040  1.48.10.2     itohy 	    sc->cue_cdata.cue_rx_chain, CUE_RX_LIST_CNT,
   1041  1.48.10.2     itohy 	    sc->cue_udev, sc->cue_ep[CUE_ENDPT_RX]))) {
   1042  1.48.10.2     itohy 		printf("%s: rx list init failed\n", USBDEVNAME(sc->cue_dev));
   1043  1.48.10.2     itohy 		splx(s);
   1044  1.48.10.2     itohy 		return (i);
   1045  1.48.10.2     itohy 	}
   1046  1.48.10.2     itohy 
   1047  1.48.10.2     itohy 	/* Start up the receive pipe. */
   1048  1.48.10.2     itohy 	for (i = 0; i < CUE_RX_LIST_CNT; i++) {
   1049  1.48.10.2     itohy 		c = &sc->cue_cdata.cue_rx_chain[i];
   1050  1.48.10.2     itohy 		(void)usbd_map_buffer_mbuf(c->ue_xfer, c->ue_mbuf);
   1051  1.48.10.2     itohy 		usbd_setup_xfer(c->ue_xfer, sc->cue_ep[CUE_ENDPT_RX],
   1052  1.48.10.2     itohy 		    c, NULL /* XXX buf */, CUE_BUFSZ,
   1053  1.48.10.2     itohy 		    USBD_SHORT_XFER_OK | USBD_NO_COPY, USBD_NO_TIMEOUT,
   1054  1.48.10.2     itohy 		    cue_rxeof);
   1055  1.48.10.2     itohy 		usbd_transfer(c->ue_xfer);
   1056  1.48.10.2     itohy 	}
   1057  1.48.10.2     itohy 
   1058       1.15  augustss 	ifp->if_flags |= IFF_RUNNING;
   1059       1.15  augustss 	ifp->if_flags &= ~IFF_OACTIVE;
   1060       1.15  augustss 
   1061       1.15  augustss 	splx(s);
   1062       1.15  augustss 
   1063       1.16  augustss 	usb_callout(sc->cue_stat_ch, hz, cue_tick, sc);
   1064  1.48.10.2     itohy 
   1065  1.48.10.2     itohy 	return (0);
   1066       1.15  augustss }
   1067       1.15  augustss 
   1068       1.17  augustss Static int
   1069       1.23  augustss cue_open_pipes(struct cue_softc	*sc)
   1070       1.15  augustss {
   1071       1.15  augustss 	usbd_status		err;
   1072       1.15  augustss 
   1073        1.1  augustss 	/* Open RX and TX pipes. */
   1074        1.1  augustss 	err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
   1075        1.1  augustss 	    USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
   1076        1.1  augustss 	if (err) {
   1077        1.1  augustss 		printf("%s: open rx pipe failed: %s\n",
   1078        1.1  augustss 		    USBDEVNAME(sc->cue_dev), usbd_errstr(err));
   1079       1.15  augustss 		return (EIO);
   1080        1.1  augustss 	}
   1081        1.1  augustss 	err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
   1082        1.1  augustss 	    USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
   1083        1.1  augustss 	if (err) {
   1084        1.1  augustss 		printf("%s: open tx pipe failed: %s\n",
   1085        1.1  augustss 		    USBDEVNAME(sc->cue_dev), usbd_errstr(err));
   1086       1.15  augustss 		return (EIO);
   1087        1.1  augustss 	}
   1088        1.1  augustss 
   1089       1.15  augustss 	return (0);
   1090        1.1  augustss }
   1091        1.1  augustss 
   1092       1.17  augustss Static int
   1093  1.48.10.3     itohy cue_ioctl(struct ifnet *ifp, u_long command, usb_ioctlarg_t data)
   1094        1.1  augustss {
   1095        1.1  augustss 	struct cue_softc	*sc = ifp->if_softc;
   1096  1.48.10.2     itohy #if 0
   1097        1.1  augustss 	struct ifaddr 		*ifa = (struct ifaddr *)data;
   1098        1.1  augustss 	struct ifreq		*ifr = (struct ifreq *)data;
   1099  1.48.10.2     itohy #endif
   1100        1.1  augustss 	int			s, error = 0;
   1101        1.1  augustss 
   1102        1.4  augustss 	if (sc->cue_dying)
   1103        1.4  augustss 		return (EIO);
   1104        1.4  augustss 
   1105       1.35   thorpej 	s = splnet();
   1106        1.1  augustss 
   1107        1.1  augustss 	switch(command) {
   1108  1.48.10.2     itohy #if 0
   1109        1.1  augustss 	case SIOCSIFADDR:
   1110        1.1  augustss 		ifp->if_flags |= IFF_UP;
   1111  1.48.10.2     itohy 		cue_init(ifp);
   1112        1.1  augustss 
   1113        1.1  augustss 		switch (ifa->ifa_addr->sa_family) {
   1114        1.1  augustss #ifdef INET
   1115        1.1  augustss 		case AF_INET:
   1116       1.18  augustss #if defined(__NetBSD__)
   1117        1.1  augustss 			arp_ifinit(ifp, ifa);
   1118       1.18  augustss #else
   1119       1.18  augustss 			arp_ifinit(&sc->arpcom, ifa);
   1120       1.18  augustss #endif
   1121        1.1  augustss 			break;
   1122        1.1  augustss #endif /* INET */
   1123        1.1  augustss 		}
   1124        1.1  augustss 		break;
   1125        1.1  augustss 
   1126        1.1  augustss 	case SIOCSIFMTU:
   1127        1.1  augustss 		if (ifr->ifr_mtu > ETHERMTU)
   1128        1.1  augustss 			error = EINVAL;
   1129        1.1  augustss 		else
   1130        1.1  augustss 			ifp->if_mtu = ifr->ifr_mtu;
   1131        1.1  augustss 		break;
   1132  1.48.10.2     itohy #endif
   1133        1.1  augustss 
   1134        1.1  augustss 	case SIOCSIFFLAGS:
   1135        1.1  augustss 		if (ifp->if_flags & IFF_UP) {
   1136        1.1  augustss 			if (ifp->if_flags & IFF_RUNNING &&
   1137        1.1  augustss 			    ifp->if_flags & IFF_PROMISC &&
   1138        1.1  augustss 			    !(sc->cue_if_flags & IFF_PROMISC)) {
   1139        1.1  augustss 				CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
   1140        1.1  augustss 				cue_setmulti(sc);
   1141        1.1  augustss 			} else if (ifp->if_flags & IFF_RUNNING &&
   1142        1.1  augustss 			    !(ifp->if_flags & IFF_PROMISC) &&
   1143        1.1  augustss 			    sc->cue_if_flags & IFF_PROMISC) {
   1144        1.1  augustss 				CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
   1145        1.1  augustss 				cue_setmulti(sc);
   1146        1.1  augustss 			} else if (!(ifp->if_flags & IFF_RUNNING))
   1147  1.48.10.2     itohy 				cue_init(ifp);
   1148        1.1  augustss 		} else {
   1149        1.1  augustss 			if (ifp->if_flags & IFF_RUNNING)
   1150  1.48.10.2     itohy 				cue_stop(ifp, 0);
   1151        1.1  augustss 		}
   1152        1.1  augustss 		sc->cue_if_flags = ifp->if_flags;
   1153        1.1  augustss 		error = 0;
   1154        1.1  augustss 		break;
   1155  1.48.10.2     itohy #if 0
   1156        1.1  augustss 	case SIOCADDMULTI:
   1157        1.1  augustss 	case SIOCDELMULTI:
   1158        1.1  augustss 		cue_setmulti(sc);
   1159        1.1  augustss 		error = 0;
   1160        1.1  augustss 		break;
   1161  1.48.10.2     itohy #endif
   1162        1.1  augustss 	default:
   1163  1.48.10.2     itohy 		error = ether_ioctl(ifp, command, data);
   1164  1.48.10.2     itohy 		if (error == ENETRESET) {
   1165  1.48.10.2     itohy 			/*
   1166  1.48.10.2     itohy 			 * Multicast list has changed; set the hardware
   1167  1.48.10.2     itohy 			 * filter accordingly.
   1168  1.48.10.2     itohy 			 */
   1169  1.48.10.2     itohy 			if (ifp->if_flags & IFF_RUNNING)
   1170  1.48.10.2     itohy 				cue_setmulti(sc);
   1171  1.48.10.2     itohy 			error = 0;
   1172  1.48.10.2     itohy 		}
   1173        1.1  augustss 		break;
   1174        1.1  augustss 	}
   1175        1.1  augustss 
   1176        1.1  augustss 	splx(s);
   1177        1.1  augustss 
   1178        1.1  augustss 	return (error);
   1179        1.1  augustss }
   1180        1.1  augustss 
   1181       1.17  augustss Static void
   1182       1.23  augustss cue_watchdog(struct ifnet *ifp)
   1183        1.1  augustss {
   1184        1.1  augustss 	struct cue_softc	*sc = ifp->if_softc;
   1185  1.48.10.2     itohy 	struct ue_chain		*c;
   1186       1.29  augustss 	usbd_status		stat;
   1187       1.29  augustss 	int			s;
   1188        1.1  augustss 
   1189       1.39  augustss 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev),__func__));
   1190        1.4  augustss 
   1191        1.4  augustss 	if (sc->cue_dying)
   1192        1.4  augustss 		return;
   1193        1.1  augustss 
   1194        1.1  augustss 	ifp->if_oerrors++;
   1195        1.1  augustss 	printf("%s: watchdog timeout\n", USBDEVNAME(sc->cue_dev));
   1196        1.1  augustss 
   1197       1.29  augustss 	s = splusb();
   1198       1.29  augustss 	c = &sc->cue_cdata.cue_tx_chain[0];
   1199  1.48.10.2     itohy 	usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
   1200  1.48.10.2     itohy 	cue_txeof(c->ue_xfer, c, stat);
   1201        1.1  augustss 
   1202       1.27   thorpej 	if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
   1203        1.1  augustss 		cue_start(ifp);
   1204       1.29  augustss 	splx(s);
   1205        1.1  augustss }
   1206        1.1  augustss 
   1207        1.1  augustss /*
   1208        1.1  augustss  * Stop the adapter and free any mbufs allocated to the
   1209        1.1  augustss  * RX and TX lists.
   1210        1.1  augustss  */
   1211       1.17  augustss Static void
   1212  1.48.10.2     itohy cue_stop(struct ifnet *ifp, int disable)
   1213        1.1  augustss {
   1214  1.48.10.2     itohy 	struct cue_softc	*sc = ifp->if_softc;
   1215        1.1  augustss 	usbd_status		err;
   1216        1.1  augustss 
   1217       1.39  augustss 	DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev),__func__));
   1218       1.15  augustss 
   1219        1.1  augustss 	ifp = GET_IFP(sc);
   1220        1.1  augustss 	ifp->if_timer = 0;
   1221        1.1  augustss 
   1222       1.15  augustss 	cue_csr_write_1(sc, CUE_ETHCTL, 0);
   1223        1.1  augustss 	cue_reset(sc);
   1224       1.16  augustss 	usb_uncallout(sc->cue_stat_ch, cue_tick, sc);
   1225        1.1  augustss 
   1226        1.1  augustss 	/* Stop transfers. */
   1227        1.1  augustss 	if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
   1228        1.1  augustss 		err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
   1229        1.1  augustss 		if (err) {
   1230        1.1  augustss 			printf("%s: abort rx pipe failed: %s\n",
   1231        1.1  augustss 			USBDEVNAME(sc->cue_dev), usbd_errstr(err));
   1232        1.1  augustss 		}
   1233        1.1  augustss 	}
   1234        1.1  augustss 
   1235        1.1  augustss 	if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
   1236        1.1  augustss 		err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
   1237        1.1  augustss 		if (err) {
   1238        1.1  augustss 			printf("%s: abort tx pipe failed: %s\n",
   1239        1.1  augustss 			USBDEVNAME(sc->cue_dev), usbd_errstr(err));
   1240        1.1  augustss 		}
   1241        1.1  augustss 	}
   1242        1.1  augustss 
   1243        1.1  augustss 	if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
   1244        1.1  augustss 		err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
   1245        1.1  augustss 		if (err) {
   1246        1.1  augustss 			printf("%s: abort intr pipe failed: %s\n",
   1247        1.1  augustss 			USBDEVNAME(sc->cue_dev), usbd_errstr(err));
   1248        1.1  augustss 		}
   1249        1.1  augustss 	}
   1250        1.1  augustss 
   1251  1.48.10.2     itohy 	/* Free RX/TX resources. */
   1252  1.48.10.2     itohy 	usb_ether_rx_list_free(sc->cue_cdata.cue_rx_chain, CUE_RX_LIST_CNT);
   1253  1.48.10.2     itohy 	usb_ether_tx_list_free(sc->cue_cdata.cue_tx_chain, CUE_TX_LIST_CNT);
   1254  1.48.10.2     itohy 
   1255  1.48.10.2     itohy 	/* Close pipes. */
   1256  1.48.10.2     itohy 	if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
   1257  1.48.10.2     itohy 		err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
   1258  1.48.10.2     itohy 		if (err) {
   1259  1.48.10.2     itohy 			printf("%s: close rx pipe failed: %s\n",
   1260  1.48.10.2     itohy 			USBDEVNAME(sc->cue_dev), usbd_errstr(err));
   1261        1.1  augustss 		}
   1262  1.48.10.2     itohy 		sc->cue_ep[CUE_ENDPT_RX] = NULL;
   1263        1.1  augustss 	}
   1264  1.48.10.2     itohy 	if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
   1265  1.48.10.2     itohy 		err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
   1266  1.48.10.2     itohy 		if (err) {
   1267  1.48.10.2     itohy 			printf("%s: close tx pipe failed: %s\n",
   1268  1.48.10.2     itohy 			    USBDEVNAME(sc->cue_dev), usbd_errstr(err));
   1269        1.1  augustss 		}
   1270  1.48.10.2     itohy 		sc->cue_ep[CUE_ENDPT_TX] = NULL;
   1271  1.48.10.2     itohy 	}
   1272  1.48.10.2     itohy 	if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
   1273  1.48.10.2     itohy 		err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
   1274  1.48.10.2     itohy 		if (err) {
   1275  1.48.10.2     itohy 			printf("%s: close intr pipe failed: %s\n",
   1276  1.48.10.2     itohy 			    USBDEVNAME(sc->cue_dev), usbd_errstr(err));
   1277        1.1  augustss 		}
   1278  1.48.10.2     itohy 		sc->cue_ep[CUE_ENDPT_INTR] = NULL;
   1279        1.1  augustss 	}
   1280        1.1  augustss 
   1281        1.1  augustss 	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
   1282        1.1  augustss }
   1283