blob: 7259fd1f6b0d2672a10567d41a3037b741903dda [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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>
Pete Zaitceva00828e2005-10-22 20:15:09 -070048#include <linux/usb_usual.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/blkdev.h>
50#include <linux/smp_lock.h>
51#include <linux/completion.h>
52#include <scsi/scsi_host.h>
53
54struct us_data;
55struct scsi_cmnd;
56
57/*
58 * Unusual device list definitions
59 */
60
61struct us_unusual_dev {
62 const char* vendorName;
63 const char* productName;
64 __u8 useProtocol;
65 __u8 useTransport;
66 int (*initFunction)(struct us_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067};
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* Dynamic flag definitions: used in set_bit() etc. */
71#define US_FLIDX_URB_ACTIVE 18 /* 0x00040000 current_urb is in use */
72#define US_FLIDX_SG_ACTIVE 19 /* 0x00080000 current_sg is in use */
73#define US_FLIDX_ABORTING 20 /* 0x00100000 abort is in progress */
74#define US_FLIDX_DISCONNECTING 21 /* 0x00200000 disconnect in progress */
75#define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \
76 (1UL << US_FLIDX_DISCONNECTING))
77#define US_FLIDX_RESETTING 22 /* 0x00400000 device reset in progress */
78#define US_FLIDX_TIMED_OUT 23 /* 0x00800000 SCSI midlayer timed out */
79
80
81#define USB_STOR_STRING_LEN 32
82
83/*
84 * We provide a DMA-mapped I/O buffer for use with small USB transfers.
85 * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
86 * 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the
87 * size we'll allocate.
88 */
89
90#define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
Alan Sternbbafa462005-10-23 19:40:22 -070091#define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
94typedef int (*trans_reset)(struct us_data*);
95typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
Matthew Dharm7931e1c2005-12-04 21:56:51 -080096typedef void (*extra_data_destructor)(void *); /* extra data destructor */
97typedef void (*pm_hook)(struct us_data *, int); /* power management hook */
98
99#define US_SUSPEND 0
100#define US_RESUME 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102/* we allocate one of these for every device that we remember */
103struct us_data {
104 /* The device we're working with
105 * It's important to note:
106 * (o) you must hold dev_semaphore to change pusb_dev
107 */
108 struct semaphore dev_semaphore; /* protect pusb_dev */
109 struct usb_device *pusb_dev; /* this usb_device */
110 struct usb_interface *pusb_intf; /* this interface */
111 struct us_unusual_dev *unusual_dev; /* device-filter entry */
112 unsigned long flags; /* from filter initially */
113 unsigned int send_bulk_pipe; /* cached pipe values */
114 unsigned int recv_bulk_pipe;
115 unsigned int send_ctrl_pipe;
116 unsigned int recv_ctrl_pipe;
117 unsigned int recv_intr_pipe;
118
119 /* information about the device */
120 char *transport_name;
121 char *protocol_name;
122 __le32 bcs_signature;
123 u8 subclass;
124 u8 protocol;
125 u8 max_lun;
126
127 u8 ifnum; /* interface number */
128 u8 ep_bInterval; /* interrupt interval */
129
130 /* function pointers for this device */
131 trans_cmnd transport; /* transport function */
132 trans_reset transport_reset; /* transport device reset */
133 proto_cmnd proto_handler; /* protocol handler */
134
135 /* SCSI interfaces */
136 struct scsi_cmnd *srb; /* current srb */
Matthew Dharm0f64e072005-07-28 14:43:08 -0700137 unsigned int tag; /* current dCBWTag */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 /* control and bulk communications data */
140 struct urb *current_urb; /* USB requests */
141 struct usb_ctrlrequest *cr; /* control requests */
142 struct usb_sg_request current_sg; /* scatter-gather req. */
143 unsigned char *iobuf; /* I/O buffer */
Alan Sternbbafa462005-10-23 19:40:22 -0700144 unsigned char *sensebuf; /* sense data buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 dma_addr_t cr_dma; /* buffer DMA addresses */
146 dma_addr_t iobuf_dma;
147
148 /* mutual exclusion and synchronization structures */
149 struct semaphore sema; /* to sleep thread on */
150 struct completion notify; /* thread begin/end */
151 wait_queue_head_t delay_wait; /* wait during scan, reset */
152
153 /* subdriver information */
154 void *extra; /* Any extra data */
155 extra_data_destructor extra_destructor;/* extra data destructor */
Matthew Dharm7931e1c2005-12-04 21:56:51 -0800156#ifdef CONFIG_PM
157 pm_hook suspend_resume_hook;
158#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
161/* Convert between us_data and the corresponding Scsi_Host */
162static struct Scsi_Host inline *us_to_host(struct us_data *us) {
163 return container_of((void *) us, struct Scsi_Host, hostdata);
164}
165static struct us_data inline *host_to_us(struct Scsi_Host *host) {
166 return (struct us_data *) host->hostdata;
167}
168
169/* Function to fill an inquiry response. See usb.c for details */
170extern void fill_inquiry_response(struct us_data *us,
171 unsigned char *data, unsigned int data_len);
172
173/* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
174 * single queue element srb for write access */
175#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
176#define scsi_lock(host) spin_lock_irq(host->host_lock)
177
178
179/* Vendor ID list for devices that require special handling */
180#define USB_VENDOR_ID_GENESYS 0x05e3 /* Genesys Logic */
181
182#endif