4 * This file is part of Xen USB Virtual Host Controller driver.
6 * Copyright (C) 2009, FUJITSU LABORATORIES LTD.
7 * Author: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
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.
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.
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/>.
24 * When distributed separately from the Linux kernel or incorporated into
25 * other software packages, subject to the following license:
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:
34 * The above copyright notice and this permission notice shall be included in
35 * all copies or substantial portions of the Software.
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.
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 <linux/usb/hcd.h>
56 #include <xen/xenbus.h>
57 #include <xen/evtchn.h>
58 #include <xen/gnttab.h>
59 #include <xen/interface/xen.h>
60 #include <xen/interface/io/usbif.h>
62 static inline struct usbfront_info *hcd_to_info(struct usb_hcd *hcd)
64 return (struct usbfront_info *) (hcd->hcd_priv);
67 static inline struct usb_hcd *info_to_hcd(struct usbfront_info *info)
69 return container_of((void *) info, struct usb_hcd, hcd_priv);
72 /* Private per-URB data */
74 struct list_head list;
76 int req_id; /* RING_REQUEST id for submitting */
77 int unlink_req_id; /* RING_REQUEST id for unlinking */
79 unsigned unlinked:1; /* dequeued marker */
82 /* virtual roothub port status */
83 struct rhport_status {
85 unsigned resuming:1; /* in resuming */
86 unsigned c_connection:1; /* connection changed */
87 unsigned long timeout;
90 /* status of attached device */
91 struct vdevice_status {
93 enum usb_device_state status;
94 enum usb_device_speed speed;
97 /* RING request shadow */
99 usbif_urb_request_t req;
103 /* statistics for tuning, monitoring, ... */
104 struct xenhcd_stats {
105 unsigned long ring_full; /* RING_FULL conditions */
106 unsigned long complete; /* normal givebacked urbs */
107 unsigned long unlink; /* unlinked urbs */
110 struct usbfront_info {
111 /* Virtual Host Controller has 4 urb queues */
112 struct list_head pending_submit_list;
113 struct list_head pending_unlink_list;
114 struct list_head in_progress_list;
115 struct list_head giveback_waiting_list;
119 /* timer that kick pending and giveback waiting urbs */
120 struct timer_list watchdog;
121 unsigned long actions;
123 /* virtual root hub */
125 struct rhport_status ports[USB_MAXCHILDREN];
126 struct vdevice_status devices[USB_MAXCHILDREN];
128 /* Xen related staff */
129 struct xenbus_device *xbdev;
132 usbif_urb_front_ring_t urb_ring;
133 usbif_conn_front_ring_t conn_ring;
135 unsigned int irq; /* event channel */
136 struct usb_shadow shadow[USB_URB_RING_SIZE];
137 unsigned long shadow_free;
139 /* RING_RESPONSE thread */
140 struct task_struct *kthread;
141 wait_queue_head_t wq;
142 unsigned int waiting_resp;
144 /* xmit statistics */
146 struct xenhcd_stats stats;
147 #define COUNT(x) do { (x)++; } while (0)
149 #define COUNT(x) do {} while (0)
153 #define XENHCD_RING_JIFFIES (HZ/200)
154 #define XENHCD_SCAN_JIFFIES 1
156 enum xenhcd_timer_action {
158 TIMER_SCAN_PENDING_URBS,
162 timer_action_done(struct usbfront_info *info, enum xenhcd_timer_action action)
164 clear_bit(action, &info->actions);
168 timer_action(struct usbfront_info *info, enum xenhcd_timer_action action)
170 if (timer_pending(&info->watchdog)
171 && test_bit(TIMER_SCAN_PENDING_URBS, &info->actions))
174 if (!test_and_set_bit(action, &info->actions)) {
178 case TIMER_RING_WATCHDOG:
179 t = XENHCD_RING_JIFFIES;
182 t = XENHCD_SCAN_JIFFIES;
185 mod_timer(&info->watchdog, t + jiffies);
189 extern struct kmem_cache *xenhcd_urbp_cachep;
190 extern struct hc_driver xen_usb20_hc_driver;
191 extern struct hc_driver xen_usb11_hc_driver;
192 irqreturn_t xenhcd_int(int irq, void *dev_id);
193 void xenhcd_rhport_state_change(struct usbfront_info *info,
194 int port, enum usb_device_speed speed);
195 int xenhcd_schedule(void *arg);
197 #endif /* __XEN_USBFRONT_H__ */