Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* Driver for USB Mass Storage compliant devices |
2 | * Transport Functions Header File | |
3 | * | |
4 | * $Id: transport.h,v 1.18 2002/04/21 02:57:59 mdharm Exp $ | |
5 | * | |
6 | * Current development and maintenance by: | |
7 | * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) | |
8 | * | |
9 | * This driver is based on the 'USB Mass Storage Class' document. This | |
10 | * describes in detail the protocol used to communicate with such | |
11 | * devices. Clearly, the designers had SCSI and ATAPI commands in | |
12 | * mind when they created this document. The commands are all very | |
13 | * similar to commands in the SCSI-II and ATAPI specifications. | |
14 | * | |
15 | * It is important to note that in a number of cases this class | |
16 | * exhibits class-specific exemptions from the USB specification. | |
17 | * Notably the usage of NAK, STALL and ACK differs from the norm, in | |
18 | * that they are used to communicate wait, failed and OK on commands. | |
19 | * | |
20 | * Also, for certain devices, the interrupt endpoint is used to convey | |
21 | * status of a command. | |
22 | * | |
23 | * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more | |
24 | * information about this driver. | |
25 | * | |
26 | * This program is free software; you can redistribute it and/or modify it | |
27 | * under the terms of the GNU General Public License as published by the | |
28 | * Free Software Foundation; either version 2, or (at your option) any | |
29 | * later version. | |
30 | * | |
31 | * This program is distributed in the hope that it will be useful, but | |
32 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
34 | * General Public License for more details. | |
35 | * | |
36 | * You should have received a copy of the GNU General Public License along | |
37 | * with this program; if not, write to the Free Software Foundation, Inc., | |
38 | * 675 Mass Ave, Cambridge, MA 02139, USA. | |
39 | */ | |
40 | ||
41 | #ifndef _TRANSPORT_H_ | |
42 | #define _TRANSPORT_H_ | |
43 | ||
1da177e4 LT |
44 | #include <linux/blkdev.h> |
45 | ||
1da177e4 LT |
46 | /* |
47 | * Bulk only data structures | |
48 | */ | |
49 | ||
50 | /* command block wrapper */ | |
51 | struct bulk_cb_wrap { | |
52 | __le32 Signature; /* contains 'USBC' */ | |
53 | __u32 Tag; /* unique per command id */ | |
54 | __le32 DataTransferLength; /* size of data */ | |
55 | __u8 Flags; /* direction in bit 0 */ | |
56 | __u8 Lun; /* LUN normally 0 */ | |
57 | __u8 Length; /* of of the CDB */ | |
58 | __u8 CDB[16]; /* max command */ | |
59 | }; | |
60 | ||
61 | #define US_BULK_CB_WRAP_LEN 31 | |
62 | #define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */ | |
63 | #define US_BULK_FLAG_IN 1 | |
64 | #define US_BULK_FLAG_OUT 0 | |
65 | ||
66 | /* command status wrapper */ | |
67 | struct bulk_cs_wrap { | |
68 | __le32 Signature; /* should = 'USBS' */ | |
69 | __u32 Tag; /* same as original command */ | |
70 | __le32 Residue; /* amount not transferred */ | |
71 | __u8 Status; /* see below */ | |
72 | __u8 Filler[18]; | |
73 | }; | |
74 | ||
75 | #define US_BULK_CS_WRAP_LEN 13 | |
76 | #define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */ | |
77 | #define US_BULK_STAT_OK 0 | |
78 | #define US_BULK_STAT_FAIL 1 | |
79 | #define US_BULK_STAT_PHASE 2 | |
80 | ||
81 | /* bulk-only class specific requests */ | |
82 | #define US_BULK_RESET_REQUEST 0xff | |
83 | #define US_BULK_GET_MAX_LUN 0xfe | |
84 | ||
85 | /* | |
86 | * usb_stor_bulk_transfer_xxx() return codes, in order of severity | |
87 | */ | |
88 | ||
89 | #define USB_STOR_XFER_GOOD 0 /* good transfer */ | |
90 | #define USB_STOR_XFER_SHORT 1 /* transferred less than expected */ | |
91 | #define USB_STOR_XFER_STALLED 2 /* endpoint stalled */ | |
92 | #define USB_STOR_XFER_LONG 3 /* device tried to send too much */ | |
93 | #define USB_STOR_XFER_ERROR 4 /* transfer died in the middle */ | |
94 | ||
95 | /* | |
96 | * Transport return codes | |
97 | */ | |
98 | ||
99 | #define USB_STOR_TRANSPORT_GOOD 0 /* Transport good, command good */ | |
100 | #define USB_STOR_TRANSPORT_FAILED 1 /* Transport good, command failed */ | |
101 | #define USB_STOR_TRANSPORT_NO_SENSE 2 /* Command failed, no auto-sense */ | |
102 | #define USB_STOR_TRANSPORT_ERROR 3 /* Transport bad (i.e. device dead) */ | |
103 | ||
104 | /* | |
105 | * We used to have USB_STOR_XFER_ABORTED and USB_STOR_TRANSPORT_ABORTED | |
106 | * return codes. But now the transport and low-level transfer routines | |
107 | * treat an abort as just another error (-ENOENT for a cancelled URB). | |
108 | * It is up to the invoke_transport() function to test for aborts and | |
109 | * distinguish them from genuine communication errors. | |
110 | */ | |
111 | ||
112 | /* | |
113 | * CBI accept device specific command | |
114 | */ | |
115 | ||
116 | #define US_CBI_ADSC 0 | |
117 | ||
118 | extern int usb_stor_CBI_transport(struct scsi_cmnd *, struct us_data*); | |
119 | ||
120 | extern int usb_stor_CB_transport(struct scsi_cmnd *, struct us_data*); | |
121 | extern int usb_stor_CB_reset(struct us_data*); | |
122 | ||
123 | extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data*); | |
124 | extern int usb_stor_Bulk_max_lun(struct us_data*); | |
125 | extern int usb_stor_Bulk_reset(struct us_data*); | |
126 | ||
127 | extern void usb_stor_invoke_transport(struct scsi_cmnd *, struct us_data*); | |
128 | extern void usb_stor_stop_transport(struct us_data*); | |
129 | ||
130 | extern int usb_stor_control_msg(struct us_data *us, unsigned int pipe, | |
131 | u8 request, u8 requesttype, u16 value, u16 index, | |
132 | void *data, u16 size, int timeout); | |
133 | extern int usb_stor_clear_halt(struct us_data *us, unsigned int pipe); | |
134 | ||
135 | extern int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe, | |
136 | u8 request, u8 requesttype, u16 value, u16 index, | |
137 | void *data, u16 size); | |
138 | extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe, | |
139 | void *buf, unsigned int length, unsigned int *act_len); | |
140 | extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe, | |
141 | void *buf, unsigned int length, int use_sg, int *residual); | |
142 | ||
4d07ef76 | 143 | extern int usb_stor_port_reset(struct us_data *us); |
1da177e4 | 144 | #endif |