]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
1. Set the Target array to zero before fill the target id.
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiDiskDxe / ScsiDisk.h
1 /*++
2
3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ScsiDisk.h
15
16 Abstract:
17
18 Header file for SCSI Disk Driver.
19
20 --*/
21
22 #ifndef _SCSI_DISK_H
23 #define _SCSI_DISK_H
24
25
26 #include <IndustryStandard/scsi.h>
27
28 #define IsDeviceFixed(a) (a)->FixedDevice ? 1 : 0
29
30 #define SCSI_DISK_DEV_SIGNATURE EFI_SIGNATURE_32 ('s', 'c', 'd', 'k')
31
32 typedef struct {
33 UINT32 Signature;
34
35 EFI_HANDLE Handle;
36
37 EFI_BLOCK_IO_PROTOCOL BlkIo;
38 EFI_BLOCK_IO_MEDIA BlkIoMedia;
39 EFI_SCSI_IO_PROTOCOL *ScsiIo;
40 UINT8 DeviceType;
41 BOOLEAN FixedDevice;
42 UINT16 Reserved;
43
44 EFI_SCSI_SENSE_DATA *SenseData;
45 UINTN SenseDataNumber;
46 EFI_SCSI_INQUIRY_DATA InquiryData;
47
48 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
49
50 } SCSI_DISK_DEV;
51
52 #define SCSI_DISK_DEV_FROM_THIS(a) CR (a, SCSI_DISK_DEV, BlkIo, SCSI_DISK_DEV_SIGNATURE)
53
54 //
55 // Global Variables
56 //
57 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding;
58 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName;
59 //
60 // action code used in detect media process
61 //
62 #define ACTION_NO_ACTION 0x00
63 #define ACTION_READ_CAPACITY 0x01
64 #define ACTION_RETRY_COMMAND_LATER 0x02
65
66 EFI_STATUS
67 EFIAPI
68 ScsiDiskDriverBindingSupported (
69 IN EFI_DRIVER_BINDING_PROTOCOL *This,
70 IN EFI_HANDLE Controller,
71 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
72 );
73
74 EFI_STATUS
75 EFIAPI
76 ScsiDiskDriverBindingStart (
77 IN EFI_DRIVER_BINDING_PROTOCOL *This,
78 IN EFI_HANDLE Controller,
79 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
80 );
81
82 EFI_STATUS
83 EFIAPI
84 ScsiDiskDriverBindingStop (
85 IN EFI_DRIVER_BINDING_PROTOCOL *This,
86 IN EFI_HANDLE Controller,
87 IN UINTN NumberOfChildren,
88 IN EFI_HANDLE *ChildHandleBuffer
89 );
90
91 //
92 // EFI Component Name Functions
93 //
94 EFI_STATUS
95 EFIAPI
96 ScsiDiskComponentNameGetDriverName (
97 IN EFI_COMPONENT_NAME_PROTOCOL *This,
98 IN CHAR8 *Language,
99 OUT CHAR16 **DriverName
100 );
101
102 EFI_STATUS
103 EFIAPI
104 ScsiDiskComponentNameGetControllerName (
105 IN EFI_COMPONENT_NAME_PROTOCOL *This,
106 IN EFI_HANDLE ControllerHandle,
107 IN EFI_HANDLE ChildHandle OPTIONAL,
108 IN CHAR8 *Language,
109 OUT CHAR16 **ControllerName
110 );
111
112 EFI_STATUS
113 EFIAPI
114 ScsiDiskReset (
115 IN EFI_BLOCK_IO_PROTOCOL *This,
116 IN BOOLEAN ExtendedVerification
117 )
118 /*++
119
120 Routine Description:
121
122 Reset SCSI Disk
123
124 Arguments:
125
126 This - The pointer of EFI_BLOCK_IO_PROTOCOL
127 ExtendedVerification - The flag about if extend verificate
128
129 Returns:
130
131 EFI_STATUS
132
133 --*/
134 ;
135
136 EFI_STATUS
137 EFIAPI
138 ScsiDiskReadBlocks (
139 IN EFI_BLOCK_IO_PROTOCOL *This,
140 IN UINT32 MediaId,
141 IN EFI_LBA LBA,
142 IN UINTN BufferSize,
143 OUT VOID *Buffer
144 )
145 /*++
146
147 Routine Description:
148
149 The function is to Read Block from SCSI Disk
150
151 Arguments:
152
153 This - The pointer of EFI_BLOCK_IO_PROTOCOL
154 MediaId - The Id of Media detected
155 LBA - The logic block address
156 BufferSize - The size of Buffer
157 Buffer - The buffer to fill the read out data
158
159 Returns:
160
161 EFI_INVALID_PARAMETER - Invalid parameter passed in.
162 EFI_SUCCESS - Successfully to read out block.
163 EFI_DEVICE_ERROR - Fail to detect media.
164 EFI_NO_MEDIA - Media is not present.
165 EFI_MEDIA_CHANGED - Media has changed.
166 EFI_BAD_BUFFER_SIZE - The buffer size is not multiple of BlockSize.
167
168 --*/
169 ;
170
171 EFI_STATUS
172 EFIAPI
173 ScsiDiskWriteBlocks (
174 IN EFI_BLOCK_IO_PROTOCOL *This,
175 IN UINT32 MediaId,
176 IN EFI_LBA LBA,
177 IN UINTN BufferSize,
178 IN VOID *Buffer
179 )
180 /*++
181
182 Routine Description:
183
184 The function is to Write Block to SCSI Disk
185
186 Arguments:
187
188 This - The pointer of EFI_BLOCK_IO_PROTOCOL
189 MediaId - The Id of Media detected
190 LBA - The logic block address
191 BufferSize - The size of Buffer
192 Buffer - The buffer to fill the read out data
193
194 Returns:
195
196 EFI_INVALID_PARAMETER - Invalid parameter passed in.
197 EFI_SUCCESS - Successfully to read out block.
198 EFI_DEVICE_ERROR - Fail to detect media.
199 EFI_NO_MEDIA - Media is not present.
200 EFI_MEDIA_CHANGED - Media has changed.
201 EFI_BAD_BUFFER_SIZE - The buffer size is not multiple of BlockSize.
202
203 --*/
204 ;
205
206 EFI_STATUS
207 EFIAPI
208 ScsiDiskFlushBlocks (
209 IN EFI_BLOCK_IO_PROTOCOL *This
210 )
211 /*++
212
213 Routine Description:
214
215 Flush Block to Disk
216
217 Arguments:
218
219 This - The pointer of EFI_BLOCK_IO_PROTOCOL
220
221 Returns:
222
223 EFI_SUCCESS
224
225 --*/
226 ;
227
228 EFI_STATUS
229 ScsiDiskDetectMedia (
230 SCSI_DISK_DEV *ScsiDiskDevice,
231 BOOLEAN MustReadCap,
232 BOOLEAN *MediaChange
233 )
234 /*++
235
236 Routine Description:
237
238 Dectect Device and read out capacity ,if error occurs, parse the sense key.
239
240 Arguments:
241
242 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
243 MustReadCapacity - The flag about reading device capacity
244 MediaChange - The pointer of flag indicates if media has changed
245
246 Returns:
247
248 EFI_DEVICE_ERROR - Indicates that error occurs
249 EFI_SUCCESS - Successfully to detect media
250
251 --*/
252 ;
253
254 EFI_STATUS
255 ScsiDiskTestUnitReady (
256 SCSI_DISK_DEV *ScsiDiskDevice,
257 BOOLEAN *NeedRetry,
258 EFI_SCSI_SENSE_DATA **SenseDataArray,
259 UINTN *NumberOfSenseKeys
260 )
261 /*++
262
263 Routine Description:
264
265 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
266 When Test Unit Ready command encounters any error caused by host adapter or
267 target, return error without retrieving Sense Keys.
268
269 Arguments:
270
271 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
272 NeedRetry - The pointer of flag indicates try again
273 SenseDataArray - The pointer of an array of sense data
274 NumberOfSenseKeys - The pointer of the number of sense data array
275
276 Returns:
277
278 EFI_DEVICE_ERROR - Indicates that error occurs
279 EFI_SUCCESS - Successfully to test unit
280
281 --*/
282 ;
283
284 EFI_STATUS
285 DetectMediaParsingSenseKeys (
286 SCSI_DISK_DEV *ScsiDiskDevice,
287 EFI_SCSI_SENSE_DATA *SenseData,
288 UINTN NumberOfSenseKeys,
289 UINTN *Action
290 )
291 /*++
292
293 Routine Description:
294
295 Parsing Sense Keys which got from request sense command.
296
297 Arguments:
298
299 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
300 SenseData - The pointer of EFI_SCSI_SENSE_DATA
301 NumberOfSenseKeys - The number of sense key
302 Action - The pointer of action which indicates what is need to do next
303
304 Returns:
305
306 EFI_DEVICE_ERROR - Indicates that error occurs
307 EFI_SUCCESS - Successfully to complete the parsing
308
309 --*/
310 ;
311
312 EFI_STATUS
313 ScsiDiskReadCapacity (
314 SCSI_DISK_DEV *ScsiDiskDevice,
315 BOOLEAN *NeedRetry,
316 EFI_SCSI_SENSE_DATA **SenseDataArray,
317 UINTN *NumberOfSenseKeys
318 )
319 /*++
320
321 Routine Description:
322
323 Send read capacity command to device and get the device parameter
324
325 Arguments:
326
327 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
328 NeedRetry - The pointer of flag indicates if need a retry
329 SenseDataArray - The pointer of an array of sense data
330 NumberOfSenseKeys - The number of sense key
331
332 Returns:
333
334 EFI_DEVICE_ERROR - Indicates that error occurs
335 EFI_SUCCESS - Successfully to read capacity
336
337 --*/
338 ;
339
340 EFI_STATUS
341 CheckHostAdapterStatus (
342 UINT8 HostAdapterStatus
343 )
344 /*++
345
346 Routine Description:
347
348 Check the HostAdapter status
349
350 Arguments:
351
352 HostAdapterStatus - Host Adapter status
353
354 Returns:
355
356 EFI_SUCCESS
357 EFI_TIMEOUT
358 EFI_NOT_READY
359 EFI_DEVICE_ERROR
360
361 --*/
362 ;
363
364 EFI_STATUS
365 CheckTargetStatus (
366 UINT8 TargetStatus
367 )
368 /*++
369
370 Routine Description:
371
372 Check the target status
373
374 Arguments:
375
376 TargetStatus - Target status
377
378 Returns:
379
380 EFI_NOT_READY
381 EFI_DEVICE_ERROR
382 EFI_SUCCESS
383
384 --*/
385 ;
386
387 EFI_STATUS
388 ScsiDiskRequestSenseKeys (
389 SCSI_DISK_DEV *ScsiDiskDevice,
390 BOOLEAN *NeedRetry,
391 EFI_SCSI_SENSE_DATA **SenseDataArray,
392 UINTN *NumberOfSenseKeys,
393 BOOLEAN AskResetIfError
394 )
395 /*++
396
397 Routine Description:
398
399 Retrieve all sense keys from the device.
400 When encountering error during the process,
401 if retrieve sense keys before error encounterred,
402 return the sense keys with return status set to EFI_SUCCESS,
403 and NeedRetry set to FALSE; otherwize, return the proper return
404 status.
405
406 Arguments:
407
408 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
409 NeedRetry - The pointer of flag indicates if need a retry
410 SenseDataArray - The pointer of an array of sense data
411 NumberOfSenseKeys - The number of sense key
412 AskResetIfError - The flag indicates if need reset when error occurs
413
414 Returns:
415
416 EFI_DEVICE_ERROR - Indicates that error occurs
417 EFI_SUCCESS - Successfully to request sense key
418
419 --*/
420 ;
421
422 EFI_STATUS
423 ScsiDiskInquiryDevice (
424 SCSI_DISK_DEV *ScsiDiskDevice,
425 BOOLEAN *NeedRetry
426 )
427 /*++
428
429 Routine Description:
430
431 Send out Inquiry command to Device
432
433 Arguments:
434
435 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
436 NeedRetry - Indicates if needs try again when error happens
437
438 Returns:
439
440 EFI_DEVICE_ERROR - Indicates that error occurs
441 EFI_SUCCESS - Successfully to detect media
442
443 --*/
444 ;
445
446 VOID
447 ParseInquiryData (
448 SCSI_DISK_DEV *ScsiDiskDevice
449 )
450 /*++
451
452 Routine Description:
453
454 Parse Inquiry data
455
456 Arguments:
457
458 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
459
460 Returns:
461
462 NONE
463
464 --*/
465 ;
466
467 EFI_STATUS
468 ScsiDiskReadSectors (
469 SCSI_DISK_DEV *ScsiDiskDevice,
470 VOID *Buffer,
471 EFI_LBA Lba,
472 UINTN NumberOfBlocks
473 )
474 /*++
475
476 Routine Description:
477
478 Read sector from SCSI Disk
479
480 Arguments:
481
482 ScsiDiskDevice - The poiniter of SCSI_DISK_DEV
483 Buffer - The buffer to fill in the read out data
484 Lba - Logic block address
485 NumberOfBlocks - The number of blocks to read
486
487 Returns:
488
489 EFI_DEVICE_ERROR
490 EFI_SUCCESS
491
492 --*/
493 ;
494
495 EFI_STATUS
496 ScsiDiskWriteSectors (
497 SCSI_DISK_DEV *ScsiDiskDevice,
498 VOID *Buffer,
499 EFI_LBA Lba,
500 UINTN NumberOfBlocks
501 )
502 /*++
503
504 Routine Description:
505
506 Write SCSI Disk sectors
507
508 Arguments:
509
510 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
511 Buffer - The data buffer to write sector
512 Lba - Logic block address
513 NumberOfBlocks - The number of blocks to write
514
515 Returns:
516
517 EFI_DEVICE_ERROR
518 EFI_SUCCESS
519
520 --*/
521 ;
522
523 EFI_STATUS
524 ScsiDiskRead10 (
525 SCSI_DISK_DEV *ScsiDiskDevice,
526 BOOLEAN *NeedRetry,
527 EFI_SCSI_SENSE_DATA **SenseDataArray,
528 UINTN *NumberOfSenseKeys,
529 UINT64 Timeout,
530 UINT8 *DataBuffer,
531 UINT32 *DataLength,
532 UINT32 StartLba,
533 UINT32 SectorSize
534 )
535 /*++
536
537 Routine Description:
538
539 Sumbmit Read command
540
541 Arguments:
542
543 ScsiDiskDevice - The pointer of ScsiDiskDevice
544 NeedRetry - The pointer of flag indicates if needs retry if error happens
545 SenseDataArray - The pointer of an array of sense data
546 NumberOfSenseKeys - The number of sense key
547 Timeout - The time to complete the command
548 DataBuffer - The buffer to fill with the read out data
549 DataLength - The length of buffer
550 StartLba - The start logic block address
551 SectorSize - The size of sector
552
553 Returns:
554
555 EFI_STATUS
556
557 --*/
558 ;
559
560 EFI_STATUS
561 ScsiDiskWrite10 (
562 SCSI_DISK_DEV *ScsiDiskDevice,
563 BOOLEAN *NeedRetry,
564 EFI_SCSI_SENSE_DATA **SenseDataArray,
565 UINTN *NumberOfSenseKeys,
566 UINT64 Timeout,
567 UINT8 *DataBuffer,
568 UINT32 *DataLength,
569 UINT32 StartLba,
570 UINT32 SectorSize
571 )
572 /*++
573
574 Routine Description:
575
576 Submit Write Command
577
578 Arguments:
579
580 ScsiDiskDevice - The pointer of ScsiDiskDevice
581 NeedRetry - The pointer of flag indicates if needs retry if error happens
582 SenseDataArray - The pointer of an array of sense data
583 NumberOfSenseKeys - The number of sense key
584 Timeout - The time to complete the command
585 DataBuffer - The buffer to fill with the read out data
586 DataLength - The length of buffer
587 StartLba - The start logic block address
588 SectorSize - The size of sector
589
590 Returns:
591
592 EFI_STATUS
593
594 --*/
595 ;
596
597 VOID
598 GetMediaInfo (
599 SCSI_DISK_DEV *ScsiDiskDevice,
600 EFI_SCSI_DISK_CAPACITY_DATA *Capacity
601 )
602 /*++
603
604 Routine Description:
605
606 Get information from media read capacity command
607
608 Arguments:
609
610 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
611 Capacity - The pointer of EFI_SCSI_DISK_CAPACITY_DATA
612
613 Returns:
614
615 NONE
616
617 --*/
618 ;
619
620 BOOLEAN
621 ScsiDiskIsNoMedia (
622 IN EFI_SCSI_SENSE_DATA *SenseData,
623 IN UINTN SenseCounts
624 )
625 /*++
626
627 Routine Description:
628
629 Check sense key to find if media presents
630
631 Arguments:
632
633 SenseData - The pointer of EFI_SCSI_SENSE_DATA
634 SenseCounts - The number of sense key
635
636 Returns:
637
638 BOOLEAN
639
640 --*/
641 ;
642
643 BOOLEAN
644 ScsiDiskIsMediaError (
645 IN EFI_SCSI_SENSE_DATA *SenseData,
646 IN UINTN SenseCounts
647 )
648 /*++
649
650 Routine Description:
651
652 Parse sense key
653
654 Arguments:
655
656 SenseData - The pointer of EFI_SCSI_SENSE_DATA
657 SenseCounts - The number of sense key
658
659 Returns:
660
661 BOOLEAN
662
663 --*/
664 ;
665
666 BOOLEAN
667 ScsiDiskIsHardwareError (
668 IN EFI_SCSI_SENSE_DATA *SenseData,
669 IN UINTN SenseCounts
670 )
671 /*++
672
673 Routine Description:
674
675 Check sense key to find if hardware error happens
676
677 Arguments:
678
679 SenseData - The pointer of EFI_SCSI_SENSE_DATA
680 SenseCounts - The number of sense key
681
682 Returns:
683
684 BOOLEAN
685
686 --*/
687 ;
688
689 BOOLEAN
690 ScsiDiskIsMediaChange (
691 IN EFI_SCSI_SENSE_DATA *SenseData,
692 IN UINTN SenseCounts
693 )
694 /*++
695
696 Routine Description:
697
698 Routine Description:
699
700 Check sense key to find if media has changed
701
702 Arguments:
703
704 SenseData - The pointer of EFI_SCSI_SENSE_DATA
705 SenseCounts - The number of sense key
706
707 Returns:
708
709 BOOLEAN
710
711 --*/
712 ;
713
714 BOOLEAN
715 ScsiDiskIsResetBefore (
716 IN EFI_SCSI_SENSE_DATA *SenseData,
717 IN UINTN SenseCounts
718 )
719 /*++
720
721 Routine Description:
722
723 Check sense key to find if reset happens
724
725 Arguments:
726
727 SenseData - The pointer of EFI_SCSI_SENSE_DATA
728 SenseCounts - The number of sense key
729
730 Returns:
731
732 BOOLEAN
733
734 --*/
735 ;
736
737 BOOLEAN
738 ScsiDiskIsDriveReady (
739 IN EFI_SCSI_SENSE_DATA *SenseData,
740 IN UINTN SenseCounts,
741 OUT BOOLEAN *NeedRetry
742 )
743 /*++
744
745 Routine Description:
746
747 Check sense key to find if the drive is ready
748
749 Arguments:
750
751 SenseData - The pointer of EFI_SCSI_SENSE_DATA
752 SenseCounts - The number of sense key
753 RetryLater - The flag means if need a retry
754
755 Returns:
756
757 BOOLEAN
758
759 --*/
760 ;
761
762 BOOLEAN
763 ScsiDiskHaveSenseKey (
764 IN EFI_SCSI_SENSE_DATA *SenseData,
765 IN UINTN SenseCounts
766 )
767 /*++
768
769 Routine Description:
770
771 Check sense key to find if it has sense key
772
773 Arguments:
774
775 SenseData - The pointer of EFI_SCSI_SENSE_DATA
776 SenseCounts - The number of sense key
777
778 Returns:
779
780 BOOLEAN
781
782 --*/
783 ;
784
785 VOID
786 ReleaseScsiDiskDeviceResources (
787 IN SCSI_DISK_DEV *ScsiDiskDevice
788 )
789 /*++
790
791 Routine Description:
792
793 Release resource about disk device
794
795 Arguments:
796
797 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
798
799 Returns:
800
801 NONE
802
803 --*/
804 ;
805
806 #endif