Linux Audio

Check our new training course

Embedded Linux training

Mar 10-20, 2025, special US time zones
Register
Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Copyright (C) 2015 Karol Kosik <karo9@interia.eu>
  4 * Copyright (C) 2015-2016 Samsung Electronics
  5 *               Igor Kotrasinski <i.kotrasinsk@samsung.com>
  6 *               Krzysztof Opasiak <k.opasiak@samsung.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
  7 */
  8
  9#ifndef __USBIP_VUDC_H
 10#define __USBIP_VUDC_H
 11
 12#include <linux/platform_device.h>
 13#include <linux/usb.h>
 14#include <linux/usb/gadget.h>
 15#include <linux/usb/ch9.h>
 16#include <linux/list.h>
 17#include <linux/timer.h>
 18#include <linux/time.h>
 19#include <linux/sysfs.h>
 20
 21#include "usbip_common.h"
 22
 23#define GADGET_NAME "usbip-vudc"
 24
 25struct vep {
 26	struct usb_ep ep;
 27	unsigned type:2; /* type, as USB_ENDPOINT_XFER_* */
 28	char name[8];	/* space for ep name */
 29
 30	const struct usb_endpoint_descriptor *desc;
 31	struct usb_gadget *gadget;
 32	struct list_head req_queue; /* Request queue */
 33	unsigned halted:1;
 34	unsigned wedged:1;
 35	unsigned already_seen:1;
 36	unsigned setup_stage:1;
 37};
 38
 39struct vrequest {
 40	struct usb_request req;
 41	struct vudc *udc;
 42	struct list_head req_entry; /* Request queue */
 43};
 44
 45struct urbp {
 46	struct urb *urb;
 47	struct vep *ep;
 48	struct list_head urb_entry; /* urb queue */
 49	unsigned long seqnum;
 50	unsigned type:2; /* for tx, since ep type can change after */
 51	unsigned new:1;
 52};
 53
 54struct v_unlink {
 55	unsigned long seqnum;
 56	__u32 status;
 57};
 58
 59enum tx_type {
 60	TX_UNLINK,
 61	TX_SUBMIT,
 62};
 63
 64struct tx_item {
 65	struct list_head tx_entry;
 66	enum tx_type type;
 67	union {
 68		struct urbp *s;
 69		struct v_unlink *u;
 70	};
 71};
 72
 73enum tr_state {
 74	VUDC_TR_RUNNING,
 75	VUDC_TR_IDLE,
 76	VUDC_TR_STOPPED,
 77};
 78
 79struct transfer_timer {
 80	struct timer_list timer;
 81	enum tr_state state;
 82	unsigned long frame_start;
 83	int frame_limit;
 84};
 85
 86struct vudc {
 87	struct usb_gadget gadget;
 88	struct usb_gadget_driver *driver;
 89	struct platform_device *pdev;
 90
 91	struct usb_device_descriptor dev_desc;
 92
 93	struct usbip_device ud;
 94	struct transfer_timer tr_timer;
 95	struct timespec64 start_time;
 96
 97	struct list_head urb_queue;
 98
 99	spinlock_t lock_tx;
100	struct list_head tx_queue;
101	wait_queue_head_t tx_waitq;
102
103	spinlock_t lock;
104	struct vep *ep;
105	int address;
106	u16 devstatus;
107
108	unsigned pullup:1;
109	unsigned connected:1;
110	unsigned desc_cached:1;
111};
112
113struct vudc_device {
114	struct platform_device *pdev;
115	struct list_head dev_entry;
116};
117
118extern const struct attribute_group *vudc_groups[];
119
120/* visible everywhere */
121
122static inline struct vep *to_vep(struct usb_ep *_ep)
123{
124	return container_of(_ep, struct vep, ep);
125}
126
127static inline struct vrequest *to_vrequest(
128	struct usb_request *_req)
129{
130	return container_of(_req, struct vrequest, req);
131}
132
133static inline struct vudc *usb_gadget_to_vudc(
134	struct usb_gadget *_gadget)
135{
136	return container_of(_gadget, struct vudc, gadget);
137}
138
139static inline struct vudc *ep_to_vudc(struct vep *ep)
140{
141	return container_of(ep->gadget, struct vudc, gadget);
142}
143
144/* vudc_sysfs.c */
145
146int get_gadget_descs(struct vudc *udc);
147
148/* vudc_tx.c */
149
150int v_tx_loop(void *data);
151void v_enqueue_ret_unlink(struct vudc *udc, __u32 seqnum, __u32 status);
152void v_enqueue_ret_submit(struct vudc *udc, struct urbp *urb_p);
153
154/* vudc_rx.c */
155
156int v_rx_loop(void *data);
157
158/* vudc_transfer.c */
159
160void v_init_timer(struct vudc *udc);
161void v_start_timer(struct vudc *udc);
162void v_kick_timer(struct vudc *udc, unsigned long time);
163void v_stop_timer(struct vudc *udc);
164
165/* vudc_dev.c */
166
167struct urbp *alloc_urbp(void);
168void free_urbp_and_urb(struct urbp *urb_p);
169
170struct vep *vudc_find_endpoint(struct vudc *udc, u8 address);
171
172struct vudc_device *alloc_vudc_device(int devid);
173void put_vudc_device(struct vudc_device *udc_dev);
174
175int vudc_probe(struct platform_device *pdev);
176void vudc_remove(struct platform_device *pdev);
177
178#endif /* __USBIP_VUDC_H */
v4.10.11
 
  1/*
  2 * Copyright (C) 2015 Karol Kosik <karo9@interia.eu>
  3 * Copyright (C) 2015-2016 Samsung Electronics
  4 *               Igor Kotrasinski <i.kotrasinsk@samsung.com>
  5 *               Krzysztof Opasiak <k.opasiak@samsung.com>
  6 *
  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.
 11 *
 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.
 16 *
 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/>.
 19 */
 20
 21#ifndef __USBIP_VUDC_H
 22#define __USBIP_VUDC_H
 23
 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>
 32
 33#include "usbip_common.h"
 34
 35#define GADGET_NAME "usbip-vudc"
 36
 37struct vep {
 38	struct usb_ep ep;
 39	unsigned type:2; /* type, as USB_ENDPOINT_XFER_* */
 40	char name[8];	/* space for ep name */
 41
 42	const struct usb_endpoint_descriptor *desc;
 43	struct usb_gadget *gadget;
 44	struct list_head req_queue; /* Request queue */
 45	unsigned halted:1;
 46	unsigned wedged:1;
 47	unsigned already_seen:1;
 48	unsigned setup_stage:1;
 49};
 50
 51struct vrequest {
 52	struct usb_request req;
 53	struct vudc *udc;
 54	struct list_head req_entry; /* Request queue */
 55};
 56
 57struct urbp {
 58	struct urb *urb;
 59	struct vep *ep;
 60	struct list_head urb_entry; /* urb queue */
 61	unsigned long seqnum;
 62	unsigned type:2; /* for tx, since ep type can change after */
 63	unsigned new:1;
 64};
 65
 66struct v_unlink {
 67	unsigned long seqnum;
 68	__u32 status;
 69};
 70
 71enum tx_type {
 72	TX_UNLINK,
 73	TX_SUBMIT,
 74};
 75
 76struct tx_item {
 77	struct list_head tx_entry;
 78	enum tx_type type;
 79	union {
 80		struct urbp *s;
 81		struct v_unlink *u;
 82	};
 83};
 84
 85enum tr_state {
 86	VUDC_TR_RUNNING,
 87	VUDC_TR_IDLE,
 88	VUDC_TR_STOPPED,
 89};
 90
 91struct transfer_timer {
 92	struct timer_list timer;
 93	enum tr_state state;
 94	unsigned long frame_start;
 95	int frame_limit;
 96};
 97
 98struct vudc {
 99	struct usb_gadget gadget;
100	struct usb_gadget_driver *driver;
101	struct platform_device *pdev;
102
103	struct usb_device_descriptor dev_desc;
104
105	struct usbip_device ud;
106	struct transfer_timer tr_timer;
107	struct timeval start_time;
108
109	struct list_head urb_queue;
110
111	spinlock_t lock_tx;
112	struct list_head tx_queue;
113	wait_queue_head_t tx_waitq;
114
115	spinlock_t lock;
116	struct vep *ep;
117	int address;
118	u16 devstatus;
119
120	unsigned pullup:1;
121	unsigned connected:1;
122	unsigned desc_cached:1;
123};
124
125struct vudc_device {
126	struct platform_device *pdev;
127	struct list_head dev_entry;
128};
129
130extern const struct attribute_group vudc_attr_group;
131
132/* visible everywhere */
133
134static inline struct vep *to_vep(struct usb_ep *_ep)
135{
136	return container_of(_ep, struct vep, ep);
137}
138
139static inline struct vrequest *to_vrequest(
140	struct usb_request *_req)
141{
142	return container_of(_req, struct vrequest, req);
143}
144
145static inline struct vudc *usb_gadget_to_vudc(
146	struct usb_gadget *_gadget)
147{
148	return container_of(_gadget, struct vudc, gadget);
149}
150
151static inline struct vudc *ep_to_vudc(struct vep *ep)
152{
153	return container_of(ep->gadget, struct vudc, gadget);
154}
155
156/* vudc_sysfs.c */
157
158int get_gadget_descs(struct vudc *udc);
159
160/* vudc_tx.c */
161
162int v_tx_loop(void *data);
163void v_enqueue_ret_unlink(struct vudc *udc, __u32 seqnum, __u32 status);
164void v_enqueue_ret_submit(struct vudc *udc, struct urbp *urb_p);
165
166/* vudc_rx.c */
167
168int v_rx_loop(void *data);
169
170/* vudc_transfer.c */
171
172void v_init_timer(struct vudc *udc);
173void v_start_timer(struct vudc *udc);
174void v_kick_timer(struct vudc *udc, unsigned long time);
175void v_stop_timer(struct vudc *udc);
176
177/* vudc_dev.c */
178
179struct urbp *alloc_urbp(void);
180void free_urbp_and_urb(struct urbp *urb_p);
181
182struct vep *vudc_find_endpoint(struct vudc *udc, u8 address);
183
184struct vudc_device *alloc_vudc_device(int devid);
185void put_vudc_device(struct vudc_device *udc_dev);
186
187int vudc_probe(struct platform_device *pdev);
188int vudc_remove(struct platform_device *pdev);
189
190#endif /* __USBIP_VUDC_H */