Merge branch 'fix/asoc' into for-linus
[cascardo/linux.git] / drivers / staging / usbip / vhci.h
1 /*
2  * Copyright (C) 2003-2008 Takahiro Hirofuchi
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <linux/device.h>
21 #include <linux/list.h>
22 #include <linux/spinlock.h>
23 #include <linux/sysfs.h>
24 #include <linux/types.h>
25 #include <linux/usb.h>
26 #include <linux/usb/hcd.h>
27 #include <linux/wait.h>
28
29 struct vhci_device {
30         struct usb_device *udev;
31
32         /*
33          * devid specifies a remote usb device uniquely instead
34          * of combination of busnum and devnum.
35          */
36         __u32 devid;
37
38         /* speed of a remote device */
39         enum usb_device_speed speed;
40
41         /* vhci root-hub port to which this device is attached */
42         __u32 rhport;
43
44         struct usbip_device ud;
45
46         /* lock for the below link lists */
47         spinlock_t priv_lock;
48
49         /* vhci_priv is linked to one of them. */
50         struct list_head priv_tx;
51         struct list_head priv_rx;
52
53         /* vhci_unlink is linked to one of them */
54         struct list_head unlink_tx;
55         struct list_head unlink_rx;
56
57         /* vhci_tx thread sleeps for this queue */
58         wait_queue_head_t waitq_tx;
59 };
60
61 /* urb->hcpriv, use container_of() */
62 struct vhci_priv {
63         unsigned long seqnum;
64         struct list_head list;
65
66         struct vhci_device *vdev;
67         struct urb *urb;
68 };
69
70 struct vhci_unlink {
71         /* seqnum of this request */
72         unsigned long seqnum;
73
74         struct list_head list;
75
76         /* seqnum of the unlink target */
77         unsigned long unlink_seqnum;
78 };
79
80 /*
81  * The number of ports is less than 16 ?
82  * USB_MAXCHILDREN is statically defined to 16 in usb.h.  Its maximum value
83  * would be 31 because the event_bits[1] of struct usb_hub is defined as
84  * unsigned long in hub.h
85  */
86 #define VHCI_NPORTS 8
87
88 /* for usb_bus.hcpriv */
89 struct vhci_hcd {
90         spinlock_t lock;
91
92         u32 port_status[VHCI_NPORTS];
93
94         unsigned resuming:1;
95         unsigned long re_timeout;
96
97         atomic_t seqnum;
98
99         /*
100          * NOTE:
101          * wIndex shows the port number and begins from 1.
102          * But, the index of this array begins from 0.
103          */
104         struct vhci_device vdev[VHCI_NPORTS];
105 };
106
107 extern struct vhci_hcd *the_controller;
108 extern struct attribute_group dev_attr_group;
109 #define hardware (&the_controller->pdev.dev)
110
111 /* vhci_hcd.c */
112 void rh_port_connect(int rhport, enum usb_device_speed speed);
113 void rh_port_disconnect(int rhport);
114
115 /* vhci_rx.c */
116 struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
117 int vhci_rx_loop(void *data);
118
119 /* vhci_tx.c */
120 int vhci_tx_loop(void *data);
121
122 static inline struct vhci_device *port_to_vdev(__u32 port)
123 {
124         return &the_controller->vdev[port];
125 }
126
127 static inline struct vhci_hcd *hcd_to_vhci(struct usb_hcd *hcd)
128 {
129         return (struct vhci_hcd *) (hcd->hcd_priv);
130 }
131
132 static inline struct usb_hcd *vhci_to_hcd(struct vhci_hcd *vhci)
133 {
134         return container_of((void *) vhci, struct usb_hcd, hcd_priv);
135 }
136
137 static inline struct device *vhci_dev(struct vhci_hcd *vhci)
138 {
139         return vhci_to_hcd(vhci)->self.controller;
140 }