X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FUefiScsiLib%2FUefiScsiLib.c;h=ac032cd4d5bce9964a97ecb2716204291809d812;hb=373b5cf97cc650d2e81d4909ff5327b6ce0b6c26;hp=20088d5cbfa7d2f490c511e3952af3e83a4c5c4b;hpb=d35be2a434d347c0ff112f89c120a5c8a79c89a7;p=mirror_edk2.git diff --git a/MdePkg/Library/UefiScsiLib/UefiScsiLib.c b/MdePkg/Library/UefiScsiLib/UefiScsiLib.c index 20088d5cbf..ac032cd4d5 100644 --- a/MdePkg/Library/UefiScsiLib/UefiScsiLib.c +++ b/MdePkg/Library/UefiScsiLib/UefiScsiLib.c @@ -14,22 +14,25 @@ #include +#include #include #include -#include +#include -/** +/** Function test the ready status of the SCSI unit. - - @param[in] ScsiIo A pointer to SCSI IO protocol. - @param[in] Timeout The length of timeout period. - @param[out] SenseData A pointer to output sense data. - @param[out] SenseDataLength The length of output sense data. - @param[out] HostAdapterStatus The status of Host Adapter. - @param[out] TargetStatus The status of the target. - + + @param[in] ScsiIo A pointer to SCSI IO protocol. + @param[in] Timeout The length of timeout period. + @param[in out] SenseData A pointer to the sense data that + was generated by the execution of the SCSI Request Packet. + @param[in out] SenseDataLength On input, the length in bytes of the SenseData buffer. On + output, the number of bytes written to the SenseData buffer. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @retval EFI_SUCCESS The status of the unit is tested successfully. @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could not be transferred. @@ -40,20 +43,21 @@ queued. @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request Packet. - @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. + @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid, or ScsiIo is NULL. @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by the SCSI initiator(i.e., SCSI Host Controller). @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. - + **/ EFI_STATUS +EFIAPI ScsiTestUnitReadyCommand ( IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, - OUT VOID *SenseData, - OUT UINT8 *SenseDataLength, + IN OUT VOID *SenseData, + IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus ) @@ -65,6 +69,13 @@ ScsiTestUnitReadyCommand ( EFI_STATUS Status; UINT8 Cdb[6]; + ASSERT (SenseDataLength != NULL); + ASSERT (HostAdapterStatus != NULL); + ASSERT (TargetStatus != NULL); + + if (ScsiIo == NULL) { + return EFI_INVALID_PARAMETER; + } ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); ZeroMem (Cdb, 6); @@ -97,19 +108,20 @@ ScsiTestUnitReadyCommand ( } -/** +/** Function to submit SCSI inquiry command. - - @param[in] ScsiIo SCSI IO Protocol to use - @param[in] Timeout The length of timeout period. - @param[out] SenseData A pointer to output sense data. - @param[in,out] SenseDataLength The length of output sense data. - @param[out] HostAdapterStatus The status of Host Adapter. - @param[out] TargetStatus The status of the target. - @param[in,out] InquirydataBuffer A pointer to inquiry data buffer. - @param[in,out] InquiryDataLength The length of inquiry data buffer. - @param[in] EnableVitalProductData Boolean to enable Vital Product Data. - + + @param[in] ScsiIo SCSI IO Protocol to use + @param[in] Timeout The length of timeout period. + @param[out] SenseData A pointer to output sense data. + @param[in out] SenseDataLength On input, the length in bytes of the SenseData buffer. On + output, the number of bytes written to the SenseData buffer. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @param[in] InquirydataBuffer A pointer to inquiry data buffer. + @param[in,out] InquiryDataLength The length of inquiry data buffer. + @param[in] EnableVitalProductData Boolean to enable Vital Product Data. + @retval EFI_SUCCESS The status of the unit is tested successfully. @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could not be transferred. @@ -120,15 +132,16 @@ ScsiTestUnitReadyCommand ( queued. @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request Packet. - @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. + @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid, or ScsiIo is NULL. @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by the SCSI initiator(i.e., SCSI Host Controller). @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. - + **/ EFI_STATUS +EFIAPI ScsiInquiryCommand ( IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, @@ -136,7 +149,7 @@ ScsiInquiryCommand ( IN OUT UINT8 *SenseDataLength, OUT UINT8 *HostAdapterStatus, OUT UINT8 *TargetStatus, - IN OUT VOID *InquiryDataBuffer, + IN VOID *InquiryDataBuffer, IN OUT UINT32 *InquiryDataLength, IN BOOLEAN EnableVitalProductData ) @@ -148,6 +161,15 @@ ScsiInquiryCommand ( EFI_STATUS Status; UINT8 Cdb[6]; + ASSERT (SenseDataLength != NULL); + ASSERT (HostAdapterStatus != NULL); + ASSERT (TargetStatus != NULL); + ASSERT (InquiryDataLength != NULL); + + if (ScsiIo == NULL) { + return EFI_INVALID_PARAMETER; + } + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); ZeroMem (Cdb, 6); @@ -186,23 +208,24 @@ ScsiInquiryCommand ( } -/** +/** Function to submit SCSI mode sense 10 command. - - @param[in] ScsiIo A pointer to SCSI IO protocol. - @param[in] Timeout The length of timeout period. - @param[out] SenseData A pointer to output sense data. - @param[in,out] SenseDataLength The length of output sense data. - @param[out] HostAdapterStatus The status of Host Adapter. - @param[out] TargetStatus The status of the target. - @param[in] DataBuffer A pointer to input data buffer. - @param[in,out] DataLength The length of input data buffer. - @param[in] DBDField The DBD Field (Optional). - @param[in] PageControl Page Control. - @param[in] PageCode Page code. - + + @param[in] ScsiIo A pointer to SCSI IO protocol. + @param[in] Timeout The length of timeout period. + @param[out] SenseData A pointer to output sense data. + @param[in out] SenseDataLength On input, the length in bytes of the SenseData buffer. On + output, the number of bytes written to the SenseData buffer. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @param[in] DataBuffer A pointer to input data buffer. + @param[in,out] DataLength The length of input data buffer. + @param[in] DBDField The DBD Field (Optional). + @param[in] PageControl Page Control. + @param[in] PageCode Page code. + @retval EFI_SUCCESS The status of the unit is tested successfully. - @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, + @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could not be transferred. The actual number of bytes transferred is returned in TransferLength. @@ -211,15 +234,16 @@ ScsiInquiryCommand ( queued. @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request Packet. - @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. + @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid, or ScsiIo is NULL. @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by the SCSI initiator(i.e., SCSI Host Controller). @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. - + **/ EFI_STATUS +EFIAPI ScsiModeSense10Command ( IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, @@ -241,6 +265,15 @@ ScsiModeSense10Command ( EFI_STATUS Status; UINT8 Cdb[10]; + ASSERT (SenseDataLength != NULL); + ASSERT (HostAdapterStatus != NULL); + ASSERT (TargetStatus != NULL); + ASSERT (DataLength != NULL); + + if (ScsiIo == NULL) { + return EFI_INVALID_PARAMETER; + } + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); ZeroMem (Cdb, 10); @@ -276,25 +309,20 @@ ScsiModeSense10Command ( } -/** +/** Function to submit SCSI request sense command. - ScsiIo - A pointer to SCSI IO protocol. - Timeout - The length of timeout period. - SenseData - A pointer to output sense data. - SenseDataLength - The length of output sense data. - HostAdapterStatus - The status of Host Adapter. - TargetStatus - The status of the target. - - @param[in] ScsiIo SCSI IO Protocol to use - @param[in] Timeout TODO: - @param[out] SenseData TODO: - @param[in,out] SenseDataLength TODO: - @param[out] HostAdapterStatus TODO: - @param[out] TargetStatus TODO: - - @retval EFI_SUCCESS Valid data returned + + @param[in] ScsiIo A pointer to SCSI IO protocol. + @param[in] Timeout The length of timeout period. + @param[in] SenseData A pointer to output sense data. + @param[in out] SenseDataLength On input, the length in bytes of the SenseData buffer. On + output, the number of bytes written to the SenseData buffer. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + + @retval EFI_SUCCESS Valid data returned @retval EFI_SUCCESS The status of the unit is tested successfully. - @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, + @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could not be transferred. The actual number of bytes transferred is returned in TransferLength. @@ -303,15 +331,16 @@ ScsiModeSense10Command ( queued. @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request Packet. - @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. + @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid, or ScsiIo is NULL. @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by the SCSI initiator(i.e., SCSI Host Controller). @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. - + **/ EFI_STATUS +EFIAPI ScsiRequestSenseCommand ( IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, @@ -328,6 +357,14 @@ ScsiRequestSenseCommand ( EFI_STATUS Status; UINT8 Cdb[6]; + ASSERT (SenseDataLength != NULL); + ASSERT (HostAdapterStatus != NULL); + ASSERT (TargetStatus != NULL); + + if (ScsiIo == NULL) { + return EFI_INVALID_PARAMETER; + } + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); ZeroMem (Cdb, 6); @@ -360,21 +397,22 @@ ScsiRequestSenseCommand ( } -/** +/** Function to submit read capacity command. - @param[in] ScsiIo A pointer to SCSI IO protocol. - @param[in] Timeout The length of timeout period. - @param[out] SenseData A pointer to output sense data. - @param[in,out] SenseDataLength The length of output sense data. - @param[out] HostAdapterStatus The status of Host Adapter. - @param[out] TargetStatus The status of the target. - @param[out] DataBuffer A pointer to a data buffer. - @param[in,out] DataLength The length of data buffer. - @param[in] PMI Partial medium indicator. - + @param[in] ScsiIo A pointer to SCSI IO protocol. + @param[in] Timeout The length of timeout period. + @param[out] SenseData A pointer to output sense data. + @param[in out] SenseDataLength On input, the length in bytes of the SenseData buffer. On + output, the number of bytes written to the SenseData buffer. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @param[out] DataBuffer A pointer to a data buffer. + @param[in,out] DataLength The length of data buffer. + @param[in] PMI Partial medium indicator. + @retval EFI_SUCCESS The status of the unit is tested successfully. - @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, + @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could not be transferred. The actual number of bytes transferred is returned in TransferLength. @@ -383,15 +421,16 @@ ScsiRequestSenseCommand ( queued. @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request Packet. - @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. + @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid, or ScsiIo is NULL. @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by the SCSI initiator(i.e., SCSI Host Controller). @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. - + **/ EFI_STATUS +EFIAPI ScsiReadCapacityCommand ( IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, @@ -411,6 +450,15 @@ ScsiReadCapacityCommand ( EFI_STATUS Status; UINT8 Cdb[10]; + ASSERT (SenseDataLength != NULL); + ASSERT (HostAdapterStatus != NULL); + ASSERT (TargetStatus != NULL); + ASSERT (DataLength != NULL); + + if (ScsiIo == NULL) { + return EFI_INVALID_PARAMETER; + } + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); ZeroMem (Cdb, 10); @@ -451,22 +499,23 @@ ScsiReadCapacityCommand ( } -/** +/** Function to submit read 10 command. - - @param[in] ScsiIo A pointer to SCSI IO protocol. - @param[in] Timeout The length of timeout period. - @param[out] SenseData A pointer to output sense data. - @param[in,out] SenseDataLength The length of output sense data. - @param[out] HostAdapterStatus The status of Host Adapter. - @param[out] TargetStatus The status of the target. - @param[out] DataBuffer Read 10 command data. - @param[in,out] DataLength The length of data buffer. - @param[in] StartLba The start address of LBA. - @param[in] SectorSize The sector size. - + + @param[in] ScsiIo A pointer to SCSI IO protocol. + @param[in] Timeout The length of timeout period. + @param[out] SenseData A pointer to output sense data. + @param[in out] SenseDataLength On input, the length in bytes of the SenseData buffer. On + output, the number of bytes written to the SenseData buffer. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @param[out] DataBuffer Read 10 command data. + @param[in,out] DataLength The length of data buffer. + @param[in] StartLba The start address of LBA. + @param[in] SectorSize The sector size. + @retval EFI_SUCCESS The status of the unit is tested successfully. - @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, + @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could not be transferred. The actual number of bytes transferred is returned in TransferLength. @@ -475,15 +524,16 @@ ScsiReadCapacityCommand ( queued. @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request Packet. - @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. + @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid, or ScsiIo is NULL. @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by the SCSI initiator(i.e., SCSI Host Controller). @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. - + **/ EFI_STATUS +EFIAPI ScsiRead10Command ( IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, @@ -504,6 +554,15 @@ ScsiRead10Command ( EFI_STATUS Status; UINT8 Cdb[10]; + ASSERT (SenseDataLength != NULL); + ASSERT (HostAdapterStatus != NULL); + ASSERT (TargetStatus != NULL); + ASSERT (DataLength != NULL); + + if (ScsiIo == NULL) { + return EFI_INVALID_PARAMETER; + } + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); ZeroMem (Cdb, 10); @@ -542,22 +601,23 @@ ScsiRead10Command ( } -/** +/** Function to submit SCSI write 10 command. - - @param[in] ScsiIo SCSI IO Protocol to use - @param[in] Timeout The length of timeout period. - @param[out] SenseData A pointer to output sense data. - @param[in,out] SenseDataLength The length of output sense data. - @param[out] HostAdapterStatus The status of Host Adapter. - @param[out] TargetStatus The status of the target. - @param[out] DataBuffer A pointer to a data buffer. - @param[in,out] DataLength The length of data buffer. - @param[in] StartLba The start address of LBA. - @param[in] SectorSize The sector size. - + + @param[in] ScsiIo SCSI IO Protocol to use + @param[in] Timeout The length of timeout period. + @param[out] SenseData A pointer to output sense data. + @param[in out] SenseDataLength On input, the length in bytes of the SenseData buffer. On + output, the number of bytes written to the SenseData buffer. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @param[out] DataBuffer A pointer to a data buffer. + @param[in,out] DataLength The length of data buffer. + @param[in] StartLba The start address of LBA. + @param[in] SectorSize The sector size. + @retval EFI_SUCCESS The status of the unit is tested successfully. - @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, + @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could not be transferred. The actual number of bytes transferred is returned in InTransferLength. @@ -566,15 +626,16 @@ ScsiRead10Command ( queued. @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request Packet. - @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. + @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid, or ScsiIo is NULL. @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by the SCSI initiator(i.e., SCSI Host Controller). @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. - + **/ EFI_STATUS +EFIAPI ScsiWrite10Command ( IN EFI_SCSI_IO_PROTOCOL *ScsiIo, IN UINT64 Timeout, @@ -595,6 +656,15 @@ ScsiWrite10Command ( EFI_STATUS Status; UINT8 Cdb[10]; + ASSERT (SenseDataLength != NULL); + ASSERT (HostAdapterStatus != NULL); + ASSERT (TargetStatus != NULL); + ASSERT (DataLength != NULL); + + if (ScsiIo == NULL) { + return EFI_INVALID_PARAMETER; + } + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); ZeroMem (Cdb, 10); @@ -627,7 +697,8 @@ ScsiWrite10Command ( *HostAdapterStatus = CommandPacket.HostAdapterStatus; *TargetStatus = CommandPacket.TargetStatus; *SenseDataLength = CommandPacket.SenseDataLength; - *DataLength = CommandPacket.InTransferLength; + *DataLength = CommandPacket.OutTransferLength; return Status; } +