stub.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 *urb;
  47. int unlinking;
  48. };
  49. struct stub_unlink {
  50. unsigned long seqnum;
  51. struct list_head list;
  52. __u32 status;
  53. };
  54. /* same as SYSFS_BUS_ID_SIZE */
  55. #define BUSID_SIZE 32
  56. struct bus_id_priv {
  57. char name[BUSID_SIZE];
  58. char status;
  59. int interf_count;
  60. struct stub_device *sdev;
  61. struct usb_device *udev;
  62. char shutdown_busid;
  63. spinlock_t busid_lock;
  64. };
  65. /* stub_priv is allocated from stub_priv_cache */
  66. extern struct kmem_cache *stub_priv_cache;
  67. /* stub_dev.c */
  68. extern struct usb_device_driver stub_driver;
  69. /* stub_main.c */
  70. struct bus_id_priv *get_busid_priv(const char *busid);
  71. void put_busid_priv(struct bus_id_priv *bid);
  72. int del_match_busid(char *busid);
  73. void stub_device_cleanup_urbs(struct stub_device *sdev);
  74. /* stub_rx.c */
  75. int stub_rx_loop(void *data);
  76. /* stub_tx.c */
  77. void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
  78. __u32 status);
  79. void stub_complete(struct urb *urb);
  80. int stub_tx_loop(void *data);
  81. #endif /* __USBIP_STUB_H */