blob: 84c0599b45b7bc58e1c60971b15660b17ee1b75c [file] [log] [blame]
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -06001/*
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
Tobias Klauser306dac62011-08-22 08:53:28 +020020#ifndef __USBIP_STUB_H
21#define __USBIP_STUB_H
22
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060023#include <linux/list.h>
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060024#include <linux/slab.h>
matt mooney7aaacb42011-05-11 22:33:43 -070025#include <linux/spinlock.h>
26#include <linux/types.h>
27#include <linux/usb.h>
28#include <linux/wait.h>
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060029
Endre Kollaraa5873e2010-07-27 12:39:30 +020030#define STUB_BUSID_OTHER 0
31#define STUB_BUSID_REMOV 1
32#define STUB_BUSID_ADDED 2
33#define STUB_BUSID_ALLOC 3
34
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060035struct stub_device {
Max Vozeler2d8f4592011-01-12 15:01:59 +020036 struct usb_device *udev;
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060037
38 struct usbip_device ud;
39 __u32 devid;
40
41 /*
42 * stub_priv preserves private data of each urb.
43 * It is allocated as stub_priv_cache and assigned to urb->context.
44 *
45 * stub_priv is always linked to any one of 3 lists;
46 * priv_init: linked to this until the comletion of a urb.
47 * priv_tx : linked to this after the completion of a urb.
48 * priv_free: linked to this after the sending of the result.
49 *
50 * Any of these list operations should be locked by priv_lock.
51 */
52 spinlock_t priv_lock;
53 struct list_head priv_init;
54 struct list_head priv_tx;
55 struct list_head priv_free;
56
57 /* see comments for unlinking in stub_rx.c */
58 struct list_head unlink_tx;
59 struct list_head unlink_free;
60
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060061 wait_queue_head_t tx_waitq;
62};
63
64/* private data into urb->priv */
65struct stub_priv {
66 unsigned long seqnum;
67 struct list_head list;
68 struct stub_device *sdev;
69 struct urb *urb;
70
71 int unlinking;
72};
73
74struct stub_unlink {
75 unsigned long seqnum;
76 struct list_head list;
77 __u32 status;
78};
79
matt mooney3e4fda92011-05-27 01:44:12 -070080/* same as SYSFS_BUS_ID_SIZE */
81#define BUSID_SIZE 32
matt mooney87352762011-05-19 21:36:56 -070082
Endre Kollaraa5873e2010-07-27 12:39:30 +020083struct bus_id_priv {
84 char name[BUSID_SIZE];
85 char status;
86 int interf_count;
87 struct stub_device *sdev;
Valentina Maneaa46034c2014-03-08 14:53:33 +020088 struct usb_device *udev;
Endre Kollaraa5873e2010-07-27 12:39:30 +020089 char shutdown_busid;
Shuah Khan (Samsung OSG)f2a6d5f2018-05-14 20:49:58 -060090 spinlock_t busid_lock;
Endre Kollaraa5873e2010-07-27 12:39:30 +020091};
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060092
matt mooney499aaae2011-05-11 01:54:22 -070093/* stub_priv is allocated from stub_priv_cache */
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060094extern struct kmem_cache *stub_priv_cache;
95
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060096/* stub_dev.c */
Valentina Maneab7945b72014-01-23 23:12:29 +020097extern struct usb_device_driver stub_driver;
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060098
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -060099/* stub_main.c */
Endre Kollaraa5873e2010-07-27 12:39:30 +0200100struct bus_id_priv *get_busid_priv(const char *busid);
Shuah Khan (Samsung OSG)f2a6d5f2018-05-14 20:49:58 -0600101void put_busid_priv(struct bus_id_priv *bid);
Endre Kollaraa5873e2010-07-27 12:39:30 +0200102int del_match_busid(char *busid);
Takahiro Hirofuchi4d7b5c72008-07-09 14:56:51 -0600103void stub_device_cleanup_urbs(struct stub_device *sdev);
matt mooney499aaae2011-05-11 01:54:22 -0700104
105/* stub_rx.c */
106int stub_rx_loop(void *data);
107
108/* stub_tx.c */
109void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
110 __u32 status);
111void stub_complete(struct urb *urb);
112int stub_tx_loop(void *data);
Tobias Klauser306dac62011-08-22 08:53:28 +0200113
114#endif /* __USBIP_STUB_H */