18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2015-2016 Samsung Electronics 48c2ecf20Sopenharmony_ci * Igor Kotrasinski <i.kotrasinsk@samsung.com> 58c2ecf20Sopenharmony_ci * Krzysztof Opasiak <k.opasiak@samsung.com> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Refactored from usbip_host_driver.c, which is: 88c2ecf20Sopenharmony_ci * Copyright (C) 2011 matt mooney <mfm@muteddisk.com> 98c2ecf20Sopenharmony_ci * 2005-2007 Takahiro Hirofuchi 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef __USBIP_HOST_COMMON_H 138c2ecf20Sopenharmony_ci#define __USBIP_HOST_COMMON_H 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <stdint.h> 168c2ecf20Sopenharmony_ci#include <libudev.h> 178c2ecf20Sopenharmony_ci#include <errno.h> 188c2ecf20Sopenharmony_ci#include "list.h" 198c2ecf20Sopenharmony_ci#include "usbip_common.h" 208c2ecf20Sopenharmony_ci#include "sysfs_utils.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistruct usbip_host_driver; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistruct usbip_host_driver_ops { 258c2ecf20Sopenharmony_ci int (*open)(struct usbip_host_driver *hdriver); 268c2ecf20Sopenharmony_ci void (*close)(struct usbip_host_driver *hdriver); 278c2ecf20Sopenharmony_ci int (*refresh_device_list)(struct usbip_host_driver *hdriver); 288c2ecf20Sopenharmony_ci struct usbip_exported_device * (*get_device)( 298c2ecf20Sopenharmony_ci struct usbip_host_driver *hdriver, int num); 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci int (*read_device)(struct udev_device *sdev, 328c2ecf20Sopenharmony_ci struct usbip_usb_device *dev); 338c2ecf20Sopenharmony_ci int (*read_interface)(struct usbip_usb_device *udev, int i, 348c2ecf20Sopenharmony_ci struct usbip_usb_interface *uinf); 358c2ecf20Sopenharmony_ci int (*is_my_device)(struct udev_device *udev); 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistruct usbip_host_driver { 398c2ecf20Sopenharmony_ci int ndevs; 408c2ecf20Sopenharmony_ci /* list of exported device */ 418c2ecf20Sopenharmony_ci struct list_head edev_list; 428c2ecf20Sopenharmony_ci const char *udev_subsystem; 438c2ecf20Sopenharmony_ci struct usbip_host_driver_ops ops; 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistruct usbip_exported_device { 478c2ecf20Sopenharmony_ci struct udev_device *sudev; 488c2ecf20Sopenharmony_ci int32_t status; 498c2ecf20Sopenharmony_ci struct usbip_usb_device udev; 508c2ecf20Sopenharmony_ci struct list_head node; 518c2ecf20Sopenharmony_ci struct usbip_usb_interface uinf[]; 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci/* External API to access the driver */ 558c2ecf20Sopenharmony_cistatic inline int usbip_driver_open(struct usbip_host_driver *hdriver) 568c2ecf20Sopenharmony_ci{ 578c2ecf20Sopenharmony_ci if (!hdriver->ops.open) 588c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 598c2ecf20Sopenharmony_ci return hdriver->ops.open(hdriver); 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic inline void usbip_driver_close(struct usbip_host_driver *hdriver) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci if (!hdriver->ops.close) 658c2ecf20Sopenharmony_ci return; 668c2ecf20Sopenharmony_ci hdriver->ops.close(hdriver); 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic inline int usbip_refresh_device_list(struct usbip_host_driver *hdriver) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci if (!hdriver->ops.refresh_device_list) 728c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 738c2ecf20Sopenharmony_ci return hdriver->ops.refresh_device_list(hdriver); 748c2ecf20Sopenharmony_ci} 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cistatic inline struct usbip_exported_device * 778c2ecf20Sopenharmony_ciusbip_get_device(struct usbip_host_driver *hdriver, int num) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci if (!hdriver->ops.get_device) 808c2ecf20Sopenharmony_ci return NULL; 818c2ecf20Sopenharmony_ci return hdriver->ops.get_device(hdriver, num); 828c2ecf20Sopenharmony_ci} 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* Helper functions for implementing driver backend */ 858c2ecf20Sopenharmony_ciint usbip_generic_driver_open(struct usbip_host_driver *hdriver); 868c2ecf20Sopenharmony_civoid usbip_generic_driver_close(struct usbip_host_driver *hdriver); 878c2ecf20Sopenharmony_ciint usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver); 888c2ecf20Sopenharmony_ciint usbip_export_device(struct usbip_exported_device *edev, int sockfd); 898c2ecf20Sopenharmony_cistruct usbip_exported_device *usbip_generic_get_device( 908c2ecf20Sopenharmony_ci struct usbip_host_driver *hdriver, int num); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#endif /* __USBIP_HOST_COMMON_H */ 93