patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / usb / storage / usb.h
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>
48 #include <linux/blkdev.h>
49 #include <linux/smp_lock.h>
50 #include <linux/completion.h>
51 #include "scsi.h"
52 #include <scsi/scsi_host.h>
53
54 struct us_data;
55
56 /*
57  * Unusual device list definitions 
58  */
59
60 struct us_unusual_dev {
61         const char* vendorName;
62         const char* productName;
63         __u8  useProtocol;
64         __u8  useTransport;
65         int (*initFunction)(struct us_data *);
66         unsigned int flags;
67 };
68
69 /* Flag definitions: these entries are static */
70 #define US_FL_SINGLE_LUN      0x00000001 /* allow access to only LUN 0      */
71 #define US_FL_MODE_XLATE      0          /* [no longer used]                */
72 #define US_FL_NEED_OVERRIDE   0x00000004 /* unusual_devs entry is necessary */
73 #define US_FL_IGNORE_SER      0          /* [no longer used]                */
74 #define US_FL_SCM_MULT_TARG   0x00000020 /* supports multiple targets       */
75 #define US_FL_FIX_INQUIRY     0x00000040 /* INQUIRY response needs faking   */
76 #define US_FL_FIX_CAPACITY    0x00000080 /* READ CAPACITY response too big  */
77
78 /* Dynamic flag definitions: used in set_bit() etc. */
79 #define US_FLIDX_URB_ACTIVE     18  /* 0x00040000  current_urb is in use  */
80 #define US_FLIDX_SG_ACTIVE      19  /* 0x00080000  current_sg is in use   */
81 #define US_FLIDX_ABORTING       20  /* 0x00100000  abort is in progress   */
82 #define US_FLIDX_DISCONNECTING  21  /* 0x00200000  disconnect in progress */
83 #define ABORTING_OR_DISCONNECTING       ((1UL << US_FLIDX_ABORTING) | \
84                                          (1UL << US_FLIDX_DISCONNECTING))
85 #define US_FLIDX_RESETTING      22  /* 0x00400000  device reset in progress */
86
87
88 /* processing state machine states */
89 #define US_STATE_IDLE           1
90 #define US_STATE_RUNNING        2
91 #define US_STATE_RESETTING      3
92 #define US_STATE_ABORTING       4
93
94 #define USB_STOR_STRING_LEN 32
95
96 /*
97  * We provide a DMA-mapped I/O buffer for use with small USB transfers.
98  * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
99  * 31-byte buffer.  But Freecom needs a 64-byte buffer, so that's the
100  * size we'll allocate.
101  */
102
103 #define US_IOBUF_SIZE           64      /* Size of the DMA-mapped I/O buffer */
104
105 typedef int (*trans_cmnd)(Scsi_Cmnd*, struct us_data*);
106 typedef int (*trans_reset)(struct us_data*);
107 typedef void (*proto_cmnd)(Scsi_Cmnd*, struct us_data*);
108 typedef void (*extra_data_destructor)(void *);   /* extra data destructor   */
109
110 /* we allocate one of these for every device that we remember */
111 struct us_data {
112         /* The device we're working with
113          * It's important to note:
114          *    (o) you must hold dev_semaphore to change pusb_dev
115          */
116         struct semaphore        dev_semaphore;   /* protect pusb_dev */
117         struct usb_device       *pusb_dev;       /* this usb_device */
118         struct usb_interface    *pusb_intf;      /* this interface */
119         struct us_unusual_dev   *unusual_dev;    /* device-filter entry     */
120         unsigned long           flags;           /* from filter initially */
121         unsigned int            send_bulk_pipe;  /* cached pipe values */
122         unsigned int            recv_bulk_pipe;
123         unsigned int            send_ctrl_pipe;
124         unsigned int            recv_ctrl_pipe;
125         unsigned int            recv_intr_pipe;
126
127         /* information about the device */
128         char                    vendor[USB_STOR_STRING_LEN];
129         char                    product[USB_STOR_STRING_LEN];
130         char                    serial[USB_STOR_STRING_LEN];
131         char                    *transport_name;
132         char                    *protocol_name;
133         u8                      subclass;
134         u8                      protocol;
135         u8                      max_lun;
136
137         u8                      ifnum;           /* interface number   */
138         u8                      ep_bInterval;    /* interrupt interval */ 
139
140         /* function pointers for this device */
141         trans_cmnd              transport;       /* transport function     */
142         trans_reset             transport_reset; /* transport device reset */
143         proto_cmnd              proto_handler;   /* protocol handler       */
144
145         /* SCSI interfaces */
146         struct Scsi_Host        *host;           /* our dummy host data */
147         Scsi_Cmnd               *srb;            /* current srb         */
148
149         /* thread information */
150         int                     pid;             /* control thread       */
151         int                     sm_state;        /* what we are doing    */
152
153         /* control and bulk communications data */
154         struct urb              *current_urb;    /* USB requests         */
155         struct usb_ctrlrequest  *cr;             /* control requests     */
156         struct usb_sg_request   current_sg;      /* scatter-gather req.  */
157         unsigned char           *iobuf;          /* I/O buffer           */
158         dma_addr_t              cr_dma;          /* buffer DMA addresses */
159         dma_addr_t              iobuf_dma;
160
161         /* mutual exclusion structures */
162         struct semaphore        sema;            /* to sleep thread on   */
163         struct completion       notify;          /* thread begin/end        */
164
165         /* subdriver information */
166         void                    *extra;          /* Any extra data          */
167         extra_data_destructor   extra_destructor;/* extra data destructor   */
168 };
169
170 /* The structure which defines our driver */
171 extern struct usb_driver usb_storage_driver;
172
173 /* Function to fill an inquiry response. See usb.c for details */
174 extern void fill_inquiry_response(struct us_data *us,
175         unsigned char *data, unsigned int data_len);
176
177 /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
178  * single queue element srb for write access */
179 #define scsi_unlock(host)       spin_unlock_irq(host->host_lock)
180 #define scsi_lock(host)         spin_lock_irq(host->host_lock)
181
182 #endif