vudc.h 3.6 KB

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