^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2003-2008 Takahiro Hirofuchi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef __USBIP_STUB_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define __USBIP_STUB_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define STUB_BUSID_OTHER 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define STUB_BUSID_REMOV 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define STUB_BUSID_ADDED 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define STUB_BUSID_ALLOC 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct stub_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct usbip_device ud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) __u32 devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * stub_priv preserves private data of each urb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * It is allocated as stub_priv_cache and assigned to urb->context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * stub_priv is always linked to any one of 3 lists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * priv_init: linked to this until the comletion of a urb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * priv_tx : linked to this after the completion of a urb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * priv_free: linked to this after the sending of the result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Any of these list operations should be locked by priv_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) spinlock_t priv_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct list_head priv_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct list_head priv_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct list_head priv_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* see comments for unlinking in stub_rx.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct list_head unlink_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct list_head unlink_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) wait_queue_head_t tx_waitq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* private data into urb->priv */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct stub_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct stub_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct urb **urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct scatterlist *sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int num_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int completed_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int urb_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int unlinking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct stub_unlink {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned long seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) __u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* same as SYSFS_BUS_ID_SIZE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define BUSID_SIZE 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct bus_id_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) char name[BUSID_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int interf_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct stub_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) char shutdown_busid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) spinlock_t busid_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* stub_priv is allocated from stub_priv_cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) extern struct kmem_cache *stub_priv_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* stub_dev.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) extern struct usb_device_driver stub_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* stub_main.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct bus_id_priv *get_busid_priv(const char *busid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) void put_busid_priv(struct bus_id_priv *bid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int del_match_busid(char *busid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) void stub_free_priv_and_urb(struct stub_priv *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) void stub_device_cleanup_urbs(struct stub_device *sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* stub_rx.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int stub_rx_loop(void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* stub_tx.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) __u32 status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void stub_complete(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int stub_tx_loop(void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #endif /* __USBIP_STUB_H */