vhci.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2003-2008 Takahiro Hirofuchi
  4. * Copyright (C) 2015 Nobuo Iwata
  5. */
  6. #ifndef __USBIP_VHCI_H
  7. #define __USBIP_VHCI_H
  8. #include <linux/device.h>
  9. #include <linux/list.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/sysfs.h>
  12. #include <linux/types.h>
  13. #include <linux/usb.h>
  14. #include <linux/usb/hcd.h>
  15. #include <linux/wait.h>
  16. struct vhci_device {
  17. struct usb_device *udev;
  18. /*
  19. * devid specifies a remote usb device uniquely instead
  20. * of combination of busnum and devnum.
  21. */
  22. __u32 devid;
  23. /* speed of a remote device */
  24. enum usb_device_speed speed;
  25. /* vhci root-hub port to which this device is attached */
  26. __u32 rhport;
  27. struct usbip_device ud;
  28. /* lock for the below link lists */
  29. spinlock_t priv_lock;
  30. /* vhci_priv is linked to one of them. */
  31. struct list_head priv_tx;
  32. struct list_head priv_rx;
  33. /* vhci_unlink is linked to one of them */
  34. struct list_head unlink_tx;
  35. struct list_head unlink_rx;
  36. /* vhci_tx thread sleeps for this queue */
  37. wait_queue_head_t waitq_tx;
  38. };
  39. /* urb->hcpriv, use container_of() */
  40. struct vhci_priv {
  41. unsigned long seqnum;
  42. struct list_head list;
  43. struct vhci_device *vdev;
  44. struct urb *urb;
  45. };
  46. struct vhci_unlink {
  47. /* seqnum of this request */
  48. unsigned long seqnum;
  49. struct list_head list;
  50. /* seqnum of the unlink target */
  51. unsigned long unlink_seqnum;
  52. };
  53. enum hub_speed {
  54. HUB_SPEED_HIGH = 0,
  55. HUB_SPEED_SUPER,
  56. };
  57. /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
  58. #ifdef CONFIG_USBIP_VHCI_HC_PORTS
  59. #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
  60. #else
  61. #define VHCI_HC_PORTS 8
  62. #endif
  63. /* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
  64. #define VHCI_PORTS (VHCI_HC_PORTS*2)
  65. #ifdef CONFIG_USBIP_VHCI_NR_HCS
  66. #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
  67. #else
  68. #define VHCI_NR_HCS 1
  69. #endif
  70. #define MAX_STATUS_NAME 16
  71. struct vhci {
  72. spinlock_t lock;
  73. struct platform_device *pdev;
  74. struct vhci_hcd *vhci_hcd_hs;
  75. struct vhci_hcd *vhci_hcd_ss;
  76. };
  77. /* for usb_hcd.hcd_priv[0] */
  78. struct vhci_hcd {
  79. struct vhci *vhci;
  80. u32 port_status[VHCI_HC_PORTS];
  81. unsigned resuming:1;
  82. unsigned long re_timeout;
  83. atomic_t seqnum;
  84. /*
  85. * NOTE:
  86. * wIndex shows the port number and begins from 1.
  87. * But, the index of this array begins from 0.
  88. */
  89. struct vhci_device vdev[VHCI_HC_PORTS];
  90. };
  91. extern int vhci_num_controllers;
  92. extern struct vhci *vhcis;
  93. extern struct attribute_group vhci_attr_group;
  94. /* vhci_hcd.c */
  95. void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
  96. /* vhci_sysfs.c */
  97. int vhci_init_attr_group(void);
  98. void vhci_finish_attr_group(void);
  99. /* vhci_rx.c */
  100. struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
  101. int vhci_rx_loop(void *data);
  102. /* vhci_tx.c */
  103. int vhci_tx_loop(void *data);
  104. static inline __u32 port_to_rhport(__u32 port)
  105. {
  106. return port % VHCI_HC_PORTS;
  107. }
  108. static inline int port_to_pdev_nr(__u32 port)
  109. {
  110. return port / VHCI_PORTS;
  111. }
  112. static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd)
  113. {
  114. return (struct vhci_hcd *) (hcd->hcd_priv);
  115. }
  116. static inline struct device *hcd_dev(struct usb_hcd *hcd)
  117. {
  118. return (hcd)->self.controller;
  119. }
  120. static inline const char *hcd_name(struct usb_hcd *hcd)
  121. {
  122. return (hcd)->self.bus_name;
  123. }
  124. static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd)
  125. {
  126. return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv);
  127. }
  128. static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev)
  129. {
  130. return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
  131. }
  132. #endif /* __USBIP_VHCI_H */