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_device *udev;
  33. struct usbip_device ud;
  34. __u32 devid;
  35. /*
  36. * stub_priv preserves private data of each urb.
  37. * It is allocated as stub_priv_cache and assigned to urb->context.
  38. *
  39. * stub_priv is always linked to any one of 3 lists;
  40. * priv_init: linked to this until the comletion of a urb.
  41. * priv_tx : linked to this after the completion of a urb.
  42. * priv_free: linked to this after the sending of the result.
  43. *
  44. * Any of these list operations should be locked by priv_lock.
  45. */
  46. spinlock_t priv_lock;
  47. struct list_head priv_init;
  48. struct list_head priv_tx;
  49. struct list_head priv_free;
  50. /* see comments for unlinking in stub_rx.c */
  51. struct list_head unlink_tx;
  52. struct list_head unlink_free;
  53. wait_queue_head_t tx_waitq;
  54. };
  55. /* private data into urb->priv */
  56. struct stub_priv {
  57. unsigned long seqnum;
  58. struct list_head list;
  59. struct stub_device *sdev;
  60. struct urb *urb;
  61. int unlinking;
  62. };
  63. struct stub_unlink {
  64. unsigned long seqnum;
  65. struct list_head list;
  66. __u32 status;
  67. };
  68. /* same as SYSFS_BUS_ID_SIZE */
  69. #define BUSID_SIZE 32
  70. struct bus_id_priv {
  71. char name[BUSID_SIZE];
  72. char status;
  73. int interf_count;
  74. struct stub_device *sdev;
  75. struct usb_device *udev;
  76. char shutdown_busid;
  77. spinlock_t busid_lock;
  78. };
  79. /* stub_priv is allocated from stub_priv_cache */
  80. extern struct kmem_cache *stub_priv_cache;
  81. /* stub_dev.c */
  82. extern struct usb_device_driver stub_driver;
  83. /* stub_main.c */
  84. struct bus_id_priv *get_busid_priv(const char *busid);
  85. void put_busid_priv(struct bus_id_priv *bid);
  86. int del_match_busid(char *busid);
  87. void stub_device_cleanup_urbs(struct stub_device *sdev);
  88. /* stub_rx.c */
  89. int stub_rx_loop(void *data);
  90. /* stub_tx.c */
  91. void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
  92. __u32 status);
  93. void stub_complete(struct urb *urb);
  94. int stub_tx_loop(void *data);
  95. #endif /* __USBIP_STUB_H */