18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2003-2008 Takahiro Hirofuchi 48c2ecf20Sopenharmony_ci * Copyright (C) 2015-2016 Samsung Electronics 58c2ecf20Sopenharmony_ci * Krzysztof Opasiak <k.opasiak@samsung.com> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef __USBIP_COMMON_H 98c2ecf20Sopenharmony_ci#define __USBIP_COMMON_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/compiler.h> 128c2ecf20Sopenharmony_ci#include <linux/device.h> 138c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 148c2ecf20Sopenharmony_ci#include <linux/net.h> 158c2ecf20Sopenharmony_ci#include <linux/printk.h> 168c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 178c2ecf20Sopenharmony_ci#include <linux/types.h> 188c2ecf20Sopenharmony_ci#include <linux/usb.h> 198c2ecf20Sopenharmony_ci#include <linux/wait.h> 208c2ecf20Sopenharmony_ci#include <linux/sched/task.h> 218c2ecf20Sopenharmony_ci#include <uapi/linux/usbip.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#undef pr_fmt 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#ifdef DEBUG 268c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": %s:%d: " fmt, __func__, __LINE__ 278c2ecf20Sopenharmony_ci#else 288c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 298c2ecf20Sopenharmony_ci#endif 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cienum { 328c2ecf20Sopenharmony_ci usbip_debug_xmit = (1 << 0), 338c2ecf20Sopenharmony_ci usbip_debug_sysfs = (1 << 1), 348c2ecf20Sopenharmony_ci usbip_debug_urb = (1 << 2), 358c2ecf20Sopenharmony_ci usbip_debug_eh = (1 << 3), 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci usbip_debug_stub_cmp = (1 << 8), 388c2ecf20Sopenharmony_ci usbip_debug_stub_dev = (1 << 9), 398c2ecf20Sopenharmony_ci usbip_debug_stub_rx = (1 << 10), 408c2ecf20Sopenharmony_ci usbip_debug_stub_tx = (1 << 11), 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci usbip_debug_vhci_rh = (1 << 8), 438c2ecf20Sopenharmony_ci usbip_debug_vhci_hc = (1 << 9), 448c2ecf20Sopenharmony_ci usbip_debug_vhci_rx = (1 << 10), 458c2ecf20Sopenharmony_ci usbip_debug_vhci_tx = (1 << 11), 468c2ecf20Sopenharmony_ci usbip_debug_vhci_sysfs = (1 << 12) 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define usbip_dbg_flag_xmit (usbip_debug_flag & usbip_debug_xmit) 508c2ecf20Sopenharmony_ci#define usbip_dbg_flag_vhci_rh (usbip_debug_flag & usbip_debug_vhci_rh) 518c2ecf20Sopenharmony_ci#define usbip_dbg_flag_vhci_hc (usbip_debug_flag & usbip_debug_vhci_hc) 528c2ecf20Sopenharmony_ci#define usbip_dbg_flag_vhci_rx (usbip_debug_flag & usbip_debug_vhci_rx) 538c2ecf20Sopenharmony_ci#define usbip_dbg_flag_vhci_tx (usbip_debug_flag & usbip_debug_vhci_tx) 548c2ecf20Sopenharmony_ci#define usbip_dbg_flag_stub_rx (usbip_debug_flag & usbip_debug_stub_rx) 558c2ecf20Sopenharmony_ci#define usbip_dbg_flag_stub_tx (usbip_debug_flag & usbip_debug_stub_tx) 568c2ecf20Sopenharmony_ci#define usbip_dbg_flag_vhci_sysfs (usbip_debug_flag & usbip_debug_vhci_sysfs) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ciextern unsigned long usbip_debug_flag; 598c2ecf20Sopenharmony_ciextern struct device_attribute dev_attr_usbip_debug; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define usbip_dbg_with_flag(flag, fmt, args...) \ 628c2ecf20Sopenharmony_ci do { \ 638c2ecf20Sopenharmony_ci if (flag & usbip_debug_flag) \ 648c2ecf20Sopenharmony_ci pr_debug(fmt, ##args); \ 658c2ecf20Sopenharmony_ci } while (0) 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define usbip_dbg_sysfs(fmt, args...) \ 688c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_sysfs, fmt , ##args) 698c2ecf20Sopenharmony_ci#define usbip_dbg_xmit(fmt, args...) \ 708c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_xmit, fmt , ##args) 718c2ecf20Sopenharmony_ci#define usbip_dbg_urb(fmt, args...) \ 728c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_urb, fmt , ##args) 738c2ecf20Sopenharmony_ci#define usbip_dbg_eh(fmt, args...) \ 748c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_eh, fmt , ##args) 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define usbip_dbg_vhci_rh(fmt, args...) \ 778c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_vhci_rh, fmt , ##args) 788c2ecf20Sopenharmony_ci#define usbip_dbg_vhci_hc(fmt, args...) \ 798c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_vhci_hc, fmt , ##args) 808c2ecf20Sopenharmony_ci#define usbip_dbg_vhci_rx(fmt, args...) \ 818c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_vhci_rx, fmt , ##args) 828c2ecf20Sopenharmony_ci#define usbip_dbg_vhci_tx(fmt, args...) \ 838c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_vhci_tx, fmt , ##args) 848c2ecf20Sopenharmony_ci#define usbip_dbg_vhci_sysfs(fmt, args...) \ 858c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_vhci_sysfs, fmt , ##args) 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define usbip_dbg_stub_cmp(fmt, args...) \ 888c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_stub_cmp, fmt , ##args) 898c2ecf20Sopenharmony_ci#define usbip_dbg_stub_rx(fmt, args...) \ 908c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_stub_rx, fmt , ##args) 918c2ecf20Sopenharmony_ci#define usbip_dbg_stub_tx(fmt, args...) \ 928c2ecf20Sopenharmony_ci usbip_dbg_with_flag(usbip_debug_stub_tx, fmt , ##args) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* 958c2ecf20Sopenharmony_ci * USB/IP request headers 968c2ecf20Sopenharmony_ci * 978c2ecf20Sopenharmony_ci * Each request is transferred across the network to its counterpart, which 988c2ecf20Sopenharmony_ci * facilitates the normal USB communication. The values contained in the headers 998c2ecf20Sopenharmony_ci * are basically the same as in a URB. Currently, four request types are 1008c2ecf20Sopenharmony_ci * defined: 1018c2ecf20Sopenharmony_ci * 1028c2ecf20Sopenharmony_ci * - USBIP_CMD_SUBMIT: a USB request block, corresponds to usb_submit_urb() 1038c2ecf20Sopenharmony_ci * (client to server) 1048c2ecf20Sopenharmony_ci * 1058c2ecf20Sopenharmony_ci * - USBIP_RET_SUBMIT: the result of USBIP_CMD_SUBMIT 1068c2ecf20Sopenharmony_ci * (server to client) 1078c2ecf20Sopenharmony_ci * 1088c2ecf20Sopenharmony_ci * - USBIP_CMD_UNLINK: an unlink request of a pending USBIP_CMD_SUBMIT, 1098c2ecf20Sopenharmony_ci * corresponds to usb_unlink_urb() 1108c2ecf20Sopenharmony_ci * (client to server) 1118c2ecf20Sopenharmony_ci * 1128c2ecf20Sopenharmony_ci * - USBIP_RET_UNLINK: the result of USBIP_CMD_UNLINK 1138c2ecf20Sopenharmony_ci * (server to client) 1148c2ecf20Sopenharmony_ci * 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_ci#define USBIP_CMD_SUBMIT 0x0001 1178c2ecf20Sopenharmony_ci#define USBIP_CMD_UNLINK 0x0002 1188c2ecf20Sopenharmony_ci#define USBIP_RET_SUBMIT 0x0003 1198c2ecf20Sopenharmony_ci#define USBIP_RET_UNLINK 0x0004 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#define USBIP_DIR_OUT 0x00 1228c2ecf20Sopenharmony_ci#define USBIP_DIR_IN 0x01 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/* 1258c2ecf20Sopenharmony_ci * Arbitrary limit for the maximum number of isochronous packets in an URB, 1268c2ecf20Sopenharmony_ci * compare for example the uhci_submit_isochronous function in 1278c2ecf20Sopenharmony_ci * drivers/usb/host/uhci-q.c 1288c2ecf20Sopenharmony_ci */ 1298c2ecf20Sopenharmony_ci#define USBIP_MAX_ISO_PACKETS 1024 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/** 1328c2ecf20Sopenharmony_ci * struct usbip_header_basic - data pertinent to every request 1338c2ecf20Sopenharmony_ci * @command: the usbip request type 1348c2ecf20Sopenharmony_ci * @seqnum: sequential number that identifies requests; incremented per 1358c2ecf20Sopenharmony_ci * connection 1368c2ecf20Sopenharmony_ci * @devid: specifies a remote USB device uniquely instead of busnum and devnum; 1378c2ecf20Sopenharmony_ci * in the stub driver, this value is ((busnum << 16) | devnum) 1388c2ecf20Sopenharmony_ci * @direction: direction of the transfer 1398c2ecf20Sopenharmony_ci * @ep: endpoint number 1408c2ecf20Sopenharmony_ci */ 1418c2ecf20Sopenharmony_cistruct usbip_header_basic { 1428c2ecf20Sopenharmony_ci __u32 command; 1438c2ecf20Sopenharmony_ci __u32 seqnum; 1448c2ecf20Sopenharmony_ci __u32 devid; 1458c2ecf20Sopenharmony_ci __u32 direction; 1468c2ecf20Sopenharmony_ci __u32 ep; 1478c2ecf20Sopenharmony_ci} __packed; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/** 1508c2ecf20Sopenharmony_ci * struct usbip_header_cmd_submit - USBIP_CMD_SUBMIT packet header 1518c2ecf20Sopenharmony_ci * @transfer_flags: URB flags 1528c2ecf20Sopenharmony_ci * @transfer_buffer_length: the data size for (in) or (out) transfer 1538c2ecf20Sopenharmony_ci * @start_frame: initial frame for isochronous or interrupt transfers 1548c2ecf20Sopenharmony_ci * @number_of_packets: number of isochronous packets 1558c2ecf20Sopenharmony_ci * @interval: maximum time for the request on the server-side host controller 1568c2ecf20Sopenharmony_ci * @setup: setup data for a control request 1578c2ecf20Sopenharmony_ci */ 1588c2ecf20Sopenharmony_cistruct usbip_header_cmd_submit { 1598c2ecf20Sopenharmony_ci __u32 transfer_flags; 1608c2ecf20Sopenharmony_ci __s32 transfer_buffer_length; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci /* it is difficult for usbip to sync frames (reserved only?) */ 1638c2ecf20Sopenharmony_ci __s32 start_frame; 1648c2ecf20Sopenharmony_ci __s32 number_of_packets; 1658c2ecf20Sopenharmony_ci __s32 interval; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci unsigned char setup[8]; 1688c2ecf20Sopenharmony_ci} __packed; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci/** 1718c2ecf20Sopenharmony_ci * struct usbip_header_ret_submit - USBIP_RET_SUBMIT packet header 1728c2ecf20Sopenharmony_ci * @status: return status of a non-iso request 1738c2ecf20Sopenharmony_ci * @actual_length: number of bytes transferred 1748c2ecf20Sopenharmony_ci * @start_frame: initial frame for isochronous or interrupt transfers 1758c2ecf20Sopenharmony_ci * @number_of_packets: number of isochronous packets 1768c2ecf20Sopenharmony_ci * @error_count: number of errors for isochronous transfers 1778c2ecf20Sopenharmony_ci */ 1788c2ecf20Sopenharmony_cistruct usbip_header_ret_submit { 1798c2ecf20Sopenharmony_ci __s32 status; 1808c2ecf20Sopenharmony_ci __s32 actual_length; 1818c2ecf20Sopenharmony_ci __s32 start_frame; 1828c2ecf20Sopenharmony_ci __s32 number_of_packets; 1838c2ecf20Sopenharmony_ci __s32 error_count; 1848c2ecf20Sopenharmony_ci} __packed; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci/** 1878c2ecf20Sopenharmony_ci * struct usbip_header_cmd_unlink - USBIP_CMD_UNLINK packet header 1888c2ecf20Sopenharmony_ci * @seqnum: the URB seqnum to unlink 1898c2ecf20Sopenharmony_ci */ 1908c2ecf20Sopenharmony_cistruct usbip_header_cmd_unlink { 1918c2ecf20Sopenharmony_ci __u32 seqnum; 1928c2ecf20Sopenharmony_ci} __packed; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci/** 1958c2ecf20Sopenharmony_ci * struct usbip_header_ret_unlink - USBIP_RET_UNLINK packet header 1968c2ecf20Sopenharmony_ci * @status: return status of the request 1978c2ecf20Sopenharmony_ci */ 1988c2ecf20Sopenharmony_cistruct usbip_header_ret_unlink { 1998c2ecf20Sopenharmony_ci __s32 status; 2008c2ecf20Sopenharmony_ci} __packed; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci/** 2038c2ecf20Sopenharmony_ci * struct usbip_header - common header for all usbip packets 2048c2ecf20Sopenharmony_ci * @base: the basic header 2058c2ecf20Sopenharmony_ci * @u: packet type dependent header 2068c2ecf20Sopenharmony_ci */ 2078c2ecf20Sopenharmony_cistruct usbip_header { 2088c2ecf20Sopenharmony_ci struct usbip_header_basic base; 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci union { 2118c2ecf20Sopenharmony_ci struct usbip_header_cmd_submit cmd_submit; 2128c2ecf20Sopenharmony_ci struct usbip_header_ret_submit ret_submit; 2138c2ecf20Sopenharmony_ci struct usbip_header_cmd_unlink cmd_unlink; 2148c2ecf20Sopenharmony_ci struct usbip_header_ret_unlink ret_unlink; 2158c2ecf20Sopenharmony_ci } u; 2168c2ecf20Sopenharmony_ci} __packed; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci/* 2198c2ecf20Sopenharmony_ci * This is the same as usb_iso_packet_descriptor but packed for pdu. 2208c2ecf20Sopenharmony_ci */ 2218c2ecf20Sopenharmony_cistruct usbip_iso_packet_descriptor { 2228c2ecf20Sopenharmony_ci __u32 offset; 2238c2ecf20Sopenharmony_ci __u32 length; /* expected length */ 2248c2ecf20Sopenharmony_ci __u32 actual_length; 2258c2ecf20Sopenharmony_ci __u32 status; 2268c2ecf20Sopenharmony_ci} __packed; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_cienum usbip_side { 2298c2ecf20Sopenharmony_ci USBIP_VHCI, 2308c2ecf20Sopenharmony_ci USBIP_STUB, 2318c2ecf20Sopenharmony_ci USBIP_VUDC, 2328c2ecf20Sopenharmony_ci}; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci/* event handler */ 2358c2ecf20Sopenharmony_ci#define USBIP_EH_SHUTDOWN (1 << 0) 2368c2ecf20Sopenharmony_ci#define USBIP_EH_BYE (1 << 1) 2378c2ecf20Sopenharmony_ci#define USBIP_EH_RESET (1 << 2) 2388c2ecf20Sopenharmony_ci#define USBIP_EH_UNUSABLE (1 << 3) 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci#define SDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_BYE) 2418c2ecf20Sopenharmony_ci#define SDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) 2428c2ecf20Sopenharmony_ci#define SDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) 2438c2ecf20Sopenharmony_ci#define SDEV_EVENT_ERROR_SUBMIT (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) 2448c2ecf20Sopenharmony_ci#define SDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE) 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci#define VUDC_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE) 2478c2ecf20Sopenharmony_ci#define VUDC_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) 2488c2ecf20Sopenharmony_ci#define VUDC_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) 2498c2ecf20Sopenharmony_ci/* catastrophic emulated usb error */ 2508c2ecf20Sopenharmony_ci#define VUDC_EVENT_ERROR_USB (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE) 2518c2ecf20Sopenharmony_ci#define VUDC_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE) 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci#define VDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE) 2548c2ecf20Sopenharmony_ci#define VDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) 2558c2ecf20Sopenharmony_ci#define VDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) 2568c2ecf20Sopenharmony_ci#define VDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE) 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci/* a common structure for stub_device and vhci_device */ 2598c2ecf20Sopenharmony_cistruct usbip_device { 2608c2ecf20Sopenharmony_ci enum usbip_side side; 2618c2ecf20Sopenharmony_ci enum usbip_device_status status; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci /* lock for status */ 2648c2ecf20Sopenharmony_ci spinlock_t lock; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci /* mutex for synchronizing sysfs store paths */ 2678c2ecf20Sopenharmony_ci struct mutex sysfs_lock; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci int sockfd; 2708c2ecf20Sopenharmony_ci struct socket *tcp_socket; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci struct task_struct *tcp_rx; 2738c2ecf20Sopenharmony_ci struct task_struct *tcp_tx; 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci unsigned long event; 2768c2ecf20Sopenharmony_ci wait_queue_head_t eh_waitq; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci struct eh_ops { 2798c2ecf20Sopenharmony_ci void (*shutdown)(struct usbip_device *); 2808c2ecf20Sopenharmony_ci void (*reset)(struct usbip_device *); 2818c2ecf20Sopenharmony_ci void (*unusable)(struct usbip_device *); 2828c2ecf20Sopenharmony_ci } eh_ops; 2838c2ecf20Sopenharmony_ci}; 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci#define kthread_get_run(threadfn, data, namefmt, ...) \ 2868c2ecf20Sopenharmony_ci({ \ 2878c2ecf20Sopenharmony_ci struct task_struct *__k \ 2888c2ecf20Sopenharmony_ci = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \ 2898c2ecf20Sopenharmony_ci if (!IS_ERR(__k)) { \ 2908c2ecf20Sopenharmony_ci get_task_struct(__k); \ 2918c2ecf20Sopenharmony_ci wake_up_process(__k); \ 2928c2ecf20Sopenharmony_ci } \ 2938c2ecf20Sopenharmony_ci __k; \ 2948c2ecf20Sopenharmony_ci}) 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci#define kthread_stop_put(k) \ 2978c2ecf20Sopenharmony_ci do { \ 2988c2ecf20Sopenharmony_ci kthread_stop(k); \ 2998c2ecf20Sopenharmony_ci put_task_struct(k); \ 3008c2ecf20Sopenharmony_ci } while (0) 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci/* usbip_common.c */ 3038c2ecf20Sopenharmony_civoid usbip_dump_urb(struct urb *purb); 3048c2ecf20Sopenharmony_civoid usbip_dump_header(struct usbip_header *pdu); 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ciint usbip_recv(struct socket *sock, void *buf, int size); 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_civoid usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd, 3098c2ecf20Sopenharmony_ci int pack); 3108c2ecf20Sopenharmony_civoid usbip_header_correct_endian(struct usbip_header *pdu, int send); 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistruct usbip_iso_packet_descriptor* 3138c2ecf20Sopenharmony_ciusbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen); 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci/* some members of urb must be substituted before. */ 3168c2ecf20Sopenharmony_ciint usbip_recv_iso(struct usbip_device *ud, struct urb *urb); 3178c2ecf20Sopenharmony_civoid usbip_pad_iso(struct usbip_device *ud, struct urb *urb); 3188c2ecf20Sopenharmony_ciint usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb); 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci/* usbip_event.c */ 3218c2ecf20Sopenharmony_ciint usbip_init_eh(void); 3228c2ecf20Sopenharmony_civoid usbip_finish_eh(void); 3238c2ecf20Sopenharmony_ciint usbip_start_eh(struct usbip_device *ud); 3248c2ecf20Sopenharmony_civoid usbip_stop_eh(struct usbip_device *ud); 3258c2ecf20Sopenharmony_civoid usbip_event_add(struct usbip_device *ud, unsigned long event); 3268c2ecf20Sopenharmony_ciint usbip_event_happened(struct usbip_device *ud); 3278c2ecf20Sopenharmony_ciint usbip_in_eh(struct task_struct *task); 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_cistatic inline int interface_to_busnum(struct usb_interface *interface) 3308c2ecf20Sopenharmony_ci{ 3318c2ecf20Sopenharmony_ci struct usb_device *udev = interface_to_usbdev(interface); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci return udev->bus->busnum; 3348c2ecf20Sopenharmony_ci} 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_cistatic inline int interface_to_devnum(struct usb_interface *interface) 3378c2ecf20Sopenharmony_ci{ 3388c2ecf20Sopenharmony_ci struct usb_device *udev = interface_to_usbdev(interface); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci return udev->devnum; 3418c2ecf20Sopenharmony_ci} 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci#endif /* __USBIP_COMMON_H */ 344