summaryrefslogtreecommitdiffstats
path: root/sys/dev/usb/usb.c
diff options
context:
space:
mode:
authorjakemsr <jakemsr@openbsd.org>2011-02-09 04:25:31 +0000
committerjakemsr <jakemsr@openbsd.org>2011-02-09 04:25:31 +0000
commit7cf8c442d041873a40cd7fc44ce53f265a78a1e6 (patch)
treeb585580188a6d91f2458816794fb164d1cb71977 /sys/dev/usb/usb.c
parentLog the time taken for all types of check, not just tcp checks. (diff)
downloadwireguard-openbsd-7cf8c442d041873a40cd7fc44ce53f265a78a1e6.tar.xz
wireguard-openbsd-7cf8c442d041873a40cd7fc44ce53f265a78a1e6.zip
revert usb.c to r1.72, and all subsequent changes that depend on it.
this is causing problems with suspend/resume for some people.
Diffstat (limited to 'sys/dev/usb/usb.c')
-rw-r--r--sys/dev/usb/usb.c119
1 files changed, 34 insertions, 85 deletions
diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c
index 1f3788739dc..af452b9c7e7 100644
--- a/sys/dev/usb/usb.c
+++ b/sys/dev/usb/usb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: usb.c,v 1.73 2011/02/04 08:21:39 jakemsr Exp $ */
+/* $OpenBSD: usb.c,v 1.74 2011/02/09 04:25:32 jakemsr Exp $ */
/* $NetBSD: usb.c,v 1.77 2003/01/01 00:10:26 thorpej Exp $ */
/*
@@ -275,15 +275,15 @@ usb_add_task(usbd_device_handle dev, struct usb_task *task)
{
int s;
- DPRINTFN(2,("%s: task=%p state=%d type=%d\n", __func__, task,
- task->state, task->type));
+ DPRINTFN(2,("%s: task=%p onqueue=%d type=%d\n", __func__, task,
+ task->onqueue, task->type));
/* Don't add task if the device's root hub is dying. */
if (usbd_is_dying(dev))
return;
s = splusb();
- if (task->state != USB_TASK_STATE_ONQ) {
+ if (!task->onqueue) {
switch (task->type) {
case USB_TASK_TYPE_ABORT:
TAILQ_INSERT_TAIL(&usb_abort_tasks, task, next);
@@ -295,7 +295,7 @@ usb_add_task(usbd_device_handle dev, struct usb_task *task)
TAILQ_INSERT_TAIL(&usb_generic_tasks, task, next);
break;
}
- task->state = USB_TASK_STATE_ONQ;
+ task->onqueue = 1;
task->dev = dev;
}
if (task->type == USB_TASK_TYPE_ABORT)
@@ -310,43 +310,38 @@ usb_rem_task(usbd_device_handle dev, struct usb_task *task)
{
int s;
- DPRINTFN(2,("%s: task=%p state=%d type=%d\n", __func__, task,
- task->state, task->type));
-
- if (task->state != USB_TASK_STATE_ONQ)
- return;
+ DPRINTFN(2,("%s: task=%p onqueue=%d type=%d\n", __func__, task,
+ task->onqueue, task->type));
s = splusb();
-
- switch (task->type) {
- case USB_TASK_TYPE_ABORT:
- TAILQ_REMOVE(&usb_abort_tasks, task, next);
- break;
- case USB_TASK_TYPE_EXPLORE:
- TAILQ_REMOVE(&usb_explore_tasks, task, next);
- break;
- case USB_TASK_TYPE_GENERIC:
- TAILQ_REMOVE(&usb_generic_tasks, task, next);
- break;
+ if (task->onqueue) {
+ switch (task->type) {
+ case USB_TASK_TYPE_ABORT:
+ TAILQ_REMOVE(&usb_abort_tasks, task, next);
+ break;
+ case USB_TASK_TYPE_EXPLORE:
+ TAILQ_REMOVE(&usb_explore_tasks, task, next);
+ break;
+ case USB_TASK_TYPE_GENERIC:
+ TAILQ_REMOVE(&usb_generic_tasks, task, next);
+ break;
+ }
+ task->onqueue = 0;
}
- task->state = USB_TASK_STATE_NONE;
-
splx(s);
}
void
-usb_wait_task(usbd_device_handle dev, struct usb_task *task)
+usb_rem_wait_task(usbd_device_handle dev, struct usb_task *task)
{
int s;
- DPRINTFN(2,("%s: task=%p state=%d type=%d\n", __func__, task,
- task->state, task->type));
-
- if (task->state == USB_TASK_STATE_NONE)
- return;
+ DPRINTFN(2,("%s: task=%p onqueue=%d type=%d\n", __func__, task,
+ task->onqueue, task->type));
s = splusb();
- while (task->state != USB_TASK_STATE_NONE) {
+ usb_rem_task(dev, task);
+ while (task->running) {
DPRINTF(("%s: waiting for task to complete\n", __func__));
tsleep(task, PWAIT, "endtask", 0);
}
@@ -354,13 +349,6 @@ usb_wait_task(usbd_device_handle dev, struct usb_task *task)
}
void
-usb_rem_wait_task(usbd_device_handle dev, struct usb_task *task)
-{
- usb_rem_task(dev, task);
- usb_wait_task(dev, task);
-}
-
-void
usb_first_explore(void *arg)
{
struct usb_softc *sc = arg;
@@ -418,16 +406,15 @@ usb_task_thread(void *arg)
tsleep(&usb_run_tasks, PWAIT, "usbtsk", 0);
continue;
}
+ task->onqueue = 0;
/* Don't execute the task if the root hub is gone. */
- if (usbd_is_dying(task->dev)) {
- task->state = USB_TASK_STATE_NONE;
+ if (usbd_is_dying(task->dev))
continue;
- }
- task->state = USB_TASK_STATE_RUN;
+ task->running = 1;
splx(s);
task->fun(task->arg);
s = splusb();
- task->state = USB_TASK_STATE_NONE;
+ task->running = 0;
wakeup(task);
}
splx(s);
@@ -456,16 +443,15 @@ usb_abort_task_thread(void *arg)
tsleep(&usb_run_abort_tasks, PWAIT, "usbatsk", 0);
continue;
}
+ task->onqueue = 0;
/* Don't execute the task if the root hub is gone. */
- if (usbd_is_dying(task->dev)) {
- task->state = USB_TASK_STATE_NONE;
+ if (usbd_is_dying(task->dev))
continue;
- }
- task->state = USB_TASK_STATE_RUN;
+ task->running = 1;
splx(s);
task->fun(task->arg);
s = splusb();
- task->state = USB_TASK_STATE_NONE;
+ task->running = 0;
wakeup(task);
}
splx(s);
@@ -507,26 +493,6 @@ usbclose(dev_t dev, int flag, int mode, struct proc *p)
return (0);
}
-void
-usbd_fill_di_task(void *arg)
-{
- struct usb_device_info *di = (struct usb_device_info *)arg;
- struct usb_softc *sc;
- usbd_device_handle dev;
-
- /* check that the bus and device are still present */
- if (di->udi_bus >= usb_cd.cd_ndevs)
- return;
- sc = usb_cd.cd_devs[di->udi_bus];
- if (sc == NULL)
- return;
- dev = sc->sc_bus->devices[di->udi_addr];
- if (dev == NULL)
- return;
-
- usbd_fill_deviceinfo(dev, di, 1);
-}
-
int
usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p)
{
@@ -623,31 +589,14 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, struct proc *p)
{
struct usb_device_info *di = (void *)data;
int addr = di->udi_addr;
- struct usb_task di_task;
usbd_device_handle dev;
if (addr < 1 || addr >= USB_MAX_DEVICES)
return (EINVAL);
-
dev = sc->sc_bus->devices[addr];
if (dev == NULL)
return (ENXIO);
-
- di->udi_bus = unit;
-
- /* All devices get a driver, thanks to ugen(4). If the
- * task ends without adding a driver name, there was an error.
- */
- di->udi_devnames[0][0] = '\0';
-
- usb_init_task(&di_task, usbd_fill_di_task, di,
- USB_TASK_TYPE_GENERIC);
- usb_add_task(sc->sc_bus->root_hub, &di_task);
- usb_wait_task(sc->sc_bus->root_hub, &di_task);
-
- if (di->udi_devnames[0][0] == '\0')
- return (ENXIO);
-
+ usbd_fill_deviceinfo(dev, di, 1);
break;
}