sys/bus/u4b/usb_request.c
usb_error_t
usbd_req_re_enumerate(struct usb_device *udev, struct lock *lock)
{
	struct usb_device *parent_hub;
	usb_error_t err;
	uint8_t old_addr;
	uint8_t do_retry = 1;

	if (udev->flags.usb_mode != USB_MODE_HOST) {
		return (USB_ERR_INVAL);
	}
	old_addr = udev->address;
	parent_hub = udev->parent_hub;
	if (parent_hub == NULL) {
		return (USB_ERR_INVAL);
	}
retry:
	/*
	 * Try to reset the High Speed parent HUB of a LOW- or FULL-
	 * speed device, if any.
	 */
	if (udev->parent_hs_hub != NULL &&
	    udev->speed != USB_SPEED_HIGH) {
		DPRINTF("Trying to reset parent High Speed TT.\n");
		err = usbd_req_reset_tt(udev->parent_hs_hub, NULL,
		    udev->hs_port_no);
		if (err) {
			DPRINTF("Resetting parent High "
			    "Speed TT failed (%s).\n",
			    usbd_errstr(err));
		}
	}

	/* Try to warm reset first */
	if (parent_hub->speed == USB_SPEED_SUPER)
		usbd_req_warm_reset_port(parent_hub, lock, udev->port_no);

	/* Try to reset the parent HUB port. */
	err = usbd_req_reset_port(parent_hub, lock, udev->port_no);
	if (err) {
		DPRINTFN(0, "addr=%d, port reset failed, %s\n", 
		    old_addr, usbd_errstr(err));
		goto done;
	}

	/*
	 * After that the port has been reset our device should be at
	 * address zero:
	 */
	udev->address = USB_START_ADDR;

	/* reset "bMaxPacketSize" */
	udev->ddesc.bMaxPacketSize = USB_MAX_IPACKET;

	/* reset USB state */
	usb_set_device_state(udev, USB_STATE_POWERED);

	/*
	 * Restore device address:
	 */
	err = usbd_req_set_address(udev, lock, old_addr);
	if (err) {
		/* XXX ignore any errors! */
		DPRINTFN(0, "addr=%d, set address failed! (%s, ignored)\n",
		    old_addr, usbd_errstr(err));
	}
	/*
	 * Restore device address, if the controller driver did not
	 * set a new one:
	 */
	if (udev->address == USB_START_ADDR)
		udev->address = old_addr;

	/* setup the device descriptor and the initial "wMaxPacketSize" */
	err = usbd_setup_device_desc(udev, lock);

done:
	if (err && do_retry) {
		/* give the USB firmware some time to load */
		usb_pause_mtx(lock, hz / 2);
		/* no more retries after this retry */
		do_retry = 0;
		/* try again */
		goto retry;
	}
	/* restore address */
	if (udev->address == USB_START_ADDR)
		udev->address = old_addr;
	/* update state, if successful */
	if (err == 0)
		usb_set_device_state(udev, USB_STATE_ADDRESSED);
	return (err);
}
/*------------------------------------------------------------------------*
 *	usbd_req_re_enumerate
 *
 * NOTE: After this function returns the hardware is in the
 * unconfigured state! The application is responsible for setting a
 * new configuration.
 *
 * Returns:
 *    0: Success
 * Else: Failure
 *------------------------------------------------------------------------*/
usbd_req_re_enumerate
NOTE: After this function returns the hardware is in the
unconfigured state. The application is responsible for setting a
new configuration.

Success
Else: Failure
usbd_req_re_enumerate NOTE : After this function returns the hardware is in the unconfigured state . The application is responsible for setting a new configuration . Success Else : Failure
usb_error_t
usbd_req_re_enumerate(struct usb_device *udev, struct lock *lock)
{
	struct usb_device *parent_hub;
	usb_error_t err;
	uint8_t old_addr;
	uint8_t do_retry = 1;
	if (udev->flags.usb_mode != USB_MODE_HOST) {
		return (USB_ERR_INVAL);
	}
	old_addr = udev->address;
	parent_hub = udev->parent_hub;
	if (parent_hub == NULL) {
		return (USB_ERR_INVAL);
	}
retry:
	if (udev->parent_hs_hub != NULL &&
	    udev->speed != USB_SPEED_HIGH) {
		DPRINTF("Trying to reset parent High Speed TT.\n");
		err = usbd_req_reset_tt(udev->parent_hs_hub, NULL,
		    udev->hs_port_no);
		if (err) {
			DPRINTF("Resetting parent High "
			    "Speed TT failed (%s).\n",
			    usbd_errstr(err));
		}
	}
	if (parent_hub->speed == USB_SPEED_SUPER)
		usbd_req_warm_reset_port(parent_hub, lock, udev->port_no);
	err = usbd_req_reset_port(parent_hub, lock, udev->port_no);
	if (err) {
		DPRINTFN(0, "addr=%d, port reset failed, %s\n", 
		    old_addr, usbd_errstr(err));
		goto done;
	}
	udev->address = USB_START_ADDR;
	udev->ddesc.bMaxPacketSize = USB_MAX_IPACKET;
	usb_set_device_state(udev, USB_STATE_POWERED);
	err = usbd_req_set_address(udev, lock, old_addr);
	if (err) {
		DPRINTFN(0, "addr=%d, set address failed! (%s, ignored)\n",
		    old_addr, usbd_errstr(err));
	}
	if (udev->address == USB_START_ADDR)
		udev->address = old_addr;
	err = usbd_setup_device_desc(udev, lock);
done:
	if (err && do_retry) {
		usb_pause_mtx(lock, hz / 2);
		do_retry = 0;
		goto retry;
	}
	if (udev->address == USB_START_ADDR)
		udev->address = old_addr;
	if (err == 0)
		usb_set_device_state(udev, USB_STATE_ADDRESSED);
	return (err);
}
usb_error_t usbd_req_re_enumerate ( struct usb_device * udev , struct lock * lock ) { struct usb_device * parent_hub ; usb_error_t err ; uint8_t old_addr ; uint8_t do_retry = 1 ; if ( udev -> flags . usb_mode != USB_MODE_HOST ) { return ( USB_ERR_INVAL ) ; } old_addr = udev -> address ; parent_hub = udev -> parent_hub ; if ( parent_hub == NULL ) { return ( USB_ERR_INVAL ) ; } retry : if ( udev -> parent_hs_hub != NULL && udev -> speed != USB_SPEED_HIGH ) { DPRINTF ( " \n " ) ; err = usbd_req_reset_tt ( udev -> parent_hs_hub , NULL , udev -> hs_port_no ) ; if ( err ) { DPRINTF ( " " " \n " , usbd_errstr ( err ) ) ; } } if ( parent_hub -> speed == USB_SPEED_SUPER ) usbd_req_warm_reset_port ( parent_hub , lock , udev -> port_no ) ; err = usbd_req_reset_port ( parent_hub , lock , udev -> port_no ) ; if ( err ) { DPRINTFN ( 0 , " \n " , old_addr , usbd_errstr ( err ) ) ; goto done ; } udev -> address = USB_START_ADDR ; udev -> ddesc . bMaxPacketSize = USB_MAX_IPACKET ; usb_set_device_state ( udev , USB_STATE_POWERED ) ; err = usbd_req_set_address ( udev , lock , old_addr ) ; if ( err ) { DPRINTFN ( 0 , " \n " , old_addr , usbd_errstr ( err ) ) ; } if ( udev -> address == USB_START_ADDR ) udev -> address = old_addr ; err = usbd_setup_device_desc ( udev , lock ) ; done : if ( err && do_retry ) { usb_pause_mtx ( lock , hz / 2 ) ; do_retry = 0 ; goto retry ; } if ( udev -> address == USB_START_ADDR ) udev -> address = old_addr ; if ( err == 0 ) usb_set_device_state ( udev , USB_STATE_ADDRESSED ) ; return ( err ) ; }
usbd_req_re_enumerate
 NOTE: After this function returns the hardware is in the
 unconfigured state!
usbd_req_re_enumerate NOTE : After this function returns the hardware is in the unconfigured state!
/*
	 * Try to reset the High Speed parent HUB of a LOW- or FULL-
	 * speed device, if any.
	 */ /* Try to warm reset first */ /* Try to reset the parent HUB port. */ /*
	 * After that the port has been reset our device should be at
	 * address zero:
	 */ /* reset "bMaxPacketSize" */ /* reset USB state */ /*
	 * Restore device address:
	 */ /* XXX ignore any errors! */ /*
	 * Restore device address, if the controller driver did not
	 * set a new one:
	 */ /* setup the device descriptor and the initial "wMaxPacketSize" */ /* give the USB firmware some time to load */ /* no more retries after this retry */ /* try again */ /* restore address */ /* update state, if successful */