162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2015-2016 Samsung Electronics 462306a36Sopenharmony_ci * Igor Kotrasinski <i.kotrasinsk@samsung.com> 562306a36Sopenharmony_ci * Krzysztof Opasiak <k.opasiak@samsung.com> 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Refactored from usbip_host_driver.c, which is: 862306a36Sopenharmony_ci * Copyright (C) 2011 matt mooney <mfm@muteddisk.com> 962306a36Sopenharmony_ci * 2005-2007 Takahiro Hirofuchi 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#ifndef __USBIP_HOST_COMMON_H 1362306a36Sopenharmony_ci#define __USBIP_HOST_COMMON_H 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <stdint.h> 1662306a36Sopenharmony_ci#include <libudev.h> 1762306a36Sopenharmony_ci#include <errno.h> 1862306a36Sopenharmony_ci#include "list.h" 1962306a36Sopenharmony_ci#include "usbip_common.h" 2062306a36Sopenharmony_ci#include "sysfs_utils.h" 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_cistruct usbip_host_driver; 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_cistruct usbip_host_driver_ops { 2562306a36Sopenharmony_ci int (*open)(struct usbip_host_driver *hdriver); 2662306a36Sopenharmony_ci void (*close)(struct usbip_host_driver *hdriver); 2762306a36Sopenharmony_ci int (*refresh_device_list)(struct usbip_host_driver *hdriver); 2862306a36Sopenharmony_ci struct usbip_exported_device * (*get_device)( 2962306a36Sopenharmony_ci struct usbip_host_driver *hdriver, int num); 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci int (*read_device)(struct udev_device *sdev, 3262306a36Sopenharmony_ci struct usbip_usb_device *dev); 3362306a36Sopenharmony_ci int (*read_interface)(struct usbip_usb_device *udev, int i, 3462306a36Sopenharmony_ci struct usbip_usb_interface *uinf); 3562306a36Sopenharmony_ci int (*is_my_device)(struct udev_device *udev); 3662306a36Sopenharmony_ci}; 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_cistruct usbip_host_driver { 3962306a36Sopenharmony_ci int ndevs; 4062306a36Sopenharmony_ci /* list of exported device */ 4162306a36Sopenharmony_ci struct list_head edev_list; 4262306a36Sopenharmony_ci const char *udev_subsystem; 4362306a36Sopenharmony_ci struct usbip_host_driver_ops ops; 4462306a36Sopenharmony_ci}; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_cistruct usbip_exported_device { 4762306a36Sopenharmony_ci struct udev_device *sudev; 4862306a36Sopenharmony_ci int32_t status; 4962306a36Sopenharmony_ci struct usbip_usb_device udev; 5062306a36Sopenharmony_ci struct list_head node; 5162306a36Sopenharmony_ci struct usbip_usb_interface uinf[]; 5262306a36Sopenharmony_ci}; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* External API to access the driver */ 5562306a36Sopenharmony_cistatic inline int usbip_driver_open(struct usbip_host_driver *hdriver) 5662306a36Sopenharmony_ci{ 5762306a36Sopenharmony_ci if (!hdriver->ops.open) 5862306a36Sopenharmony_ci return -EOPNOTSUPP; 5962306a36Sopenharmony_ci return hdriver->ops.open(hdriver); 6062306a36Sopenharmony_ci} 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_cistatic inline void usbip_driver_close(struct usbip_host_driver *hdriver) 6362306a36Sopenharmony_ci{ 6462306a36Sopenharmony_ci if (!hdriver->ops.close) 6562306a36Sopenharmony_ci return; 6662306a36Sopenharmony_ci hdriver->ops.close(hdriver); 6762306a36Sopenharmony_ci} 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cistatic inline int usbip_refresh_device_list(struct usbip_host_driver *hdriver) 7062306a36Sopenharmony_ci{ 7162306a36Sopenharmony_ci if (!hdriver->ops.refresh_device_list) 7262306a36Sopenharmony_ci return -EOPNOTSUPP; 7362306a36Sopenharmony_ci return hdriver->ops.refresh_device_list(hdriver); 7462306a36Sopenharmony_ci} 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_cistatic inline struct usbip_exported_device * 7762306a36Sopenharmony_ciusbip_get_device(struct usbip_host_driver *hdriver, int num) 7862306a36Sopenharmony_ci{ 7962306a36Sopenharmony_ci if (!hdriver->ops.get_device) 8062306a36Sopenharmony_ci return NULL; 8162306a36Sopenharmony_ci return hdriver->ops.get_device(hdriver, num); 8262306a36Sopenharmony_ci} 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/* Helper functions for implementing driver backend */ 8562306a36Sopenharmony_ciint usbip_generic_driver_open(struct usbip_host_driver *hdriver); 8662306a36Sopenharmony_civoid usbip_generic_driver_close(struct usbip_host_driver *hdriver); 8762306a36Sopenharmony_ciint usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver); 8862306a36Sopenharmony_ciint usbip_export_device(struct usbip_exported_device *edev, int sockfd); 8962306a36Sopenharmony_cistruct usbip_exported_device *usbip_generic_get_device( 9062306a36Sopenharmony_ci struct usbip_host_driver *hdriver, int num); 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci#endif /* __USBIP_HOST_COMMON_H */ 93