WIP FPC-III support
[linux/fpc-iii.git] / tools / usb / usbip / libsrc / usbip_host_common.h
blobf46967c0aa18de78b491f9234666f410e881be07
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>
7 * Refactored from usbip_host_driver.c, which is:
8 * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
9 * 2005-2007 Takahiro Hirofuchi
12 #ifndef __USBIP_HOST_COMMON_H
13 #define __USBIP_HOST_COMMON_H
15 #include <stdint.h>
16 #include <libudev.h>
17 #include <errno.h>
18 #include "list.h"
19 #include "usbip_common.h"
20 #include "sysfs_utils.h"
22 struct usbip_host_driver;
24 struct usbip_host_driver_ops {
25 int (*open)(struct usbip_host_driver *hdriver);
26 void (*close)(struct usbip_host_driver *hdriver);
27 int (*refresh_device_list)(struct usbip_host_driver *hdriver);
28 struct usbip_exported_device * (*get_device)(
29 struct usbip_host_driver *hdriver, int num);
31 int (*read_device)(struct udev_device *sdev,
32 struct usbip_usb_device *dev);
33 int (*read_interface)(struct usbip_usb_device *udev, int i,
34 struct usbip_usb_interface *uinf);
35 int (*is_my_device)(struct udev_device *udev);
38 struct usbip_host_driver {
39 int ndevs;
40 /* list of exported device */
41 struct list_head edev_list;
42 const char *udev_subsystem;
43 struct usbip_host_driver_ops ops;
46 struct usbip_exported_device {
47 struct udev_device *sudev;
48 int32_t status;
49 struct usbip_usb_device udev;
50 struct list_head node;
51 struct usbip_usb_interface uinf[];
54 /* External API to access the driver */
55 static inline int usbip_driver_open(struct usbip_host_driver *hdriver)
57 if (!hdriver->ops.open)
58 return -EOPNOTSUPP;
59 return hdriver->ops.open(hdriver);
62 static inline void usbip_driver_close(struct usbip_host_driver *hdriver)
64 if (!hdriver->ops.close)
65 return;
66 hdriver->ops.close(hdriver);
69 static inline int usbip_refresh_device_list(struct usbip_host_driver *hdriver)
71 if (!hdriver->ops.refresh_device_list)
72 return -EOPNOTSUPP;
73 return hdriver->ops.refresh_device_list(hdriver);
76 static inline struct usbip_exported_device *
77 usbip_get_device(struct usbip_host_driver *hdriver, int num)
79 if (!hdriver->ops.get_device)
80 return NULL;
81 return hdriver->ops.get_device(hdriver, num);
84 /* Helper functions for implementing driver backend */
85 int usbip_generic_driver_open(struct usbip_host_driver *hdriver);
86 void usbip_generic_driver_close(struct usbip_host_driver *hdriver);
87 int usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver);
88 int usbip_export_device(struct usbip_exported_device *edev, int sockfd);
89 struct usbip_exported_device *usbip_generic_get_device(
90 struct usbip_host_driver *hdriver, int num);
92 #endif /* __USBIP_HOST_COMMON_H */