TianoCore EDK2 master
Loading...
Searching...
No Matches
UefiScsiLib.c
Go to the documentation of this file.
1
9#include <Uefi.h>
10#include <Library/BaseLib.h>
11#include <Library/DebugLib.h>
12#include <Library/UefiScsiLib.h>
16
18
19//
20// Scsi Command Length
21//
22#define EFI_SCSI_OP_LENGTH_SIX 0x6
23#define EFI_SCSI_OP_LENGTH_TEN 0xa
24#define EFI_SCSI_OP_LENGTH_TWELVE 0xc
25#define EFI_SCSI_OP_LENGTH_SIXTEEN 0x10
26
27//
28// The context structure used when non-blocking SCSI read/write operation
29// completes.
30//
31typedef struct {
52 UINT32 *DataLength;
59
128EFIAPI
130 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
131 IN UINT64 Timeout,
132 IN OUT VOID *SenseData OPTIONAL,
133 IN OUT UINT8 *SenseDataLength,
134 OUT UINT8 *HostAdapterStatus,
135 OUT UINT8 *TargetStatus
136 )
137{
139 EFI_STATUS Status;
140 UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX];
141
142 ASSERT (SenseDataLength != NULL);
143 ASSERT (HostAdapterStatus != NULL);
144 ASSERT (TargetStatus != NULL);
145 ASSERT (ScsiIo != NULL);
146
147 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
148 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);
149
150 CommandPacket.Timeout = Timeout;
151 CommandPacket.InDataBuffer = NULL;
152 CommandPacket.InTransferLength = 0;
153 CommandPacket.OutDataBuffer = NULL;
154 CommandPacket.OutTransferLength = 0;
155 CommandPacket.SenseData = SenseData;
156 CommandPacket.Cdb = Cdb;
157 //
158 // Fill Cdb for Test Unit Ready Command
159 //
160 Cdb[0] = EFI_SCSI_OP_TEST_UNIT_READY;
161 CommandPacket.CdbLength = (UINT8)EFI_SCSI_OP_LENGTH_SIX;
162 CommandPacket.SenseDataLength = *SenseDataLength;
163
164 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
165
166 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
167 *TargetStatus = CommandPacket.TargetStatus;
168 *SenseDataLength = CommandPacket.SenseDataLength;
169
170 return Status;
171}
172
263EFIAPI
265 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
266 IN UINT64 Timeout,
267 IN OUT VOID *SenseData OPTIONAL,
268 IN OUT UINT8 *SenseDataLength,
269 OUT UINT8 *HostAdapterStatus,
270 OUT UINT8 *TargetStatus,
271 IN OUT VOID *InquiryDataBuffer OPTIONAL,
272 IN OUT UINT32 *InquiryDataLength,
273 IN BOOLEAN EnableVitalProductData,
274 IN UINT8 PageCode
275 )
276{
278 EFI_STATUS Status;
279 UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX];
280
281 ASSERT (SenseDataLength != NULL);
282 ASSERT (HostAdapterStatus != NULL);
283 ASSERT (TargetStatus != NULL);
284 ASSERT (InquiryDataLength != NULL);
285 ASSERT (ScsiIo != NULL);
286
287 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
288 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);
289
290 CommandPacket.Timeout = Timeout;
291 CommandPacket.InDataBuffer = InquiryDataBuffer;
292 CommandPacket.InTransferLength = *InquiryDataLength;
293 CommandPacket.SenseData = SenseData;
294 CommandPacket.SenseDataLength = *SenseDataLength;
295 CommandPacket.Cdb = Cdb;
296
297 Cdb[0] = EFI_SCSI_OP_INQUIRY;
298 if (EnableVitalProductData) {
299 Cdb[1] |= 0x01;
300 Cdb[2] = PageCode;
301 }
302
303 if (*InquiryDataLength > 0xff) {
304 *InquiryDataLength = 0xff;
305 }
306
307 Cdb[4] = (UINT8)(*InquiryDataLength);
308 CommandPacket.CdbLength = (UINT8)EFI_SCSI_OP_LENGTH_SIX;
309 CommandPacket.DataDirection = EFI_SCSI_DATA_IN;
310
311 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
312
313 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
314 *TargetStatus = CommandPacket.TargetStatus;
315 *SenseDataLength = CommandPacket.SenseDataLength;
316 *InquiryDataLength = CommandPacket.InTransferLength;
317
318 return Status;
319}
320
409EFIAPI
411 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
412 IN UINT64 Timeout,
413 IN OUT VOID *SenseData OPTIONAL,
414 IN OUT UINT8 *SenseDataLength,
415 OUT UINT8 *HostAdapterStatus,
416 OUT UINT8 *TargetStatus,
417 IN OUT VOID *InquiryDataBuffer OPTIONAL,
418 IN OUT UINT32 *InquiryDataLength,
419 IN BOOLEAN EnableVitalProductData
420 )
421{
422 return ScsiInquiryCommandEx (
423 ScsiIo,
424 Timeout,
425 SenseData,
426 SenseDataLength,
427 HostAdapterStatus,
428 TargetStatus,
429 InquiryDataBuffer,
430 InquiryDataLength,
431 EnableVitalProductData,
432 0
433 );
434}
435
526EFIAPI
528 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
529 IN UINT64 Timeout,
530 IN OUT VOID *SenseData OPTIONAL,
531 IN OUT UINT8 *SenseDataLength,
532 OUT UINT8 *HostAdapterStatus,
533 OUT UINT8 *TargetStatus,
534 IN OUT VOID *DataBuffer OPTIONAL,
535 IN OUT UINT32 *DataLength,
536 IN UINT8 DBDField OPTIONAL,
537 IN UINT8 PageControl,
538 IN UINT8 PageCode
539 )
540{
542 EFI_STATUS Status;
543 UINT8 Cdb[EFI_SCSI_OP_LENGTH_TEN];
544
545 ASSERT (SenseDataLength != NULL);
546 ASSERT (HostAdapterStatus != NULL);
547 ASSERT (TargetStatus != NULL);
548 ASSERT (DataLength != NULL);
549 ASSERT (ScsiIo != NULL);
550
551 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
552 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);
553
554 CommandPacket.Timeout = Timeout;
555 CommandPacket.InDataBuffer = DataBuffer;
556 CommandPacket.SenseData = SenseData;
557 CommandPacket.InTransferLength = *DataLength;
558 CommandPacket.Cdb = Cdb;
559 //
560 // Fill Cdb for Mode Sense (10) Command
561 //
562 Cdb[0] = EFI_SCSI_OP_MODE_SEN10;
563 //
564 // DBDField is in Cdb[1] bit3 of (bit7..0)
565 //
566 Cdb[1] = (UINT8)((DBDField << 3) & 0x08);
567 //
568 // PageControl is in Cdb[2] bit7..6, PageCode is in Cdb[2] bit5..0
569 //
570 Cdb[2] = (UINT8)(((PageControl << 6) & 0xc0) | (PageCode & 0x3f));
571 Cdb[7] = (UINT8)(*DataLength >> 8);
572 Cdb[8] = (UINT8)(*DataLength);
573
574 CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TEN;
575 CommandPacket.DataDirection = EFI_SCSI_DATA_IN;
576 CommandPacket.SenseDataLength = *SenseDataLength;
577
578 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
579
580 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
581 *TargetStatus = CommandPacket.TargetStatus;
582 *SenseDataLength = CommandPacket.SenseDataLength;
583 *DataLength = CommandPacket.InTransferLength;
584
585 return Status;
586}
587
621EFIAPI
623 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
624 IN UINT64 Timeout,
625 IN OUT VOID *SenseData OPTIONAL,
626 IN OUT UINT8 *SenseDataLength,
627 OUT UINT8 *HostAdapterStatus,
628 OUT UINT8 *TargetStatus
629 )
630{
632 EFI_STATUS Status;
633 UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX];
634
635 ASSERT (SenseDataLength != NULL);
636 ASSERT (HostAdapterStatus != NULL);
637 ASSERT (TargetStatus != NULL);
638 ASSERT (ScsiIo != NULL);
639
640 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
641 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);
642
643 CommandPacket.Timeout = Timeout;
644 CommandPacket.InDataBuffer = SenseData;
645 CommandPacket.SenseData = NULL;
646 CommandPacket.InTransferLength = *SenseDataLength;
647 CommandPacket.Cdb = Cdb;
648 //
649 // Fill Cdb for Request Sense Command
650 //
651 Cdb[0] = EFI_SCSI_OP_REQUEST_SENSE;
652 Cdb[4] = (UINT8)(*SenseDataLength);
653
654 CommandPacket.CdbLength = (UINT8)EFI_SCSI_OP_LENGTH_SIX;
655 CommandPacket.DataDirection = EFI_SCSI_DATA_IN;
656 CommandPacket.SenseDataLength = 0;
657
658 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
659
660 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
661 *TargetStatus = CommandPacket.TargetStatus;
662 *SenseDataLength = (UINT8)CommandPacket.InTransferLength;
663
664 return Status;
665}
666
712EFIAPI
714 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
715 IN UINT64 Timeout,
716 IN OUT VOID *SenseData OPTIONAL,
717 IN OUT UINT8 *SenseDataLength,
718 OUT UINT8 *HostAdapterStatus,
719 OUT UINT8 *TargetStatus,
720 IN OUT VOID *DataBuffer OPTIONAL,
721 IN OUT UINT32 *DataLength,
722 IN BOOLEAN Pmi
723 )
724{
726 EFI_STATUS Status;
727 UINT8 Cdb[EFI_SCSI_OP_LENGTH_TEN];
728
729 ASSERT (SenseDataLength != NULL);
730 ASSERT (HostAdapterStatus != NULL);
731 ASSERT (TargetStatus != NULL);
732 ASSERT (DataLength != NULL);
733 ASSERT (ScsiIo != NULL);
734
735 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
736 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);
737
738 CommandPacket.Timeout = Timeout;
739 CommandPacket.InDataBuffer = DataBuffer;
740 CommandPacket.SenseData = SenseData;
741 CommandPacket.InTransferLength = *DataLength;
742 CommandPacket.Cdb = Cdb;
743 //
744 // Fill Cdb for Read Capacity Command
745 //
746 Cdb[0] = EFI_SCSI_OP_READ_CAPACITY;
747 if (!Pmi) {
748 //
749 // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO.
750 //
751 ZeroMem ((Cdb + 2), 4);
752 } else {
753 Cdb[8] |= 0x01;
754 }
755
756 CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TEN;
757 CommandPacket.DataDirection = EFI_SCSI_DATA_IN;
758 CommandPacket.SenseDataLength = *SenseDataLength;
759
760 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
761
762 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
763 *TargetStatus = CommandPacket.TargetStatus;
764 *SenseDataLength = CommandPacket.SenseDataLength;
765 *DataLength = CommandPacket.InTransferLength;
766
767 return Status;
768}
769
815EFIAPI
817 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
818 IN UINT64 Timeout,
819 IN OUT VOID *SenseData OPTIONAL,
820 IN OUT UINT8 *SenseDataLength,
821 OUT UINT8 *HostAdapterStatus,
822 OUT UINT8 *TargetStatus,
823 IN OUT VOID *DataBuffer OPTIONAL,
824 IN OUT UINT32 *DataLength,
825 IN BOOLEAN Pmi
826 )
827{
829 EFI_STATUS Status;
830 UINT8 Cdb[16];
831
832 ASSERT (SenseDataLength != NULL);
833 ASSERT (HostAdapterStatus != NULL);
834 ASSERT (TargetStatus != NULL);
835 ASSERT (DataLength != NULL);
836 ASSERT (ScsiIo != NULL);
837
838 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
839 ZeroMem (Cdb, 16);
840
841 CommandPacket.Timeout = Timeout;
842 CommandPacket.InDataBuffer = DataBuffer;
843 CommandPacket.SenseData = SenseData;
844 CommandPacket.InTransferLength = *DataLength;
845 CommandPacket.Cdb = Cdb;
846 //
847 // Fill Cdb for Read Capacity Command
848 //
849 Cdb[0] = EFI_SCSI_OP_READ_CAPACITY16;
850 Cdb[1] = 0x10;
851 if (!Pmi) {
852 //
853 // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.9 MUST BE ZERO.
854 //
855 ZeroMem ((Cdb + 2), 8);
856 } else {
857 Cdb[14] |= 0x01;
858 }
859
860 Cdb[13] = 0x20;
861 CommandPacket.CdbLength = 16;
862 CommandPacket.DataDirection = EFI_SCSI_DATA_IN;
863 CommandPacket.SenseDataLength = *SenseDataLength;
864
865 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
866
867 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
868 *TargetStatus = CommandPacket.TargetStatus;
869 *SenseDataLength = CommandPacket.SenseDataLength;
870 *DataLength = CommandPacket.InTransferLength;
871
872 return Status;
873}
874
921EFIAPI
923 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
924 IN UINT64 Timeout,
925 IN OUT VOID *SenseData OPTIONAL,
926 IN OUT UINT8 *SenseDataLength,
927 OUT UINT8 *HostAdapterStatus,
928 OUT UINT8 *TargetStatus,
929 IN OUT VOID *DataBuffer OPTIONAL,
930 IN OUT UINT32 *DataLength,
931 IN UINT32 StartLba,
932 IN UINT32 SectorSize
933 )
934{
936 EFI_STATUS Status;
937 UINT8 Cdb[EFI_SCSI_OP_LENGTH_TEN];
938
939 ASSERT (SenseDataLength != NULL);
940 ASSERT (HostAdapterStatus != NULL);
941 ASSERT (TargetStatus != NULL);
942 ASSERT (DataLength != NULL);
943 ASSERT (ScsiIo != NULL);
944
945 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
946 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);
947
948 CommandPacket.Timeout = Timeout;
949 CommandPacket.InDataBuffer = DataBuffer;
950 CommandPacket.SenseData = SenseData;
951 CommandPacket.InTransferLength = *DataLength;
952 CommandPacket.Cdb = Cdb;
953 //
954 // Fill Cdb for Read (10) Command
955 //
956 Cdb[0] = EFI_SCSI_OP_READ10;
957 WriteUnaligned32 ((UINT32 *)&Cdb[2], SwapBytes32 (StartLba));
958 WriteUnaligned16 ((UINT16 *)&Cdb[7], SwapBytes16 ((UINT16)SectorSize));
959
960 CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TEN;
961 CommandPacket.DataDirection = EFI_SCSI_DATA_IN;
962 CommandPacket.SenseDataLength = *SenseDataLength;
963
964 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
965
966 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
967 *TargetStatus = CommandPacket.TargetStatus;
968 *SenseDataLength = CommandPacket.SenseDataLength;
969 *DataLength = CommandPacket.InTransferLength;
970
971 return Status;
972}
973
1020EFIAPI
1022 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
1023 IN UINT64 Timeout,
1024 IN OUT VOID *SenseData OPTIONAL,
1025 IN OUT UINT8 *SenseDataLength,
1026 OUT UINT8 *HostAdapterStatus,
1027 OUT UINT8 *TargetStatus,
1028 IN OUT VOID *DataBuffer OPTIONAL,
1029 IN OUT UINT32 *DataLength,
1030 IN UINT32 StartLba,
1031 IN UINT32 SectorSize
1032 )
1033{
1034 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
1035 EFI_STATUS Status;
1036 UINT8 Cdb[EFI_SCSI_OP_LENGTH_TEN];
1037
1038 ASSERT (SenseDataLength != NULL);
1039 ASSERT (HostAdapterStatus != NULL);
1040 ASSERT (TargetStatus != NULL);
1041 ASSERT (DataLength != NULL);
1042 ASSERT (ScsiIo != NULL);
1043
1044 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
1045 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);
1046
1047 CommandPacket.Timeout = Timeout;
1048 CommandPacket.OutDataBuffer = DataBuffer;
1049 CommandPacket.SenseData = SenseData;
1050 CommandPacket.OutTransferLength = *DataLength;
1051 CommandPacket.Cdb = Cdb;
1052 //
1053 // Fill Cdb for Write (10) Command
1054 //
1055 Cdb[0] = EFI_SCSI_OP_WRITE10;
1056 Cdb[1] = EFI_SCSI_BLOCK_FUA;
1057 WriteUnaligned32 ((UINT32 *)&Cdb[2], SwapBytes32 (StartLba));
1058 WriteUnaligned16 ((UINT16 *)&Cdb[7], SwapBytes16 ((UINT16)SectorSize));
1059
1060 CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TEN;
1061 CommandPacket.DataDirection = EFI_SCSI_DATA_OUT;
1062 CommandPacket.SenseDataLength = *SenseDataLength;
1063
1064 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
1065
1066 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
1067 *TargetStatus = CommandPacket.TargetStatus;
1068 *SenseDataLength = CommandPacket.SenseDataLength;
1069 *DataLength = CommandPacket.OutTransferLength;
1070
1071 return Status;
1072}
1073
1120EFIAPI
1122 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
1123 IN UINT64 Timeout,
1124 IN OUT VOID *SenseData OPTIONAL,
1125 IN OUT UINT8 *SenseDataLength,
1126 OUT UINT8 *HostAdapterStatus,
1127 OUT UINT8 *TargetStatus,
1128 IN OUT VOID *DataBuffer OPTIONAL,
1129 IN OUT UINT32 *DataLength,
1130 IN UINT64 StartLba,
1131 IN UINT32 SectorSize
1132 )
1133{
1134 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
1135 EFI_STATUS Status;
1136 UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIXTEEN];
1137
1138 ASSERT (SenseDataLength != NULL);
1139 ASSERT (HostAdapterStatus != NULL);
1140 ASSERT (TargetStatus != NULL);
1141 ASSERT (DataLength != NULL);
1142 ASSERT (ScsiIo != NULL);
1143
1144 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
1145 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIXTEEN);
1146
1147 CommandPacket.Timeout = Timeout;
1148 CommandPacket.InDataBuffer = DataBuffer;
1149 CommandPacket.SenseData = SenseData;
1150 CommandPacket.InTransferLength = *DataLength;
1151 CommandPacket.Cdb = Cdb;
1152 //
1153 // Fill Cdb for Read (16) Command
1154 //
1155 Cdb[0] = EFI_SCSI_OP_READ16;
1156 WriteUnaligned64 ((UINT64 *)&Cdb[2], SwapBytes64 (StartLba));
1157 WriteUnaligned32 ((UINT32 *)&Cdb[10], SwapBytes32 (SectorSize));
1158
1159 CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_SIXTEEN;
1160 CommandPacket.DataDirection = EFI_SCSI_DATA_IN;
1161 CommandPacket.SenseDataLength = *SenseDataLength;
1162
1163 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
1164
1165 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
1166 *TargetStatus = CommandPacket.TargetStatus;
1167 *SenseDataLength = CommandPacket.SenseDataLength;
1168 *DataLength = CommandPacket.InTransferLength;
1169
1170 return Status;
1171}
1172
1219EFIAPI
1221 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
1222 IN UINT64 Timeout,
1223 IN OUT VOID *SenseData OPTIONAL,
1224 IN OUT UINT8 *SenseDataLength,
1225 OUT UINT8 *HostAdapterStatus,
1226 OUT UINT8 *TargetStatus,
1227 IN OUT VOID *DataBuffer OPTIONAL,
1228 IN OUT UINT32 *DataLength,
1229 IN UINT64 StartLba,
1230 IN UINT32 SectorSize
1231 )
1232{
1233 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
1234 EFI_STATUS Status;
1235 UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIXTEEN];
1236
1237 ASSERT (SenseDataLength != NULL);
1238 ASSERT (HostAdapterStatus != NULL);
1239 ASSERT (TargetStatus != NULL);
1240 ASSERT (DataLength != NULL);
1241 ASSERT (ScsiIo != NULL);
1242
1243 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
1244 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIXTEEN);
1245
1246 CommandPacket.Timeout = Timeout;
1247 CommandPacket.OutDataBuffer = DataBuffer;
1248 CommandPacket.SenseData = SenseData;
1249 CommandPacket.OutTransferLength = *DataLength;
1250 CommandPacket.Cdb = Cdb;
1251 //
1252 // Fill Cdb for Write (16) Command
1253 //
1254 Cdb[0] = EFI_SCSI_OP_WRITE16;
1255 Cdb[1] = EFI_SCSI_BLOCK_FUA;
1256 WriteUnaligned64 ((UINT64 *)&Cdb[2], SwapBytes64 (StartLba));
1257 WriteUnaligned32 ((UINT32 *)&Cdb[10], SwapBytes32 (SectorSize));
1258
1259 CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_SIXTEEN;
1260 CommandPacket.DataDirection = EFI_SCSI_DATA_OUT;
1261 CommandPacket.SenseDataLength = *SenseDataLength;
1262
1263 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
1264
1265 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
1266 *TargetStatus = CommandPacket.TargetStatus;
1267 *SenseDataLength = CommandPacket.SenseDataLength;
1268 *DataLength = CommandPacket.OutTransferLength;
1269
1270 return Status;
1271}
1272
1322EFIAPI
1324 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
1325 IN UINT64 Timeout,
1326 IN OUT VOID *SenseData OPTIONAL,
1327 IN OUT UINT8 *SenseDataLength,
1328 OUT UINT8 *HostAdapterStatus,
1329 OUT UINT8 *TargetStatus,
1330 IN UINT8 SecurityProtocol,
1331 IN UINT16 SecurityProtocolSpecific,
1332 IN BOOLEAN Inc512,
1333 IN UINTN DataLength,
1334 IN OUT VOID *DataBuffer OPTIONAL,
1335 OUT UINTN *TransferLength
1336 )
1337{
1338 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
1339 EFI_STATUS Status;
1340 UINT8 Cdb[EFI_SCSI_OP_LENGTH_TWELVE];
1341
1342 ASSERT (SenseDataLength != NULL);
1343 ASSERT (HostAdapterStatus != NULL);
1344 ASSERT (TargetStatus != NULL);
1345 ASSERT (ScsiIo != NULL);
1346 ASSERT (TransferLength != NULL);
1347 ASSERT (DataLength <= MAX_UINT32);
1348
1349 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
1350 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TWELVE);
1351
1352 CommandPacket.Timeout = Timeout;
1353 CommandPacket.InDataBuffer = DataBuffer;
1354 CommandPacket.SenseData = SenseData;
1355 CommandPacket.InTransferLength = (UINT32)DataLength;
1356 CommandPacket.Cdb = Cdb;
1357 //
1358 // Fill Cdb for Security Protocol In Command
1359 //
1360 Cdb[0] = EFI_SCSI_OP_SECURITY_PROTOCOL_IN;
1361 Cdb[1] = SecurityProtocol;
1362 WriteUnaligned16 ((UINT16 *)&Cdb[2], SwapBytes16 (SecurityProtocolSpecific));
1363
1364 if (Inc512) {
1365 if (DataLength % 512 != 0) {
1366 return EFI_INVALID_PARAMETER;
1367 }
1368
1369 Cdb[4] = BIT7;
1370 WriteUnaligned32 ((UINT32 *)&Cdb[6], SwapBytes32 ((UINT32)DataLength / 512));
1371 } else {
1372 WriteUnaligned32 ((UINT32 *)&Cdb[6], SwapBytes32 ((UINT32)DataLength));
1373 }
1374
1375 CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TWELVE;
1376 CommandPacket.DataDirection = EFI_SCSI_DATA_IN;
1377 CommandPacket.SenseDataLength = *SenseDataLength;
1378
1379 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
1380
1381 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
1382 *TargetStatus = CommandPacket.TargetStatus;
1383 *SenseDataLength = CommandPacket.SenseDataLength;
1384 *TransferLength = (UINTN)CommandPacket.InTransferLength;
1385
1386 return Status;
1387}
1388
1435EFIAPI
1437 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
1438 IN UINT64 Timeout,
1439 IN OUT VOID *SenseData OPTIONAL,
1440 IN OUT UINT8 *SenseDataLength,
1441 OUT UINT8 *HostAdapterStatus,
1442 OUT UINT8 *TargetStatus,
1443 IN UINT8 SecurityProtocol,
1444 IN UINT16 SecurityProtocolSpecific,
1445 IN BOOLEAN Inc512,
1446 IN UINTN DataLength,
1447 IN OUT VOID *DataBuffer OPTIONAL
1448 )
1449{
1450 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
1451 EFI_STATUS Status;
1452 UINT8 Cdb[EFI_SCSI_OP_LENGTH_TWELVE];
1453
1454 ASSERT (SenseDataLength != NULL);
1455 ASSERT (HostAdapterStatus != NULL);
1456 ASSERT (TargetStatus != NULL);
1457 ASSERT (ScsiIo != NULL);
1458 ASSERT (DataLength <= MAX_UINT32);
1459
1460 ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
1461 ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TWELVE);
1462
1463 CommandPacket.Timeout = Timeout;
1464 CommandPacket.OutDataBuffer = DataBuffer;
1465 CommandPacket.SenseData = SenseData;
1466 CommandPacket.OutTransferLength = (UINT32)DataLength;
1467 CommandPacket.Cdb = Cdb;
1468 //
1469 // Fill Cdb for Security Protocol Out Command
1470 //
1471 Cdb[0] = EFI_SCSI_OP_SECURITY_PROTOCOL_OUT;
1472 Cdb[1] = SecurityProtocol;
1473 WriteUnaligned16 ((UINT16 *)&Cdb[2], SwapBytes16 (SecurityProtocolSpecific));
1474
1475 if (Inc512) {
1476 if (DataLength % 512 != 0) {
1477 return EFI_INVALID_PARAMETER;
1478 }
1479
1480 Cdb[4] = BIT7;
1481 WriteUnaligned32 ((UINT32 *)&Cdb[6], SwapBytes32 ((UINT32)DataLength / 512));
1482 } else {
1483 WriteUnaligned32 ((UINT32 *)&Cdb[6], SwapBytes32 ((UINT32)DataLength));
1484 }
1485
1486 CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TWELVE;
1487 CommandPacket.DataDirection = EFI_SCSI_DATA_OUT;
1488 CommandPacket.SenseDataLength = *SenseDataLength;
1489
1490 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
1491
1492 *HostAdapterStatus = CommandPacket.HostAdapterStatus;
1493 *TargetStatus = CommandPacket.TargetStatus;
1494 *SenseDataLength = CommandPacket.SenseDataLength;
1495
1496 return Status;
1497}
1498
1507VOID
1508EFIAPI
1510 IN EFI_EVENT Event,
1511 IN VOID *Context
1512 )
1513{
1514 EFI_SCSI_LIB_ASYNC_CONTEXT *LibContext;
1515 EFI_SCSI_IO_SCSI_REQUEST_PACKET *CommandPacket;
1516 EFI_EVENT CallerEvent;
1517
1518 LibContext = (EFI_SCSI_LIB_ASYNC_CONTEXT *)Context;
1519 CommandPacket = &LibContext->CommandPacket;
1520 CallerEvent = LibContext->CallerEvent;
1521
1522 //
1523 // Update SCSI Read/Write operation results
1524 //
1525 *LibContext->SenseDataLength = CommandPacket->SenseDataLength;
1526 *LibContext->HostAdapterStatus = CommandPacket->HostAdapterStatus;
1527 *LibContext->TargetStatus = CommandPacket->TargetStatus;
1528 if (CommandPacket->InDataBuffer != NULL) {
1529 *LibContext->DataLength = CommandPacket->InTransferLength;
1530 } else {
1531 *LibContext->DataLength = CommandPacket->OutTransferLength;
1532 }
1533
1534 if (CommandPacket->Cdb != NULL) {
1535 FreePool (CommandPacket->Cdb);
1536 }
1537
1538 FreePool (Context);
1539
1540 gBS->CloseEvent (Event);
1541 gBS->SignalEvent (CallerEvent);
1542}
1543
1618EFIAPI
1620 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
1621 IN UINT64 Timeout,
1622 IN OUT VOID *SenseData OPTIONAL,
1623 IN OUT UINT8 *SenseDataLength,
1624 OUT UINT8 *HostAdapterStatus,
1625 OUT UINT8 *TargetStatus,
1626 IN OUT VOID *DataBuffer OPTIONAL,
1627 IN OUT UINT32 *DataLength,
1628 IN UINT32 StartLba,
1629 IN UINT32 SectorSize,
1630 IN EFI_EVENT Event OPTIONAL
1631 )
1632{
1634 EFI_SCSI_IO_SCSI_REQUEST_PACKET *CommandPacket;
1635 EFI_STATUS Status;
1636 UINT8 *Cdb;
1637 EFI_EVENT SelfEvent;
1638
1639 if (Event == NULL) {
1640 return ScsiRead10Command (
1641 ScsiIo,
1642 Timeout,
1643 SenseData,
1644 SenseDataLength,
1645 HostAdapterStatus,
1646 TargetStatus,
1647 DataBuffer,
1648 DataLength,
1649 StartLba,
1650 SectorSize
1651 );
1652 }
1653
1654 ASSERT (SenseDataLength != NULL);
1655 ASSERT (HostAdapterStatus != NULL);
1656 ASSERT (TargetStatus != NULL);
1657 ASSERT (DataLength != NULL);
1658 ASSERT (ScsiIo != NULL);
1659
1660 Context = AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT));
1661 if (Context == NULL) {
1662 return EFI_OUT_OF_RESOURCES;
1663 }
1664
1665 Cdb = AllocateZeroPool (EFI_SCSI_OP_LENGTH_TEN);
1666 if (Cdb == NULL) {
1667 Status = EFI_OUT_OF_RESOURCES;
1668 goto ErrorExit;
1669 }
1670
1671 Context->SenseDataLength = SenseDataLength;
1672 Context->HostAdapterStatus = HostAdapterStatus;
1673 Context->TargetStatus = TargetStatus;
1674 Context->CallerEvent = Event;
1675
1676 CommandPacket = &Context->CommandPacket;
1677 CommandPacket->Timeout = Timeout;
1678 CommandPacket->InDataBuffer = DataBuffer;
1679 CommandPacket->SenseData = SenseData;
1680 CommandPacket->InTransferLength = *DataLength;
1681 CommandPacket->Cdb = Cdb;
1682 //
1683 // Fill Cdb for Read (10) Command
1684 //
1685 Cdb[0] = EFI_SCSI_OP_READ10;
1686 WriteUnaligned32 ((UINT32 *)&Cdb[2], SwapBytes32 (StartLba));
1687 WriteUnaligned16 ((UINT16 *)&Cdb[7], SwapBytes16 ((UINT16)SectorSize));
1688
1689 CommandPacket->CdbLength = EFI_SCSI_OP_LENGTH_TEN;
1690 CommandPacket->DataDirection = EFI_SCSI_DATA_IN;
1691 CommandPacket->SenseDataLength = *SenseDataLength;
1692
1693 //
1694 // Create Event
1695 //
1696 Status = gBS->CreateEvent (
1697 EVT_NOTIFY_SIGNAL,
1698 TPL_NOTIFY,
1700 Context,
1701 &SelfEvent
1702 );
1703 if (EFI_ERROR (Status)) {
1704 goto ErrorExit;
1705 }
1706
1707 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, CommandPacket, SelfEvent);
1708 if (EFI_ERROR (Status)) {
1709 //
1710 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
1711 // returns with error, close the event here.
1712 //
1713 gBS->CloseEvent (SelfEvent);
1714 goto ErrorExit;
1715 } else {
1716 return EFI_SUCCESS;
1717 }
1718
1719ErrorExit:
1720 if (Context != NULL) {
1721 FreePool (Context);
1722 }
1723
1724 return Status;
1725}
1726
1801EFIAPI
1803 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
1804 IN UINT64 Timeout,
1805 IN OUT VOID *SenseData OPTIONAL,
1806 IN OUT UINT8 *SenseDataLength,
1807 OUT UINT8 *HostAdapterStatus,
1808 OUT UINT8 *TargetStatus,
1809 IN OUT VOID *DataBuffer OPTIONAL,
1810 IN OUT UINT32 *DataLength,
1811 IN UINT32 StartLba,
1812 IN UINT32 SectorSize,
1813 IN EFI_EVENT Event OPTIONAL
1814 )
1815{
1817 EFI_SCSI_IO_SCSI_REQUEST_PACKET *CommandPacket;
1818 EFI_STATUS Status;
1819 UINT8 *Cdb;
1820 EFI_EVENT SelfEvent;
1821
1822 if (Event == NULL) {
1823 return ScsiWrite10Command (
1824 ScsiIo,
1825 Timeout,
1826 SenseData,
1827 SenseDataLength,
1828 HostAdapterStatus,
1829 TargetStatus,
1830 DataBuffer,
1831 DataLength,
1832 StartLba,
1833 SectorSize
1834 );
1835 }
1836
1837 ASSERT (SenseDataLength != NULL);
1838 ASSERT (HostAdapterStatus != NULL);
1839 ASSERT (TargetStatus != NULL);
1840 ASSERT (DataLength != NULL);
1841 ASSERT (ScsiIo != NULL);
1842
1843 Context = AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT));
1844 if (Context == NULL) {
1845 return EFI_OUT_OF_RESOURCES;
1846 }
1847
1848 Cdb = AllocateZeroPool (EFI_SCSI_OP_LENGTH_TEN);
1849 if (Cdb == NULL) {
1850 Status = EFI_OUT_OF_RESOURCES;
1851 goto ErrorExit;
1852 }
1853
1854 Context->SenseDataLength = SenseDataLength;
1855 Context->HostAdapterStatus = HostAdapterStatus;
1856 Context->TargetStatus = TargetStatus;
1857 Context->CallerEvent = Event;
1858
1859 CommandPacket = &Context->CommandPacket;
1860 CommandPacket->Timeout = Timeout;
1861 CommandPacket->OutDataBuffer = DataBuffer;
1862 CommandPacket->SenseData = SenseData;
1863 CommandPacket->OutTransferLength = *DataLength;
1864 CommandPacket->Cdb = Cdb;
1865 //
1866 // Fill Cdb for Write (10) Command
1867 //
1868 Cdb[0] = EFI_SCSI_OP_WRITE10;
1869 WriteUnaligned32 ((UINT32 *)&Cdb[2], SwapBytes32 (StartLba));
1870 WriteUnaligned16 ((UINT16 *)&Cdb[7], SwapBytes16 ((UINT16)SectorSize));
1871
1872 CommandPacket->CdbLength = EFI_SCSI_OP_LENGTH_TEN;
1873 CommandPacket->DataDirection = EFI_SCSI_DATA_OUT;
1874 CommandPacket->SenseDataLength = *SenseDataLength;
1875
1876 //
1877 // Create Event
1878 //
1879 Status = gBS->CreateEvent (
1880 EVT_NOTIFY_SIGNAL,
1881 TPL_NOTIFY,
1883 Context,
1884 &SelfEvent
1885 );
1886 if (EFI_ERROR (Status)) {
1887 goto ErrorExit;
1888 }
1889
1890 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, CommandPacket, SelfEvent);
1891 if (EFI_ERROR (Status)) {
1892 //
1893 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
1894 // returns with error, close the event here.
1895 //
1896 gBS->CloseEvent (SelfEvent);
1897 goto ErrorExit;
1898 } else {
1899 return EFI_SUCCESS;
1900 }
1901
1902ErrorExit:
1903 if (Context != NULL) {
1904 FreePool (Context);
1905 }
1906
1907 return Status;
1908}
1909
1984EFIAPI
1986 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
1987 IN UINT64 Timeout,
1988 IN OUT VOID *SenseData OPTIONAL,
1989 IN OUT UINT8 *SenseDataLength,
1990 OUT UINT8 *HostAdapterStatus,
1991 OUT UINT8 *TargetStatus,
1992 IN OUT VOID *DataBuffer OPTIONAL,
1993 IN OUT UINT32 *DataLength,
1994 IN UINT64 StartLba,
1995 IN UINT32 SectorSize,
1996 IN EFI_EVENT Event OPTIONAL
1997 )
1998{
2000 EFI_SCSI_IO_SCSI_REQUEST_PACKET *CommandPacket;
2001 EFI_STATUS Status;
2002 UINT8 *Cdb;
2003 EFI_EVENT SelfEvent;
2004
2005 if (Event == NULL) {
2006 return ScsiRead16Command (
2007 ScsiIo,
2008 Timeout,
2009 SenseData,
2010 SenseDataLength,
2011 HostAdapterStatus,
2012 TargetStatus,
2013 DataBuffer,
2014 DataLength,
2015 StartLba,
2016 SectorSize
2017 );
2018 }
2019
2020 ASSERT (SenseDataLength != NULL);
2021 ASSERT (HostAdapterStatus != NULL);
2022 ASSERT (TargetStatus != NULL);
2023 ASSERT (DataLength != NULL);
2024 ASSERT (ScsiIo != NULL);
2025
2026 Context = AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT));
2027 if (Context == NULL) {
2028 return EFI_OUT_OF_RESOURCES;
2029 }
2030
2031 Cdb = AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN);
2032 if (Cdb == NULL) {
2033 Status = EFI_OUT_OF_RESOURCES;
2034 goto ErrorExit;
2035 }
2036
2037 Context->SenseDataLength = SenseDataLength;
2038 Context->HostAdapterStatus = HostAdapterStatus;
2039 Context->TargetStatus = TargetStatus;
2040 Context->CallerEvent = Event;
2041
2042 CommandPacket = &Context->CommandPacket;
2043 CommandPacket->Timeout = Timeout;
2044 CommandPacket->InDataBuffer = DataBuffer;
2045 CommandPacket->SenseData = SenseData;
2046 CommandPacket->InTransferLength = *DataLength;
2047 CommandPacket->Cdb = Cdb;
2048 //
2049 // Fill Cdb for Read (16) Command
2050 //
2051 Cdb[0] = EFI_SCSI_OP_READ16;
2052 WriteUnaligned64 ((UINT64 *)&Cdb[2], SwapBytes64 (StartLba));
2053 WriteUnaligned32 ((UINT32 *)&Cdb[10], SwapBytes32 (SectorSize));
2054
2055 CommandPacket->CdbLength = EFI_SCSI_OP_LENGTH_SIXTEEN;
2056 CommandPacket->DataDirection = EFI_SCSI_DATA_IN;
2057 CommandPacket->SenseDataLength = *SenseDataLength;
2058
2059 //
2060 // Create Event
2061 //
2062 Status = gBS->CreateEvent (
2063 EVT_NOTIFY_SIGNAL,
2064 TPL_NOTIFY,
2066 Context,
2067 &SelfEvent
2068 );
2069 if (EFI_ERROR (Status)) {
2070 goto ErrorExit;
2071 }
2072
2073 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, CommandPacket, SelfEvent);
2074 if (EFI_ERROR (Status)) {
2075 //
2076 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
2077 // returns with error, close the event here.
2078 //
2079 gBS->CloseEvent (SelfEvent);
2080 goto ErrorExit;
2081 } else {
2082 return EFI_SUCCESS;
2083 }
2084
2085ErrorExit:
2086 if (Context != NULL) {
2087 FreePool (Context);
2088 }
2089
2090 return Status;
2091}
2092
2167EFIAPI
2169 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
2170 IN UINT64 Timeout,
2171 IN OUT VOID *SenseData OPTIONAL,
2172 IN OUT UINT8 *SenseDataLength,
2173 OUT UINT8 *HostAdapterStatus,
2174 OUT UINT8 *TargetStatus,
2175 IN OUT VOID *DataBuffer OPTIONAL,
2176 IN OUT UINT32 *DataLength,
2177 IN UINT64 StartLba,
2178 IN UINT32 SectorSize,
2179 IN EFI_EVENT Event OPTIONAL
2180 )
2181{
2183 EFI_SCSI_IO_SCSI_REQUEST_PACKET *CommandPacket;
2184 EFI_STATUS Status;
2185 UINT8 *Cdb;
2186 EFI_EVENT SelfEvent;
2187
2188 if (Event == NULL) {
2189 return ScsiWrite16Command (
2190 ScsiIo,
2191 Timeout,
2192 SenseData,
2193 SenseDataLength,
2194 HostAdapterStatus,
2195 TargetStatus,
2196 DataBuffer,
2197 DataLength,
2198 StartLba,
2199 SectorSize
2200 );
2201 }
2202
2203 ASSERT (SenseDataLength != NULL);
2204 ASSERT (HostAdapterStatus != NULL);
2205 ASSERT (TargetStatus != NULL);
2206 ASSERT (DataLength != NULL);
2207 ASSERT (ScsiIo != NULL);
2208
2209 Context = AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT));
2210 if (Context == NULL) {
2211 return EFI_OUT_OF_RESOURCES;
2212 }
2213
2214 Cdb = AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN);
2215 if (Cdb == NULL) {
2216 Status = EFI_OUT_OF_RESOURCES;
2217 goto ErrorExit;
2218 }
2219
2220 Context->SenseDataLength = SenseDataLength;
2221 Context->HostAdapterStatus = HostAdapterStatus;
2222 Context->TargetStatus = TargetStatus;
2223 Context->CallerEvent = Event;
2224
2225 CommandPacket = &Context->CommandPacket;
2226 CommandPacket->Timeout = Timeout;
2227 CommandPacket->OutDataBuffer = DataBuffer;
2228 CommandPacket->SenseData = SenseData;
2229 CommandPacket->OutTransferLength = *DataLength;
2230 CommandPacket->Cdb = Cdb;
2231 //
2232 // Fill Cdb for Write (16) Command
2233 //
2234 Cdb[0] = EFI_SCSI_OP_WRITE16;
2235 WriteUnaligned64 ((UINT64 *)&Cdb[2], SwapBytes64 (StartLba));
2236 WriteUnaligned32 ((UINT32 *)&Cdb[10], SwapBytes32 (SectorSize));
2237
2238 CommandPacket->CdbLength = EFI_SCSI_OP_LENGTH_SIXTEEN;
2239 CommandPacket->DataDirection = EFI_SCSI_DATA_OUT;
2240 CommandPacket->SenseDataLength = *SenseDataLength;
2241
2242 //
2243 // Create Event
2244 //
2245 Status = gBS->CreateEvent (
2246 EVT_NOTIFY_SIGNAL,
2247 TPL_NOTIFY,
2249 Context,
2250 &SelfEvent
2251 );
2252 if (EFI_ERROR (Status)) {
2253 goto ErrorExit;
2254 }
2255
2256 Status = ScsiIo->ExecuteScsiCommand (ScsiIo, CommandPacket, SelfEvent);
2257 if (EFI_ERROR (Status)) {
2258 //
2259 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
2260 // returns with error, close the event here.
2261 //
2262 gBS->CloseEvent (SelfEvent);
2263 goto ErrorExit;
2264 } else {
2265 return EFI_SUCCESS;
2266 }
2267
2268ErrorExit:
2269 if (Context != NULL) {
2270 FreePool (Context);
2271 }
2272
2273 return Status;
2274}
UINT64 UINTN
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
Definition: SwapBytes16.c:25
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
Definition: Unaligned.c:177
UINT16 EFIAPI WriteUnaligned16(OUT UINT16 *Buffer, IN UINT16 Value)
Definition: Unaligned.c:61
UINT64 EFIAPI SwapBytes64(IN UINT64 Value)
Definition: SwapBytes64.c:25
UINT64 EFIAPI WriteUnaligned64(OUT UINT64 *Buffer, IN UINT64 Value)
Definition: Unaligned.c:236
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define EFI_SCSI_BLOCK_FUA
Force Unit Access.
Definition: Scsi.h:181
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI ScsiWrite10CommandEx(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN UINT32 StartLba, IN UINT32 SectorSize, IN EFI_EVENT Event OPTIONAL)
Definition: UefiScsiLib.c:1802
EFI_STATUS EFIAPI ScsiSecurityProtocolInCommand(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN UINT8 SecurityProtocol, IN UINT16 SecurityProtocolSpecific, IN BOOLEAN Inc512, IN UINTN DataLength, IN OUT VOID *DataBuffer OPTIONAL, OUT UINTN *TransferLength)
Definition: UefiScsiLib.c:1323
EFI_STATUS EFIAPI ScsiRead10CommandEx(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN UINT32 StartLba, IN UINT32 SectorSize, IN EFI_EVENT Event OPTIONAL)
Definition: UefiScsiLib.c:1619
EFI_STATUS EFIAPI ScsiRead10Command(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN UINT32 StartLba, IN UINT32 SectorSize)
Definition: UefiScsiLib.c:922
EFI_STATUS EFIAPI ScsiModeSense10Command(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN UINT8 DBDField OPTIONAL, IN UINT8 PageControl, IN UINT8 PageCode)
Definition: UefiScsiLib.c:527
EFI_STATUS EFIAPI ScsiTestUnitReadyCommand(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus)
Definition: UefiScsiLib.c:129
EFI_STATUS EFIAPI ScsiWrite16Command(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN UINT64 StartLba, IN UINT32 SectorSize)
Definition: UefiScsiLib.c:1220
VOID EFIAPI ScsiLibNotify(IN EFI_EVENT Event, IN VOID *Context)
Definition: UefiScsiLib.c:1509
EFI_STATUS EFIAPI ScsiRequestSenseCommand(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus)
Definition: UefiScsiLib.c:622
EFI_STATUS EFIAPI ScsiInquiryCommandEx(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *InquiryDataBuffer OPTIONAL, IN OUT UINT32 *InquiryDataLength, IN BOOLEAN EnableVitalProductData, IN UINT8 PageCode)
Definition: UefiScsiLib.c:264
EFI_STATUS EFIAPI ScsiWrite16CommandEx(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN UINT64 StartLba, IN UINT32 SectorSize, IN EFI_EVENT Event OPTIONAL)
Definition: UefiScsiLib.c:2168
EFI_STATUS EFIAPI ScsiSecurityProtocolOutCommand(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN UINT8 SecurityProtocol, IN UINT16 SecurityProtocolSpecific, IN BOOLEAN Inc512, IN UINTN DataLength, IN OUT VOID *DataBuffer OPTIONAL)
Definition: UefiScsiLib.c:1436
EFI_STATUS EFIAPI ScsiRead16CommandEx(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN UINT64 StartLba, IN UINT32 SectorSize, IN EFI_EVENT Event OPTIONAL)
Definition: UefiScsiLib.c:1985
EFI_STATUS EFIAPI ScsiInquiryCommand(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *InquiryDataBuffer OPTIONAL, IN OUT UINT32 *InquiryDataLength, IN BOOLEAN EnableVitalProductData)
Definition: UefiScsiLib.c:410
EFI_STATUS EFIAPI ScsiReadCapacity16Command(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN BOOLEAN Pmi)
Definition: UefiScsiLib.c:816
EFI_STATUS EFIAPI ScsiRead16Command(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN UINT64 StartLba, IN UINT32 SectorSize)
Definition: UefiScsiLib.c:1121
EFI_STATUS EFIAPI ScsiWrite10Command(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN UINT32 StartLba, IN UINT32 SectorSize)
Definition: UefiScsiLib.c:1021
EFI_STATUS EFIAPI ScsiReadCapacityCommand(IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, IN OUT VOID *SenseData OPTIONAL, IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, IN OUT VOID *DataBuffer OPTIONAL, IN OUT UINT32 *DataLength, IN BOOLEAN Pmi)
Definition: UefiScsiLib.c:713
EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
Definition: UefiScsiLib.c:36