18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2003-2008 Takahiro Hirofuchi 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __USBIP_STUB_H 78c2ecf20Sopenharmony_ci#define __USBIP_STUB_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/list.h> 108c2ecf20Sopenharmony_ci#include <linux/slab.h> 118c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 128c2ecf20Sopenharmony_ci#include <linux/types.h> 138c2ecf20Sopenharmony_ci#include <linux/usb.h> 148c2ecf20Sopenharmony_ci#include <linux/wait.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define STUB_BUSID_OTHER 0 178c2ecf20Sopenharmony_ci#define STUB_BUSID_REMOV 1 188c2ecf20Sopenharmony_ci#define STUB_BUSID_ADDED 2 198c2ecf20Sopenharmony_ci#define STUB_BUSID_ALLOC 3 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistruct stub_device { 228c2ecf20Sopenharmony_ci struct usb_device *udev; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci struct usbip_device ud; 258c2ecf20Sopenharmony_ci __u32 devid; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci /* 288c2ecf20Sopenharmony_ci * stub_priv preserves private data of each urb. 298c2ecf20Sopenharmony_ci * It is allocated as stub_priv_cache and assigned to urb->context. 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci * stub_priv is always linked to any one of 3 lists; 328c2ecf20Sopenharmony_ci * priv_init: linked to this until the comletion of a urb. 338c2ecf20Sopenharmony_ci * priv_tx : linked to this after the completion of a urb. 348c2ecf20Sopenharmony_ci * priv_free: linked to this after the sending of the result. 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * Any of these list operations should be locked by priv_lock. 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_ci spinlock_t priv_lock; 398c2ecf20Sopenharmony_ci struct list_head priv_init; 408c2ecf20Sopenharmony_ci struct list_head priv_tx; 418c2ecf20Sopenharmony_ci struct list_head priv_free; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci /* see comments for unlinking in stub_rx.c */ 448c2ecf20Sopenharmony_ci struct list_head unlink_tx; 458c2ecf20Sopenharmony_ci struct list_head unlink_free; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci wait_queue_head_t tx_waitq; 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* private data into urb->priv */ 518c2ecf20Sopenharmony_cistruct stub_priv { 528c2ecf20Sopenharmony_ci unsigned long seqnum; 538c2ecf20Sopenharmony_ci struct list_head list; 548c2ecf20Sopenharmony_ci struct stub_device *sdev; 558c2ecf20Sopenharmony_ci struct urb **urbs; 568c2ecf20Sopenharmony_ci struct scatterlist *sgl; 578c2ecf20Sopenharmony_ci int num_urbs; 588c2ecf20Sopenharmony_ci int completed_urbs; 598c2ecf20Sopenharmony_ci int urb_status; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci int unlinking; 628c2ecf20Sopenharmony_ci}; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistruct stub_unlink { 658c2ecf20Sopenharmony_ci unsigned long seqnum; 668c2ecf20Sopenharmony_ci struct list_head list; 678c2ecf20Sopenharmony_ci __u32 status; 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* same as SYSFS_BUS_ID_SIZE */ 718c2ecf20Sopenharmony_ci#define BUSID_SIZE 32 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistruct bus_id_priv { 748c2ecf20Sopenharmony_ci char name[BUSID_SIZE]; 758c2ecf20Sopenharmony_ci char status; 768c2ecf20Sopenharmony_ci int interf_count; 778c2ecf20Sopenharmony_ci struct stub_device *sdev; 788c2ecf20Sopenharmony_ci struct usb_device *udev; 798c2ecf20Sopenharmony_ci char shutdown_busid; 808c2ecf20Sopenharmony_ci spinlock_t busid_lock; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/* stub_priv is allocated from stub_priv_cache */ 848c2ecf20Sopenharmony_ciextern struct kmem_cache *stub_priv_cache; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* stub_dev.c */ 878c2ecf20Sopenharmony_ciextern struct usb_device_driver stub_driver; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* stub_main.c */ 908c2ecf20Sopenharmony_cistruct bus_id_priv *get_busid_priv(const char *busid); 918c2ecf20Sopenharmony_civoid put_busid_priv(struct bus_id_priv *bid); 928c2ecf20Sopenharmony_ciint del_match_busid(char *busid); 938c2ecf20Sopenharmony_civoid stub_free_priv_and_urb(struct stub_priv *priv); 948c2ecf20Sopenharmony_civoid stub_device_cleanup_urbs(struct stub_device *sdev); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* stub_rx.c */ 978c2ecf20Sopenharmony_ciint stub_rx_loop(void *data); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* stub_tx.c */ 1008c2ecf20Sopenharmony_civoid stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum, 1018c2ecf20Sopenharmony_ci __u32 status); 1028c2ecf20Sopenharmony_civoid stub_complete(struct urb *urb); 1038c2ecf20Sopenharmony_ciint stub_tx_loop(void *data); 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#endif /* __USBIP_STUB_H */ 106