From 9a12dd0ebe8ec440cbfc5761e5c400836cc8abce Mon Sep 17 00:00:00 2001 From: joff Date: Mon, 24 Jan 2005 01:30:38 +0000 Subject: [PATCH] Implementation requirements of usb_needs_reattach(), from OpenBSD and required for atu(4) to do a USB reconnect after firmware upload. --- sys/dev/usb/uhub.c | 11 +++++++---- sys/dev/usb/usb.c | 13 +++++++++++-- sys/dev/usb/usbdivar.h | 4 +++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sys/dev/usb/uhub.c b/sys/dev/usb/uhub.c index d56dc3acafc9..113099038729 100644 --- a/sys/dev/usb/uhub.c +++ b/sys/dev/usb/uhub.c @@ -1,4 +1,4 @@ -/* $NetBSD: uhub.c,v 1.71 2004/10/26 05:00:59 augustss Exp $ */ +/* $NetBSD: uhub.c,v 1.72 2005/01/24 01:30:38 joff Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */ /* @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.71 2004/10/26 05:00:59 augustss Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.72 2005/01/24 01:30:38 joff Exp $"); #include #include @@ -310,6 +310,7 @@ USB_ATTACH(uhub) else up->power = USB_MIN_POWER; up->restartcnt = 0; + up->reattach = 0; if (UHUB_IS_HIGH_SPEED(sc)) { up->tt = &tts[UHUB_IS_SINGLE_TT(sc) ? 0 : p]; up->tt->hub = hub; @@ -356,7 +357,7 @@ uhub_explore(usbd_device_handle dev) usbd_status err; int speed; int port; - int change, status; + int change, status, reconnect; DPRINTFN(10, ("uhub_explore dev=%p addr=%d\n", dev, dev->address)); @@ -377,6 +378,8 @@ uhub_explore(usbd_device_handle dev) } status = UGETW(up->status.wPortStatus); change = UGETW(up->status.wPortChange); + reconnect = up->reattach; + up->reattach = 0; DPRINTFN(3,("uhub_explore: %s port %d status 0x%04x 0x%04x\n", USBDEVNAME(sc->sc_dev), port, status, change)); if (change & UPS_C_PORT_ENABLED) { @@ -403,7 +406,7 @@ uhub_explore(usbd_device_handle dev) USBDEVNAME(sc->sc_dev), port); } } - if (!(change & UPS_C_CONNECT_STATUS)) { + if (!reconnect && !(change & UPS_C_CONNECT_STATUS)) { DPRINTFN(3,("uhub_explore: port=%d !C_CONNECT_" "STATUS\n", port)); /* No status change, just do recursive explore. */ diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c index 520b07d16d25..59a3087a5a0f 100644 --- a/sys/dev/usb/usb.c +++ b/sys/dev/usb/usb.c @@ -1,4 +1,4 @@ -/* $NetBSD: usb.c,v 1.80 2003/11/07 17:03:25 wiz Exp $ */ +/* $NetBSD: usb.c,v 1.81 2005/01/24 01:30:38 joff Exp $ */ /* * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc. @@ -44,7 +44,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.80 2003/11/07 17:03:25 wiz Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.81 2005/01/24 01:30:38 joff Exp $"); #include "ohci.h" #include "uhci.h" @@ -678,6 +678,15 @@ usb_needs_explore(usbd_device_handle dev) wakeup(&dev->bus->needs_explore); } +void +usb_needs_reattach(usbd_device_handle dev) +{ + DPRINTFN(2,("usb_needs_reattach\n")); + dev->powersrc->reattach = 1; + dev->bus->needs_explore = 1; + wakeup(&dev->bus->needs_explore); +} + /* Called at splusb() */ int usb_get_next_event(struct usb_event *ue) diff --git a/sys/dev/usb/usbdivar.h b/sys/dev/usb/usbdivar.h index 4b4a06e355e7..6ddb8f441f97 100644 --- a/sys/dev/usb/usbdivar.h +++ b/sys/dev/usb/usbdivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: usbdivar.h,v 1.72 2004/10/23 16:17:56 augustss Exp $ */ +/* $NetBSD: usbdivar.h,v 1.73 2005/01/24 01:30:38 joff Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdivar.h,v 1.11 1999/11/17 22:33:51 n_hibma Exp $ */ /* @@ -83,6 +83,7 @@ struct usbd_port { u_int8_t portno; u_int8_t restartcnt; #define USBD_RESTART_MAX 5 + u_int8_t reattach; struct usbd_device *device; /* Connected device */ struct usbd_device *parent; /* The ports hub */ struct usbd_tt *tt; /* Transaction translator (if any) */ @@ -260,6 +261,7 @@ void usb_disconnect_port(struct usbd_port *, device_ptr_t); /* Routines from usb.c */ void usb_needs_explore(usbd_device_handle); +void usb_needs_reattach(usbd_device_handle); void usb_schedsoftintr(struct usbd_bus *); /*