vhci.h 3.7 KB

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