usbip_host_common.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2015-2016 Samsung Electronics
  4. * Igor Kotrasinski <i.kotrasinsk@samsung.com>
  5. * Krzysztof Opasiak <k.opasiak@samsung.com>
  6. *
  7. * Refactored from usbip_host_driver.c, which is:
  8. * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
  9. * 2005-2007 Takahiro Hirofuchi
  10. */
  11. #ifndef __USBIP_HOST_COMMON_H
  12. #define __USBIP_HOST_COMMON_H
  13. #include <stdint.h>
  14. #include <libudev.h>
  15. #include <errno.h>
  16. #include "list.h"
  17. #include "usbip_common.h"
  18. #include "sysfs_utils.h"
  19. struct usbip_host_driver;
  20. struct usbip_host_driver_ops {
  21. int (*open)(struct usbip_host_driver *hdriver);
  22. void (*close)(struct usbip_host_driver *hdriver);
  23. int (*refresh_device_list)(struct usbip_host_driver *hdriver);
  24. struct usbip_exported_device * (*get_device)(
  25. struct usbip_host_driver *hdriver, int num);
  26. int (*read_device)(struct udev_device *sdev,
  27. struct usbip_usb_device *dev);
  28. int (*read_interface)(struct usbip_usb_device *udev, int i,
  29. struct usbip_usb_interface *uinf);
  30. int (*is_my_device)(struct udev_device *udev);
  31. };
  32. struct usbip_host_driver {
  33. int ndevs;
  34. /* list of exported device */
  35. struct list_head edev_list;
  36. const char *udev_subsystem;
  37. struct usbip_host_driver_ops ops;
  38. };
  39. struct usbip_exported_device {
  40. struct udev_device *sudev;
  41. int32_t status;
  42. struct usbip_usb_device udev;
  43. struct list_head node;
  44. struct usbip_usb_interface uinf[];
  45. };
  46. /* External API to access the driver */
  47. static inline int usbip_driver_open(struct usbip_host_driver *hdriver)
  48. {
  49. if (!hdriver->ops.open)
  50. return -EOPNOTSUPP;
  51. return hdriver->ops.open(hdriver);
  52. }
  53. static inline void usbip_driver_close(struct usbip_host_driver *hdriver)
  54. {
  55. if (!hdriver->ops.close)
  56. return;
  57. hdriver->ops.close(hdriver);
  58. }
  59. static inline int usbip_refresh_device_list(struct usbip_host_driver *hdriver)
  60. {
  61. if (!hdriver->ops.refresh_device_list)
  62. return -EOPNOTSUPP;
  63. return hdriver->ops.refresh_device_list(hdriver);
  64. }
  65. static inline struct usbip_exported_device *
  66. usbip_get_device(struct usbip_host_driver *hdriver, int num)
  67. {
  68. if (!hdriver->ops.get_device)
  69. return NULL;
  70. return hdriver->ops.get_device(hdriver, num);
  71. }
  72. /* Helper functions for implementing driver backend */
  73. int usbip_generic_driver_open(struct usbip_host_driver *hdriver);
  74. void usbip_generic_driver_close(struct usbip_host_driver *hdriver);
  75. int usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver);
  76. int usbip_export_device(struct usbip_exported_device *edev, int sockfd);
  77. struct usbip_exported_device *usbip_generic_get_device(
  78. struct usbip_host_driver *hdriver, int num);
  79. #endif /* __USBIP_HOST_COMMON_H */