Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Copyright (C) 2015 Karol Kosik <karo9@interia.eu>
0004  * Copyright (C) 2015-2016 Samsung Electronics
0005  *               Igor Kotrasinski <i.kotrasinsk@samsung.com>
0006  *               Krzysztof Opasiak <k.opasiak@samsung.com>
0007  */
0008 
0009 #ifndef __USBIP_VUDC_H
0010 #define __USBIP_VUDC_H
0011 
0012 #include <linux/platform_device.h>
0013 #include <linux/usb.h>
0014 #include <linux/usb/gadget.h>
0015 #include <linux/usb/ch9.h>
0016 #include <linux/list.h>
0017 #include <linux/timer.h>
0018 #include <linux/time.h>
0019 #include <linux/sysfs.h>
0020 
0021 #include "usbip_common.h"
0022 
0023 #define GADGET_NAME "usbip-vudc"
0024 
0025 struct vep {
0026     struct usb_ep ep;
0027     unsigned type:2; /* type, as USB_ENDPOINT_XFER_* */
0028     char name[8];   /* space for ep name */
0029 
0030     const struct usb_endpoint_descriptor *desc;
0031     struct usb_gadget *gadget;
0032     struct list_head req_queue; /* Request queue */
0033     unsigned halted:1;
0034     unsigned wedged:1;
0035     unsigned already_seen:1;
0036     unsigned setup_stage:1;
0037 };
0038 
0039 struct vrequest {
0040     struct usb_request req;
0041     struct vudc *udc;
0042     struct list_head req_entry; /* Request queue */
0043 };
0044 
0045 struct urbp {
0046     struct urb *urb;
0047     struct vep *ep;
0048     struct list_head urb_entry; /* urb queue */
0049     unsigned long seqnum;
0050     unsigned type:2; /* for tx, since ep type can change after */
0051     unsigned new:1;
0052 };
0053 
0054 struct v_unlink {
0055     unsigned long seqnum;
0056     __u32 status;
0057 };
0058 
0059 enum tx_type {
0060     TX_UNLINK,
0061     TX_SUBMIT,
0062 };
0063 
0064 struct tx_item {
0065     struct list_head tx_entry;
0066     enum tx_type type;
0067     union {
0068         struct urbp *s;
0069         struct v_unlink *u;
0070     };
0071 };
0072 
0073 enum tr_state {
0074     VUDC_TR_RUNNING,
0075     VUDC_TR_IDLE,
0076     VUDC_TR_STOPPED,
0077 };
0078 
0079 struct transfer_timer {
0080     struct timer_list timer;
0081     enum tr_state state;
0082     unsigned long frame_start;
0083     int frame_limit;
0084 };
0085 
0086 struct vudc {
0087     struct usb_gadget gadget;
0088     struct usb_gadget_driver *driver;
0089     struct platform_device *pdev;
0090 
0091     struct usb_device_descriptor dev_desc;
0092 
0093     struct usbip_device ud;
0094     struct transfer_timer tr_timer;
0095     struct timespec64 start_time;
0096 
0097     struct list_head urb_queue;
0098 
0099     spinlock_t lock_tx;
0100     struct list_head tx_queue;
0101     wait_queue_head_t tx_waitq;
0102 
0103     spinlock_t lock;
0104     struct vep *ep;
0105     int address;
0106     u16 devstatus;
0107 
0108     unsigned pullup:1;
0109     unsigned connected:1;
0110     unsigned desc_cached:1;
0111 };
0112 
0113 struct vudc_device {
0114     struct platform_device *pdev;
0115     struct list_head dev_entry;
0116 };
0117 
0118 extern const struct attribute_group *vudc_groups[];
0119 
0120 /* visible everywhere */
0121 
0122 static inline struct vep *to_vep(struct usb_ep *_ep)
0123 {
0124     return container_of(_ep, struct vep, ep);
0125 }
0126 
0127 static inline struct vrequest *to_vrequest(
0128     struct usb_request *_req)
0129 {
0130     return container_of(_req, struct vrequest, req);
0131 }
0132 
0133 static inline struct vudc *usb_gadget_to_vudc(
0134     struct usb_gadget *_gadget)
0135 {
0136     return container_of(_gadget, struct vudc, gadget);
0137 }
0138 
0139 static inline struct vudc *ep_to_vudc(struct vep *ep)
0140 {
0141     return container_of(ep->gadget, struct vudc, gadget);
0142 }
0143 
0144 /* vudc_sysfs.c */
0145 
0146 int get_gadget_descs(struct vudc *udc);
0147 
0148 /* vudc_tx.c */
0149 
0150 int v_tx_loop(void *data);
0151 void v_enqueue_ret_unlink(struct vudc *udc, __u32 seqnum, __u32 status);
0152 void v_enqueue_ret_submit(struct vudc *udc, struct urbp *urb_p);
0153 
0154 /* vudc_rx.c */
0155 
0156 int v_rx_loop(void *data);
0157 
0158 /* vudc_transfer.c */
0159 
0160 void v_init_timer(struct vudc *udc);
0161 void v_start_timer(struct vudc *udc);
0162 void v_kick_timer(struct vudc *udc, unsigned long time);
0163 void v_stop_timer(struct vudc *udc);
0164 
0165 /* vudc_dev.c */
0166 
0167 struct urbp *alloc_urbp(void);
0168 void free_urbp_and_urb(struct urbp *urb_p);
0169 
0170 struct vep *vudc_find_endpoint(struct vudc *udc, u8 address);
0171 
0172 struct vudc_device *alloc_vudc_device(int devid);
0173 void put_vudc_device(struct vudc_device *udc_dev);
0174 
0175 int vudc_probe(struct platform_device *pdev);
0176 int vudc_remove(struct platform_device *pdev);
0177 
0178 #endif /* __USBIP_VUDC_H */