vudc.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #ifndef __USBIP_VUDC_H
  21. #define __USBIP_VUDC_H
  22. #include <linux/platform_device.h>
  23. #include <linux/usb.h>
  24. #include <linux/usb/gadget.h>
  25. #include <linux/usb/ch9.h>
  26. #include <linux/list.h>
  27. #include <linux/timer.h>
  28. #include <linux/time.h>
  29. #include <linux/sysfs.h>
  30. #include "usbip_common.h"
  31. #define GADGET_NAME "usbip-vudc"
  32. struct vep {
  33. struct usb_ep ep;
  34. unsigned type:2; /* type, as USB_ENDPOINT_XFER_* */
  35. char name[8]; /* space for ep name */
  36. const struct usb_endpoint_descriptor *desc;
  37. struct usb_gadget *gadget;
  38. struct list_head req_queue; /* Request queue */
  39. unsigned halted:1;
  40. unsigned wedged:1;
  41. unsigned already_seen:1;
  42. unsigned setup_stage:1;
  43. };
  44. struct vrequest {
  45. struct usb_request req;
  46. struct vudc *udc;
  47. struct list_head req_entry; /* Request queue */
  48. };
  49. struct urbp {
  50. struct urb *urb;
  51. struct vep *ep;
  52. struct list_head urb_entry; /* urb queue */
  53. unsigned long seqnum;
  54. unsigned type:2; /* for tx, since ep type can change after */
  55. unsigned new:1;
  56. };
  57. struct v_unlink {
  58. unsigned long seqnum;
  59. __u32 status;
  60. };
  61. enum tx_type {
  62. TX_UNLINK,
  63. TX_SUBMIT,
  64. };
  65. struct tx_item {
  66. struct list_head tx_entry;
  67. enum tx_type type;
  68. union {
  69. struct urbp *s;
  70. struct v_unlink *u;
  71. };
  72. };
  73. enum tr_state {
  74. VUDC_TR_RUNNING,
  75. VUDC_TR_IDLE,
  76. VUDC_TR_STOPPED,
  77. };
  78. struct transfer_timer {
  79. struct timer_list timer;
  80. enum tr_state state;
  81. unsigned long frame_start;
  82. int frame_limit;
  83. };
  84. struct vudc {
  85. struct usb_gadget gadget;
  86. struct usb_gadget_driver *driver;
  87. struct platform_device *pdev;
  88. struct usb_device_descriptor dev_desc;
  89. struct usbip_device ud;
  90. struct transfer_timer tr_timer;
  91. struct timeval start_time;
  92. struct list_head urb_queue;
  93. spinlock_t lock_tx;
  94. struct list_head tx_queue;
  95. wait_queue_head_t tx_waitq;
  96. spinlock_t lock;
  97. struct vep *ep;
  98. int address;
  99. u16 devstatus;
  100. unsigned pullup:1;
  101. unsigned connected:1;
  102. unsigned desc_cached:1;
  103. };
  104. struct vudc_device {
  105. struct platform_device *pdev;
  106. struct list_head dev_entry;
  107. };
  108. extern const struct attribute_group vudc_attr_group;
  109. /* visible everywhere */
  110. static inline struct vep *to_vep(struct usb_ep *_ep)
  111. {
  112. return container_of(_ep, struct vep, ep);
  113. }
  114. static inline struct vrequest *to_vrequest(
  115. struct usb_request *_req)
  116. {
  117. return container_of(_req, struct vrequest, req);
  118. }
  119. static inline struct vudc *usb_gadget_to_vudc(
  120. struct usb_gadget *_gadget)
  121. {
  122. return container_of(_gadget, struct vudc, gadget);
  123. }
  124. static inline struct vudc *ep_to_vudc(struct vep *ep)
  125. {
  126. return container_of(ep->gadget, struct vudc, gadget);
  127. }
  128. /* vudc_sysfs.c */
  129. int get_gadget_descs(struct vudc *udc);
  130. /* vudc_tx.c */
  131. int v_tx_loop(void *data);
  132. void v_enqueue_ret_unlink(struct vudc *udc, __u32 seqnum, __u32 status);
  133. void v_enqueue_ret_submit(struct vudc *udc, struct urbp *urb_p);
  134. /* vudc_rx.c */
  135. int v_rx_loop(void *data);
  136. /* vudc_transfer.c */
  137. void v_init_timer(struct vudc *udc);
  138. void v_start_timer(struct vudc *udc);
  139. void v_kick_timer(struct vudc *udc, unsigned long time);
  140. void v_stop_timer(struct vudc *udc);
  141. /* vudc_dev.c */
  142. struct urbp *alloc_urbp(void);
  143. void free_urbp_and_urb(struct urbp *urb_p);
  144. struct vep *vudc_find_endpoint(struct vudc *udc, u8 address);
  145. struct vudc_device *alloc_vudc_device(int devid);
  146. void put_vudc_device(struct vudc_device *udc_dev);
  147. int vudc_probe(struct platform_device *pdev);
  148. int vudc_remove(struct platform_device *pdev);
  149. #endif /* __USBIP_VUDC_H */