Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 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 | |
Tobias Klauser | 306dac6 | 2011-08-22 08:53:28 +0200 | [diff] [blame] | 20 | #ifndef __USBIP_STUB_H |
| 21 | #define __USBIP_STUB_H |
| 22 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 23 | #include <linux/list.h> |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 24 | #include <linux/slab.h> |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/types.h> |
| 27 | #include <linux/usb.h> |
| 28 | #include <linux/wait.h> |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 29 | |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 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 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 35 | struct stub_device { |
| 36 | struct usb_interface *interface; |
Max Vozeler | 2d8f459 | 2011-01-12 15:01:59 +0200 | [diff] [blame] | 37 | struct usb_device *udev; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 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 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 62 | wait_queue_head_t tx_waitq; |
| 63 | }; |
| 64 | |
| 65 | /* private data into urb->priv */ |
| 66 | struct 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 | |
| 75 | struct stub_unlink { |
| 76 | unsigned long seqnum; |
| 77 | struct list_head list; |
| 78 | __u32 status; |
| 79 | }; |
| 80 | |
matt mooney | 3e4fda9 | 2011-05-27 01:44:12 -0700 | [diff] [blame] | 81 | /* same as SYSFS_BUS_ID_SIZE */ |
| 82 | #define BUSID_SIZE 32 |
matt mooney | 8735276 | 2011-05-19 21:36:56 -0700 | [diff] [blame] | 83 | |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 84 | struct bus_id_priv { |
| 85 | char name[BUSID_SIZE]; |
| 86 | char status; |
| 87 | int interf_count; |
| 88 | struct stub_device *sdev; |
Valentina Manea | a46034c | 2014-03-08 14:53:33 +0200 | [diff] [blame] | 89 | struct usb_device *udev; |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 90 | char shutdown_busid; |
| 91 | }; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 92 | |
matt mooney | 499aaae | 2011-05-11 01:54:22 -0700 | [diff] [blame] | 93 | /* stub_priv is allocated from stub_priv_cache */ |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 94 | extern struct kmem_cache *stub_priv_cache; |
| 95 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 96 | /* stub_dev.c */ |
Valentina Manea | b7945b7 | 2014-01-23 23:12:29 +0200 | [diff] [blame] | 97 | extern struct usb_device_driver stub_driver; |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 98 | |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 99 | /* stub_main.c */ |
Endre Kollar | aa5873e | 2010-07-27 12:39:30 +0200 | [diff] [blame] | 100 | struct bus_id_priv *get_busid_priv(const char *busid); |
| 101 | int del_match_busid(char *busid); |
Takahiro Hirofuchi | 4d7b5c7 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 102 | void stub_device_cleanup_urbs(struct stub_device *sdev); |
matt mooney | 499aaae | 2011-05-11 01:54:22 -0700 | [diff] [blame] | 103 | |
| 104 | /* stub_rx.c */ |
| 105 | int stub_rx_loop(void *data); |
| 106 | |
| 107 | /* stub_tx.c */ |
| 108 | void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum, |
| 109 | __u32 status); |
| 110 | void stub_complete(struct urb *urb); |
| 111 | int stub_tx_loop(void *data); |
Tobias Klauser | 306dac6 | 2011-08-22 08:53:28 +0200 | [diff] [blame] | 112 | |
| 113 | #endif /* __USBIP_STUB_H */ |