Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Copyright (C) 2003-2008 Takahiro Hirofuchi
0004  */
0005 
0006 #ifndef __USBIP_STUB_H
0007 #define __USBIP_STUB_H
0008 
0009 #include <linux/list.h>
0010 #include <linux/slab.h>
0011 #include <linux/spinlock.h>
0012 #include <linux/types.h>
0013 #include <linux/usb.h>
0014 #include <linux/wait.h>
0015 
0016 #define STUB_BUSID_OTHER 0
0017 #define STUB_BUSID_REMOV 1
0018 #define STUB_BUSID_ADDED 2
0019 #define STUB_BUSID_ALLOC 3
0020 
0021 struct stub_device {
0022     struct usb_device *udev;
0023 
0024     struct usbip_device ud;
0025     __u32 devid;
0026 
0027     /*
0028      * stub_priv preserves private data of each urb.
0029      * It is allocated as stub_priv_cache and assigned to urb->context.
0030      *
0031      * stub_priv is always linked to any one of 3 lists;
0032      *  priv_init: linked to this until the comletion of a urb.
0033      *  priv_tx  : linked to this after the completion of a urb.
0034      *  priv_free: linked to this after the sending of the result.
0035      *
0036      * Any of these list operations should be locked by priv_lock.
0037      */
0038     spinlock_t priv_lock;
0039     struct list_head priv_init;
0040     struct list_head priv_tx;
0041     struct list_head priv_free;
0042 
0043     /* see comments for unlinking in stub_rx.c */
0044     struct list_head unlink_tx;
0045     struct list_head unlink_free;
0046 
0047     wait_queue_head_t tx_waitq;
0048 };
0049 
0050 /* private data into urb->priv */
0051 struct stub_priv {
0052     unsigned long seqnum;
0053     struct list_head list;
0054     struct stub_device *sdev;
0055     struct urb **urbs;
0056     struct scatterlist *sgl;
0057     int num_urbs;
0058     int completed_urbs;
0059     int urb_status;
0060 
0061     int unlinking;
0062 };
0063 
0064 struct stub_unlink {
0065     unsigned long seqnum;
0066     struct list_head list;
0067     __u32 status;
0068 };
0069 
0070 /* same as SYSFS_BUS_ID_SIZE */
0071 #define BUSID_SIZE 32
0072 
0073 struct bus_id_priv {
0074     char name[BUSID_SIZE];
0075     char status;
0076     int interf_count;
0077     struct stub_device *sdev;
0078     struct usb_device *udev;
0079     char shutdown_busid;
0080     spinlock_t busid_lock;
0081 };
0082 
0083 /* stub_priv is allocated from stub_priv_cache */
0084 extern struct kmem_cache *stub_priv_cache;
0085 
0086 /* stub_dev.c */
0087 extern struct usb_device_driver stub_driver;
0088 
0089 /* stub_main.c */
0090 struct bus_id_priv *get_busid_priv(const char *busid);
0091 void put_busid_priv(struct bus_id_priv *bid);
0092 int del_match_busid(char *busid);
0093 void stub_free_priv_and_urb(struct stub_priv *priv);
0094 void stub_device_cleanup_urbs(struct stub_device *sdev);
0095 
0096 /* stub_rx.c */
0097 int stub_rx_loop(void *data);
0098 
0099 /* stub_tx.c */
0100 void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
0101                  __u32 status);
0102 void stub_complete(struct urb *urb);
0103 int stub_tx_loop(void *data);
0104 
0105 #endif /* __USBIP_STUB_H */