On 11/27/14 02:36, Tian, Feng wrote:
> Fine to me. let's wait MdePkg maintainer's feedback.

Thanks, Feng!

Mike -- can you spare a few cycles to look this over please? :)

Thanks!
Laszlo

> 
> -----Original Message-----
> From: Laszlo Ersek [mailto:ler...@redhat.com] 
> Sent: Thursday, November 27, 2014 00:09
> To: edk2-devel@lists.sourceforge.net
> Subject: [edk2] [PATCH v4 2/2] MdePkg: UefiScsiLib: do not encode LUN in CDB 
> for other SCSI commands
> 
> The TEST UNIT READY, INQUIRY, MODE SENSE, REQUEST SENSE and READ CAPACITY 
> commands define bits [7:5] of Cdb[1] as Reserved (potentially as part of a 
> larger Reserved bitfield):
> 
>   Command             Reserved bitfield in Cdb[1]  SCSI spec reference
>   ------------------  ---------------------------  -------------------
>   TEST UNIT READY     all bits                     SPC-4 6.37
>   INQUIRY             bits [7:2]                   SPC-4 6.4.1
>   MODE SENSE (6)      bits [7:4]                   SPC-4 6.11.1
>   MODE SENSE (10)     bits [7:5]                   SPC-4 6.12
>   REQUEST SENSE       bits [7:1]                   SPC-4 6.29
>   READ CAPACITY (10)  bits [7:1]                   SBC-3 5.16
>   READ CAPACITY (16)  bits [7:5]                   SBC-3 5.17
> 
> Update the UefiScsiLib functions accordingly.
> 
> (In ScsiReadCapacity16Command() the LUN has not been encoded, so there we 
> just remove the useless ScsiIo->GetDeviceLocation() call, with its auxiliary 
> local variables.)
> 
> The EFI_SCSI_TARGET_MAX_BYTES and EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK macros 
> become unused with this patch, remove them too.
> 
> Suggested-by: Feng Tian <feng.t...@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Laszlo Ersek <ler...@redhat.com>
> ---
> 
> Notes:
>     v4:
>     - new in v4 [Feng]
> 
>  MdePkg/Library/UefiScsiLib/UefiScsiLib.c | 53 
> +-------------------------------
>  1 file changed, 1 insertion(+), 52 deletions(-)
> 
> diff --git a/MdePkg/Library/UefiScsiLib/UefiScsiLib.c 
> b/MdePkg/Library/UefiScsiLib/UefiScsiLib.c
> index 1dbe874..8a073db 100644
> --- a/MdePkg/Library/UefiScsiLib/UefiScsiLib.c
> +++ b/MdePkg/Library/UefiScsiLib/UefiScsiLib.c
> @@ -15,33 +15,22 @@
>  
>  #include <Uefi.h>
>  #include <Library/BaseLib.h>
>  #include <Library/DebugLib.h>
>  #include <Library/UefiScsiLib.h>
>  #include <Library/BaseMemoryLib.h>
>    
>  #include <IndustryStandard/Scsi.h>
>    
>    
>    //
> -  // Max bytes needed to represent ID of a SCSI device
> -  //
> -#define EFI_SCSI_TARGET_MAX_BYTES (0x10)
> -
> -  //
> -  // bit5..7 are for Logical unit number
> -  // 11100000b (0xe0)
> -  //
> -#define EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK 0xe0
> -
> -  //
>    // Scsi Command Length
>    //
>  #define EFI_SCSI_OP_LENGTH_SIX      0x6
>  #define EFI_SCSI_OP_LENGTH_TEN      0xa
>  #define EFI_SCSI_OP_LENGTH_SIXTEEN  0x10
>  
>  
>  
>  /**
>    Execute Test Unit Ready SCSI command on a specific SCSI target.
>  
> @@ -109,51 +98,44 @@ 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
>    )
>  {
>    EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
> -  UINT64                          Lun;
> -  UINT8                           *Target;
> -  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];
>    EFI_STATUS                      Status;
>    UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];
>  
>    ASSERT (SenseDataLength != NULL);
>    ASSERT (HostAdapterStatus != NULL);
>    ASSERT (TargetStatus != NULL);
>    ASSERT (ScsiIo != NULL);
>  
>    ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
>    ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);
>  
>    CommandPacket.Timeout         = Timeout;
>    CommandPacket.InDataBuffer    = NULL;
>    CommandPacket.InTransferLength= 0;
>    CommandPacket.OutDataBuffer    = NULL;
>    CommandPacket.OutTransferLength= 0;
>    CommandPacket.SenseData       = SenseData;
>    CommandPacket.Cdb             = Cdb;
>    //
>    // Fill Cdb for Test Unit Ready Command
>    //
> -  Target = &TargetArray[0];
> -  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);
> -
>    Cdb[0]                        = EFI_SCSI_OP_TEST_UNIT_READY;
> -  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & 
> EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
>    CommandPacket.CdbLength       = (UINT8) EFI_SCSI_OP_LENGTH_SIX;
>    CommandPacket.SenseDataLength = *SenseDataLength;
>  
>    Status                        = ScsiIo->ExecuteScsiCommand (ScsiIo, 
> &CommandPacket, NULL);
>  
>    *HostAdapterStatus            = CommandPacket.HostAdapterStatus;
>    *TargetStatus                 = CommandPacket.TargetStatus;
>    *SenseDataLength              = CommandPacket.SenseDataLength;
>  
>    return Status;
>  }
> @@ -247,49 +229,42 @@ ScsiInquiryCommandEx (
>    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
>    )
>  {
>    EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
> -  UINT64                          Lun;
> -  UINT8                           *Target;
> -  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];
>    EFI_STATUS                      Status;
>    UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];
>  
>    ASSERT (SenseDataLength != NULL);
>    ASSERT (HostAdapterStatus != NULL);
>    ASSERT (TargetStatus != NULL);
>    ASSERT (InquiryDataLength != NULL);
>    ASSERT (ScsiIo != NULL);
>  
>    ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
>    ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);
>  
>    CommandPacket.Timeout         = Timeout;
>    CommandPacket.InDataBuffer    = InquiryDataBuffer;
>    CommandPacket.InTransferLength= *InquiryDataLength;
>    CommandPacket.SenseData       = SenseData;
>    CommandPacket.SenseDataLength = *SenseDataLength;
>    CommandPacket.Cdb             = Cdb;
>  
> -  Target = &TargetArray[0];
> -  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);
> -
>    Cdb[0]  = EFI_SCSI_OP_INQUIRY;
> -  Cdb[1]  = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
>    if (EnableVitalProductData) {
>      Cdb[1] |= 0x01;
>      Cdb[2]  = PageCode;
>    }
>  
>    if (*InquiryDataLength > 0xff) {
>      *InquiryDataLength = 0xff;
>    }
>  
>    Cdb[4]                      = (UINT8) (*InquiryDataLength);
>    CommandPacket.CdbLength     = (UINT8) EFI_SCSI_OP_LENGTH_SIX;
> @@ -502,53 +477,47 @@ ScsiModeSense10Command (
>    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
>    )
>  {
>    EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
> -  UINT64                          Lun;
> -  UINT8                           *Target;
> -  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];
>    EFI_STATUS                      Status;
>    UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];
>  
>    ASSERT (SenseDataLength != NULL);
>    ASSERT (HostAdapterStatus != NULL);
>    ASSERT (TargetStatus != NULL);
>    ASSERT (DataLength != NULL);
>    ASSERT (ScsiIo != NULL);
>  
>    ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
>    ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);
>  
>    CommandPacket.Timeout         = Timeout;
>    CommandPacket.InDataBuffer    = DataBuffer;
>    CommandPacket.SenseData       = SenseData;
>    CommandPacket.InTransferLength= *DataLength;
>    CommandPacket.Cdb             = Cdb;
>    //
>    // Fill Cdb for Mode Sense (10) Command
>    //
> -  Target = &TargetArray[0];
> -  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);
> -
>    Cdb[0]                        = EFI_SCSI_OP_MODE_SEN10;
>    //
>    // DBDField is in Cdb[1] bit3 of (bit7..0)
>    //
> -  Cdb[1]                        = (UINT8) ((LShiftU64 (Lun, 5) & 
> EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK) + ((DBDField << 3) & 0x08));
> +  Cdb[1]                        = (UINT8) ((DBDField << 3) & 0x08);
>    //
>    // PageControl is in Cdb[2] bit7..6, PageCode is in Cdb[2] bit5..0
>    //
>    Cdb[2]                        = (UINT8) (((PageControl << 6) & 0xc0) | 
> (PageCode & 0x3f));
>    Cdb[7]                        = (UINT8) (*DataLength >> 8);
>    Cdb[8]                        = (UINT8) (*DataLength);
>  
>    CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;
>    CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;
>    CommandPacket.SenseDataLength = *SenseDataLength;
>  
> @@ -594,49 +563,42 @@ 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
>    )
>  {
>    EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
> -  UINT64                          Lun;
> -  UINT8                           *Target;
> -  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];
>    EFI_STATUS                      Status;
>    UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];
>  
>    ASSERT (SenseDataLength != NULL);
>    ASSERT (HostAdapterStatus != NULL);
>    ASSERT (TargetStatus != NULL);
>    ASSERT (ScsiIo != NULL);
>  
>    ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
>    ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);
>  
>    CommandPacket.Timeout         = Timeout;
>    CommandPacket.InDataBuffer    = SenseData;
>    CommandPacket.SenseData       = NULL;
>    CommandPacket.InTransferLength= *SenseDataLength;
>    CommandPacket.Cdb             = Cdb;
>    //
>    // Fill Cdb for Request Sense Command
>    //
> -  Target = &TargetArray[0];
> -  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);
> -
>    Cdb[0]                        = EFI_SCSI_OP_REQUEST_SENSE;
> -  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & 
> EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
>    Cdb[4]                        = (UINT8) (*SenseDataLength);
>  
>    CommandPacket.CdbLength       = (UINT8) EFI_SCSI_OP_LENGTH_SIX;
>    CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;
>    CommandPacket.SenseDataLength = 0;
>  
>    Status                        = ScsiIo->ExecuteScsiCommand (ScsiIo, 
> &CommandPacket, NULL);
>  
>    *HostAdapterStatus            = CommandPacket.HostAdapterStatus;
>    *TargetStatus                 = CommandPacket.TargetStatus;
>    *SenseDataLength              = (UINT8) CommandPacket.InTransferLength;
> @@ -687,50 +649,43 @@ ScsiReadCapacityCommand (
>    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
>    )
>  {
>    EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
> -  UINT64                          Lun;
> -  UINT8                           *Target;
> -  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];
>    EFI_STATUS                      Status;
>    UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];
>  
>    ASSERT (SenseDataLength != NULL);
>    ASSERT (HostAdapterStatus != NULL);
>    ASSERT (TargetStatus != NULL);
>    ASSERT (DataLength != NULL);
>    ASSERT (ScsiIo != NULL);
>  
>    ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
>    ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);
>  
>    CommandPacket.Timeout         = Timeout;
>    CommandPacket.InDataBuffer    = DataBuffer;
>    CommandPacket.SenseData       = SenseData;
>    CommandPacket.InTransferLength= *DataLength;
>    CommandPacket.Cdb             = Cdb;
>    //
>    // Fill Cdb for Read Capacity Command
>    //
> -  Target = &TargetArray[0];
> -  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);
> -
>    Cdb[0]  = EFI_SCSI_OP_READ_CAPACITY;
> -  Cdb[1]  = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
>    if (!Pmi) {
>      //
>      // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.5 MUST BE 
> ZERO.
>      //
>      ZeroMem ((Cdb + 2), 4);
>    } else {
>      Cdb[8] |= 0x01;
>    }
>  
>    CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;
>    CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;
> @@ -789,48 +744,42 @@ ScsiReadCapacity16Command (
>    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
>    )
>  {
>    EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
> -  UINT64                          Lun;
> -  UINT8                           *Target;
> -  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];
>    EFI_STATUS                      Status;
>    UINT8                           Cdb[16];
>  
>    ASSERT (SenseDataLength != NULL);
>    ASSERT (HostAdapterStatus != NULL);
>    ASSERT (TargetStatus != NULL);
>    ASSERT (DataLength != NULL);
>    ASSERT (ScsiIo != NULL);
>  
>    ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
>    ZeroMem (Cdb, 16);
>  
>    CommandPacket.Timeout         = Timeout;
>    CommandPacket.InDataBuffer    = DataBuffer;
>    CommandPacket.SenseData       = SenseData;
>    CommandPacket.InTransferLength= *DataLength;
>    CommandPacket.Cdb             = Cdb;
>    //
>    // Fill Cdb for Read Capacity Command
>    //
> -  Target = &TargetArray[0];
> -  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);
> -
>    Cdb[0]  = EFI_SCSI_OP_READ_CAPACITY16;
>    Cdb[1]  = 0x10;
>    if (!Pmi) {
>      //
>      // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.9 MUST BE 
> ZERO.
>      //
>      ZeroMem ((Cdb + 2), 8);
>    } else {
>      Cdb[14] |= 0x01;
>    }
>  
> --
> 1.8.3.1
> 
> 
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
> 
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
> 


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to