vhci.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) 2003-2008 Takahiro Hirofuchi
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. */
  10. #ifndef __USBIP_VHCI_H
  11. #define __USBIP_VHCI_H
  12. #include <linux/device.h>
  13. #include <linux/list.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/sysfs.h>
  16. #include <linux/types.h>
  17. #include <linux/usb.h>
  18. #include <linux/usb/hcd.h>
  19. #include <linux/wait.h>
  20. struct vhci_device {
  21. struct usb_device *udev;
  22. /*
  23. * devid specifies a remote usb device uniquely instead
  24. * of combination of busnum and devnum.
  25. */
  26. __u32 devid;
  27. /* speed of a remote device */
  28. enum usb_device_speed speed;
  29. /* vhci root-hub port to which this device is attached */
  30. __u32 rhport;
  31. struct usbip_device ud;
  32. /* lock for the below link lists */
  33. spinlock_t priv_lock;
  34. /* vhci_priv is linked to one of them. */
  35. struct list_head priv_tx;
  36. struct list_head priv_rx;
  37. /* vhci_unlink is linked to one of them */
  38. struct list_head unlink_tx;
  39. struct list_head unlink_rx;
  40. /* vhci_tx thread sleeps for this queue */
  41. wait_queue_head_t waitq_tx;
  42. };
  43. /* urb->hcpriv, use container_of() */
  44. struct vhci_priv {
  45. unsigned long seqnum;
  46. struct list_head list;
  47. struct vhci_device *vdev;
  48. struct urb *urb;
  49. };
  50. struct vhci_unlink {
  51. /* seqnum of this request */
  52. unsigned long seqnum;
  53. struct list_head list;
  54. /* seqnum of the unlink target */
  55. unsigned long unlink_seqnum;
  56. };
  57. /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
  58. #define VHCI_NPORTS 8
  59. /* for usb_bus.hcpriv */
  60. struct vhci_hcd {
  61. spinlock_t lock;
  62. u32 port_status[VHCI_NPORTS];
  63. unsigned resuming:1;
  64. unsigned long re_timeout;
  65. atomic_t seqnum;
  66. /*
  67. * NOTE:
  68. * wIndex shows the port number and begins from 1.
  69. * But, the index of this array begins from 0.
  70. */
  71. struct vhci_device vdev[VHCI_NPORTS];
  72. };
  73. extern struct vhci_hcd *the_controller;
  74. extern const struct attribute_group dev_attr_group;
  75. /* vhci_hcd.c */
  76. void rh_port_connect(int rhport, enum usb_device_speed speed);
  77. /* vhci_rx.c */
  78. struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
  79. int vhci_rx_loop(void *data);
  80. /* vhci_tx.c */
  81. int vhci_tx_loop(void *data);
  82. static inline struct vhci_device *port_to_vdev(__u32 port)
  83. {
  84. return &the_controller->vdev[port];
  85. }
  86. static inline struct vhci_hcd *hcd_to_vhci(struct usb_hcd *hcd)
  87. {
  88. return (struct vhci_hcd *) (hcd->hcd_priv);
  89. }
  90. static inline struct usb_hcd *vhci_to_hcd(struct vhci_hcd *vhci)
  91. {
  92. return container_of((void *) vhci, struct usb_hcd, hcd_priv);
  93. }
  94. static inline struct device *vhci_dev(struct vhci_hcd *vhci)
  95. {
  96. return vhci_to_hcd(vhci)->self.controller;
  97. }
  98. #endif /* __USBIP_VHCI_H */