Home | History | Annotate | Line # | Download | only in usb
if_cdce.c revision 1.38.18.1
      1  1.38.18.1     skrll /*	$NetBSD: if_cdce.c,v 1.38.18.1 2016/09/06 20:33:08 skrll Exp $ */
      2        1.1  augustss 
      3        1.1  augustss /*
      4        1.1  augustss  * Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul <wpaul (at) windriver.com>
      5        1.1  augustss  * Copyright (c) 2003 Craig Boston
      6        1.1  augustss  * Copyright (c) 2004 Daniel Hartmeier
      7        1.1  augustss  * All rights reserved.
      8        1.1  augustss  *
      9        1.1  augustss  * Redistribution and use in source and binary forms, with or without
     10        1.1  augustss  * modification, are permitted provided that the following conditions
     11        1.1  augustss  * are met:
     12        1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     13        1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     14        1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     15        1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     16        1.1  augustss  *    documentation and/or other materials provided with the distribution.
     17        1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     18        1.1  augustss  *    must display the following acknowledgement:
     19        1.1  augustss  *	This product includes software developed by Bill Paul.
     20        1.1  augustss  * 4. Neither the name of the author nor the names of any co-contributors
     21        1.1  augustss  *    may be used to endorse or promote products derived from this software
     22        1.1  augustss  *    without specific prior written permission.
     23        1.1  augustss  *
     24        1.1  augustss  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
     25        1.1  augustss  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26        1.1  augustss  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27        1.1  augustss  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul, THE VOICES IN HIS HEAD OR
     28        1.1  augustss  * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     29        1.1  augustss  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     30        1.1  augustss  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     31        1.1  augustss  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     32        1.1  augustss  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     33        1.1  augustss  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     34        1.1  augustss  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35        1.1  augustss  */
     36        1.1  augustss 
     37        1.1  augustss /*
     38        1.1  augustss  * USB Communication Device Class (Ethernet Networking Control Model)
     39        1.1  augustss  * http://www.usb.org/developers/devclass_docs/usbcdc11.pdf
     40        1.1  augustss  *
     41        1.1  augustss  */
     42        1.1  augustss 
     43        1.1  augustss #include <sys/cdefs.h>
     44  1.38.18.1     skrll __KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.38.18.1 2016/09/06 20:33:08 skrll Exp $");
     45       1.36       mrg 
     46       1.38  christos #ifdef _KERNEL_OPT
     47       1.18        ws #include "opt_inet.h"
     48       1.18        ws #endif
     49        1.1  augustss 
     50        1.1  augustss #include <sys/param.h>
     51        1.1  augustss #include <sys/systm.h>
     52        1.1  augustss #include <sys/sockio.h>
     53        1.1  augustss #include <sys/mbuf.h>
     54        1.1  augustss #include <sys/kernel.h>
     55        1.1  augustss #include <sys/socket.h>
     56        1.1  augustss #include <sys/device.h>
     57        1.1  augustss 
     58        1.1  augustss #include <sys/rnd.h>
     59        1.1  augustss 
     60        1.1  augustss #include <net/if.h>
     61        1.1  augustss #include <net/if_arp.h>
     62        1.1  augustss #include <net/if_dl.h>
     63        1.1  augustss #include <net/if_media.h>
     64        1.1  augustss 
     65        1.1  augustss #include <net/bpf.h>
     66        1.1  augustss 
     67        1.1  augustss #include <net/if_ether.h>
     68        1.1  augustss #ifdef INET
     69        1.1  augustss #include <netinet/in.h>
     70        1.1  augustss #include <netinet/if_inarp.h>
     71        1.1  augustss #endif
     72        1.1  augustss 
     73        1.1  augustss 
     74        1.1  augustss 
     75        1.1  augustss #include <dev/usb/usb.h>
     76        1.1  augustss #include <dev/usb/usbdi.h>
     77        1.1  augustss #include <dev/usb/usbdi_util.h>
     78        1.1  augustss #include <dev/usb/usbdevs.h>
     79        1.1  augustss #include <dev/usb/usbcdc.h>
     80        1.1  augustss 
     81        1.1  augustss #include <dev/usb/if_cdcereg.h>
     82        1.1  augustss 
     83        1.1  augustss Static int	 cdce_tx_list_init(struct cdce_softc *);
     84        1.1  augustss Static int	 cdce_rx_list_init(struct cdce_softc *);
     85        1.1  augustss Static int	 cdce_newbuf(struct cdce_softc *, struct cdce_chain *,
     86        1.1  augustss 		    struct mbuf *);
     87        1.1  augustss Static int	 cdce_encap(struct cdce_softc *, struct mbuf *, int);
     88  1.38.18.1     skrll Static void	 cdce_rxeof(struct usbd_xfer *, void *, usbd_status);
     89  1.38.18.1     skrll Static void	 cdce_txeof(struct usbd_xfer *, void *, usbd_status);
     90        1.1  augustss Static void	 cdce_start(struct ifnet *);
     91       1.13  christos Static int	 cdce_ioctl(struct ifnet *, u_long, void *);
     92        1.1  augustss Static void	 cdce_init(void *);
     93        1.1  augustss Static void	 cdce_watchdog(struct ifnet *);
     94        1.1  augustss Static void	 cdce_stop(struct cdce_softc *);
     95        1.1  augustss 
     96        1.1  augustss Static const struct cdce_type cdce_devs[] = {
     97       1.33   msaitoh   {{ USB_VENDOR_ACERLABS, USB_PRODUCT_ACERLABS_M5632 }, CDCE_NO_UNION },
     98       1.33   msaitoh   {{ USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_IPAQLINUX }, CDCE_NO_UNION },
     99       1.33   msaitoh   {{ USB_VENDOR_GMATE, USB_PRODUCT_GMATE_YP3X00 }, CDCE_NO_UNION },
    100       1.33   msaitoh   {{ USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN }, CDCE_ZAURUS | CDCE_NO_UNION },
    101       1.33   msaitoh   {{ USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN2 }, CDCE_ZAURUS | CDCE_NO_UNION },
    102        1.1  augustss   {{ USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2501 }, CDCE_NO_UNION },
    103        1.1  augustss   {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5500 }, CDCE_ZAURUS },
    104        1.1  augustss   {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_A300 }, CDCE_ZAURUS | CDCE_NO_UNION },
    105        1.1  augustss   {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5600 }, CDCE_ZAURUS | CDCE_NO_UNION },
    106        1.1  augustss   {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_C700 }, CDCE_ZAURUS | CDCE_NO_UNION },
    107        1.1  augustss   {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_C750 }, CDCE_ZAURUS | CDCE_NO_UNION },
    108        1.1  augustss };
    109       1.33   msaitoh #define cdce_lookup(v, p) \
    110       1.33   msaitoh 	((const struct cdce_type *)usb_lookup(cdce_devs, v, p))
    111        1.1  augustss 
    112       1.23    dyoung int cdce_match(device_t, cfdata_t, void *);
    113       1.23    dyoung void cdce_attach(device_t, device_t, void *);
    114       1.23    dyoung int cdce_detach(device_t, int);
    115       1.23    dyoung int cdce_activate(device_t, enum devact);
    116       1.23    dyoung extern struct cfdriver cdce_cd;
    117       1.23    dyoung CFATTACH_DECL_NEW(cdce, sizeof(struct cdce_softc), cdce_match, cdce_attach,
    118       1.23    dyoung     cdce_detach, cdce_activate);
    119        1.1  augustss 
    120       1.23    dyoung int
    121       1.23    dyoung cdce_match(device_t parent, cfdata_t match, void *aux)
    122        1.1  augustss {
    123  1.38.18.1     skrll 	struct usbif_attach_arg *uiaa = aux;
    124        1.1  augustss 
    125  1.38.18.1     skrll 	if (cdce_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product) != NULL)
    126  1.38.18.1     skrll 		return UMATCH_VENDOR_PRODUCT;
    127        1.1  augustss 
    128  1.38.18.1     skrll 	if (uiaa->uiaa_class == UICLASS_CDC && uiaa->uiaa_subclass ==
    129        1.1  augustss 	    UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL)
    130  1.38.18.1     skrll 		return UMATCH_IFACECLASS_GENERIC;
    131        1.1  augustss 
    132  1.38.18.1     skrll 	return UMATCH_NONE;
    133        1.1  augustss }
    134        1.1  augustss 
    135       1.23    dyoung void
    136       1.23    dyoung cdce_attach(device_t parent, device_t self, void *aux)
    137        1.1  augustss {
    138       1.23    dyoung 	struct cdce_softc *sc = device_private(self);
    139  1.38.18.1     skrll 	struct usbif_attach_arg *uiaa = aux;
    140       1.33   msaitoh 	char				*devinfop;
    141        1.1  augustss 	int				 s;
    142        1.1  augustss 	struct ifnet			*ifp;
    143  1.38.18.1     skrll 	struct usbd_device	        *dev = uiaa->uiaa_device;
    144        1.1  augustss 	const struct cdce_type		*t;
    145        1.1  augustss 	usb_interface_descriptor_t	*id;
    146        1.1  augustss 	usb_endpoint_descriptor_t	*ed;
    147        1.2  augustss 	const usb_cdc_union_descriptor_t *ud;
    148       1.22      tron 	usb_config_descriptor_t		*cd;
    149        1.1  augustss 	int				 data_ifcno;
    150       1.22      tron 	int				 i, j, numalts;
    151        1.1  augustss 	u_char				 eaddr[ETHER_ADDR_LEN];
    152        1.2  augustss 	const usb_cdc_ethernet_descriptor_t *ue;
    153        1.5  augustss 	char				 eaddr_str[USB_MAX_ENCODED_STRING_LEN];
    154        1.1  augustss 
    155       1.25    plunky 	sc->cdce_dev = self;
    156       1.25    plunky 
    157       1.23    dyoung 	aprint_naive("\n");
    158       1.23    dyoung 	aprint_normal("\n");
    159       1.25    plunky 
    160       1.25    plunky 	devinfop = usbd_devinfo_alloc(dev, 0);
    161       1.16      cube 	aprint_normal_dev(self, "%s\n", devinfop);
    162        1.6  augustss 	usbd_devinfo_free(devinfop);
    163        1.1  augustss 
    164  1.38.18.1     skrll 	sc->cdce_udev = uiaa->uiaa_device;
    165  1.38.18.1     skrll 	sc->cdce_ctl_iface = uiaa->uiaa_iface;
    166        1.1  augustss 
    167  1.38.18.1     skrll 	t = cdce_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product);
    168        1.1  augustss 	if (t)
    169        1.1  augustss 		sc->cdce_flags = t->cdce_flags;
    170        1.1  augustss 
    171        1.1  augustss 	if (sc->cdce_flags & CDCE_NO_UNION)
    172        1.1  augustss 		sc->cdce_data_iface = sc->cdce_ctl_iface;
    173        1.1  augustss 	else {
    174        1.7  christos 		ud = (const usb_cdc_union_descriptor_t *)usb_find_desc(sc->cdce_udev,
    175        1.2  augustss 		    UDESC_CS_INTERFACE, UDESCSUB_CDC_UNION);
    176        1.1  augustss 		if (ud == NULL) {
    177       1.16      cube 			aprint_error_dev(self, "no union descriptor\n");
    178       1.24    dyoung 			return;
    179        1.1  augustss 		}
    180        1.1  augustss 		data_ifcno = ud->bSlaveInterface[0];
    181        1.1  augustss 
    182  1.38.18.1     skrll 		for (i = 0; i < uiaa->uiaa_nifaces; i++) {
    183  1.38.18.1     skrll 			if (uiaa->uiaa_ifaces[i] != NULL) {
    184        1.1  augustss 				id = usbd_get_interface_descriptor(
    185  1.38.18.1     skrll 				    uiaa->uiaa_ifaces[i]);
    186        1.1  augustss 				if (id != NULL && id->bInterfaceNumber ==
    187        1.1  augustss 				    data_ifcno) {
    188  1.38.18.1     skrll 					sc->cdce_data_iface = uiaa->uiaa_ifaces[i];
    189  1.38.18.1     skrll 					uiaa->uiaa_ifaces[i] = NULL;
    190        1.1  augustss 				}
    191        1.1  augustss 			}
    192        1.1  augustss 		}
    193        1.1  augustss 	}
    194        1.1  augustss 
    195        1.1  augustss 	if (sc->cdce_data_iface == NULL) {
    196       1.16      cube 		aprint_error_dev(self, "no data interface\n");
    197       1.24    dyoung 		return;
    198        1.1  augustss 	}
    199        1.1  augustss 
    200       1.22      tron 	/*
    201       1.22      tron 	 * <quote>
    202       1.22      tron 	 *  The Data Class interface of a networking device shall have a minimum
    203       1.22      tron 	 *  of two interface settings. The first setting (the default interface
    204       1.22      tron 	 *  setting) includes no endpoints and therefore no networking traffic is
    205       1.22      tron 	 *  exchanged whenever the default interface setting is selected. One or
    206       1.22      tron 	 *  more additional interface settings are used for normal operation, and
    207       1.22      tron 	 *  therefore each includes a pair of endpoints (one IN, and one OUT) to
    208       1.22      tron 	 *  exchange network traffic. Select an alternate interface setting to
    209       1.22      tron 	 *  initialize the network aspects of the device and to enable the
    210       1.22      tron 	 *  exchange of network traffic.
    211       1.22      tron 	 * </quote>
    212       1.22      tron 	 *
    213       1.22      tron 	 * Some devices, most notably cable modems, include interface settings
    214       1.22      tron 	 * that have no IN or OUT endpoint, therefore loop through the list of all
    215       1.22      tron 	 * available interface settings looking for one with both IN and OUT
    216       1.22      tron 	 * endpoints.
    217       1.22      tron 	 */
    218        1.1  augustss 	id = usbd_get_interface_descriptor(sc->cdce_data_iface);
    219       1.22      tron 	cd = usbd_get_config_descriptor(sc->cdce_udev);
    220       1.22      tron 	numalts = usbd_get_no_alts(cd, id->bInterfaceNumber);
    221       1.22      tron 
    222       1.22      tron 	for (j = 0; j < numalts; j++) {
    223       1.22      tron 		if (usbd_set_interface(sc->cdce_data_iface, j)) {
    224       1.22      tron 			aprint_error_dev(sc->cdce_dev,
    225       1.22      tron 					"setting alternate interface failed\n");
    226       1.24    dyoung 			return;
    227        1.1  augustss 		}
    228       1.22      tron 		/* Find endpoints. */
    229       1.22      tron 		id = usbd_get_interface_descriptor(sc->cdce_data_iface);
    230       1.22      tron 		sc->cdce_bulkin_no = sc->cdce_bulkout_no = -1;
    231       1.22      tron 		for (i = 0; i < id->bNumEndpoints; i++) {
    232       1.22      tron 			ed = usbd_interface2endpoint_descriptor(sc->cdce_data_iface, i);
    233       1.22      tron 			if (!ed) {
    234       1.22      tron 				aprint_error_dev(self,
    235       1.22      tron 						"could not read endpoint descriptor\n");
    236       1.24    dyoung 				return;
    237       1.22      tron 			}
    238       1.22      tron 			if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    239       1.22      tron 					UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    240       1.22      tron 				sc->cdce_bulkin_no = ed->bEndpointAddress;
    241       1.22      tron 			} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
    242       1.22      tron 					UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    243       1.22      tron 				sc->cdce_bulkout_no = ed->bEndpointAddress;
    244       1.22      tron 			} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    245       1.22      tron 					UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
    246       1.22      tron 				/* XXX: CDC spec defines an interrupt pipe, but it is not
    247       1.22      tron 				 * needed for simple host-to-host applications. */
    248       1.22      tron 			} else {
    249       1.22      tron 				aprint_error_dev(self, "unexpected endpoint\n");
    250       1.22      tron 			}
    251        1.1  augustss 		}
    252       1.22      tron 		/* If we found something, try and use it... */
    253       1.22      tron 		if ((sc->cdce_bulkin_no != -1) && (sc->cdce_bulkout_no != -1))
    254       1.22      tron 			break;
    255        1.1  augustss 	}
    256        1.1  augustss 
    257        1.1  augustss 	if (sc->cdce_bulkin_no == -1) {
    258       1.16      cube 		aprint_error_dev(self, "could not find data bulk in\n");
    259       1.24    dyoung 		return;
    260        1.1  augustss 	}
    261        1.1  augustss 	if (sc->cdce_bulkout_no == -1 ) {
    262       1.16      cube 		aprint_error_dev(self, "could not find data bulk out\n");
    263       1.24    dyoung 		return;
    264        1.1  augustss 	}
    265        1.1  augustss 
    266        1.7  christos 	ue = (const usb_cdc_ethernet_descriptor_t *)usb_find_desc(dev,
    267       1.30  jakllsch 	    UDESC_CS_INTERFACE, UDESCSUB_CDC_ENF);
    268       1.30  jakllsch 	if (!ue || usbd_get_string(dev, ue->iMacAddress, eaddr_str) ||
    269       1.30  jakllsch 	    ether_aton_r(eaddr, sizeof(eaddr), eaddr_str)) {
    270       1.16      cube 		aprint_normal_dev(self, "faking address\n");
    271        1.2  augustss 		eaddr[0]= 0x2a;
    272       1.30  jakllsch 		memcpy(&eaddr[1], &hardclock_ticks, sizeof(uint32_t));
    273       1.30  jakllsch 		eaddr[5] = (uint8_t)(device_unit(sc->cdce_dev));
    274        1.2  augustss 	}
    275        1.2  augustss 
    276        1.1  augustss 	s = splnet();
    277        1.1  augustss 
    278       1.16      cube 	aprint_normal_dev(self, "address %s\n", ether_sprintf(eaddr));
    279        1.1  augustss 
    280        1.1  augustss 	ifp = GET_IFP(sc);
    281        1.1  augustss 	ifp->if_softc = sc;
    282        1.1  augustss 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
    283        1.1  augustss 	ifp->if_ioctl = cdce_ioctl;
    284        1.1  augustss 	ifp->if_start = cdce_start;
    285        1.1  augustss 	ifp->if_watchdog = cdce_watchdog;
    286       1.24    dyoung 	strncpy(ifp->if_xname, device_xname(sc->cdce_dev), IFNAMSIZ);
    287        1.1  augustss 
    288        1.1  augustss 	IFQ_SET_READY(&ifp->if_snd);
    289        1.1  augustss 
    290        1.1  augustss 	if_attach(ifp);
    291       1.24    dyoung 	ether_ifattach(ifp, eaddr);
    292        1.1  augustss 
    293        1.1  augustss 	sc->cdce_attached = 1;
    294        1.1  augustss 	splx(s);
    295        1.1  augustss 
    296        1.1  augustss 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->cdce_udev,
    297       1.24    dyoung 	    sc->cdce_dev);
    298        1.1  augustss 
    299       1.31  jakllsch 	if (!pmf_device_register(self, NULL, NULL))
    300       1.31  jakllsch 		aprint_error_dev(self, "couldn't establish power handler\n");
    301       1.31  jakllsch 
    302       1.24    dyoung 	return;
    303        1.1  augustss }
    304        1.1  augustss 
    305       1.23    dyoung int
    306       1.23    dyoung cdce_detach(device_t self, int flags)
    307        1.1  augustss {
    308       1.24    dyoung 	struct cdce_softc *sc = device_private(self);
    309        1.1  augustss 	struct ifnet	*ifp = GET_IFP(sc);
    310        1.1  augustss 	int		 s;
    311        1.1  augustss 
    312       1.37    plunky 	pmf_device_deregister(self);
    313       1.31  jakllsch 
    314        1.1  augustss 	s = splusb();
    315        1.1  augustss 
    316        1.1  augustss 	if (!sc->cdce_attached) {
    317        1.1  augustss 		splx(s);
    318  1.38.18.1     skrll 		return 0;
    319        1.1  augustss 	}
    320        1.1  augustss 
    321        1.1  augustss 	if (ifp->if_flags & IFF_RUNNING)
    322        1.1  augustss 		cdce_stop(sc);
    323        1.1  augustss 
    324        1.1  augustss 	ether_ifdetach(ifp);
    325        1.1  augustss 
    326        1.1  augustss 	if_detach(ifp);
    327        1.1  augustss 
    328        1.1  augustss 	sc->cdce_attached = 0;
    329        1.1  augustss 	splx(s);
    330        1.1  augustss 
    331  1.38.18.1     skrll 	return 0;
    332        1.1  augustss }
    333        1.1  augustss 
    334        1.1  augustss Static void
    335        1.1  augustss cdce_start(struct ifnet *ifp)
    336        1.1  augustss {
    337        1.1  augustss 	struct cdce_softc	*sc = ifp->if_softc;
    338        1.1  augustss 	struct mbuf		*m_head = NULL;
    339        1.1  augustss 
    340        1.1  augustss 	if (sc->cdce_dying || (ifp->if_flags & IFF_OACTIVE))
    341        1.1  augustss 		return;
    342        1.1  augustss 
    343        1.1  augustss 	IFQ_POLL(&ifp->if_snd, m_head);
    344        1.1  augustss 	if (m_head == NULL)
    345        1.1  augustss 		return;
    346        1.1  augustss 
    347        1.1  augustss 	if (cdce_encap(sc, m_head, 0)) {
    348        1.1  augustss 		ifp->if_flags |= IFF_OACTIVE;
    349        1.1  augustss 		return;
    350        1.1  augustss 	}
    351        1.1  augustss 
    352        1.1  augustss 	IFQ_DEQUEUE(&ifp->if_snd, m_head);
    353        1.1  augustss 
    354       1.28     joerg 	bpf_mtap(ifp, m_head);
    355        1.1  augustss 
    356        1.1  augustss 	ifp->if_flags |= IFF_OACTIVE;
    357        1.1  augustss 
    358        1.1  augustss 	ifp->if_timer = 6;
    359        1.1  augustss }
    360        1.1  augustss 
    361        1.1  augustss Static int
    362        1.1  augustss cdce_encap(struct cdce_softc *sc, struct mbuf *m, int idx)
    363        1.1  augustss {
    364        1.1  augustss 	struct cdce_chain	*c;
    365        1.1  augustss 	usbd_status		 err;
    366        1.1  augustss 	int			 extra = 0;
    367        1.1  augustss 
    368        1.1  augustss 	c = &sc->cdce_cdata.cdce_tx_chain[idx];
    369        1.1  augustss 
    370        1.1  augustss 	m_copydata(m, 0, m->m_pkthdr.len, c->cdce_buf);
    371        1.1  augustss 	if (sc->cdce_flags & CDCE_ZAURUS) {
    372        1.1  augustss 		/* Zaurus wants a 32-bit CRC appended to every frame */
    373       1.30  jakllsch 		uint32_t crc;
    374        1.1  augustss 
    375       1.30  jakllsch 		crc = htole32(~ether_crc32_le(c->cdce_buf, m->m_pkthdr.len));
    376       1.30  jakllsch 		memcpy(c->cdce_buf + m->m_pkthdr.len, &crc, sizeof(crc));
    377       1.30  jakllsch 		extra = sizeof(crc);
    378        1.1  augustss 	}
    379        1.1  augustss 	c->cdce_mbuf = m;
    380        1.1  augustss 
    381  1.38.18.1     skrll 	usbd_setup_xfer(c->cdce_xfer, c, c->cdce_buf, m->m_pkthdr.len + extra,
    382  1.38.18.1     skrll 	    USBD_FORCE_SHORT_XFER, 10000, cdce_txeof);
    383        1.1  augustss 	err = usbd_transfer(c->cdce_xfer);
    384        1.1  augustss 	if (err != USBD_IN_PROGRESS) {
    385        1.1  augustss 		cdce_stop(sc);
    386  1.38.18.1     skrll 		return EIO;
    387        1.1  augustss 	}
    388        1.1  augustss 
    389        1.1  augustss 	sc->cdce_cdata.cdce_tx_cnt++;
    390        1.1  augustss 
    391  1.38.18.1     skrll 	return 0;
    392        1.1  augustss }
    393        1.1  augustss 
    394        1.1  augustss Static void
    395        1.1  augustss cdce_stop(struct cdce_softc *sc)
    396        1.1  augustss {
    397        1.1  augustss 	usbd_status	 err;
    398        1.1  augustss 	struct ifnet	*ifp = GET_IFP(sc);
    399        1.1  augustss 	int		 i;
    400        1.1  augustss 
    401        1.1  augustss 	ifp->if_timer = 0;
    402        1.1  augustss 
    403        1.1  augustss 	if (sc->cdce_bulkin_pipe != NULL) {
    404        1.1  augustss 		err = usbd_abort_pipe(sc->cdce_bulkin_pipe);
    405        1.1  augustss 		if (err)
    406        1.1  augustss 			printf("%s: abort rx pipe failed: %s\n",
    407       1.24    dyoung 			    device_xname(sc->cdce_dev), usbd_errstr(err));
    408        1.1  augustss 	}
    409        1.1  augustss 
    410        1.1  augustss 	if (sc->cdce_bulkout_pipe != NULL) {
    411        1.1  augustss 		err = usbd_abort_pipe(sc->cdce_bulkout_pipe);
    412        1.1  augustss 		if (err)
    413        1.1  augustss 			printf("%s: abort tx pipe failed: %s\n",
    414       1.24    dyoung 			    device_xname(sc->cdce_dev), usbd_errstr(err));
    415        1.1  augustss 	}
    416        1.1  augustss 
    417        1.1  augustss 	for (i = 0; i < CDCE_RX_LIST_CNT; i++) {
    418        1.1  augustss 		if (sc->cdce_cdata.cdce_rx_chain[i].cdce_mbuf != NULL) {
    419        1.1  augustss 			m_freem(sc->cdce_cdata.cdce_rx_chain[i].cdce_mbuf);
    420        1.1  augustss 			sc->cdce_cdata.cdce_rx_chain[i].cdce_mbuf = NULL;
    421        1.1  augustss 		}
    422        1.1  augustss 		if (sc->cdce_cdata.cdce_rx_chain[i].cdce_xfer != NULL) {
    423  1.38.18.1     skrll 			usbd_destroy_xfer
    424       1.33   msaitoh 			    (sc->cdce_cdata.cdce_rx_chain[i].cdce_xfer);
    425        1.1  augustss 			sc->cdce_cdata.cdce_rx_chain[i].cdce_xfer = NULL;
    426        1.1  augustss 		}
    427        1.1  augustss 	}
    428        1.1  augustss 
    429        1.1  augustss 	for (i = 0; i < CDCE_TX_LIST_CNT; i++) {
    430        1.1  augustss 		if (sc->cdce_cdata.cdce_tx_chain[i].cdce_mbuf != NULL) {
    431        1.1  augustss 			m_freem(sc->cdce_cdata.cdce_tx_chain[i].cdce_mbuf);
    432        1.1  augustss 			sc->cdce_cdata.cdce_tx_chain[i].cdce_mbuf = NULL;
    433        1.1  augustss 		}
    434        1.1  augustss 		if (sc->cdce_cdata.cdce_tx_chain[i].cdce_xfer != NULL) {
    435  1.38.18.1     skrll 			usbd_destroy_xfer(
    436       1.33   msaitoh 				sc->cdce_cdata.cdce_tx_chain[i].cdce_xfer);
    437        1.1  augustss 			sc->cdce_cdata.cdce_tx_chain[i].cdce_xfer = NULL;
    438        1.1  augustss 		}
    439        1.1  augustss 	}
    440        1.1  augustss 
    441  1.38.18.1     skrll 	if (sc->cdce_bulkin_pipe != NULL) {
    442  1.38.18.1     skrll 		err = usbd_close_pipe(sc->cdce_bulkin_pipe);
    443  1.38.18.1     skrll 		if (err)
    444  1.38.18.1     skrll 			printf("%s: close rx pipe failed: %s\n",
    445  1.38.18.1     skrll 			    device_xname(sc->cdce_dev), usbd_errstr(err));
    446  1.38.18.1     skrll 		sc->cdce_bulkin_pipe = NULL;
    447  1.38.18.1     skrll 	}
    448  1.38.18.1     skrll 
    449  1.38.18.1     skrll 	if (sc->cdce_bulkout_pipe != NULL) {
    450  1.38.18.1     skrll 		err = usbd_close_pipe(sc->cdce_bulkout_pipe);
    451  1.38.18.1     skrll 		if (err)
    452  1.38.18.1     skrll 			printf("%s: close tx pipe failed: %s\n",
    453  1.38.18.1     skrll 			    device_xname(sc->cdce_dev), usbd_errstr(err));
    454  1.38.18.1     skrll 		sc->cdce_bulkout_pipe = NULL;
    455  1.38.18.1     skrll 	}
    456  1.38.18.1     skrll 
    457        1.1  augustss 	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
    458        1.1  augustss }
    459        1.1  augustss 
    460        1.1  augustss Static int
    461       1.13  christos cdce_ioctl(struct ifnet *ifp, u_long command, void *data)
    462        1.1  augustss {
    463        1.1  augustss 	struct cdce_softc	*sc = ifp->if_softc;
    464        1.1  augustss 	struct ifaddr		*ifa = (struct ifaddr *)data;
    465        1.1  augustss 	struct ifreq		*ifr = (struct ifreq *)data;
    466        1.1  augustss 	int			 s, error = 0;
    467        1.1  augustss 
    468        1.1  augustss 	if (sc->cdce_dying)
    469  1.38.18.1     skrll 		return EIO;
    470        1.1  augustss 
    471        1.1  augustss 	s = splnet();
    472        1.1  augustss 
    473        1.1  augustss 	switch(command) {
    474       1.19    dyoung 	case SIOCINITIFADDR:
    475        1.1  augustss 		ifp->if_flags |= IFF_UP;
    476        1.1  augustss 		cdce_init(sc);
    477        1.1  augustss 		switch (ifa->ifa_addr->sa_family) {
    478        1.1  augustss #ifdef INET
    479        1.1  augustss 		case AF_INET:
    480        1.1  augustss 			arp_ifinit(ifp, ifa);
    481        1.1  augustss 			break;
    482        1.1  augustss #endif /* INET */
    483        1.1  augustss 		}
    484        1.1  augustss 		break;
    485        1.1  augustss 
    486        1.1  augustss 	case SIOCSIFMTU:
    487       1.15    dyoung 		if (ifr->ifr_mtu < ETHERMIN || ifr->ifr_mtu > ETHERMTU)
    488        1.1  augustss 			error = EINVAL;
    489       1.15    dyoung 		else if ((error = ifioctl_common(ifp, command, data)) == ENETRESET)
    490       1.15    dyoung 			error = 0;
    491        1.1  augustss 		break;
    492        1.1  augustss 
    493        1.1  augustss 	case SIOCSIFFLAGS:
    494       1.19    dyoung 		if ((error = ifioctl_common(ifp, command, data)) != 0)
    495       1.19    dyoung 			break;
    496       1.19    dyoung 		/* XXX re-use ether_ioctl() */
    497       1.19    dyoung 		switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
    498       1.19    dyoung 		case IFF_UP:
    499       1.19    dyoung 			cdce_init(sc);
    500       1.19    dyoung 			break;
    501       1.19    dyoung 		case IFF_RUNNING:
    502       1.19    dyoung 			cdce_stop(sc);
    503       1.19    dyoung 			break;
    504       1.19    dyoung 		default:
    505       1.19    dyoung 			break;
    506        1.1  augustss 		}
    507        1.1  augustss 		break;
    508        1.1  augustss 
    509        1.1  augustss 	default:
    510       1.19    dyoung 		error = ether_ioctl(ifp, command, data);
    511        1.1  augustss 		break;
    512        1.1  augustss 	}
    513        1.1  augustss 
    514        1.1  augustss 	splx(s);
    515        1.1  augustss 
    516       1.30  jakllsch 	if (error == ENETRESET)
    517       1.30  jakllsch 		error = 0;
    518       1.30  jakllsch 
    519  1.38.18.1     skrll 	return error;
    520        1.1  augustss }
    521        1.1  augustss 
    522        1.1  augustss Static void
    523        1.1  augustss cdce_watchdog(struct ifnet *ifp)
    524        1.1  augustss {
    525        1.1  augustss 	struct cdce_softc	*sc = ifp->if_softc;
    526        1.1  augustss 
    527        1.1  augustss 	if (sc->cdce_dying)
    528        1.1  augustss 		return;
    529        1.1  augustss 
    530        1.1  augustss 	ifp->if_oerrors++;
    531       1.24    dyoung 	printf("%s: watchdog timeout\n", device_xname(sc->cdce_dev));
    532        1.1  augustss }
    533        1.1  augustss 
    534        1.1  augustss Static void
    535        1.1  augustss cdce_init(void *xsc)
    536        1.1  augustss {
    537        1.1  augustss 	struct cdce_softc	*sc = xsc;
    538        1.1  augustss 	struct ifnet		*ifp = GET_IFP(sc);
    539        1.1  augustss 	struct cdce_chain	*c;
    540        1.1  augustss 	usbd_status		 err;
    541        1.1  augustss 	int			 s, i;
    542        1.1  augustss 
    543        1.1  augustss 	if (ifp->if_flags & IFF_RUNNING)
    544        1.1  augustss 		return;
    545        1.1  augustss 
    546        1.1  augustss 	s = splnet();
    547        1.1  augustss 
    548        1.1  augustss 	/* Maybe set multicast / broadcast here??? */
    549        1.1  augustss 
    550        1.1  augustss 	err = usbd_open_pipe(sc->cdce_data_iface, sc->cdce_bulkin_no,
    551        1.1  augustss 	    USBD_EXCLUSIVE_USE, &sc->cdce_bulkin_pipe);
    552        1.1  augustss 	if (err) {
    553       1.24    dyoung 		printf("%s: open rx pipe failed: %s\n", device_xname(sc->cdce_dev),
    554        1.1  augustss 		    usbd_errstr(err));
    555        1.1  augustss 		splx(s);
    556        1.1  augustss 		return;
    557        1.1  augustss 	}
    558        1.1  augustss 
    559        1.1  augustss 	err = usbd_open_pipe(sc->cdce_data_iface, sc->cdce_bulkout_no,
    560        1.1  augustss 	    USBD_EXCLUSIVE_USE, &sc->cdce_bulkout_pipe);
    561        1.1  augustss 	if (err) {
    562       1.24    dyoung 		printf("%s: open tx pipe failed: %s\n",
    563       1.24    dyoung 		    device_xname(sc->cdce_dev), usbd_errstr(err));
    564        1.1  augustss 		splx(s);
    565        1.1  augustss 		return;
    566        1.1  augustss 	}
    567        1.1  augustss 
    568  1.38.18.1     skrll 	if (cdce_tx_list_init(sc)) {
    569  1.38.18.1     skrll 		printf("%s: tx list init failed\n", device_xname(sc->cdce_dev));
    570  1.38.18.1     skrll 		splx(s);
    571  1.38.18.1     skrll 		return;
    572  1.38.18.1     skrll 	}
    573  1.38.18.1     skrll 
    574  1.38.18.1     skrll 	if (cdce_rx_list_init(sc)) {
    575  1.38.18.1     skrll 		printf("%s: rx list init failed\n", device_xname(sc->cdce_dev));
    576  1.38.18.1     skrll 		splx(s);
    577  1.38.18.1     skrll 		return;
    578  1.38.18.1     skrll 	}
    579  1.38.18.1     skrll 
    580        1.1  augustss 	for (i = 0; i < CDCE_RX_LIST_CNT; i++) {
    581        1.1  augustss 		c = &sc->cdce_cdata.cdce_rx_chain[i];
    582  1.38.18.1     skrll 
    583  1.38.18.1     skrll 		usbd_setup_xfer(c->cdce_xfer, c, c->cdce_buf, CDCE_BUFSZ,
    584  1.38.18.1     skrll 		    USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cdce_rxeof);
    585        1.1  augustss 		usbd_transfer(c->cdce_xfer);
    586        1.1  augustss 	}
    587        1.1  augustss 
    588        1.1  augustss 	ifp->if_flags |= IFF_RUNNING;
    589        1.1  augustss 	ifp->if_flags &= ~IFF_OACTIVE;
    590        1.1  augustss 
    591        1.1  augustss 	splx(s);
    592        1.1  augustss }
    593        1.1  augustss 
    594        1.1  augustss Static int
    595        1.1  augustss cdce_newbuf(struct cdce_softc *sc, struct cdce_chain *c, struct mbuf *m)
    596        1.1  augustss {
    597        1.1  augustss 	struct mbuf	*m_new = NULL;
    598        1.1  augustss 
    599        1.1  augustss 	if (m == NULL) {
    600        1.1  augustss 		MGETHDR(m_new, M_DONTWAIT, MT_DATA);
    601        1.1  augustss 		if (m_new == NULL) {
    602        1.1  augustss 			printf("%s: no memory for rx list "
    603       1.24    dyoung 			    "-- packet dropped!\n", device_xname(sc->cdce_dev));
    604  1.38.18.1     skrll 			return ENOBUFS;
    605        1.1  augustss 		}
    606        1.1  augustss 		MCLGET(m_new, M_DONTWAIT);
    607        1.1  augustss 		if (!(m_new->m_flags & M_EXT)) {
    608        1.1  augustss 			printf("%s: no memory for rx list "
    609       1.24    dyoung 			    "-- packet dropped!\n", device_xname(sc->cdce_dev));
    610        1.1  augustss 			m_freem(m_new);
    611  1.38.18.1     skrll 			return ENOBUFS;
    612        1.1  augustss 		}
    613        1.1  augustss 		m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
    614        1.1  augustss 	} else {
    615        1.1  augustss 		m_new = m;
    616        1.1  augustss 		m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
    617        1.1  augustss 		m_new->m_data = m_new->m_ext.ext_buf;
    618        1.1  augustss 	}
    619        1.1  augustss 	c->cdce_mbuf = m_new;
    620  1.38.18.1     skrll 	return 0;
    621        1.1  augustss }
    622        1.1  augustss 
    623        1.1  augustss Static int
    624        1.1  augustss cdce_rx_list_init(struct cdce_softc *sc)
    625        1.1  augustss {
    626        1.1  augustss 	struct cdce_cdata	*cd;
    627        1.1  augustss 	struct cdce_chain	*c;
    628        1.1  augustss 	int			 i;
    629        1.1  augustss 
    630        1.1  augustss 	cd = &sc->cdce_cdata;
    631        1.1  augustss 	for (i = 0; i < CDCE_RX_LIST_CNT; i++) {
    632        1.1  augustss 		c = &cd->cdce_rx_chain[i];
    633        1.1  augustss 		c->cdce_sc = sc;
    634        1.1  augustss 		c->cdce_idx = i;
    635        1.1  augustss 		if (cdce_newbuf(sc, c, NULL) == ENOBUFS)
    636  1.38.18.1     skrll 			return ENOBUFS;
    637        1.1  augustss 		if (c->cdce_xfer == NULL) {
    638  1.38.18.1     skrll 			int err = usbd_create_xfer(sc->cdce_bulkin_pipe,
    639  1.38.18.1     skrll 			    CDCE_BUFSZ, USBD_SHORT_XFER_OK, 0, &c->cdce_xfer);
    640  1.38.18.1     skrll 			if (err)
    641  1.38.18.1     skrll 				return err;
    642  1.38.18.1     skrll 			c->cdce_buf = usbd_get_buffer(c->cdce_xfer);
    643        1.1  augustss 		}
    644        1.1  augustss 	}
    645        1.1  augustss 
    646  1.38.18.1     skrll 	return 0;
    647        1.1  augustss }
    648        1.1  augustss 
    649        1.1  augustss Static int
    650        1.1  augustss cdce_tx_list_init(struct cdce_softc *sc)
    651        1.1  augustss {
    652        1.1  augustss 	struct cdce_cdata	*cd;
    653        1.1  augustss 	struct cdce_chain	*c;
    654        1.1  augustss 	int			 i;
    655        1.1  augustss 
    656        1.1  augustss 	cd = &sc->cdce_cdata;
    657        1.1  augustss 	for (i = 0; i < CDCE_TX_LIST_CNT; i++) {
    658        1.1  augustss 		c = &cd->cdce_tx_chain[i];
    659        1.1  augustss 		c->cdce_sc = sc;
    660        1.1  augustss 		c->cdce_idx = i;
    661        1.1  augustss 		c->cdce_mbuf = NULL;
    662        1.1  augustss 		if (c->cdce_xfer == NULL) {
    663  1.38.18.1     skrll 			int err = usbd_create_xfer(sc->cdce_bulkout_pipe,
    664  1.38.18.1     skrll 			    CDCE_BUFSZ, USBD_FORCE_SHORT_XFER, 0,
    665  1.38.18.1     skrll 			    &c->cdce_xfer);
    666  1.38.18.1     skrll 			if (err)
    667  1.38.18.1     skrll 				return err;
    668  1.38.18.1     skrll 			c->cdce_buf = usbd_get_buffer(c->cdce_xfer);
    669        1.1  augustss 		}
    670        1.1  augustss 	}
    671        1.1  augustss 
    672  1.38.18.1     skrll 	return 0;
    673        1.1  augustss }
    674        1.1  augustss 
    675        1.1  augustss Static void
    676  1.38.18.1     skrll cdce_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
    677        1.1  augustss {
    678        1.1  augustss 	struct cdce_chain	*c = priv;
    679        1.1  augustss 	struct cdce_softc	*sc = c->cdce_sc;
    680        1.1  augustss 	struct ifnet		*ifp = GET_IFP(sc);
    681        1.1  augustss 	struct mbuf		*m;
    682        1.1  augustss 	int			 total_len = 0;
    683        1.1  augustss 	int			 s;
    684        1.1  augustss 
    685        1.1  augustss 	if (sc->cdce_dying || !(ifp->if_flags & IFF_RUNNING))
    686        1.1  augustss 		return;
    687        1.1  augustss 
    688        1.1  augustss 	if (status != USBD_NORMAL_COMPLETION) {
    689        1.1  augustss 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
    690        1.1  augustss 			return;
    691        1.1  augustss 		if (sc->cdce_rxeof_errors == 0)
    692        1.1  augustss 			printf("%s: usb error on rx: %s\n",
    693       1.24    dyoung 			    device_xname(sc->cdce_dev), usbd_errstr(status));
    694        1.1  augustss 		if (status == USBD_STALLED)
    695        1.8  augustss 			usbd_clear_endpoint_stall_async(sc->cdce_bulkin_pipe);
    696        1.1  augustss 		DELAY(sc->cdce_rxeof_errors * 10000);
    697        1.1  augustss 		sc->cdce_rxeof_errors++;
    698        1.1  augustss 		goto done;
    699        1.1  augustss 	}
    700        1.1  augustss 
    701        1.1  augustss 	sc->cdce_rxeof_errors = 0;
    702        1.1  augustss 
    703        1.1  augustss 	usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
    704        1.1  augustss 	if (sc->cdce_flags & CDCE_ZAURUS)
    705        1.1  augustss 		total_len -= 4;	/* Strip off CRC added by Zaurus */
    706        1.1  augustss 	if (total_len <= 1)
    707        1.1  augustss 		goto done;
    708        1.1  augustss 
    709        1.1  augustss 	m = c->cdce_mbuf;
    710        1.1  augustss 	memcpy(mtod(m, char *), c->cdce_buf, total_len);
    711        1.1  augustss 
    712        1.1  augustss 	if (total_len < sizeof(struct ether_header)) {
    713        1.1  augustss 		ifp->if_ierrors++;
    714        1.1  augustss 		goto done;
    715        1.1  augustss 	}
    716        1.1  augustss 
    717        1.1  augustss 	ifp->if_ipackets++;
    718        1.1  augustss 	m->m_pkthdr.len = m->m_len = total_len;
    719        1.1  augustss 	m->m_pkthdr.rcvif = ifp;
    720        1.1  augustss 
    721        1.1  augustss 	s = splnet();
    722        1.1  augustss 
    723        1.1  augustss 	if (cdce_newbuf(sc, c, NULL) == ENOBUFS) {
    724        1.1  augustss 		ifp->if_ierrors++;
    725        1.1  augustss 		goto done1;
    726        1.1  augustss 	}
    727        1.1  augustss 
    728       1.28     joerg 	bpf_mtap(ifp, m);
    729        1.1  augustss 
    730       1.24    dyoung 	(*(ifp)->if_input)((ifp), (m));
    731        1.1  augustss 
    732        1.1  augustss done1:
    733        1.1  augustss 	splx(s);
    734        1.1  augustss 
    735        1.1  augustss done:
    736        1.1  augustss 	/* Setup new transfer. */
    737  1.38.18.1     skrll 	usbd_setup_xfer(c->cdce_xfer, c, c->cdce_buf, CDCE_BUFSZ,
    738  1.38.18.1     skrll 	    USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cdce_rxeof);
    739        1.1  augustss 	usbd_transfer(c->cdce_xfer);
    740        1.1  augustss }
    741        1.1  augustss 
    742        1.1  augustss Static void
    743  1.38.18.1     skrll cdce_txeof(struct usbd_xfer *xfer, void *priv,
    744       1.11  christos     usbd_status status)
    745        1.1  augustss {
    746        1.1  augustss 	struct cdce_chain	*c = priv;
    747        1.1  augustss 	struct cdce_softc	*sc = c->cdce_sc;
    748        1.1  augustss 	struct ifnet		*ifp = GET_IFP(sc);
    749        1.1  augustss 	usbd_status		 err;
    750        1.1  augustss 	int			 s;
    751        1.1  augustss 
    752        1.1  augustss 	if (sc->cdce_dying)
    753        1.1  augustss 		return;
    754        1.1  augustss 
    755        1.1  augustss 	s = splnet();
    756        1.1  augustss 
    757        1.1  augustss 	ifp->if_timer = 0;
    758        1.1  augustss 	ifp->if_flags &= ~IFF_OACTIVE;
    759        1.1  augustss 
    760        1.1  augustss 	if (status != USBD_NORMAL_COMPLETION) {
    761        1.1  augustss 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
    762        1.1  augustss 			splx(s);
    763        1.1  augustss 			return;
    764        1.1  augustss 		}
    765        1.1  augustss 		ifp->if_oerrors++;
    766       1.24    dyoung 		printf("%s: usb error on tx: %s\n", device_xname(sc->cdce_dev),
    767       1.24    dyoung 		    usbd_errstr(status));
    768        1.1  augustss 		if (status == USBD_STALLED)
    769        1.8  augustss 			usbd_clear_endpoint_stall_async(sc->cdce_bulkout_pipe);
    770        1.1  augustss 		splx(s);
    771        1.1  augustss 		return;
    772        1.1  augustss 	}
    773        1.1  augustss 
    774        1.1  augustss 	usbd_get_xfer_status(c->cdce_xfer, NULL, NULL, NULL, &err);
    775        1.1  augustss 
    776        1.1  augustss 	if (c->cdce_mbuf != NULL) {
    777        1.1  augustss 		m_freem(c->cdce_mbuf);
    778        1.1  augustss 		c->cdce_mbuf = NULL;
    779        1.1  augustss 	}
    780        1.1  augustss 
    781        1.1  augustss 	if (err)
    782        1.1  augustss 		ifp->if_oerrors++;
    783        1.1  augustss 	else
    784        1.1  augustss 		ifp->if_opackets++;
    785        1.1  augustss 
    786        1.1  augustss 	if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
    787        1.1  augustss 		cdce_start(ifp);
    788        1.1  augustss 
    789        1.1  augustss 	splx(s);
    790        1.1  augustss }
    791        1.1  augustss 
    792        1.4  augustss int
    793       1.23    dyoung cdce_activate(device_t self, enum devact act)
    794        1.1  augustss {
    795       1.16      cube 	struct cdce_softc *sc = device_private(self);
    796        1.1  augustss 
    797        1.1  augustss 	switch (act) {
    798        1.1  augustss 	case DVACT_DEACTIVATE:
    799        1.1  augustss 		if_deactivate(GET_IFP(sc));
    800        1.1  augustss 		sc->cdce_dying = 1;
    801       1.26    dyoung 		return 0;
    802       1.26    dyoung 	default:
    803       1.26    dyoung 		return EOPNOTSUPP;
    804        1.1  augustss 	}
    805        1.1  augustss }
    806