stub.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2003-2008 Takahiro Hirofuchi
  4. */
  5. #ifndef __USBIP_STUB_H
  6. #define __USBIP_STUB_H
  7. #include <linux/list.h>
  8. #include <linux/slab.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/types.h>
  11. #include <linux/usb.h>
  12. #include <linux/wait.h>
  13. #define STUB_BUSID_OTHER 0
  14. #define STUB_BUSID_REMOV 1
  15. #define STUB_BUSID_ADDED 2
  16. #define STUB_BUSID_ALLOC 3
  17. struct stub_device {
  18. struct usb_device *udev;
  19. struct usbip_device ud;
  20. __u32 devid;
  21. /*
  22. * stub_priv preserves private data of each urb.
  23. * It is allocated as stub_priv_cache and assigned to urb->context.
  24. *
  25. * stub_priv is always linked to any one of 3 lists;
  26. * priv_init: linked to this until the comletion of a urb.
  27. * priv_tx : linked to this after the completion of a urb.
  28. * priv_free: linked to this after the sending of the result.
  29. *
  30. * Any of these list operations should be locked by priv_lock.
  31. */
  32. spinlock_t priv_lock;
  33. struct list_head priv_init;
  34. struct list_head priv_tx;
  35. struct list_head priv_free;
  36. /* see comments for unlinking in stub_rx.c */
  37. struct list_head unlink_tx;
  38. struct list_head unlink_free;
  39. wait_queue_head_t tx_waitq;
  40. };
  41. /* private data into urb->priv */
  42. struct stub_priv {
  43. unsigned long seqnum;
  44. struct list_head list;
  45. struct stub_device *sdev;
  46. struct urb **urbs;
  47. struct scatterlist *sgl;
  48. int num_urbs;
  49. int completed_urbs;
  50. int urb_status;
  51. int unlinking;
  52. };
  53. struct stub_unlink {
  54. unsigned long seqnum;
  55. struct list_head list;
  56. __u32 status;
  57. };
  58. /* same as SYSFS_BUS_ID_SIZE */
  59. #define BUSID_SIZE 32
  60. struct bus_id_priv {
  61. char name[BUSID_SIZE];
  62. char status;
  63. int interf_count;
  64. struct stub_device *sdev;
  65. struct usb_device *udev;
  66. char shutdown_busid;
  67. spinlock_t busid_lock;
  68. };
  69. /* stub_priv is allocated from stub_priv_cache */
  70. extern struct kmem_cache *stub_priv_cache;
  71. /* stub_dev.c */
  72. extern struct usb_device_driver stub_driver;
  73. /* stub_main.c */
  74. struct bus_id_priv *get_busid_priv(const char *busid);
  75. void put_busid_priv(struct bus_id_priv *bid);
  76. int del_match_busid(char *busid);
  77. void stub_free_priv_and_urb(struct stub_priv *priv);
  78. void stub_device_cleanup_urbs(struct stub_device *sdev);
  79. /* stub_rx.c */
  80. int stub_rx_loop(void *data);
  81. /* stub_tx.c */
  82. void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
  83. __u32 status);
  84. void stub_complete(struct urb *urb);
  85. int stub_tx_loop(void *data);
  86. #endif /* __USBIP_STUB_H */