]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/ScsiDiskDxe: Update proper device name for ScsiDisk drive
authorCheripally Gopi <gopic@ami.com>
Wed, 26 Oct 2022 12:07:25 +0000 (17:37 +0530)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 31 Oct 2022 02:46:52 +0000 (02:46 +0000)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4100

ScsiDiskDxe driver updates ControllerNameTable with common string
"SCSI Disk Device" for all SCSI disks. Due to this, when multiple
SCSI disk devices connected, facing difficulty in identifying correct SCSI
disk device. As per SCSI spec, standard Inquiry Data is having the fields
to know Vendor and Product information. Updated "ControllerNameTable" with
Vendor and Product information. So that, device specific name can be
retrieved using ComponentName protocol.

Cc: Vasudevan Sambandan <vasudevans@ami.com>
Cc: Sundaresan Selvaraj <sundaresans@ami.com>
Signed-off-by: Cheripally Gopi <gopic@ami.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf

index 98e84b4ea8aae04ff02f004cc08155975c83aa2b..0928605dc4c49f87b4b055028449b8566f023506 100644 (file)
@@ -2,6 +2,7 @@
   SCSI disk driver that layers on every SCSI IO protocol in the system.\r
 \r
 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 1985 - 2022, American Megatrends International LLC.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -67,6 +68,33 @@ FreeAlignedBuffer (
   }\r
 }\r
 \r
+/**\r
+  Remove trailing spaces from the string.\r
+\r
+  @param String   The ASCII string to remove the trailing spaces.\r
+\r
+  @retval the new length of the string.\r
+**/\r
+UINTN\r
+RemoveTrailingSpaces (\r
+  IN OUT CHAR8  *String\r
+  )\r
+{\r
+  UINTN  Length;\r
+\r
+  Length = AsciiStrLen (String);\r
+  if (Length == 0) {\r
+    return 0;\r
+  }\r
+\r
+  while ((Length > 0) && (String[Length-1] == ' ')) {\r
+    Length--;\r
+  }\r
+\r
+  String[Length] = '\0';\r
+  return Length;\r
+}\r
+\r
 /**\r
   The user Entry Point for module ScsiDisk.\r
 \r
@@ -203,6 +231,9 @@ ScsiDiskDriverBindingStart (
   UINT8                 MaxRetry;\r
   BOOLEAN               NeedRetry;\r
   BOOLEAN               MustReadCapacity;\r
+  CHAR8                 VendorStr[VENDOR_IDENTIFICATION_LENGTH + 1];\r
+  CHAR8                 ProductStr[PRODUCT_IDENTIFICATION_LENGTH + 1];\r
+  CHAR16                DeviceStr[VENDOR_IDENTIFICATION_LENGTH + PRODUCT_IDENTIFICATION_LENGTH + 2];\r
 \r
   MustReadCapacity = TRUE;\r
 \r
@@ -354,19 +385,37 @@ ScsiDiskDriverBindingStart (
           }\r
         }\r
 \r
+        CopyMem (\r
+          VendorStr,\r
+          &ScsiDiskDevice->InquiryData.Reserved_5_95[VENDOR_IDENTIFICATION_OFFSET],\r
+          VENDOR_IDENTIFICATION_LENGTH\r
+          );\r
+        VendorStr[VENDOR_IDENTIFICATION_LENGTH] = 0;\r
+        RemoveTrailingSpaces (VendorStr);\r
+\r
+        CopyMem (\r
+          ProductStr,\r
+          &ScsiDiskDevice->InquiryData.Reserved_5_95[PRODUCT_IDENTIFICATION_OFFSET],\r
+          PRODUCT_IDENTIFICATION_LENGTH\r
+          );\r
+        ProductStr[PRODUCT_IDENTIFICATION_LENGTH] = 0;\r
+        RemoveTrailingSpaces (ProductStr);\r
+\r
+        UnicodeSPrint (DeviceStr, sizeof (DeviceStr), L"%a %a", VendorStr, ProductStr);\r
+\r
         ScsiDiskDevice->ControllerNameTable = NULL;\r
         AddUnicodeString2 (\r
           "eng",\r
           gScsiDiskComponentName.SupportedLanguages,\r
           &ScsiDiskDevice->ControllerNameTable,\r
-          L"SCSI Disk Device",\r
+          DeviceStr,\r
           TRUE\r
           );\r
         AddUnicodeString2 (\r
           "en",\r
           gScsiDiskComponentName2.SupportedLanguages,\r
           &ScsiDiskDevice->ControllerNameTable,\r
-          L"SCSI Disk Device",\r
+          DeviceStr,\r
           FALSE\r
           );\r
         return EFI_SUCCESS;\r
index d54282df5f3649a3c756e015528e8b517a991deb..5b4047e1dbdd632a2f0dd142c0566fefce0b93e2 100644 (file)
@@ -2,6 +2,7 @@
   Header file for SCSI Disk Driver.\r
 \r
 Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 1985 - 2022, American Megatrends International LLC.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -30,6 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/UefiScsiLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/DevicePathLib.h>\r
+#include <Library/PrintLib.h>\r
 \r
 #include <IndustryStandard/Scsi.h>\r
 #include <IndustryStandard/Atapi.h>\r
@@ -179,6 +181,13 @@ extern EFI_COMPONENT_NAME2_PROTOCOL  gScsiDiskComponentName2;
 #define SCSI_COMMAND_VERSION_2  0x02\r
 #define SCSI_COMMAND_VERSION_3  0x03\r
 \r
+// Per SCSI spec, EFI_SCSI_INQUIRY_DATA.Reserved_5_95[3 - 10] has the Vendor identification\r
+// EFI_SCSI_INQUIRY_DATA.Reserved_5_95[11 - 26] has the product identification\r
+#define VENDOR_IDENTIFICATION_OFFSET   3\r
+#define VENDOR_IDENTIFICATION_LENGTH   8\r
+#define PRODUCT_IDENTIFICATION_OFFSET  11\r
+#define PRODUCT_IDENTIFICATION_LENGTH  16\r
+\r
 //\r
 // SCSI Disk Timeout Experience Value\r
 //\r
index 40818e669b0a321caabe6544f6624324f0569aa3..26227132e8c7be39500dd6f046e832a53209cfca 100644 (file)
@@ -4,6 +4,7 @@
 #  the device handle.\r
 #\r
 #  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 1985 - 2022, American Megatrends International LLC.<BR>\r
 #  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 ##\r
@@ -46,6 +47,7 @@
   UefiDriverEntryPoint\r
   DebugLib\r
   DevicePathLib\r
+  PrintLib\r
 \r
 [Protocols]\r
   gEfiDiskInfoProtocolGuid                      ## BY_START\r