stub.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * This is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #ifndef __USBIP_STUB_H
  20. #define __USBIP_STUB_H
  21. #include <linux/list.h>
  22. #include <linux/slab.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/types.h>
  25. #include <linux/usb.h>
  26. #include <linux/wait.h>
  27. #define STUB_BUSID_OTHER 0
  28. #define STUB_BUSID_REMOV 1
  29. #define STUB_BUSID_ADDED 2
  30. #define STUB_BUSID_ALLOC 3
  31. struct stub_device {
  32. struct usb_interface *interface;
  33. struct usb_device *udev;
  34. struct usbip_device ud;
  35. __u32 devid;
  36. /*
  37. * stub_priv preserves private data of each urb.
  38. * It is allocated as stub_priv_cache and assigned to urb->context.
  39. *
  40. * stub_priv is always linked to any one of 3 lists;
  41. * priv_init: linked to this until the comletion of a urb.
  42. * priv_tx : linked to this after the completion of a urb.
  43. * priv_free: linked to this after the sending of the result.
  44. *
  45. * Any of these list operations should be locked by priv_lock.
  46. */
  47. spinlock_t priv_lock;
  48. struct list_head priv_init;
  49. struct list_head priv_tx;
  50. struct list_head priv_free;
  51. /* see comments for unlinking in stub_rx.c */
  52. struct list_head unlink_tx;
  53. struct list_head unlink_free;
  54. wait_queue_head_t tx_waitq;
  55. };
  56. /* private data into urb->priv */
  57. struct stub_priv {
  58. unsigned long seqnum;
  59. struct list_head list;
  60. struct stub_device *sdev;
  61. struct urb *urb;
  62. int unlinking;
  63. };
  64. struct stub_unlink {
  65. unsigned long seqnum;
  66. struct list_head list;
  67. __u32 status;
  68. };
  69. /* same as SYSFS_BUS_ID_SIZE */
  70. #define BUSID_SIZE 32
  71. struct bus_id_priv {
  72. char name[BUSID_SIZE];
  73. char status;
  74. int interf_count;
  75. struct stub_device *sdev;
  76. struct usb_device *udev;
  77. char shutdown_busid;
  78. spinlock_t busid_lock;
  79. };
  80. /* stub_priv is allocated from stub_priv_cache */
  81. extern struct kmem_cache *stub_priv_cache;
  82. /* stub_dev.c */
  83. extern struct usb_device_driver stub_driver;
  84. /* stub_main.c */
  85. struct bus_id_priv *get_busid_priv(const char *busid);
  86. void put_busid_priv(struct bus_id_priv *bid);
  87. int del_match_busid(char *busid);
  88. void stub_device_cleanup_urbs(struct stub_device *sdev);
  89. /* stub_rx.c */
  90. int stub_rx_loop(void *data);
  91. /* stub_tx.c */
  92. void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
  93. __u32 status);
  94. void stub_complete(struct urb *urb);
  95. int stub_tx_loop(void *data);
  96. #endif /* __USBIP_STUB_H */