blob: 35618ceb279134bc02c6d8ff83671f55b25c82a8 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0+
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -06002/*
3 * Copyright (C) 2003-2008 Takahiro Hirofuchi
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -06004 */
5
Tobias Klauser306dac62011-08-22 08:53:28 +02006#ifndef __USBIP_STUB_H
7#define __USBIP_STUB_H
8
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -06009#include <linux/list.h>
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060010#include <linux/slab.h>
matt mooney7aaacb42011-05-11 22:33:43 -070011#include <linux/spinlock.h>
12#include <linux/types.h>
13#include <linux/usb.h>
14#include <linux/wait.h>
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060015
Endre Kollaraa5873e2010-07-27 12:39:30 +020016#define STUB_BUSID_OTHER 0
17#define STUB_BUSID_REMOV 1
18#define STUB_BUSID_ADDED 2
19#define STUB_BUSID_ALLOC 3
20
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060021struct stub_device {
Max Vozeler2d8f4592011-01-12 15:01:59 +020022 struct usb_device *udev;
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060023
24 struct usbip_device ud;
25 __u32 devid;
26
27 /*
28 * stub_priv preserves private data of each urb.
29 * It is allocated as stub_priv_cache and assigned to urb->context.
30 *
31 * stub_priv is always linked to any one of 3 lists;
32 * priv_init: linked to this until the comletion of a urb.
33 * priv_tx : linked to this after the completion of a urb.
34 * priv_free: linked to this after the sending of the result.
35 *
36 * Any of these list operations should be locked by priv_lock.
37 */
38 spinlock_t priv_lock;
39 struct list_head priv_init;
40 struct list_head priv_tx;
41 struct list_head priv_free;
42
43 /* see comments for unlinking in stub_rx.c */
44 struct list_head unlink_tx;
45 struct list_head unlink_free;
46
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060047 wait_queue_head_t tx_waitq;
48};
49
50/* private data into urb->priv */
51struct stub_priv {
52 unsigned long seqnum;
53 struct list_head list;
54 struct stub_device *sdev;
55 struct urb *urb;
56
57 int unlinking;
58};
59
60struct stub_unlink {
61 unsigned long seqnum;
62 struct list_head list;
63 __u32 status;
64};
65
matt mooney3e4fda92011-05-27 01:44:12 -070066/* same as SYSFS_BUS_ID_SIZE */
67#define BUSID_SIZE 32
matt mooney87352762011-05-19 21:36:56 -070068
Endre Kollaraa5873e2010-07-27 12:39:30 +020069struct bus_id_priv {
70 char name[BUSID_SIZE];
71 char status;
72 int interf_count;
73 struct stub_device *sdev;
Valentina Maneaa46034c2014-03-08 14:53:33 +020074 struct usb_device *udev;
Endre Kollaraa5873e2010-07-27 12:39:30 +020075 char shutdown_busid;
Shuah Khan (Samsung OSG)220765572018-05-14 20:49:58 -060076 spinlock_t busid_lock;
Endre Kollaraa5873e2010-07-27 12:39:30 +020077};
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060078
matt mooney499aaae2011-05-11 01:54:22 -070079/* stub_priv is allocated from stub_priv_cache */
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060080extern struct kmem_cache *stub_priv_cache;
81
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060082/* stub_dev.c */
Valentina Maneab7945b72014-01-23 23:12:29 +020083extern struct usb_device_driver stub_driver;
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060084
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060085/* stub_main.c */
Endre Kollaraa5873e2010-07-27 12:39:30 +020086struct bus_id_priv *get_busid_priv(const char *busid);
Shuah Khan (Samsung OSG)220765572018-05-14 20:49:58 -060087void put_busid_priv(struct bus_id_priv *bid);
Endre Kollaraa5873e2010-07-27 12:39:30 +020088int del_match_busid(char *busid);
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060089void stub_device_cleanup_urbs(struct stub_device *sdev);
matt mooney499aaae2011-05-11 01:54:22 -070090
91/* stub_rx.c */
92int stub_rx_loop(void *data);
93
94/* stub_tx.c */
95void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
96 __u32 status);
97void stub_complete(struct urb *urb);
98int stub_tx_loop(void *data);
Tobias Klauser306dac62011-08-22 08:53:28 +020099
100#endif /* __USBIP_STUB_H */