Loading...
1/*
2 * Copyright (C) 2003-2008 Takahiro Hirofuchi
3 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20#ifndef __USBIP_STUB_H
21#define __USBIP_STUB_H
22
23#include <linux/list.h>
24#include <linux/slab.h>
25#include <linux/spinlock.h>
26#include <linux/types.h>
27#include <linux/usb.h>
28#include <linux/wait.h>
29
30#define STUB_BUSID_OTHER 0
31#define STUB_BUSID_REMOV 1
32#define STUB_BUSID_ADDED 2
33#define STUB_BUSID_ALLOC 3
34
35struct stub_device {
36 struct usb_interface *interface;
37 struct usb_device *udev;
38
39 struct usbip_device ud;
40 __u32 devid;
41
42 /*
43 * stub_priv preserves private data of each urb.
44 * It is allocated as stub_priv_cache and assigned to urb->context.
45 *
46 * stub_priv is always linked to any one of 3 lists;
47 * priv_init: linked to this until the comletion of a urb.
48 * priv_tx : linked to this after the completion of a urb.
49 * priv_free: linked to this after the sending of the result.
50 *
51 * Any of these list operations should be locked by priv_lock.
52 */
53 spinlock_t priv_lock;
54 struct list_head priv_init;
55 struct list_head priv_tx;
56 struct list_head priv_free;
57
58 /* see comments for unlinking in stub_rx.c */
59 struct list_head unlink_tx;
60 struct list_head unlink_free;
61
62 wait_queue_head_t tx_waitq;
63};
64
65/* private data into urb->priv */
66struct stub_priv {
67 unsigned long seqnum;
68 struct list_head list;
69 struct stub_device *sdev;
70 struct urb *urb;
71
72 int unlinking;
73};
74
75struct stub_unlink {
76 unsigned long seqnum;
77 struct list_head list;
78 __u32 status;
79};
80
81/* same as SYSFS_BUS_ID_SIZE */
82#define BUSID_SIZE 32
83
84struct bus_id_priv {
85 char name[BUSID_SIZE];
86 char status;
87 int interf_count;
88 struct stub_device *sdev;
89 struct usb_device *udev;
90 char shutdown_busid;
91};
92
93/* stub_priv is allocated from stub_priv_cache */
94extern struct kmem_cache *stub_priv_cache;
95
96/* stub_dev.c */
97extern struct usb_device_driver stub_driver;
98
99/* stub_main.c */
100struct bus_id_priv *get_busid_priv(const char *busid);
101int del_match_busid(char *busid);
102void stub_device_cleanup_urbs(struct stub_device *sdev);
103
104/* stub_rx.c */
105int stub_rx_loop(void *data);
106
107/* stub_tx.c */
108void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
109 __u32 status);
110void stub_complete(struct urb *urb);
111int stub_tx_loop(void *data);
112
113#endif /* __USBIP_STUB_H */
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2003-2008 Takahiro Hirofuchi
4 */
5
6#ifndef __USBIP_STUB_H
7#define __USBIP_STUB_H
8
9#include <linux/list.h>
10#include <linux/slab.h>
11#include <linux/spinlock.h>
12#include <linux/types.h>
13#include <linux/usb.h>
14#include <linux/wait.h>
15
16#define STUB_BUSID_OTHER 0
17#define STUB_BUSID_REMOV 1
18#define STUB_BUSID_ADDED 2
19#define STUB_BUSID_ALLOC 3
20
21struct stub_device {
22 struct usb_device *udev;
23
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
47 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 **urbs;
56 struct scatterlist *sgl;
57 int num_urbs;
58 int completed_urbs;
59 int urb_status;
60
61 int unlinking;
62};
63
64struct stub_unlink {
65 unsigned long seqnum;
66 struct list_head list;
67 __u32 status;
68};
69
70/* same as SYSFS_BUS_ID_SIZE */
71#define BUSID_SIZE 32
72
73struct bus_id_priv {
74 char name[BUSID_SIZE];
75 char status;
76 int interf_count;
77 struct stub_device *sdev;
78 struct usb_device *udev;
79 char shutdown_busid;
80 spinlock_t busid_lock;
81};
82
83/* stub_priv is allocated from stub_priv_cache */
84extern struct kmem_cache *stub_priv_cache;
85
86/* stub_dev.c */
87extern struct usb_device_driver stub_driver;
88
89/* stub_main.c */
90struct bus_id_priv *get_busid_priv(const char *busid);
91void put_busid_priv(struct bus_id_priv *bid);
92int del_match_busid(char *busid);
93void stub_free_priv_and_urb(struct stub_priv *priv);
94void stub_device_cleanup_urbs(struct stub_device *sdev);
95
96/* stub_rx.c */
97int stub_rx_loop(void *data);
98
99/* stub_tx.c */
100void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
101 __u32 status);
102void stub_complete(struct urb *urb);
103int stub_tx_loop(void *data);
104
105#endif /* __USBIP_STUB_H */