ia64/linux-2.6.18-xen.hg

view drivers/xen/usbfront/usbfront.h @ 845:4c7eb2e71e9d

pvusb: Fix license headers.

Signed-off-by: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 31 11:11:23 2009 +0100 (2009-03-31)
parents 8f996719f2ff
children
line source
1 /*
2 * usbfront.h
3 *
4 * This file is part of Xen USB Virtual Host Controller driver.
5 *
6 * Copyright (C) 2009, FUJITSU LABORATORIES LTD.
7 * Author: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 *
22 * or, by your choice,
23 *
24 * When distributed separately from the Linux kernel or incorporated into
25 * other software packages, subject to the following license:
26 *
27 * Permission is hereby granted, free of charge, to any person obtaining a copy
28 * of this software and associated documentation files (the "Software"), to
29 * deal in the Software without restriction, including without limitation the
30 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
31 * sell copies of the Software, and to permit persons to whom the Software is
32 * furnished to do so, subject to the following conditions:
33 *
34 * The above copyright notice and this permission notice shall be included in
35 * all copies or substantial portions of the Software.
36 *
37 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
43 * DEALINGS IN THE SOFTWARE.
44 */
46 #ifndef __XEN_USBFRONT_H__
47 #define __XEN_USBFRONT_H__
49 #include <linux/module.h>
50 #include <linux/usb.h>
51 #include <linux/list.h>
52 #include <linux/kthread.h>
53 #include <linux/wait.h>
54 #include <asm/io.h>
55 #include <xen/xenbus.h>
56 #include <xen/evtchn.h>
57 #include <xen/gnttab.h>
58 #include <xen/interface/xen.h>
59 #include <xen/interface/io/usbif.h>
61 /*
62 * usbfront needs USB HCD headers,
63 * drivers/usb/core/hcd.h and drivers/usb/core/hub.h,
64 * but, they are not in public include path.
65 */
66 #include "../../usb/core/hcd.h"
67 #include "../../usb/core/hub.h"
69 #define DRIVER_DESC "Xen USB2.0 Virtual Host Controller driver (usbfront)"
71 static inline struct usbfront_info *hcd_to_info(struct usb_hcd *hcd)
72 {
73 return (struct usbfront_info *) (hcd->hcd_priv);
74 }
76 static inline struct usb_hcd *info_to_hcd(struct usbfront_info *info)
77 {
78 return container_of ((void *) info, struct usb_hcd, hcd_priv);
79 }
81 /*
82 * Private per-URB data
83 */
84 struct urb_priv {
85 struct list_head list;
86 struct urb *urb;
87 int req_id; /* RING_REQUEST id */
88 unsigned unlinked:1; /* dequeued urb just marked */
89 };
91 /* virtual roothub port status */
92 struct rhport_status {
93 u32 status;
94 unsigned resuming:1; /* in resuming */
95 unsigned c_connection:1; /* connection changed */
96 unsigned long timeout;
97 };
99 /* status of attached device */
100 struct vdevice_status {
101 int devnum;
102 enum usb_device_state status;
103 enum usb_device_speed speed;
104 };
106 /* RING request shadow */
107 struct usb_shadow {
108 usbif_request_t req;
109 struct urb *urb;
110 };
112 /* statistics for tuning, monitoring, ... */
113 struct xenhcd_stats {
114 unsigned long ring_full; /* RING_FULL conditions */
115 unsigned long complete; /* normal givebacked urbs */
116 unsigned long unlink; /* unlinked urbs */
117 };
119 struct usbfront_info {
120 /*
121 * Virtual Host Controller has 3 queues.
122 *
123 * pending_urbs:
124 * If xenhcd_urb_enqueue() called in RING_FULL state,
125 * the enqueued urbs are added to this queue, and waits
126 * to be sent to the backend.
127 *
128 * inprogress_urbs:
129 * After xenhcd_urb_enqueue() called and RING_REQUEST sent,
130 * the urbs are added to this queue and waits for RING_RESPONSE.
131 *
132 * unlinked_urbs:
133 * When xenhcd_urb_dequeue() called, if the dequeued urb is
134 * listed in pending_urbs, that urb is moved to this queue
135 * and waits to be given back to the USB core.
136 */
137 struct list_head pending_urbs;
138 struct list_head inprogress_urbs;
139 struct list_head unlinked_urbs;
140 spinlock_t lock;
142 /*
143 * timer function that kick pending_urbs and unlink_urbs.
144 */
145 unsigned long actions;
146 struct timer_list watchdog;
148 /*
149 * Virtual roothub:
150 * Emulates the hub ports and the attached devices status.
151 * USB_MAXCHILDREN is defined (16) in include/linux/usb.h
152 */
153 int rh_numports;
154 struct rhport_status ports[USB_MAXCHILDREN];
155 struct vdevice_status devices[USB_MAXCHILDREN];
157 #ifdef XENHCD_STATS
158 struct xenhcd_stats stats;
159 #define COUNT(x) do { (x)++; } while (0)
160 #else
161 #define COUNT(x) do {} while (0)
162 #endif
164 /* Xen related staff */
165 struct xenbus_device *xbdev;
166 int ring_ref;
167 usbif_front_ring_t ring;
168 unsigned int irq;
169 struct usb_shadow shadow[USB_RING_SIZE];
170 unsigned long shadow_free;
172 /* RING_RESPONSE thread */
173 struct task_struct *kthread;
174 wait_queue_head_t wq;
175 unsigned int waiting_resp;
176 };
178 #define XENHCD_RING_JIFFIES (HZ/200)
179 #define XENHCD_SCAN_JIFFIES 1
181 enum xenhcd_timer_action {
182 TIMER_RING_WATCHDOG,
183 TIMER_SCAN_PENDING_URBS,
184 };
186 static inline void
187 timer_action_done(struct usbfront_info *info, enum xenhcd_timer_action action)
188 {
189 clear_bit(action, &info->actions);
190 }
192 static inline void
193 timer_action(struct usbfront_info *info, enum xenhcd_timer_action action)
194 {
195 if (timer_pending(&info->watchdog)
196 && test_bit(TIMER_SCAN_PENDING_URBS, &info->actions))
197 return;
199 if (!test_and_set_bit(action, &info->actions)) {
200 unsigned long t;
202 switch(action) {
203 case TIMER_RING_WATCHDOG:
204 t = XENHCD_RING_JIFFIES;
205 break;
206 default:
207 t = XENHCD_SCAN_JIFFIES;
208 break;
209 }
210 mod_timer(&info->watchdog, t + jiffies);
211 }
212 }
214 irqreturn_t xenhcd_int(int irq, void *dev_id, struct pt_regs *ptregs);
216 #endif /* __XEN_USBFRONT_H__ */