powerpc: use consistent types in mktree
[zen-stable.git] / drivers / staging / usbip / usbip_event.c
blob4318553ab20ce629ff8c42a7c592d18d04602730
1 /*
2 * Copyright (C) 2003-2008 Takahiro Hirofuchi
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
20 #include "usbip_common.h"
22 static int event_handler(struct usbip_device *ud)
24 dbg_eh("enter\n");
27 * Events are handled by only this thread.
29 while (usbip_event_happend(ud)) {
30 dbg_eh("pending event %lx\n", ud->event);
33 * NOTE: shutdown must come first.
34 * Shutdown the device.
36 if (ud->event & USBIP_EH_SHUTDOWN) {
37 ud->eh_ops.shutdown(ud);
39 ud->event &= ~USBIP_EH_SHUTDOWN;
41 break;
44 /* Stop the error handler. */
45 if (ud->event & USBIP_EH_BYE)
46 return -1;
48 /* Reset the device. */
49 if (ud->event & USBIP_EH_RESET) {
50 ud->eh_ops.reset(ud);
52 ud->event &= ~USBIP_EH_RESET;
54 break;
57 /* Mark the device as unusable. */
58 if (ud->event & USBIP_EH_UNUSABLE) {
59 ud->eh_ops.unusable(ud);
61 ud->event &= ~USBIP_EH_UNUSABLE;
63 break;
66 /* NOTREACHED */
67 printk(KERN_ERR "%s: unknown event\n", __func__);
68 return -1;
71 return 0;
74 static void event_handler_loop(struct usbip_task *ut)
76 struct usbip_device *ud = container_of(ut, struct usbip_device, eh);
78 while (1) {
79 if (signal_pending(current)) {
80 dbg_eh("signal catched!\n");
81 break;
84 if (event_handler(ud) < 0)
85 break;
87 wait_event_interruptible(ud->eh_waitq, usbip_event_happend(ud));
88 dbg_eh("wakeup\n");
92 void usbip_start_eh(struct usbip_device *ud)
94 struct usbip_task *eh = &ud->eh;
96 init_waitqueue_head(&ud->eh_waitq);
97 ud->event = 0;
99 usbip_task_init(eh, "usbip_eh", event_handler_loop);
101 kernel_thread(usbip_thread, (void *)eh, 0);
103 wait_for_completion(&eh->thread_done);
105 EXPORT_SYMBOL_GPL(usbip_start_eh);
107 void usbip_stop_eh(struct usbip_device *ud)
109 struct usbip_task *eh = &ud->eh;
111 wait_for_completion(&eh->thread_done);
112 dbg_eh("usbip_eh has finished\n");
114 EXPORT_SYMBOL_GPL(usbip_stop_eh);
116 void usbip_event_add(struct usbip_device *ud, unsigned long event)
118 spin_lock(&ud->lock);
120 ud->event |= event;
122 wake_up(&ud->eh_waitq);
124 spin_unlock(&ud->lock);
126 EXPORT_SYMBOL_GPL(usbip_event_add);
128 int usbip_event_happend(struct usbip_device *ud)
130 int happend = 0;
132 spin_lock(&ud->lock);
134 if (ud->event != 0)
135 happend = 1;
137 spin_unlock(&ud->lock);
139 return happend;
141 EXPORT_SYMBOL_GPL(usbip_event_happend);