3 * Copyright (C) 2015-2016 Samsung Electronics
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef __USBIP_VUDC_H
22 #define __USBIP_VUDC_H
24 #include <linux/platform_device.h>
25 #include <linux/usb.h>
26 #include <linux/usb/gadget.h>
27 #include <linux/usb/ch9.h>
28 #include <linux/list.h>
29 #include <linux/timer.h>
30 #include <linux/time.h>
31 #include <linux/sysfs.h>
33 #include "usbip_common.h"
35 #define GADGET_NAME "usbip-vudc"
39 unsigned type:2; /* type, as USB_ENDPOINT_XFER_* */
40 char name[8]; /* space for ep name */
42 const struct usb_endpoint_descriptor *desc;
43 struct usb_gadget *gadget;
44 struct list_head req_queue; /* Request queue */
47 unsigned already_seen:1;
48 unsigned setup_stage:1;
52 struct usb_request req;
54 struct list_head req_entry; /* Request queue */
60 struct list_head urb_entry; /* urb queue */
62 unsigned type:2; /* for tx, since ep type can change after */
77 struct list_head tx_entry;
91 struct transfer_timer {
92 struct timer_list timer;
94 unsigned long frame_start;
99 struct usb_gadget gadget;
100 struct usb_gadget_driver *driver;
101 struct platform_device *pdev;
103 struct usb_device_descriptor dev_desc;
105 struct usbip_device ud;
106 struct transfer_timer tr_timer;
107 struct timeval start_time;
109 struct list_head urb_queue;
112 struct list_head tx_queue;
113 wait_queue_head_t tx_waitq;
121 unsigned connected:1;
122 unsigned desc_cached:1;
126 struct platform_device *pdev;
127 struct list_head dev_entry;
130 extern const struct attribute_group vudc_attr_group;
132 /* visible everywhere */
134 static inline struct vep *to_vep(struct usb_ep *_ep)
136 return container_of(_ep, struct vep, ep);
139 static inline struct vrequest *to_vrequest(
140 struct usb_request *_req)
142 return container_of(_req, struct vrequest, req);
145 static inline struct vudc *usb_gadget_to_vudc(
146 struct usb_gadget *_gadget)
148 return container_of(_gadget, struct vudc, gadget);
151 static inline struct vudc *ep_to_vudc(struct vep *ep)
153 return container_of(ep->gadget, struct vudc, gadget);
158 int get_gadget_descs(struct vudc *udc);
162 int v_tx_loop(void *data);
163 void v_enqueue_ret_unlink(struct vudc *udc, __u32 seqnum, __u32 status);
164 void v_enqueue_ret_submit(struct vudc *udc, struct urbp *urb_p);
168 int v_rx_loop(void *data);
170 /* vudc_transfer.c */
172 void v_init_timer(struct vudc *udc);
173 void v_start_timer(struct vudc *udc);
174 void v_kick_timer(struct vudc *udc, unsigned long time);
175 void v_stop_timer(struct vudc *udc);
179 struct urbp *alloc_urbp(void);
180 void free_urbp_and_urb(struct urbp *urb_p);
182 struct vep *vudc_find_endpoint(struct vudc *udc, u8 address);
184 struct vudc_device *alloc_vudc_device(int devid);
185 void put_vudc_device(struct vudc_device *udc_dev);
187 int vudc_probe(struct platform_device *pdev);
188 int vudc_remove(struct platform_device *pdev);
190 #endif /* __USBIP_VUDC_H */