Add back logic to encode LUN in CDB for compatibility with SCSI-2 spec, although...
authorrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 19 May 2009 09:07:38 +0000 (09:07 +0000)
committerrsun3 <rsun3@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 19 May 2009 09:07:38 +0000 (09:07 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8334 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/UefiScsiLib/UefiScsiLib.c

index 434640c..12af133 100644 (file)
@@ -115,6 +115,9 @@ ScsiTestUnitReadyCommand (
   )\r
 {\r
   EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];\r
 \r
@@ -136,7 +139,11 @@ ScsiTestUnitReadyCommand (
   //\r
   // Fill Cdb for Test Unit Ready Command\r
   //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
   Cdb[0]                        = EFI_SCSI_OP_TEST_UNIT_READY;\r
+  Cdb[1]                        = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   CommandPacket.CdbLength       = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r
   CommandPacket.SenseDataLength = *SenseDataLength;\r
 \r
@@ -243,6 +250,9 @@ ScsiInquiryCommand (
   )\r
 {\r
   EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];\r
 \r
@@ -262,7 +272,11 @@ ScsiInquiryCommand (
   CommandPacket.SenseDataLength = *SenseDataLength;\r
   CommandPacket.Cdb             = Cdb;\r
 \r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
   Cdb[0]  = EFI_SCSI_OP_INQUIRY;\r
+  Cdb[1]  = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   if (EnableVitalProductData) {\r
     Cdb[1] |= 0x01;\r
   }\r
@@ -384,6 +398,9 @@ ScsiModeSense10Command (
   )\r
 {\r
   EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];\r
 \r
@@ -404,15 +421,18 @@ ScsiModeSense10Command (
   //\r
   // Fill Cdb for Mode Sense (10) Command\r
   //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
   Cdb[0]                        = EFI_SCSI_OP_MODE_SEN10;\r
   //\r
   // DBDField is in Cdb[1] bit3 of (bit7..0)\r
   //\r
-  Cdb[1]                        = (UINT8) ((DBDField << 3) & 0x08);\r
+  Cdb[1]                        = (UINT8) (((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK) + ((DBDField << 3) & 0x08));\r
   //\r
   // PageControl is in Cdb[2] bit7..6, PageCode is in Cdb[2] bit5..0\r
   //\r
-  Cdb[2]                        = (UINT8) (((PageControl & 0x3) << 6) | (PageCode & 0x3f));\r
+  Cdb[2]                        = (UINT8) (((PageControl << 6) & 0xc0) | (PageCode & 0x3f));\r
   Cdb[7]                        = (UINT8) (*DataLength >> 8);\r
   Cdb[8]                        = (UINT8) (*DataLength);\r
 \r
@@ -470,6 +490,9 @@ ScsiRequestSenseCommand (
   )\r
 {\r
   EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];\r
 \r
@@ -489,7 +512,11 @@ ScsiRequestSenseCommand (
   //\r
   // Fill Cdb for Request Sense Command\r
   //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
   Cdb[0]                        = EFI_SCSI_OP_REQUEST_SENSE;\r
+  Cdb[1]                        = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   Cdb[4]                        = (UINT8) (*SenseDataLength);\r
 \r
   CommandPacket.CdbLength       = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r
@@ -556,6 +583,9 @@ ScsiReadCapacityCommand (
   )\r
 {\r
   EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];\r
 \r
@@ -576,7 +606,11 @@ ScsiReadCapacityCommand (
   //\r
   // Fill Cdb for Read Capacity Command\r
   //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
   Cdb[0]  = EFI_SCSI_OP_READ_CAPACITY;\r
+  Cdb[1]  = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   if (!Pmi) {\r
     //\r
     // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO.\r
@@ -651,6 +685,9 @@ ScsiReadCapacity16Command (
   )\r
 {\r
   EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[16];\r
 \r
@@ -665,6 +702,9 @@ ScsiReadCapacity16Command (
   //\r
   // Fill Cdb for Read Capacity Command\r
   //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
   Cdb[0]  = EFI_SCSI_OP_READ_CAPACITY16;\r
   Cdb[1]  = 0x10;\r
   if (!Pmi) {\r
@@ -745,6 +785,9 @@ ScsiRead10Command (
   )\r
 {\r
   EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];\r
 \r
@@ -765,7 +808,11 @@ ScsiRead10Command (
   //\r
   // Fill Cdb for Read (10) Command\r
   //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
   Cdb[0]                        = EFI_SCSI_OP_READ10;\r
+  Cdb[1]                        = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   Cdb[2]                        = (UINT8) (StartLba >> 24);\r
   Cdb[3]                        = (UINT8) (StartLba >> 16);\r
   Cdb[4]                        = (UINT8) (StartLba >> 8);\r
@@ -840,6 +887,9 @@ ScsiWrite10Command (
   )\r
 {\r
   EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];\r
 \r
@@ -860,7 +910,11 @@ ScsiWrite10Command (
   //\r
   // Fill Cdb for Write (10) Command\r
   //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
   Cdb[0]                        = EFI_SCSI_OP_WRITE10;\r
+  Cdb[1]                        = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   Cdb[2]                        = (UINT8) (StartLba >> 24);\r
   Cdb[3]                        = (UINT8) (StartLba >> 16);\r
   Cdb[4]                        = (UINT8) (StartLba >> 8);\r