1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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
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
{
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
;
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
)
59 return hdriver
->ops
.open(hdriver
);
62 static inline void usbip_driver_close(struct usbip_host_driver
*hdriver
)
64 if (!hdriver
->ops
.close
)
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
)
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
)
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 */