vhci.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
  59. #ifdef CONFIG_USBIP_VHCI_HC_PORTS
  60. #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
  61. #else
  62. #define VHCI_HC_PORTS 8
  63. #endif
  64. #ifdef CONFIG_USBIP_VHCI_NR_HCS
  65. #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
  66. #else
  67. #define VHCI_NR_HCS 1
  68. #endif
  69. #define MAX_STATUS_NAME 16
  70. /* for usb_bus.hcpriv */
  71. struct vhci_hcd {
  72. spinlock_t lock;
  73. u32 port_status[VHCI_HC_PORTS];
  74. unsigned resuming:1;
  75. unsigned long re_timeout;
  76. atomic_t seqnum;
  77. /*
  78. * NOTE:
  79. * wIndex shows the port number and begins from 1.
  80. * But, the index of this array begins from 0.
  81. */
  82. struct vhci_device vdev[VHCI_HC_PORTS];
  83. };
  84. extern int vhci_num_controllers;
  85. extern struct platform_device **vhci_pdevs;
  86. extern struct attribute_group vhci_attr_group;
  87. /* vhci_hcd.c */
  88. void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
  89. /* vhci_sysfs.c */
  90. int vhci_init_attr_group(void);
  91. void vhci_finish_attr_group(void);
  92. /* vhci_rx.c */
  93. struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
  94. int vhci_rx_loop(void *data);
  95. /* vhci_tx.c */
  96. int vhci_tx_loop(void *data);
  97. static inline __u32 port_to_rhport(__u32 port)
  98. {
  99. return port % VHCI_HC_PORTS;
  100. }
  101. static inline int port_to_pdev_nr(__u32 port)
  102. {
  103. return port / VHCI_HC_PORTS;
  104. }
  105. static inline struct vhci_hcd *hcd_to_vhci(struct usb_hcd *hcd)
  106. {
  107. return (struct vhci_hcd *) (hcd->hcd_priv);
  108. }
  109. static inline struct device *hcd_dev(struct usb_hcd *hcd)
  110. {
  111. return (hcd)->self.controller;
  112. }
  113. static inline const char *hcd_name(struct usb_hcd *hcd)
  114. {
  115. return (hcd)->self.bus_name;
  116. }
  117. static inline struct usb_hcd *vhci_to_hcd(struct vhci_hcd *vhci)
  118. {
  119. return container_of((void *) vhci, struct usb_hcd, hcd_priv);
  120. }
  121. static inline struct vhci_hcd *vdev_to_vhci(struct vhci_device *vdev)
  122. {
  123. return container_of(
  124. (void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
  125. }
  126. #endif /* __USBIP_VHCI_H */