Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 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 | * |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 9 | */ |
| 10 | |
Tobias Klauser | 306dac6 | 2011-08-22 08:53:28 +0200 | [diff] [blame] | 11 | #ifndef __USBIP_VHCI_H |
| 12 | #define __USBIP_VHCI_H |
| 13 | |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 14 | #include <linux/device.h> |
| 15 | #include <linux/list.h> |
| 16 | #include <linux/spinlock.h> |
| 17 | #include <linux/sysfs.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/usb.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 20 | #include <linux/usb/hcd.h> |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 21 | #include <linux/wait.h> |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 22 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 23 | struct vhci_device { |
| 24 | struct usb_device *udev; |
| 25 | |
| 26 | /* |
| 27 | * devid specifies a remote usb device uniquely instead |
| 28 | * of combination of busnum and devnum. |
| 29 | */ |
| 30 | __u32 devid; |
| 31 | |
| 32 | /* speed of a remote device */ |
| 33 | enum usb_device_speed speed; |
| 34 | |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 35 | /* vhci root-hub port to which this device is attached */ |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 36 | __u32 rhport; |
| 37 | |
| 38 | struct usbip_device ud; |
| 39 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 40 | /* lock for the below link lists */ |
| 41 | spinlock_t priv_lock; |
| 42 | |
| 43 | /* vhci_priv is linked to one of them. */ |
| 44 | struct list_head priv_tx; |
| 45 | struct list_head priv_rx; |
| 46 | |
| 47 | /* vhci_unlink is linked to one of them */ |
| 48 | struct list_head unlink_tx; |
| 49 | struct list_head unlink_rx; |
| 50 | |
| 51 | /* vhci_tx thread sleeps for this queue */ |
| 52 | wait_queue_head_t waitq_tx; |
| 53 | }; |
| 54 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 55 | /* urb->hcpriv, use container_of() */ |
| 56 | struct vhci_priv { |
| 57 | unsigned long seqnum; |
| 58 | struct list_head list; |
| 59 | |
| 60 | struct vhci_device *vdev; |
| 61 | struct urb *urb; |
| 62 | }; |
| 63 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 64 | struct vhci_unlink { |
| 65 | /* seqnum of this request */ |
| 66 | unsigned long seqnum; |
| 67 | |
| 68 | struct list_head list; |
| 69 | |
| 70 | /* seqnum of the unlink target */ |
| 71 | unsigned long unlink_seqnum; |
| 72 | }; |
| 73 | |
Bart Westgeest | 1132b9a | 2012-06-11 16:57:30 -0400 | [diff] [blame] | 74 | /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */ |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 75 | #define VHCI_NPORTS 8 |
| 76 | |
| 77 | /* for usb_bus.hcpriv */ |
| 78 | struct vhci_hcd { |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 79 | spinlock_t lock; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 80 | |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 81 | u32 port_status[VHCI_NPORTS]; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 82 | |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 83 | unsigned resuming:1; |
| 84 | unsigned long re_timeout; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 85 | |
| 86 | atomic_t seqnum; |
| 87 | |
| 88 | /* |
| 89 | * NOTE: |
| 90 | * wIndex shows the port number and begins from 1. |
| 91 | * But, the index of this array begins from 0. |
| 92 | */ |
| 93 | struct vhci_device vdev[VHCI_NPORTS]; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 94 | }; |
| 95 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 96 | extern struct vhci_hcd *the_controller; |
Márton Németh | cf77acf | 2011-05-30 21:50:26 +0200 | [diff] [blame] | 97 | extern const struct attribute_group dev_attr_group; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 98 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 99 | /* vhci_hcd.c */ |
| 100 | void rh_port_connect(int rhport, enum usb_device_speed speed); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 101 | |
matt mooney | fc184a3 | 2011-05-11 01:54:23 -0700 | [diff] [blame] | 102 | /* vhci_rx.c */ |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 103 | struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum); |
matt mooney | fc184a3 | 2011-05-11 01:54:23 -0700 | [diff] [blame] | 104 | int vhci_rx_loop(void *data); |
Max Vozeler | b92a5e2 | 2011-01-12 15:02:01 +0200 | [diff] [blame] | 105 | |
matt mooney | fc184a3 | 2011-05-11 01:54:23 -0700 | [diff] [blame] | 106 | /* vhci_tx.c */ |
| 107 | int vhci_tx_loop(void *data); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 108 | |
| 109 | static inline struct vhci_device *port_to_vdev(__u32 port) |
| 110 | { |
| 111 | return &the_controller->vdev[port]; |
| 112 | } |
| 113 | |
| 114 | static inline struct vhci_hcd *hcd_to_vhci(struct usb_hcd *hcd) |
| 115 | { |
| 116 | return (struct vhci_hcd *) (hcd->hcd_priv); |
| 117 | } |
| 118 | |
| 119 | static inline struct usb_hcd *vhci_to_hcd(struct vhci_hcd *vhci) |
| 120 | { |
| 121 | return container_of((void *) vhci, struct usb_hcd, hcd_priv); |
| 122 | } |
| 123 | |
| 124 | static inline struct device *vhci_dev(struct vhci_hcd *vhci) |
| 125 | { |
| 126 | return vhci_to_hcd(vhci)->self.controller; |
| 127 | } |
Tobias Klauser | 306dac6 | 2011-08-22 08:53:28 +0200 | [diff] [blame] | 128 | |
| 129 | #endif /* __USBIP_VHCI_H */ |