]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/usb/storage/usb.h
[PATCH] USB: convert a bunch of USB semaphores to mutexes
[mirror_ubuntu-zesty-kernel.git] / drivers / usb / storage / usb.h
CommitLineData
1da177e4
LT
1/* Driver for USB Mass Storage compliant devices
2 * Main Header File
3 *
4 * $Id: usb.h,v 1.21 2002/04/21 02:57:59 mdharm Exp $
5 *
6 * Current development and maintenance by:
7 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 *
9 * Initial work by:
10 * (c) 1999 Michael Gee (michael@linuxspecific.com)
11 *
12 * This driver is based on the 'USB Mass Storage Class' document. This
13 * describes in detail the protocol used to communicate with such
14 * devices. Clearly, the designers had SCSI and ATAPI commands in
15 * mind when they created this document. The commands are all very
16 * similar to commands in the SCSI-II and ATAPI specifications.
17 *
18 * It is important to note that in a number of cases this class
19 * exhibits class-specific exemptions from the USB specification.
20 * Notably the usage of NAK, STALL and ACK differs from the norm, in
21 * that they are used to communicate wait, failed and OK on commands.
22 *
23 * Also, for certain devices, the interrupt endpoint is used to convey
24 * status of a command.
25 *
26 * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
27 * information about this driver.
28 *
29 * This program is free software; you can redistribute it and/or modify it
30 * under the terms of the GNU General Public License as published by the
31 * Free Software Foundation; either version 2, or (at your option) any
32 * later version.
33 *
34 * This program is distributed in the hope that it will be useful, but
35 * WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 * General Public License for more details.
38 *
39 * You should have received a copy of the GNU General Public License along
40 * with this program; if not, write to the Free Software Foundation, Inc.,
41 * 675 Mass Ave, Cambridge, MA 02139, USA.
42 */
43
44#ifndef _USB_H_
45#define _USB_H_
46
47#include <linux/usb.h>
a00828e9 48#include <linux/usb_usual.h>
1da177e4
LT
49#include <linux/blkdev.h>
50#include <linux/smp_lock.h>
51#include <linux/completion.h>
4186ecf8 52#include <linux/mutex.h>
1da177e4
LT
53#include <scsi/scsi_host.h>
54
55struct us_data;
56struct scsi_cmnd;
57
58/*
59 * Unusual device list definitions
60 */
61
62struct us_unusual_dev {
63 const char* vendorName;
64 const char* productName;
65 __u8 useProtocol;
66 __u8 useTransport;
67 int (*initFunction)(struct us_data *);
1da177e4
LT
68};
69
1da177e4
LT
70
71/* Dynamic flag definitions: used in set_bit() etc. */
72#define US_FLIDX_URB_ACTIVE 18 /* 0x00040000 current_urb is in use */
73#define US_FLIDX_SG_ACTIVE 19 /* 0x00080000 current_sg is in use */
74#define US_FLIDX_ABORTING 20 /* 0x00100000 abort is in progress */
75#define US_FLIDX_DISCONNECTING 21 /* 0x00200000 disconnect in progress */
76#define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \
77 (1UL << US_FLIDX_DISCONNECTING))
78#define US_FLIDX_RESETTING 22 /* 0x00400000 device reset in progress */
79#define US_FLIDX_TIMED_OUT 23 /* 0x00800000 SCSI midlayer timed out */
80
81
82#define USB_STOR_STRING_LEN 32
83
84/*
85 * We provide a DMA-mapped I/O buffer for use with small USB transfers.
86 * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
87 * 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the
88 * size we'll allocate.
89 */
90
91#define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
bbafa466 92#define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
1da177e4
LT
93
94typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
95typedef int (*trans_reset)(struct us_data*);
96typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
7931e1c6
MD
97typedef void (*extra_data_destructor)(void *); /* extra data destructor */
98typedef void (*pm_hook)(struct us_data *, int); /* power management hook */
99
100#define US_SUSPEND 0
101#define US_RESUME 1
1da177e4
LT
102
103/* we allocate one of these for every device that we remember */
104struct us_data {
105 /* The device we're working with
106 * It's important to note:
4186ecf8 107 * (o) you must hold dev_mutex to change pusb_dev
1da177e4 108 */
4186ecf8 109 struct mutex dev_mutex; /* protect pusb_dev */
1da177e4
LT
110 struct usb_device *pusb_dev; /* this usb_device */
111 struct usb_interface *pusb_intf; /* this interface */
112 struct us_unusual_dev *unusual_dev; /* device-filter entry */
113 unsigned long flags; /* from filter initially */
114 unsigned int send_bulk_pipe; /* cached pipe values */
115 unsigned int recv_bulk_pipe;
116 unsigned int send_ctrl_pipe;
117 unsigned int recv_ctrl_pipe;
118 unsigned int recv_intr_pipe;
119
120 /* information about the device */
121 char *transport_name;
122 char *protocol_name;
123 __le32 bcs_signature;
124 u8 subclass;
125 u8 protocol;
126 u8 max_lun;
127
128 u8 ifnum; /* interface number */
129 u8 ep_bInterval; /* interrupt interval */
130
131 /* function pointers for this device */
132 trans_cmnd transport; /* transport function */
133 trans_reset transport_reset; /* transport device reset */
134 proto_cmnd proto_handler; /* protocol handler */
135
136 /* SCSI interfaces */
137 struct scsi_cmnd *srb; /* current srb */
0f64e078 138 unsigned int tag; /* current dCBWTag */
1da177e4 139
1da177e4
LT
140 /* control and bulk communications data */
141 struct urb *current_urb; /* USB requests */
142 struct usb_ctrlrequest *cr; /* control requests */
143 struct usb_sg_request current_sg; /* scatter-gather req. */
144 unsigned char *iobuf; /* I/O buffer */
bbafa466 145 unsigned char *sensebuf; /* sense data buffer */
1da177e4
LT
146 dma_addr_t cr_dma; /* buffer DMA addresses */
147 dma_addr_t iobuf_dma;
148
149 /* mutual exclusion and synchronization structures */
150 struct semaphore sema; /* to sleep thread on */
151 struct completion notify; /* thread begin/end */
152 wait_queue_head_t delay_wait; /* wait during scan, reset */
153
154 /* subdriver information */
155 void *extra; /* Any extra data */
156 extra_data_destructor extra_destructor;/* extra data destructor */
7931e1c6
MD
157#ifdef CONFIG_PM
158 pm_hook suspend_resume_hook;
159#endif
1da177e4
LT
160};
161
162/* Convert between us_data and the corresponding Scsi_Host */
163static struct Scsi_Host inline *us_to_host(struct us_data *us) {
164 return container_of((void *) us, struct Scsi_Host, hostdata);
165}
166static struct us_data inline *host_to_us(struct Scsi_Host *host) {
167 return (struct us_data *) host->hostdata;
168}
169
170/* Function to fill an inquiry response. See usb.c for details */
171extern void fill_inquiry_response(struct us_data *us,
172 unsigned char *data, unsigned int data_len);
173
174/* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
175 * single queue element srb for write access */
176#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
177#define scsi_lock(host) spin_lock_irq(host->host_lock)
178
179
180/* Vendor ID list for devices that require special handling */
181#define USB_VENDOR_ID_GENESYS 0x05e3 /* Genesys Logic */
182
183#endif