]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h
Fixed unexpected timeout in Usb MassStorage Driver.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMassBoot.h
... / ...
CommitLineData
1/** @file\r
2\r
3Copyright (c) 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 UsbMassBoot.h\r
15\r
16Abstract:\r
17\r
18 The definition of command and data of the USB mass storage for\r
19 bootability command set.\r
20\r
21Revision History\r
22\r
23\r
24**/\r
25\r
26#ifndef _EFI_USB_MASS_BOOT_H_\r
27#define _EFI_USB_MASS_BOOT_H_\r
28\r
29enum {\r
30 //\r
31 // The opcodes of various usb boot commands:\r
32 // INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified\r
33 // by MMC command set. Others are "Group 1 Timeout Commands". That\r
34 // is they should be retried if driver is ready. \r
35 // We can't use the Peripheral Device Type in Inquiry data to \r
36 // determine the timeout used. For example, both floppy and flash\r
37 // are likely set their PDT to 0, or Direct Access Device.\r
38 //\r
39 USB_BOOT_INQUIRY_OPCODE = 0x12,\r
40 USB_BOOT_REQUEST_SENSE_OPCODE = 0x03,\r
41 USB_BOOT_MODE_SENSE10_OPCODE = 0x5A,\r
42 USB_BOOT_READ_CAPACITY_OPCODE = 0x25,\r
43 USB_BOOT_TEST_UNIT_READY_OPCODE = 0x00,\r
44 USB_BOOT_READ10_OPCODE = 0x28,\r
45 USB_BOOT_WRITE10_OPCODE = 0x2A,\r
46\r
47 USB_SCSI_MODE_SENSE6_OPCODE = 0x1A,\r
48 \r
49 //\r
50 // The Sense Key part of the sense data. Sense data has three levels:\r
51 // Sense key, Additional Sense Code and Additional Sense Code Qualifier\r
52 //\r
53 USB_BOOT_SENSE_NO_SENSE = 0x00, // No sense key\r
54 USB_BOOT_SENSE_RECOVERED = 0x01, // Last command succeed with recovery actions\r
55 USB_BOOT_SENSE_NOT_READY = 0x02, // Device not ready\r
56 USB_BOOT_SNESE_MEDIUM_ERROR = 0X03, // Failed probably because flaw in the media\r
57 USB_BOOT_SENSE_HARDWARE_ERROR = 0X04, // Non-recoverable hardware failure\r
58 USB_BOOT_SENSE_ILLEGAL_REQUEST = 0X05, // Illegal parameters in the request\r
59 USB_BOOT_SENSE_UNIT_ATTENTION = 0X06, // Removable medium may have been changed\r
60 USB_BOOT_SNESE_DATA_PROTECT = 0X07, // Write protected\r
61 USB_BOOT_SENSE_BLANK_CHECK = 0X08, // Blank/non-blank medium while reading/writing\r
62 USB_BOOT_SENSE_VENDOR = 0X09, // Vendor specific sense key\r
63 USB_BOOT_SENSE_ABORTED = 0X0B, // Command aborted by the device\r
64 USB_BOOT_SENSE_VOLUME_OVERFLOW = 0x0D, // Partition overflow\r
65 USB_BOOT_SENSE_MISCOMPARE = 0x0E, // Source data mis-match while verfying.\r
66\r
67 USB_BOOT_ASC_NOT_READY = 0x04,\r
68 USB_BOOT_ASC_NO_MEDIA = 0x3A,\r
69 USB_BOOT_ASC_MEDIA_CHANGE = 0x28,\r
70\r
71 //\r
72 // Supported PDT codes, or Peripheral Device Type\r
73 //\r
74 USB_PDT_DIRECT_ACCESS = 0x00, // Direct access device\r
75 USB_PDT_CDROM = 0x05, // CDROM\r
76 USB_PDT_OPTICAL = 0x07, // Non-CD optical disks\r
77 USB_PDT_SIMPLE_DIRECT = 0x0E, // Simplified direct access device\r
78 \r
79 //\r
80 // Other parameters, Max carried size is 512B * 128 = 64KB\r
81 //\r
82 USB_BOOT_IO_BLOCKS = 128,\r
83\r
84 //\r
85 // Retry mass command times, set by experience\r
86 //\r
87 USB_BOOT_COMMAND_RETRY = 5,\r
88 USB_BOOT_INIT_MEDIA_RETRY = 5,\r
89\r
90 //\r
91 // Wait for unit ready command, set by experience\r
92 //\r
93 USB_BOOT_RETRY_UNIT_READY_STALL = 500 * USB_MASS_1_MILLISECOND,\r
94\r
95 //\r
96 // Mass command timeout, refers to specification[USB20-9.2.6.1]\r
97 //\r
98 // USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy, \r
99 // USB CD-Rom and iPod devices are much slower than USB key when reponse \r
100 // most of commands, So we set 5s as timeout here.\r
101 // \r
102 //\r
103 USB_BOOT_GENERAL_CMD_TIMEOUT = 5 * USB_MASS_1_SECOND,\r
104};\r
105\r
106//\r
107// The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,\r
108// READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA\r
109// so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY\r
110// command to retrieve the disk gemotrics. \r
111//\r
112#pragma pack(1)\r
113typedef struct {\r
114 UINT8 OpCode;\r
115 UINT8 Lun; // Lun (high 3 bits)\r
116 UINT8 Reserved0[2];\r
117 UINT8 AllocLen;\r
118 UINT8 Reserved1;\r
119 UINT8 Pad[6];\r
120} USB_BOOT_INQUIRY_CMD;\r
121\r
122typedef struct {\r
123 UINT8 Pdt; // Peripheral Device Type (low 5 bits)\r
124 UINT8 Removable; // Removable Media (highest bit)\r
125 UINT8 Reserved0[2];\r
126 UINT8 AddLen; // Additional length\r
127 UINT8 Reserved1[3];\r
128 UINT8 VendorID[8];\r
129 UINT8 ProductID[16];\r
130 UINT8 ProductRevision[4];\r
131} USB_BOOT_INQUIRY_DATA;\r
132\r
133typedef struct {\r
134 UINT8 OpCode;\r
135 UINT8 Lun;\r
136 UINT8 Reserved0[8];\r
137 UINT8 Pad[2];\r
138} USB_BOOT_READ_CAPACITY_CMD;\r
139\r
140typedef struct {\r
141 UINT8 LastLba[4];\r
142 UINT8 BlockLen[4];\r
143} USB_BOOT_READ_CAPACITY_DATA;\r
144\r
145typedef struct {\r
146 UINT8 OpCode;\r
147 UINT8 Lun;\r
148 UINT8 Reserved[4];\r
149 UINT8 Pad[6];\r
150} USB_BOOT_TEST_UNIT_READY_CMD;\r
151\r
152typedef struct {\r
153 UINT8 OpCode;\r
154 UINT8 Lun;\r
155 UINT8 PageCode;\r
156 UINT8 Reserved0[4];\r
157 UINT8 ParaListLenMsb;\r
158 UINT8 ParaListLenLsb;\r
159 UINT8 Reserved1;\r
160 UINT8 Pad[2];\r
161} USB_BOOT_MODE_SENSE10_CMD;\r
162\r
163typedef struct {\r
164 UINT8 ModeDataLenMsb;\r
165 UINT8 ModeDataLenLsb;\r
166 UINT8 Reserved0[4];\r
167 UINT8 BlkDesLenMsb;\r
168 UINT8 BlkDesLenLsb;\r
169} USB_BOOT_MODE_SENSE10_PARA_HEADER;\r
170\r
171typedef struct {\r
172 UINT8 OpCode;\r
173 UINT8 Lun; // Lun (High 3 bits)\r
174 UINT8 Lba[4]; // Logical block address\r
175 UINT8 Reserved0;\r
176 UINT8 TransferLen[2]; // Transfer length\r
177 UINT8 Reserverd1;\r
178 UINT8 Pad[2];\r
179} USB_BOOT_READ10_CMD;\r
180\r
181typedef struct {\r
182 UINT8 OpCode;\r
183 UINT8 Lun;\r
184 UINT8 Lba[4];\r
185 UINT8 Reserved0;\r
186 UINT8 TransferLen[2];\r
187 UINT8 Reserverd1;\r
188 UINT8 Pad[2];\r
189} USB_BOOT_WRITE10_CMD;\r
190\r
191typedef struct {\r
192 UINT8 OpCode;\r
193 UINT8 Lun; // Lun (High 3 bits)\r
194 UINT8 Reserved0[2];\r
195 UINT8 AllocLen; // Allocation length\r
196 UINT8 Reserved1;\r
197 UINT8 Pad[6];\r
198} USB_BOOT_REQUEST_SENSE_CMD;\r
199\r
200typedef struct {\r
201 UINT8 ErrorCode;\r
202 UINT8 Reserved0;\r
203 UINT8 SenseKey; // Sense key (low 4 bits)\r
204 UINT8 Infor[4];\r
205 UINT8 AddLen; // Additional Sense length, 10\r
206 UINT8 Reserved1[4];\r
207 UINT8 ASC; // Additional Sense Code\r
208 UINT8 ASCQ; // Additional Sense Code Qualifier\r
209 UINT8 Reserverd2[4];\r
210} USB_BOOT_REQUEST_SENSE_DATA;\r
211\r
212typedef struct {\r
213 UINT8 OpCode;\r
214 UINT8 Lun;\r
215 UINT8 PageCode;\r
216 UINT8 Reserved0;\r
217 UINT8 AllocateLen;\r
218 UINT8 Control;\r
219} USB_SCSI_MODE_SENSE6_CMD;\r
220\r
221typedef struct {\r
222 UINT8 ModeDataLen;\r
223 UINT8 MediumType;\r
224 UINT8 DevicePara;\r
225 UINT8 BlkDesLen;\r
226} USB_SCSI_MODE_SENSE6_PARA_HEADER;\r
227#pragma pack()\r
228\r
229//\r
230// Convert a LUN number to that in the command\r
231//\r
232#define USB_BOOT_LUN(Lun) ((Lun) << 5)\r
233\r
234//\r
235// Get the removable, PDT, and sense key bits from the command data\r
236//\r
237#define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & 0x80) != 0)\r
238#define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)\r
239#define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)\r
240\r
241//\r
242// Swap the byte sequence of a UINT32. Intel CPU uses little endian\r
243// in UEFI environment, but USB boot uses big endian.\r
244//\r
245#define USB_BOOT_SWAP32(Data32) \\r
246 ((((Data32) & 0x000000ff) << 24) | (((Data32) & 0xff000000) >> 24) | \\r
247 (((Data32) & 0x0000ff00) << 8) | (((Data32) & 0x00ff0000) >> 8)) \r
248\r
249#define USB_BOOT_SWAP16(Data16) \\r
250 ((((Data16) & 0x00ff) << 8) | (((Data16) & 0xff00) >> 8))\r
251\r
252EFI_STATUS\r
253UsbBootGetParams (\r
254 IN USB_MASS_DEVICE *UsbMass\r
255 );\r
256\r
257EFI_STATUS\r
258UsbBootIsUnitReady (\r
259 IN USB_MASS_DEVICE *UsbMass\r
260 );\r
261\r
262EFI_STATUS\r
263UsbBootDetectMedia (\r
264 IN USB_MASS_DEVICE *UsbMass\r
265 );\r
266\r
267EFI_STATUS\r
268UsbBootReadBlocks (\r
269 IN USB_MASS_DEVICE *UsbMass,\r
270 IN UINT32 Lba,\r
271 IN UINTN TotalBlock,\r
272 OUT UINT8 *Buffer\r
273 );\r
274\r
275EFI_STATUS\r
276UsbBootWriteBlocks (\r
277 IN USB_MASS_DEVICE *UsbMass,\r
278 IN UINT32 Lba,\r
279 IN UINTN TotalBlock,\r
280 OUT UINT8 *Buffer\r
281 );\r
282#endif\r
283\r