* [PATCH v2 01/13] OvmfPkg/MptScsiDxe: Create empty driver
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-28 8:12 ` Laszlo Ersek
2020-02-26 16:41 ` [PATCH v2 02/13] OvmfPkg/MptScsiDxe: Install DriverBinding Protocol Nikita Leshenko
` (13 subsequent siblings)
14 siblings, 1 reply; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
In preparation for implementing LSI Fusion MPT SCSI devices, create a
basic scaffolding for a driver.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 30 +++++++++++++++++++++++++++++
OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 32 +++++++++++++++++++++++++++++++
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32.fdf | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.fdf | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/OvmfPkgX64.fdf | 1 +
8 files changed, 68 insertions(+)
create mode 100644 OvmfPkg/MptScsiDxe/MptScsi.c
create mode 100644 OvmfPkg/MptScsiDxe/MptScsiDxe.inf
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
new file mode 100644
index 0000000000..9e0dd449d9
--- /dev/null
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -0,0 +1,30 @@
+/** @file
+
+ This driver produces Extended SCSI Pass Thru Protocol instances for
+ LSI Fusion MPT SCSI devices.
+
+ Copyright (C) 2020, Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+//
+// Entry Point
+//
+
+EFI_STATUS
+EFIAPI
+MptScsiEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return EFI_UNSUPPORTED;
+}
diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
new file mode 100644
index 0000000000..bf1e0bff82
--- /dev/null
+++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
@@ -0,0 +1,32 @@
+## @file
+# This driver produces Extended SCSI Pass Thru Protocol instances for
+# LSI Fusion MPT SCSI devices.
+#
+# Copyright (C) 2020, Oracle and/or its affiliates. All rights reserved.
+#
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 1.29
+ BASE_NAME = MptScsiDxe
+ FILE_GUID = 2B3DB5DD-B315-4961-8454-0AFF3C811B19
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = MptScsiEntryPoint
+
+[Sources]
+ MptScsi.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiDriverEntryPoint
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 19728f20b3..6d9c7c92db 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -718,6 +718,7 @@
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
OvmfPkg/XenBusDxe/XenBusDxe.inf
OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+ OvmfPkg/MptScsiDxe/MptScsiDxe.inf
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index 63607551ed..548ce0b614 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -227,6 +227,7 @@ INF OvmfPkg/VirtioRngDxe/VirtioRng.inf
INF OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
INF OvmfPkg/XenBusDxe/XenBusDxe.inf
INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+INF OvmfPkg/MptScsiDxe/MptScsiDxe.inf
!if $(SECURE_BOOT_ENABLE) == TRUE
INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 3c0c229e3a..fdaebef73d 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -731,6 +731,7 @@
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
OvmfPkg/XenBusDxe/XenBusDxe.inf
OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+ OvmfPkg/MptScsiDxe/MptScsiDxe.inf
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index 0488e5d95f..09364102de 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -228,6 +228,7 @@ INF OvmfPkg/VirtioRngDxe/VirtioRng.inf
INF OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
INF OvmfPkg/XenBusDxe/XenBusDxe.inf
INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+INF OvmfPkg/MptScsiDxe/MptScsiDxe.inf
!if $(SECURE_BOOT_ENABLE) == TRUE
INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index f6c1d8d228..ee43202e09 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -729,6 +729,7 @@
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
OvmfPkg/XenBusDxe/XenBusDxe.inf
OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+ OvmfPkg/MptScsiDxe/MptScsiDxe.inf
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index 0488e5d95f..09364102de 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -228,6 +228,7 @@ INF OvmfPkg/VirtioRngDxe/VirtioRng.inf
INF OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
INF OvmfPkg/XenBusDxe/XenBusDxe.inf
INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+INF OvmfPkg/MptScsiDxe/MptScsiDxe.inf
!if $(SECURE_BOOT_ENABLE) == TRUE
INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/13] OvmfPkg/MptScsiDxe: Create empty driver
2020-02-26 16:41 ` [PATCH v2 01/13] OvmfPkg/MptScsiDxe: Create empty driver Nikita Leshenko
@ 2020-02-28 8:12 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 8:12 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> In preparation for implementing LSI Fusion MPT SCSI devices, create a
> basic scaffolding for a driver.
>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Aaron Young <aaron.young@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> ---
> OvmfPkg/MptScsiDxe/MptScsi.c | 30 +++++++++++++++++++++++++++++
> OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 32 +++++++++++++++++++++++++++++++
> OvmfPkg/OvmfPkgIa32.dsc | 1 +
> OvmfPkg/OvmfPkgIa32.fdf | 1 +
> OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
> OvmfPkg/OvmfPkgIa32X64.fdf | 1 +
> OvmfPkg/OvmfPkgX64.dsc | 1 +
> OvmfPkg/OvmfPkgX64.fdf | 1 +
> 8 files changed, 68 insertions(+)
> create mode 100644 OvmfPkg/MptScsiDxe/MptScsi.c
> create mode 100644 OvmfPkg/MptScsiDxe/MptScsiDxe.inf
With my requests under the blurb addressed:
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 02/13] OvmfPkg/MptScsiDxe: Install DriverBinding Protocol
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
2020-02-26 16:41 ` [PATCH v2 01/13] OvmfPkg/MptScsiDxe: Create empty driver Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-28 8:16 ` Laszlo Ersek
2020-02-26 16:41 ` [PATCH v2 03/13] OvmfPkg/MptScsiDxe: Report name of driver Nikita Leshenko
` (12 subsequent siblings)
14 siblings, 1 reply; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
In order to probe and connect to the MptScsi device we need this
protocol. Currently it does nothing.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 68 ++++++++++++++++++++++++++++++-
OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 1 +
2 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 9e0dd449d9..82d8add3a9 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -15,6 +15,65 @@
**/
+#include <Library/UefiLib.h>
+
+//
+// Higher versions will be used before lower, 0x10-0xffffffef is the version
+// range for IVH (Indie Hardware Vendors)
+//
+#define MPT_SCSI_BINDING_VERSION 0x10
+
+//
+// Driver Binding
+//
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiControllerSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiControllerStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiControllerStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_DRIVER_BINDING_PROTOCOL mMptScsiDriverBinding = {
+ &MptScsiControllerSupported,
+ &MptScsiControllerStart,
+ &MptScsiControllerStop,
+ MPT_SCSI_BINDING_VERSION,
+ NULL, // ImageHandle, filled by EfiLibInstallDriverBindingComponentName2
+ NULL, // DriverBindingHandle, filled as well
+};
+
//
// Entry Point
//
@@ -26,5 +85,12 @@ MptScsiEntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- return EFI_UNSUPPORTED;
+ return EfiLibInstallDriverBindingComponentName2 (
+ ImageHandle,
+ SystemTable,
+ &mMptScsiDriverBinding,
+ ImageHandle, // The handle to install onto
+ NULL, // TODO Component name
+ NULL // TODO Component name
+ );
}
diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
index bf1e0bff82..4b1a23c33a 100644
--- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
+++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
@@ -30,3 +30,4 @@
[LibraryClasses]
UefiDriverEntryPoint
+ UefiLib
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 02/13] OvmfPkg/MptScsiDxe: Install DriverBinding Protocol
2020-02-26 16:41 ` [PATCH v2 02/13] OvmfPkg/MptScsiDxe: Install DriverBinding Protocol Nikita Leshenko
@ 2020-02-28 8:16 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 8:16 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> In order to probe and connect to the MptScsi device we need this
> protocol. Currently it does nothing.
>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Aaron Young <aaron.young@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> ---
> OvmfPkg/MptScsiDxe/MptScsi.c | 68 ++++++++++++++++++++++++++++++-
> OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 1 +
> 2 files changed, 68 insertions(+), 1 deletion(-)
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 03/13] OvmfPkg/MptScsiDxe: Report name of driver
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
2020-02-26 16:41 ` [PATCH v2 01/13] OvmfPkg/MptScsiDxe: Create empty driver Nikita Leshenko
2020-02-26 16:41 ` [PATCH v2 02/13] OvmfPkg/MptScsiDxe: Install DriverBinding Protocol Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-28 8:17 ` Laszlo Ersek
2020-02-26 16:41 ` [PATCH v2 04/13] OvmfPkg/MptScsiDxe: Probe PCI devices and look for MptScsi Nikita Leshenko
` (11 subsequent siblings)
14 siblings, 1 reply; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
Install Component Name protocols to have a nice display name for the
driver in places such as UEFI shell.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 61 ++++++++++++++++++++++++++++++++++--
1 file changed, 59 insertions(+), 2 deletions(-)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 82d8add3a9..40194b5ead 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -74,6 +74,63 @@ EFI_DRIVER_BINDING_PROTOCOL mMptScsiDriverBinding = {
NULL, // DriverBindingHandle, filled as well
};
+//
+// Component Name
+//
+
+STATIC
+EFI_UNICODE_STRING_TABLE mDriverNameTable[] = {
+ { "eng;en", L"LSI Fusion MPT SCSI Driver" },
+ { NULL, NULL }
+};
+
+STATIC
+EFI_COMPONENT_NAME_PROTOCOL mComponentName;
+
+EFI_STATUS
+EFIAPI
+MptScsiGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+{
+ return LookupUnicodeString2 (
+ Language,
+ This->SupportedLanguages,
+ mDriverNameTable,
+ DriverName,
+ (BOOLEAN)(This == &mComponentName) // Iso639Language
+ );
+}
+
+EFI_STATUS
+EFIAPI
+MptScsiGetDeviceName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE DeviceHandle,
+ IN EFI_HANDLE ChildHandle,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_COMPONENT_NAME_PROTOCOL mComponentName = {
+ &MptScsiGetDriverName,
+ &MptScsiGetDeviceName,
+ "eng" // SupportedLanguages, ISO 639-2 language codes
+};
+
+STATIC
+EFI_COMPONENT_NAME2_PROTOCOL mComponentName2 = {
+ (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) &MptScsiGetDriverName,
+ (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &MptScsiGetDeviceName,
+ "en" // SupportedLanguages, RFC 4646 language codes
+};
+
//
// Entry Point
//
@@ -90,7 +147,7 @@ MptScsiEntryPoint (
SystemTable,
&mMptScsiDriverBinding,
ImageHandle, // The handle to install onto
- NULL, // TODO Component name
- NULL // TODO Component name
+ &mComponentName,
+ &mComponentName2
);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 03/13] OvmfPkg/MptScsiDxe: Report name of driver
2020-02-26 16:41 ` [PATCH v2 03/13] OvmfPkg/MptScsiDxe: Report name of driver Nikita Leshenko
@ 2020-02-28 8:17 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 8:17 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> Install Component Name protocols to have a nice display name for the
> driver in places such as UEFI shell.
>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Aaron Young <aaron.young@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
> ---
> OvmfPkg/MptScsiDxe/MptScsi.c | 61 ++++++++++++++++++++++++++++++++++--
> 1 file changed, 59 insertions(+), 2 deletions(-)
My R-b stands.
Thanks
Laszlo
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 04/13] OvmfPkg/MptScsiDxe: Probe PCI devices and look for MptScsi
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (2 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 03/13] OvmfPkg/MptScsiDxe: Report name of driver Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-28 8:26 ` Laszlo Ersek
2020-02-26 16:41 ` [PATCH v2 05/13] OvmfPkg/MptScsiDxe: Install stubbed EXT_SCSI_PASS_THRU Nikita Leshenko
` (10 subsequent siblings)
14 siblings, 1 reply; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
The MptScsiControllerSupported function is called on handles passed in
by the ConnectController() boot service and if the handle is the
lsi53c1030 controller the function would return success. A successful
return value will attach our driver to the device.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
.../Include/IndustryStandard/FusionMptScsi.h | 24 +++++++++
OvmfPkg/MptScsiDxe/MptScsi.c | 50 ++++++++++++++++++-
OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 6 +++
3 files changed, 79 insertions(+), 1 deletion(-)
create mode 100644 OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
diff --git a/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
new file mode 100644
index 0000000000..3b911bdb5b
--- /dev/null
+++ b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
@@ -0,0 +1,24 @@
+/** @file
+
+ Macros and type definitions for LSI Fusion MPT SCSI devices.
+
+ Copyright (C) 2020, Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+//
+// Device offsets and constants
+//
+
+#define LSI_LOGIC_PCI_VENDOR_ID 0x1000
+#define LSI_53C1030_PCI_DEVICE_ID 0x0030
+#define LSI_SAS1068_PCI_DEVICE_ID 0x0054
+#define LSI_SAS1068E_PCI_DEVICE_ID 0x0058
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 40194b5ead..6dc6257eba 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -15,7 +15,12 @@
**/
+#include <IndustryStandard/Pci.h>
+#include <IndustryStandard/FusionMptScsi.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
+#include <Protocol/PciIo.h>
//
// Higher versions will be used before lower, 0x10-0xffffffef is the version
@@ -36,7 +41,50 @@ MptScsiControllerSupported (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
- return EFI_UNSUPPORTED;
+ EFI_STATUS Status;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ PCI_TYPE00 Pci;
+
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiPciIoProtocolGuid,
+ (VOID **)&PciIo,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = PciIo->Pci.Read (
+ PciIo,
+ EfiPciIoWidthUint32,
+ 0,
+ sizeof (Pci) / sizeof (UINT32),
+ &Pci
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ if (Pci.Hdr.VendorId == LSI_LOGIC_PCI_VENDOR_ID &&
+ (Pci.Hdr.DeviceId == LSI_53C1030_PCI_DEVICE_ID ||
+ Pci.Hdr.DeviceId == LSI_SAS1068_PCI_DEVICE_ID ||
+ Pci.Hdr.DeviceId == LSI_SAS1068E_PCI_DEVICE_ID)) {
+ Status = EFI_SUCCESS;
+ } else {
+ Status = EFI_UNSUPPORTED;
+ }
+
+Done:
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiPciIoProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+ return Status;
}
STATIC
diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
index 4b1a23c33a..dc3795c867 100644
--- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
+++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
@@ -27,7 +27,13 @@
[Packages]
MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
[LibraryClasses]
+ DebugLib
+ UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib
+
+[Protocols]
+ gEfiPciIoProtocolGuid ## TO_START
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 04/13] OvmfPkg/MptScsiDxe: Probe PCI devices and look for MptScsi
2020-02-26 16:41 ` [PATCH v2 04/13] OvmfPkg/MptScsiDxe: Probe PCI devices and look for MptScsi Nikita Leshenko
@ 2020-02-28 8:26 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 8:26 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> The MptScsiControllerSupported function is called on handles passed in
> by the ConnectController() boot service and if the handle is the
> lsi53c1030 controller the function would return success. A successful
> return value will attach our driver to the device.
>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Aaron Young <aaron.young@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> ---
> .../Include/IndustryStandard/FusionMptScsi.h | 24 +++++++++
> OvmfPkg/MptScsiDxe/MptScsi.c | 50 ++++++++++++++++++-
> OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 6 +++
> 3 files changed, 79 insertions(+), 1 deletion(-)
> create mode 100644 OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
>
> diff --git a/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
> new file mode 100644
> index 0000000000..3b911bdb5b
> --- /dev/null
> +++ b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
> @@ -0,0 +1,24 @@
> +/** @file
> +
> + Macros and type definitions for LSI Fusion MPT SCSI devices.
> +
> + Copyright (C) 2020, Oracle and/or its affiliates. All rights reserved.
> +
> + This program and the accompanying materials are licensed and made available
> + under the terms and conditions of the BSD License which accompanies this
> + distribution. The full text of the license may be found at
> + http://opensource.org/licenses/bsd-license.php
> +
> + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
> + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +
> +**/
> +
> +//
> +// Device offsets and constants
> +//
> +
> +#define LSI_LOGIC_PCI_VENDOR_ID 0x1000
Matches PCI_VENDOR_ID_LSI_LOGIC from QEMU's "include/hw/pci/pci_ids.h". OK.
> +#define LSI_53C1030_PCI_DEVICE_ID 0x0030
Not sure about this one; possibly implemented by a different hypervisor.
But that should be OK.
> +#define LSI_SAS1068_PCI_DEVICE_ID 0x0054
matches PCI_DEVICE_ID_LSI_SAS1068
> +#define LSI_SAS1068E_PCI_DEVICE_ID 0x0058
Also from another hypervisor, I'd guess; OK.
> diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
> index 40194b5ead..6dc6257eba 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsi.c
> +++ b/OvmfPkg/MptScsiDxe/MptScsi.c
> @@ -15,7 +15,12 @@
>
> **/
>
> +#include <IndustryStandard/Pci.h>
> +#include <IndustryStandard/FusionMptScsi.h>
> +#include <Library/DebugLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> #include <Library/UefiLib.h>
> +#include <Protocol/PciIo.h>
(1) Please keep #include directives sorted.
>
> //
> // Higher versions will be used before lower, 0x10-0xffffffef is the version
> @@ -36,7 +41,50 @@ MptScsiControllerSupported (
> IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
> )
> {
> - return EFI_UNSUPPORTED;
> + EFI_STATUS Status;
> + EFI_PCI_IO_PROTOCOL *PciIo;
> + PCI_TYPE00 Pci;
> +
> + Status = gBS->OpenProtocol (
> + ControllerHandle,
> + &gEfiPciIoProtocolGuid,
> + (VOID **)&PciIo,
> + This->DriverBindingHandle,
> + ControllerHandle,
> + EFI_OPEN_PROTOCOL_BY_DRIVER
> + );
> + if (EFI_ERROR (Status)) {
> + return Status;
> + }
> +
> + Status = PciIo->Pci.Read (
> + PciIo,
> + EfiPciIoWidthUint32,
> + 0,
> + sizeof (Pci) / sizeof (UINT32),
> + &Pci
> + );
> + if (EFI_ERROR (Status)) {
> + goto Done;
> + }
> +
> + if (Pci.Hdr.VendorId == LSI_LOGIC_PCI_VENDOR_ID &&
> + (Pci.Hdr.DeviceId == LSI_53C1030_PCI_DEVICE_ID ||
> + Pci.Hdr.DeviceId == LSI_SAS1068_PCI_DEVICE_ID ||
> + Pci.Hdr.DeviceId == LSI_SAS1068E_PCI_DEVICE_ID)) {
> + Status = EFI_SUCCESS;
> + } else {
> + Status = EFI_UNSUPPORTED;
> + }
> +
> +Done:
> + gBS->CloseProtocol (
> + ControllerHandle,
> + &gEfiPciIoProtocolGuid,
> + This->DriverBindingHandle,
> + ControllerHandle
> + );
> + return Status;
> }
>
> STATIC
> diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
> index 4b1a23c33a..dc3795c867 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
> +++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
> @@ -27,7 +27,13 @@
>
> [Packages]
> MdePkg/MdePkg.dec
> + OvmfPkg/OvmfPkg.dec
>
> [LibraryClasses]
> + DebugLib
> + UefiBootServicesTableLib
> UefiDriverEntryPoint
> UefiLib
> +
> +[Protocols]
> + gEfiPciIoProtocolGuid ## TO_START
>
We don't necessarily have to pull in DebugLib in this patch, but it's
also harmless.
With (1) addressed:
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 05/13] OvmfPkg/MptScsiDxe: Install stubbed EXT_SCSI_PASS_THRU
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (3 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 04/13] OvmfPkg/MptScsiDxe: Probe PCI devices and look for MptScsi Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-28 8:35 ` Laszlo Ersek
2020-02-26 16:41 ` [PATCH v2 06/13] OvmfPkg/MptScsiDxe: Report one Target and one LUN Nikita Leshenko
` (9 subsequent siblings)
14 siblings, 1 reply; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
Support dynamic insertion and removal of the protocol
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 178 +++++++++++++++++++++++++++++-
OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 5 +-
2 files changed, 180 insertions(+), 3 deletions(-)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 6dc6257eba..b8eabfb23c 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -17,10 +17,13 @@
#include <IndustryStandard/Pci.h>
#include <IndustryStandard/FusionMptScsi.h>
+#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/PciIo.h>
+#include <Protocol/ScsiPassThruExt.h>
//
// Higher versions will be used before lower, 0x10-0xffffffef is the version
@@ -28,6 +31,109 @@
//
#define MPT_SCSI_BINDING_VERSION 0x10
+//
+// Runtime Structures
+//
+
+#define MPT_SCSI_DEV_SIGNATURE SIGNATURE_32 ('M','P','T','S')
+typedef struct {
+ UINT32 Signature;
+ EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;
+ EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;
+} MPT_SCSI_DEV;
+
+#define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \
+ CR (PassThruPtr, MPT_SCSI_DEV, PassThru, MPT_SCSI_DEV_SIGNATURE)
+
+//
+// Ext SCSI Pass Thru
+//
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiPassThru (
+ IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
+ IN UINT8 *Target,
+ IN UINT64 Lun,
+ IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
+ IN EFI_EVENT Event OPTIONAL
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiGetNextTargetLun (
+ IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
+ IN OUT UINT8 **Target,
+ IN OUT UINT64 *Lun
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiGetNextTarget (
+ IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
+ IN OUT UINT8 **Target
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiBuildDevicePath (
+ IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
+ IN UINT8 *Target,
+ IN UINT64 Lun,
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiGetTargetLun (
+ IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ OUT UINT8 **Target,
+ OUT UINT64 *Lun
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiResetChannel (
+ IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+MptScsiResetTargetLun (
+ IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
+ IN UINT8 *Target,
+ IN UINT64 Lun
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
//
// Driver Binding
//
@@ -96,7 +202,49 @@ MptScsiControllerStart (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
- return EFI_UNSUPPORTED;
+ EFI_STATUS Status;
+ MPT_SCSI_DEV *Dev;
+
+ Dev = AllocateZeroPool (sizeof (*Dev));
+ if (Dev == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Dev->Signature = MPT_SCSI_DEV_SIGNATURE;
+
+ //
+ // Host adapter channel, doesn't exist
+ //
+ Dev->PassThruMode.AdapterId = MAX_UINT32;
+ Dev->PassThruMode.Attributes =
+ EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL
+ | EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL;
+
+ Dev->PassThru.Mode = &Dev->PassThruMode;
+ Dev->PassThru.PassThru = &MptScsiPassThru;
+ Dev->PassThru.GetNextTargetLun = &MptScsiGetNextTargetLun;
+ Dev->PassThru.BuildDevicePath = &MptScsiBuildDevicePath;
+ Dev->PassThru.GetTargetLun = &MptScsiGetTargetLun;
+ Dev->PassThru.ResetChannel = &MptScsiResetChannel;
+ Dev->PassThru.ResetTargetLun = &MptScsiResetTargetLun;
+ Dev->PassThru.GetNextTarget = &MptScsiGetNextTarget;
+
+ Status = gBS->InstallProtocolInterface (
+ &ControllerHandle,
+ &gEfiExtScsiPassThruProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &Dev->PassThru
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+Done:
+ if (EFI_ERROR (Status)) {
+ FreePool (Dev);
+ }
+
+ return Status;
}
STATIC
@@ -109,7 +257,33 @@ MptScsiControllerStop (
IN EFI_HANDLE *ChildHandleBuffer
)
{
- return EFI_UNSUPPORTED;
+ EFI_STATUS Status;
+ EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru;
+ MPT_SCSI_DEV *Dev;
+
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiExtScsiPassThruProtocolGuid,
+ (VOID **)&PassThru,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL // Lookup only
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Dev = MPT_SCSI_FROM_PASS_THRU (PassThru);
+
+ gBS->UninstallProtocolInterface (
+ ControllerHandle,
+ &gEfiExtScsiPassThruProtocolGuid,
+ &Dev->PassThru
+ );
+
+ FreePool (Dev);
+
+ return Status;
}
STATIC
diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
index dc3795c867..1cb5df4233 100644
--- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
+++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
@@ -30,10 +30,13 @@
OvmfPkg/OvmfPkg.dec
[LibraryClasses]
+ BaseMemoryLib
DebugLib
+ MemoryAllocationLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib
[Protocols]
- gEfiPciIoProtocolGuid ## TO_START
+ gEfiPciIoProtocolGuid ## TO_START
+ gEfiExtScsiPassThruProtocolGuid ## BY_START
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 05/13] OvmfPkg/MptScsiDxe: Install stubbed EXT_SCSI_PASS_THRU
2020-02-26 16:41 ` [PATCH v2 05/13] OvmfPkg/MptScsiDxe: Install stubbed EXT_SCSI_PASS_THRU Nikita Leshenko
@ 2020-02-28 8:35 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 8:35 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> Support dynamic insertion and removal of the protocol
>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Aaron Young <aaron.young@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> ---
> OvmfPkg/MptScsiDxe/MptScsi.c | 178 +++++++++++++++++++++++++++++-
> OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 5 +-
> 2 files changed, 180 insertions(+), 3 deletions(-)
>
> diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
> index 6dc6257eba..b8eabfb23c 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsi.c
> +++ b/OvmfPkg/MptScsiDxe/MptScsi.c
> @@ -17,10 +17,13 @@
>
> #include <IndustryStandard/Pci.h>
> #include <IndustryStandard/FusionMptScsi.h>
> +#include <Library/BaseMemoryLib.h>
> #include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h>
> #include <Library/UefiBootServicesTableLib.h>
> #include <Library/UefiLib.h>
> #include <Protocol/PciIo.h>
> +#include <Protocol/ScsiPassThruExt.h>
>
> //
> // Higher versions will be used before lower, 0x10-0xffffffef is the version
> @@ -28,6 +31,109 @@
> //
> #define MPT_SCSI_BINDING_VERSION 0x10
>
> +//
> +// Runtime Structures
> +//
> +
> +#define MPT_SCSI_DEV_SIGNATURE SIGNATURE_32 ('M','P','T','S')
> +typedef struct {
> + UINT32 Signature;
> + EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;
> + EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;
> +} MPT_SCSI_DEV;
> +
> +#define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \
> + CR (PassThruPtr, MPT_SCSI_DEV, PassThru, MPT_SCSI_DEV_SIGNATURE)
> +
> +//
> +// Ext SCSI Pass Thru
> +//
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +MptScsiPassThru (
> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
> + IN UINT8 *Target,
> + IN UINT64 Lun,
> + IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
> + IN EFI_EVENT Event OPTIONAL
> + )
> +{
> + return EFI_UNSUPPORTED;
> +}
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +MptScsiGetNextTargetLun (
> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
> + IN OUT UINT8 **Target,
> + IN OUT UINT64 *Lun
> + )
> +{
> + return EFI_UNSUPPORTED;
> +}
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +MptScsiGetNextTarget (
> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
> + IN OUT UINT8 **Target
> + )
> +{
> + return EFI_UNSUPPORTED;
> +}
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +MptScsiBuildDevicePath (
> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
> + IN UINT8 *Target,
> + IN UINT64 Lun,
> + IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
> + )
> +{
> + return EFI_UNSUPPORTED;
> +}
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +MptScsiGetTargetLun (
> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
> + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
> + OUT UINT8 **Target,
> + OUT UINT64 *Lun
> + )
> +{
> + return EFI_UNSUPPORTED;
> +}
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +MptScsiResetChannel (
> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
> + )
> +{
> + return EFI_UNSUPPORTED;
> +}
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +MptScsiResetTargetLun (
> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
> + IN UINT8 *Target,
> + IN UINT64 Lun
> + )
> +{
> + return EFI_UNSUPPORTED;
> +}
> +
> //
> // Driver Binding
> //
> @@ -96,7 +202,49 @@ MptScsiControllerStart (
> IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
> )
> {
> - return EFI_UNSUPPORTED;
> + EFI_STATUS Status;
> + MPT_SCSI_DEV *Dev;
> +
> + Dev = AllocateZeroPool (sizeof (*Dev));
> + if (Dev == NULL) {
> + return EFI_OUT_OF_RESOURCES;
> + }
> +
> + Dev->Signature = MPT_SCSI_DEV_SIGNATURE;
> +
> + //
> + // Host adapter channel, doesn't exist
> + //
> + Dev->PassThruMode.AdapterId = MAX_UINT32;
> + Dev->PassThruMode.Attributes =
> + EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL
> + | EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL;
> +
> + Dev->PassThru.Mode = &Dev->PassThruMode;
> + Dev->PassThru.PassThru = &MptScsiPassThru;
> + Dev->PassThru.GetNextTargetLun = &MptScsiGetNextTargetLun;
> + Dev->PassThru.BuildDevicePath = &MptScsiBuildDevicePath;
> + Dev->PassThru.GetTargetLun = &MptScsiGetTargetLun;
> + Dev->PassThru.ResetChannel = &MptScsiResetChannel;
> + Dev->PassThru.ResetTargetLun = &MptScsiResetTargetLun;
> + Dev->PassThru.GetNextTarget = &MptScsiGetNextTarget;
> +
> + Status = gBS->InstallProtocolInterface (
> + &ControllerHandle,
> + &gEfiExtScsiPassThruProtocolGuid,
> + EFI_NATIVE_INTERFACE,
> + &Dev->PassThru
> + );
> + if (EFI_ERROR (Status)) {
> + goto Done;
> + }
> +
> +Done:
> + if (EFI_ERROR (Status)) {
> + FreePool (Dev);
> + }
> +
> + return Status;
> }
>
> STATIC
> @@ -109,7 +257,33 @@ MptScsiControllerStop (
> IN EFI_HANDLE *ChildHandleBuffer
> )
> {
> - return EFI_UNSUPPORTED;
> + EFI_STATUS Status;
> + EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru;
> + MPT_SCSI_DEV *Dev;
> +
> + Status = gBS->OpenProtocol (
> + ControllerHandle,
> + &gEfiExtScsiPassThruProtocolGuid,
> + (VOID **)&PassThru,
> + This->DriverBindingHandle,
> + ControllerHandle,
> + EFI_OPEN_PROTOCOL_GET_PROTOCOL // Lookup only
> + );
> + if (EFI_ERROR (Status)) {
> + return Status;
> + }
> +
> + Dev = MPT_SCSI_FROM_PASS_THRU (PassThru);
> +
> + gBS->UninstallProtocolInterface (
> + ControllerHandle,
> + &gEfiExtScsiPassThruProtocolGuid,
> + &Dev->PassThru
> + );
(1) I think it's reasonable to assume that this will always succeed, but
please at least assign the retval to Status, and then follow up with an
ASSERT_EFI_ERROR(), before proceeding to the FreePool() below.
With this fixed:
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
> +
> + FreePool (Dev);
> +
> + return Status;
> }
>
> STATIC
> diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
> index dc3795c867..1cb5df4233 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
> +++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
> @@ -30,10 +30,13 @@
> OvmfPkg/OvmfPkg.dec
>
> [LibraryClasses]
> + BaseMemoryLib
> DebugLib
> + MemoryAllocationLib
> UefiBootServicesTableLib
> UefiDriverEntryPoint
> UefiLib
>
> [Protocols]
> - gEfiPciIoProtocolGuid ## TO_START
> + gEfiPciIoProtocolGuid ## TO_START
> + gEfiExtScsiPassThruProtocolGuid ## BY_START
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 06/13] OvmfPkg/MptScsiDxe: Report one Target and one LUN
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (4 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 05/13] OvmfPkg/MptScsiDxe: Install stubbed EXT_SCSI_PASS_THRU Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-28 8:41 ` Laszlo Ersek
2020-02-26 16:41 ` [PATCH v2 07/13] OvmfPkg/MptScsiDxe: Build DevicePath for discovered devices Nikita Leshenko
` (8 subsequent siblings)
14 siblings, 1 reply; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
Support for multiple targets will be implemented in a later commit in
this series.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index b8eabfb23c..76f0515b52 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -63,6 +63,21 @@ MptScsiPassThru (
return EFI_UNSUPPORTED;
}
+STATIC
+BOOLEAN
+IsTargetInitialized (
+ IN UINT8 *Target
+ )
+{
+ int i;
+ for (i = 0; i < TARGET_MAX_BYTES; ++i) {
+ if (Target[i] != 0xFF) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
STATIC
EFI_STATUS
EFIAPI
@@ -72,7 +87,16 @@ MptScsiGetNextTargetLun (
IN OUT UINT64 *Lun
)
{
- return EFI_UNSUPPORTED;
+ //
+ // Currently support only target 0 LUN 0, so hardcode it
+ //
+ if (!IsTargetInitialized (*Target)) {
+ **Target = 0;
+ *Lun = 0;
+ return EFI_SUCCESS;
+ } else {
+ return EFI_NOT_FOUND;
+ }
}
STATIC
@@ -83,7 +107,15 @@ MptScsiGetNextTarget (
IN OUT UINT8 **Target
)
{
- return EFI_UNSUPPORTED;
+ //
+ // Currently support only target 0 LUN 0, so hardcode it
+ //
+ if (!IsTargetInitialized (*Target)) {
+ **Target = 0;
+ return EFI_SUCCESS;
+ } else {
+ return EFI_NOT_FOUND;
+ }
}
STATIC
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 06/13] OvmfPkg/MptScsiDxe: Report one Target and one LUN
2020-02-26 16:41 ` [PATCH v2 06/13] OvmfPkg/MptScsiDxe: Report one Target and one LUN Nikita Leshenko
@ 2020-02-28 8:41 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 8:41 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> Support for multiple targets will be implemented in a later commit in
> this series.
>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Aaron Young <aaron.young@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> ---
> OvmfPkg/MptScsiDxe/MptScsi.c | 36 ++++++++++++++++++++++++++++++++++--
> 1 file changed, 34 insertions(+), 2 deletions(-)
>
> diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
> index b8eabfb23c..76f0515b52 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsi.c
> +++ b/OvmfPkg/MptScsiDxe/MptScsi.c
> @@ -63,6 +63,21 @@ MptScsiPassThru (
> return EFI_UNSUPPORTED;
> }
>
> +STATIC
> +BOOLEAN
> +IsTargetInitialized (
> + IN UINT8 *Target
> + )
> +{
> + int i;
(1) Please replace this variable with:
UINTN Idx;
and add an empty line after it.
With this fixed:
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks,
Laszlo
> + for (i = 0; i < TARGET_MAX_BYTES; ++i) {
> + if (Target[i] != 0xFF) {
> + return TRUE;
> + }
> + }
> + return FALSE;
> +}
> +
> STATIC
> EFI_STATUS
> EFIAPI
> @@ -72,7 +87,16 @@ MptScsiGetNextTargetLun (
> IN OUT UINT64 *Lun
> )
> {
> - return EFI_UNSUPPORTED;
> + //
> + // Currently support only target 0 LUN 0, so hardcode it
> + //
> + if (!IsTargetInitialized (*Target)) {
> + **Target = 0;
> + *Lun = 0;
> + return EFI_SUCCESS;
> + } else {
> + return EFI_NOT_FOUND;
> + }
> }
>
> STATIC
> @@ -83,7 +107,15 @@ MptScsiGetNextTarget (
> IN OUT UINT8 **Target
> )
> {
> - return EFI_UNSUPPORTED;
> + //
> + // Currently support only target 0 LUN 0, so hardcode it
> + //
> + if (!IsTargetInitialized (*Target)) {
> + **Target = 0;
> + return EFI_SUCCESS;
> + } else {
> + return EFI_NOT_FOUND;
> + }
> }
>
> STATIC
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 07/13] OvmfPkg/MptScsiDxe: Build DevicePath for discovered devices
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (5 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 06/13] OvmfPkg/MptScsiDxe: Report one Target and one LUN Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-28 9:03 ` Laszlo Ersek
2020-02-26 16:41 ` [PATCH v2 08/13] OvmfPkg/MptScsiDxe: Implement GetTargetLun Nikita Leshenko
` (7 subsequent siblings)
14 siblings, 1 reply; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
Used to identify the individual disks in the hardware tree
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 76f0515b52..593cf30f6b 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -128,7 +128,22 @@ MptScsiBuildDevicePath (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
)
{
- return EFI_UNSUPPORTED;
+ SCSI_DEVICE_PATH *ScsiDevicePath;
+
+ ScsiDevicePath = AllocateZeroPool (sizeof (*ScsiDevicePath));
+ if (ScsiDevicePath == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ ScsiDevicePath->Header.Type = MESSAGING_DEVICE_PATH;
+ ScsiDevicePath->Header.SubType = MSG_SCSI_DP;
+ ScsiDevicePath->Header.Length[0] = (UINT8)sizeof (*ScsiDevicePath);
+ ScsiDevicePath->Header.Length[1] = (UINT8)sizeof (*ScsiDevicePath) >> 8;
+ ScsiDevicePath->Pun = *Target;
+ ScsiDevicePath->Lun = (UINT16)Lun;
+
+ *DevicePath = &ScsiDevicePath->Header;
+ return EFI_SUCCESS;
}
STATIC
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 07/13] OvmfPkg/MptScsiDxe: Build DevicePath for discovered devices
2020-02-26 16:41 ` [PATCH v2 07/13] OvmfPkg/MptScsiDxe: Build DevicePath for discovered devices Nikita Leshenko
@ 2020-02-28 9:03 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 9:03 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> Used to identify the individual disks in the hardware tree
>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Aaron Young <aaron.young@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> ---
> OvmfPkg/MptScsiDxe/MptScsi.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
> index 76f0515b52..593cf30f6b 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsi.c
> +++ b/OvmfPkg/MptScsiDxe/MptScsi.c
> @@ -128,7 +128,22 @@ MptScsiBuildDevicePath (
> IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
> )
> {
> - return EFI_UNSUPPORTED;
> + SCSI_DEVICE_PATH *ScsiDevicePath;
> +
> + ScsiDevicePath = AllocateZeroPool (sizeof (*ScsiDevicePath));
> + if (ScsiDevicePath == NULL) {
> + return EFI_OUT_OF_RESOURCES;
> + }
> +
> + ScsiDevicePath->Header.Type = MESSAGING_DEVICE_PATH;
> + ScsiDevicePath->Header.SubType = MSG_SCSI_DP;
> + ScsiDevicePath->Header.Length[0] = (UINT8)sizeof (*ScsiDevicePath);
> + ScsiDevicePath->Header.Length[1] = (UINT8)sizeof (*ScsiDevicePath) >> 8;
(1) This does not cause ill behavior in practice, but the value makes no
sense. You are first casting the result of the sizeof operator to UINT8,
and then right-shifting that by 8 bits. That is guaranteed to produce
zero, regardless of what sizeof returns. You should use
(UINT8)(sizeof (*ScsiDevicePath) >> 8)
> + ScsiDevicePath->Pun = *Target;
(2) Aha, OK. I was a bit surprised by the previous patch, but it is
certainly valid. You want to use target identifiers that are all 0xFF
bytes, except the very first byte.
That's fine (and "PcdMptScsiMaxTargetLimit" is also consistent with
that, having type UINT8), but please announce this decision more
visibly. Please append:
----
This driver uses the first byte (out of TARGET_MAX_BYTES) in Target IDs
for representing the target, the other bytes are always 0xFF in Target IDs.
----
to the commit messages of:
- OvmfPkg/MptScsiDxe: Report one Target and one LUN
- OvmfPkg/MptScsiDxe: Build DevicePath for discovered devices
- OvmfPkg/MptScsiDxe: Implement GetTargetLun
- OvmfPkg/MptScsiDxe: Report multiple targets
> + ScsiDevicePath->Lun = (UINT16)Lun;
This funcion is missing the target / lun validity check at the top (the
UEFI spec describes that related to the EFI_NOT_FOUND return status --
"The SCSI devices specified by Target and Lun does not exist on the
SCSI channel").
My understanding is that the driver only supports (*Target=0 && Lun=0)
at this point.
(3) So please express that at the start of the function. (Return
EFI_NOT_FOUND otherwise.)
(4) And, in patch "OvmfPkg/MptScsiDxe: Report multiple targets", please
also update this function -- MptScsiBuildDevicePath() --, so that it
accept (*Target) values up to and including "Dev->MaxTarget".
> +
> + *DevicePath = &ScsiDevicePath->Header;
> + return EFI_SUCCESS;
> }
>
> STATIC
>
Thanks
Laszlo
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 08/13] OvmfPkg/MptScsiDxe: Implement GetTargetLun
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (6 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 07/13] OvmfPkg/MptScsiDxe: Build DevicePath for discovered devices Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-28 9:16 ` Laszlo Ersek
2020-02-26 16:41 ` [PATCH v2 09/13] OvmfPkg/MptScsiDxe: Open PciIo protocol for later use Nikita Leshenko
` (6 subsequent siblings)
14 siblings, 1 reply; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 593cf30f6b..d72af2b3f7 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -156,7 +156,18 @@ MptScsiGetTargetLun (
OUT UINT64 *Lun
)
{
- return EFI_UNSUPPORTED;
+ SCSI_DEVICE_PATH *ScsiDevicePath;
+
+ if (DevicePath->Type != MESSAGING_DEVICE_PATH ||
+ DevicePath->SubType != MSG_SCSI_DP) {
+ return EFI_UNSUPPORTED;
+ }
+
+ ScsiDevicePath = (SCSI_DEVICE_PATH *)DevicePath;
+ **Target = ScsiDevicePath->Pun;
+ *Lun = ScsiDevicePath->Lun;
+
+ return EFI_SUCCESS;
}
STATIC
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 08/13] OvmfPkg/MptScsiDxe: Implement GetTargetLun
2020-02-26 16:41 ` [PATCH v2 08/13] OvmfPkg/MptScsiDxe: Implement GetTargetLun Nikita Leshenko
@ 2020-02-28 9:16 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 9:16 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Aaron Young <aaron.young@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
(1) Please add at least one sentence to the commit message body.
> ---
> OvmfPkg/MptScsiDxe/MptScsi.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
> index 593cf30f6b..d72af2b3f7 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsi.c
> +++ b/OvmfPkg/MptScsiDxe/MptScsi.c
> @@ -156,7 +156,18 @@ MptScsiGetTargetLun (
> OUT UINT64 *Lun
> )
> {
> - return EFI_UNSUPPORTED;
> + SCSI_DEVICE_PATH *ScsiDevicePath;
> +
> + if (DevicePath->Type != MESSAGING_DEVICE_PATH ||
> + DevicePath->SubType != MSG_SCSI_DP) {
> + return EFI_UNSUPPORTED;
> + }
> +
> + ScsiDevicePath = (SCSI_DEVICE_PATH *)DevicePath;
> + **Target = ScsiDevicePath->Pun;
> + *Lun = ScsiDevicePath->Lun;
> +
> + return EFI_SUCCESS;
> }
>
> STATIC
>
(2) Same comment with regard to EFI_NOT_FOUND as under the previous patch:
- in this patch, you should return EFI_NOT_FOUND unless both **Target
and *Lun end up being 0
- in patch "OvmfPkg/MptScsiDxe: Report multiple targets", the **Target
check should be relaxed to permit values up to "Dev->MaxTarget".
Thanks
Laszlo
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 09/13] OvmfPkg/MptScsiDxe: Open PciIo protocol for later use
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (7 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 08/13] OvmfPkg/MptScsiDxe: Implement GetTargetLun Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-28 9:50 ` Laszlo Ersek
2020-02-26 16:41 ` [PATCH v2 10/13] OvmfPkg/MptScsiDxe: Set and restore PCI attributes Nikita Leshenko
` (5 subsequent siblings)
14 siblings, 1 reply; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
This will give us an exclusive access to the PciIo of this device
after it was started and until is will be stopped.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index d72af2b3f7..22001da763 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -40,6 +40,7 @@ typedef struct {
UINT32 Signature;
EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;
EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;
+ EFI_PCI_IO_PROTOCOL *PciIo;
} MPT_SCSI_DEV;
#define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \
@@ -270,6 +271,18 @@ MptScsiControllerStart (
Dev->Signature = MPT_SCSI_DEV_SIGNATURE;
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiPciIoProtocolGuid,
+ (VOID **)&Dev->PciIo,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
//
// Host adapter channel, doesn't exist
//
@@ -299,6 +312,15 @@ MptScsiControllerStart (
Done:
if (EFI_ERROR (Status)) {
+ if (Dev->PciIo) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiPciIoProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+ }
+
FreePool (Dev);
}
@@ -339,6 +361,13 @@ MptScsiControllerStop (
&Dev->PassThru
);
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiPciIoProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+
FreePool (Dev);
return Status;
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 09/13] OvmfPkg/MptScsiDxe: Open PciIo protocol for later use
2020-02-26 16:41 ` [PATCH v2 09/13] OvmfPkg/MptScsiDxe: Open PciIo protocol for later use Nikita Leshenko
@ 2020-02-28 9:50 ` Laszlo Ersek
2020-02-28 9:53 ` Laszlo Ersek
0 siblings, 1 reply; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 9:50 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> This will give us an exclusive access to the PciIo of this device
> after it was started and until is will be stopped.
(1) s/is/it/
>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reviewed-by: Aaron Young <aaron.young@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> ---
> OvmfPkg/MptScsiDxe/MptScsi.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
> index d72af2b3f7..22001da763 100644
> --- a/OvmfPkg/MptScsiDxe/MptScsi.c
> +++ b/OvmfPkg/MptScsiDxe/MptScsi.c
> @@ -40,6 +40,7 @@ typedef struct {
> UINT32 Signature;
> EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;
> EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;
> + EFI_PCI_IO_PROTOCOL *PciIo;
> } MPT_SCSI_DEV;
>
> #define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \
> @@ -270,6 +271,18 @@ MptScsiControllerStart (
>
> Dev->Signature = MPT_SCSI_DEV_SIGNATURE;
>
> + Status = gBS->OpenProtocol (
> + ControllerHandle,
> + &gEfiPciIoProtocolGuid,
> + (VOID **)&Dev->PciIo,
> + This->DriverBindingHandle,
> + ControllerHandle,
> + EFI_OPEN_PROTOCOL_BY_DRIVER
> + );
> + if (EFI_ERROR (Status)) {
> + goto Done;
> + }
> +
> //
> // Host adapter channel, doesn't exist
> //
> @@ -299,6 +312,15 @@ MptScsiControllerStart (
>
> Done:
> if (EFI_ERROR (Status)) {
> + if (Dev->PciIo) {
> + gBS->CloseProtocol (
> + ControllerHandle,
> + &gEfiPciIoProtocolGuid,
> + This->DriverBindingHandle,
> + ControllerHandle
> + );
> + }
> +
> FreePool (Dev);
> }
>
I don't like where this is going.
It is bad style to mix:
- "goto" statements that jump to the end of the function "epilogue"
- with *conditional* releasing of resources in the epilogue
*unless*:
(a) some of those resources are indeed optional, or
(b) we intentionally reuse the epilogue for both success and error (that
is, when the epilogue releases *temporary* resources)
In this case, neither excuse (a) or excuse (b) apply, so please don't do
this.
I was a bit concerned at patch "OvmfPkg/MptScsiDxe: Install stubbed
EXT_SCSI_PASS_THRU" already, seeing how you added an EFI_ERROR() check
under the "Done" label. And this patch confirms (and the final state of
the function proves) the direction we're headed, and it's not good.
Mixing goto with conditionalized release is the most difficult approach
to reason about. With nested "ifs", the explicit block scopes help us
reason about lifecycles. With a cascade of labels, the label names help
us reason about lifecycles. But if we have just one label, that gives us
neither useful label names, nor scoping help, and we're down to
awkwardly checking whether each individual resource should be released
or not. This forces the reviewer to think about a combinatorial
explosion of *seemingly* possible states.
Either use nested "if"s *only* (no gotos), or use "goto"s exclusively
(multiple lables, no "if" nesting). Again, unless we have excuse (a) or
(b), but those don't apply now.
And, in edk2, we don't generally use nested "if"s, because identifiers
are long, so we don't want to waste horizontal space on deep
indentation. So please stick with the "goto"s.
So, in the final state of this function, the epilogue should reflect the
Stop() function almost verbatim, except you'd have different labels (a
cascade of labels) placed between the individual actions. The cascade
(releasing of resources) should occur in reverse order of allocation.
And, instead of introducing awkward BOOLEAN variables like
"PciAttributesChanged", the context (jump origin, and jump target) would
express what resources need to be released.
In particular, in patch "OvmfPkg/MptScsiDxe: Install stubbed
EXT_SCSI_PASS_THRU", the pattern should be laid out like this:
-----------
Status = gBS->InstallProtocolInterface (...);
if (EFI_ERROR (Status)) {
goto FreeDev;
}
return EFI_SUCCESS;
FreeDev:
FreePool (Dev);
return Status;
-----------
and then the rest of the patches should build upon that -- introduce new
labels always at the top of the existent "stack" of labels.
> @@ -339,6 +361,13 @@ MptScsiControllerStop (
> &Dev->PassThru
> );
>
> + gBS->CloseProtocol (
> + ControllerHandle,
> + &gEfiPciIoProtocolGuid,
> + This->DriverBindingHandle,
> + ControllerHandle
> + );
> +
> FreePool (Dev);
>
> return Status;
>
This hunk is good.
Thanks
Laszlo
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 09/13] OvmfPkg/MptScsiDxe: Open PciIo protocol for later use
2020-02-28 9:50 ` Laszlo Ersek
@ 2020-02-28 9:53 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 9:53 UTC (permalink / raw)
To: Nikita Leshenko, devel
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/28/20 10:50, Laszlo Ersek wrote:
> In particular, in patch "OvmfPkg/MptScsiDxe: Install stubbed
> EXT_SCSI_PASS_THRU", the pattern should be laid out like this:
>
> -----------
> Status = gBS->InstallProtocolInterface (...);
> if (EFI_ERROR (Status)) {
> goto FreeDev;
> }
> return EFI_SUCCESS;
>
> FreeDev:
> FreePool (Dev);
>
> return Status;
> -----------
>
> and then the rest of the patches should build upon that -- introduce new
> labels always at the top of the existent "stack" of labels.
If it's OK with you, I'd like to stop reviewing version 2 at this point.
I'm going to be tripped up continuously by the mixing of goto +
conditional release.
I'll make an effort to review v3 reasonably quickly once you post it.
Thanks,
Laszlo
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 10/13] OvmfPkg/MptScsiDxe: Set and restore PCI attributes
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (8 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 09/13] OvmfPkg/MptScsiDxe: Open PciIo protocol for later use Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-26 16:41 ` [PATCH v2 11/13] OvmfPkg/MptScsiDxe: Initialize hardware Nikita Leshenko
` (4 subsequent siblings)
14 siblings, 0 replies; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
Enable the IO Space and Bus Mastering and restore the original values
when the device is stopped. This is a standard procedure in PCI
drivers.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 44 ++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 22001da763..f5f774e431 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -41,6 +41,7 @@ typedef struct {
EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;
EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;
EFI_PCI_IO_PROTOCOL *PciIo;
+ UINT64 OriginalPciAttributes;
} MPT_SCSI_DEV;
#define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \
@@ -263,6 +264,7 @@ MptScsiControllerStart (
{
EFI_STATUS Status;
MPT_SCSI_DEV *Dev;
+ BOOLEAN PciAttributesChanged;
Dev = AllocateZeroPool (sizeof (*Dev));
if (Dev == NULL) {
@@ -270,6 +272,7 @@ MptScsiControllerStart (
}
Dev->Signature = MPT_SCSI_DEV_SIGNATURE;
+ PciAttributesChanged = FALSE;
Status = gBS->OpenProtocol (
ControllerHandle,
@@ -283,6 +286,31 @@ MptScsiControllerStart (
goto Done;
}
+ Status = Dev->PciIo->Attributes (
+ Dev->PciIo,
+ EfiPciIoAttributeOperationGet,
+ 0,
+ &Dev->OriginalPciAttributes
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ //
+ // Enable I/O Space & Bus-Mastering
+ //
+ Status = Dev->PciIo->Attributes (
+ Dev->PciIo,
+ EfiPciIoAttributeOperationEnable,
+ (EFI_PCI_IO_ATTRIBUTE_IO |
+ EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+ PciAttributesChanged = TRUE;
+
//
// Host adapter channel, doesn't exist
//
@@ -312,6 +340,15 @@ MptScsiControllerStart (
Done:
if (EFI_ERROR (Status)) {
+ if (PciAttributesChanged) {
+ Dev->PciIo->Attributes (
+ Dev->PciIo,
+ EfiPciIoAttributeOperationEnable,
+ Dev->OriginalPciAttributes,
+ NULL
+ );
+ }
+
if (Dev->PciIo) {
gBS->CloseProtocol (
ControllerHandle,
@@ -361,6 +398,13 @@ MptScsiControllerStop (
&Dev->PassThru
);
+ Dev->PciIo->Attributes (
+ Dev->PciIo,
+ EfiPciIoAttributeOperationEnable,
+ Dev->OriginalPciAttributes,
+ NULL
+ );
+
gBS->CloseProtocol (
ControllerHandle,
&gEfiPciIoProtocolGuid,
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 11/13] OvmfPkg/MptScsiDxe: Initialize hardware
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (9 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 10/13] OvmfPkg/MptScsiDxe: Set and restore PCI attributes Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-26 16:41 ` [PATCH v2 12/13] OvmfPkg/MptScsiDxe: Implement the PassThru method Nikita Leshenko
` (3 subsequent siblings)
14 siblings, 0 replies; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
Reset and send the IO controller initialization request. The reply is
read back to complete the doorbell function but it isn't useful to us
because it doesn't contain relevant data or status codes.
See "LSI53C1030 PCI-X to Dual Channel Ultra320 SCSI Multifunction
Controller" technical manual for more information.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
.../Include/IndustryStandard/FusionMptScsi.h | 115 ++++++++++++
OvmfPkg/MptScsiDxe/MptScsi.c | 168 ++++++++++++++++++
2 files changed, 283 insertions(+)
diff --git a/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
index 3b911bdb5b..20f535a2c8 100644
--- a/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
+++ b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
@@ -22,3 +22,118 @@
#define LSI_53C1030_PCI_DEVICE_ID 0x0030
#define LSI_SAS1068_PCI_DEVICE_ID 0x0054
#define LSI_SAS1068E_PCI_DEVICE_ID 0x0058
+
+#define MPT_REG_DOORBELL 0x00
+#define MPT_REG_WRITE_SEQ 0x04
+#define MPT_REG_HOST_DIAG 0x08
+#define MPT_REG_TEST 0x0c
+#define MPT_REG_DIAG_DATA 0x10
+#define MPT_REG_DIAG_ADDR 0x14
+#define MPT_REG_ISTATUS 0x30
+#define MPT_REG_IMASK 0x34
+#define MPT_REG_REQ_Q 0x40
+#define MPT_REG_REP_Q 0x44
+
+#define MPT_DOORBELL_RESET 0x40
+#define MPT_DOORBELL_HANDSHAKE 0x42
+
+#define MPT_IMASK_DOORBELL 0x01
+#define MPT_IMASK_REPLY 0x08
+
+#define MPT_MESSAGE_HDR_FUNCTION_SCSI_IO_REQUEST 0x00
+#define MPT_MESSAGE_HDR_FUNCTION_IOC_INIT 0x02
+
+#define MPT_SG_ENTRY_TYPE_SIMPLE 0x01
+
+#define MPT_IOC_WHOINIT_ROM_BIOS 0x02
+
+//
+// Device structures
+//
+
+typedef struct {
+#pragma pack (1)
+ struct {
+ UINT8 WhoInit;
+ UINT8 Reserved1;
+ UINT8 ChainOffset;
+ UINT8 Function;
+ UINT8 Flags;
+ UINT8 MaxDevices;
+ UINT8 MaxBuses;
+ UINT8 MessageFlags;
+ UINT32 MessageContext;
+ UINT16 ReplyFrameSize;
+ UINT16 Reserved2;
+ UINT32 HostMfaHighAddr;
+ UINT32 SenseBufferHighAddr;
+ } Data;
+#pragma pack ()
+ UINT64 Uint64; // 8 byte alignment required by HW
+} MPT_IO_CONTROLLER_INIT_REQUEST;
+#pragma pack (1)
+typedef struct {
+ UINT8 WhoInit;
+ UINT8 Reserved1;
+ UINT8 MessageLength;
+ UINT8 Function;
+ UINT8 Flags;
+ UINT8 MaxDevices;
+ UINT8 MaxBuses;
+ UINT8 MessageFlags;
+ UINT32 MessageContext;
+ UINT16 Reserved2;
+ UINT16 IOCStatus;
+ UINT32 IOCLogInfo;
+} MPT_IO_CONTROLLER_INIT_REPLY;
+typedef struct {
+ UINT8 TargetID;
+ UINT8 Bus;
+ UINT8 ChainOffset;
+ UINT8 Function;
+ UINT8 CDBLength;
+ UINT8 SenseBufferLength;
+ UINT8 Reserved;
+ UINT8 MessageFlags;
+ UINT32 MessageContext;
+ UINT8 LUN[8];
+ UINT32 Control;
+ UINT8 CDB[16];
+ UINT32 DataLength;
+ UINT32 SenseBufferLowAddress;
+} MPT_SCSI_IO_REQUEST;
+typedef struct {
+ UINT32 Length: 24;
+ UINT32 EndOfList: 1;
+ UINT32 Is64BitAddress: 1;
+ UINT32 BufferContainsData: 1;
+ UINT32 LocalAddress: 1;
+ UINT32 ElementType: 2;
+ UINT32 EndOfBuffer: 1;
+ UINT32 LastElement: 1;
+ UINT64 DataBufferAddress;
+} MPT_SG_ENTRY_SIMPLE;
+#pragma pack ()
+typedef struct {
+#pragma pack (1)
+ struct {
+ UINT8 TargetID;
+ UINT8 Bus;
+ UINT8 MessageLength;
+ UINT8 Function;
+ UINT8 CDBLength;
+ UINT8 SenseBufferLength;
+ UINT8 Reserved;
+ UINT8 MessageFlags;
+ UINT32 MessageContext;
+ UINT8 SCSIStatus;
+ UINT8 SCSIState;
+ UINT16 IOCStatus;
+ UINT32 IOCLogInfo;
+ UINT32 TransferCount;
+ UINT32 SenseCount;
+ UINT32 ResponseInfo;
+ } Data;
+#pragma pack ()
+ UINT64 Uint64; // 8 byte alignment required by HW
+} MPT_SCSI_IO_ERROR_REPLY;
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index f5f774e431..4cb35046c4 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -47,6 +47,167 @@ typedef struct {
#define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \
CR (PassThruPtr, MPT_SCSI_DEV, PassThru, MPT_SCSI_DEV_SIGNATURE)
+//
+// Hardware functions
+//
+
+STATIC
+EFI_STATUS
+Out32 (
+ IN MPT_SCSI_DEV *Dev,
+ IN UINT32 Addr,
+ IN UINT32 Data
+ )
+{
+ return Dev->PciIo->Io.Write (
+ Dev->PciIo,
+ EfiPciIoWidthUint32,
+ 0, // BAR0
+ Addr,
+ 1,
+ &Data
+ );
+}
+
+STATIC
+EFI_STATUS
+In32 (
+ IN MPT_SCSI_DEV *Dev,
+ IN UINT32 Addr,
+ OUT UINT32 *Data
+ )
+{
+ return Dev->PciIo->Io.Read (
+ Dev->PciIo,
+ EfiPciIoWidthUint32,
+ 0, // BAR0
+ Addr,
+ 1,
+ Data
+ );
+}
+
+STATIC
+EFI_STATUS
+MptDoorbell (
+ IN MPT_SCSI_DEV *Dev,
+ IN UINT8 DoorbellFunc,
+ IN UINT8 DoorbellArg
+ )
+{
+ return Out32 (
+ Dev,
+ MPT_REG_DOORBELL,
+ (((UINT32)DoorbellFunc) << 24) | (DoorbellArg << 16)
+ );
+}
+
+STATIC
+EFI_STATUS
+MptScsiReset (
+ IN MPT_SCSI_DEV *Dev
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Reset hardware
+ //
+ Status = MptDoorbell (Dev, MPT_DOORBELL_RESET, 0);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ //
+ // Mask interrupts
+ //
+ Status = Out32 (Dev, MPT_REG_IMASK, MPT_IMASK_DOORBELL|MPT_IMASK_REPLY);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ //
+ // Clear interrupt status
+ //
+ Status = Out32 (Dev, MPT_REG_ISTATUS, 0);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MptScsiInit (
+ IN MPT_SCSI_DEV *Dev
+ )
+{
+ EFI_STATUS Status;
+ MPT_IO_CONTROLLER_INIT_REQUEST Req;
+ MPT_IO_CONTROLLER_INIT_REPLY Reply;
+ UINT8 *ReplyBytes;
+ UINT32 Reply32;
+
+ Status = MptScsiReset (Dev);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ ZeroMem (&Req, sizeof (Req));
+ ZeroMem (&Reply, sizeof (Reply));
+ Req.Data.WhoInit = MPT_IOC_WHOINIT_ROM_BIOS;
+ Req.Data.Function = MPT_MESSAGE_HDR_FUNCTION_IOC_INIT;
+ Req.Data.MaxDevices = 1;
+ Req.Data.MaxBuses = 1;
+ Req.Data.ReplyFrameSize = sizeof (MPT_SCSI_IO_ERROR_REPLY);
+
+ //
+ // Send controller init through doorbell
+ //
+ Status = MptDoorbell (
+ Dev,
+ MPT_DOORBELL_HANDSHAKE,
+ sizeof (Req) / sizeof (UINT32)
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ Status = Dev->PciIo->Io.Write (
+ Dev->PciIo,
+ EfiPciIoWidthFifoUint32,
+ 0,
+ MPT_REG_DOORBELL,
+ sizeof (Req) / sizeof (UINT32),
+ &Req
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Read reply through doorbell
+ // Each 32bit read produces 16bit of data
+ //
+ ReplyBytes = (UINT8 *)&Reply;
+ while (ReplyBytes != (UINT8 *)(&Reply + 1)) {
+ Status = In32 (Dev, MPT_REG_DOORBELL, &Reply32);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ CopyMem (ReplyBytes, &Reply32, sizeof (UINT16));
+ ReplyBytes += sizeof (UINT16);
+ }
+
+ //
+ // Clear interrupts generated by doorbell reply
+ //
+ Status = Out32 (Dev, MPT_REG_ISTATUS, 0);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
+
//
// Ext SCSI Pass Thru
//
@@ -311,6 +472,11 @@ MptScsiControllerStart (
}
PciAttributesChanged = TRUE;
+ Status = MptScsiInit (Dev);
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
//
// Host adapter channel, doesn't exist
//
@@ -398,6 +564,8 @@ MptScsiControllerStop (
&Dev->PassThru
);
+ MptScsiReset (Dev);
+
Dev->PciIo->Attributes (
Dev->PciIo,
EfiPciIoAttributeOperationEnable,
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 12/13] OvmfPkg/MptScsiDxe: Implement the PassThru method
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (10 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 11/13] OvmfPkg/MptScsiDxe: Initialize hardware Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-26 16:41 ` [PATCH v2 13/13] OvmfPkg/MptScsiDxe: Report multiple targets Nikita Leshenko
` (2 subsequent siblings)
14 siblings, 0 replies; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
Machines should be able to boot after this commit. Tested with different Linux
distributions (Ubuntu, CentOS) and different Windows versions (Windows 7,
Windows 10, Server 2016).
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
.../Include/IndustryStandard/FusionMptScsi.h | 17 +
OvmfPkg/MptScsiDxe/MptScsi.c | 335 +++++++++++++++++-
OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 3 +
OvmfPkg/OvmfPkg.dec | 3 +
4 files changed, 357 insertions(+), 1 deletion(-)
diff --git a/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
index 20f535a2c8..83aff3ea3f 100644
--- a/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
+++ b/OvmfPkg/Include/IndustryStandard/FusionMptScsi.h
@@ -47,6 +47,11 @@
#define MPT_IOC_WHOINIT_ROM_BIOS 0x02
+#define MPT_SCSIIO_REQUEST_CONTROL_TXDIR_WRITE (0x01 << 24)
+#define MPT_SCSIIO_REQUEST_CONTROL_TXDIR_READ (0x02 << 24)
+
+#define MPT_SCSI_IO_ERROR_IOCSTATUS_DEVICE_NOT_THERE 0x0043
+
//
// Device structures
//
@@ -106,6 +111,10 @@ typedef struct {
UINT32 Length: 24;
UINT32 EndOfList: 1;
UINT32 Is64BitAddress: 1;
+ //
+ // True when the buffer contains data to be transfered. Otherwise it's the
+ // destination buffer
+ //
UINT32 BufferContainsData: 1;
UINT32 LocalAddress: 1;
UINT32 ElementType: 2;
@@ -137,3 +146,11 @@ typedef struct {
#pragma pack ()
UINT64 Uint64; // 8 byte alignment required by HW
} MPT_SCSI_IO_ERROR_REPLY;
+
+typedef union {
+ struct {
+ MPT_SCSI_IO_REQUEST Header;
+ MPT_SG_ENTRY_SIMPLE Sg;
+ } Data;
+ UINT64 Uint64; // 8 byte alignment required by HW
+} MPT_SCSI_REQUEST_WITH_SG;
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 4cb35046c4..6c70112bbc 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -23,6 +23,7 @@
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/PciIo.h>
+#include <Protocol/PciRootBridgeIo.h>
#include <Protocol/ScsiPassThruExt.h>
//
@@ -35,6 +36,13 @@
// Runtime Structures
//
+typedef struct {
+ MPT_SCSI_IO_ERROR_REPLY IoErrorReply;
+ MPT_SCSI_REQUEST_WITH_SG IoRequest;
+ UINT8 Sense[MAX_UINT8];
+ UINT8 Data[0x2000];
+} MPT_SCSI_DMA_BUFFER;
+
#define MPT_SCSI_DEV_SIGNATURE SIGNATURE_32 ('M','P','T','S')
typedef struct {
UINT32 Signature;
@@ -42,11 +50,18 @@ typedef struct {
EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;
EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 OriginalPciAttributes;
+ UINT32 StallPerPollUsec;
+ MPT_SCSI_DMA_BUFFER *Dma;
+ EFI_PHYSICAL_ADDRESS DmaPhysical;
+ VOID *DmaMapping;
} MPT_SCSI_DEV;
#define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \
CR (PassThruPtr, MPT_SCSI_DEV, PassThru, MPT_SCSI_DEV_SIGNATURE)
+#define MPT_SCSI_DMA_ADDR(Dev, MemberName) \
+ (Dev->DmaPhysical + OFFSET_OF(MPT_SCSI_DMA_BUFFER, MemberName))
+
//
// Hardware functions
//
@@ -147,6 +162,8 @@ MptScsiInit (
UINT8 *ReplyBytes;
UINT32 Reply32;
+ Dev->StallPerPollUsec = PcdGet32 (PcdMptScsiStallPerPollUsec);
+
Status = MptScsiReset (Dev);
if (EFI_ERROR (Status)) {
return Status;
@@ -205,6 +222,220 @@ MptScsiInit (
return Status;
}
+ //
+ // Put one free reply frame on the reply queue, the hardware may use it to
+ // report an error to us.
+ //
+ Status = Out32 (Dev, MPT_REG_REP_Q, MPT_SCSI_DMA_ADDR (Dev, IoErrorReply));
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MptScsiPopulateRequest (
+ IN MPT_SCSI_DEV *Dev,
+ IN UINT8 Target,
+ IN UINT64 Lun,
+ IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
+ )
+{
+ MPT_SCSI_REQUEST_WITH_SG *Request;
+
+ Request = &Dev->Dma->IoRequest;
+
+ if (Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_BIDIRECTIONAL ||
+ Packet->CdbLength > sizeof (Request->Data.Header.CDB)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Target > 0 || Lun > 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Packet->InTransferLength > sizeof (Dev->Dma->Data)) {
+ Packet->InTransferLength = sizeof (Dev->Dma->Data);
+ return EFI_BAD_BUFFER_SIZE;
+ }
+ if (Packet->OutTransferLength > sizeof (Dev->Dma->Data)) {
+ Packet->OutTransferLength = sizeof (Dev->Dma->Data);
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ ZeroMem (Request, sizeof (*Request));
+ Request->Data.Header.TargetID = Target;
+ //
+ // It's 1 and not 0, for some reason...
+ //
+ Request->Data.Header.LUN[1] = Lun;
+ Request->Data.Header.Function = MPT_MESSAGE_HDR_FUNCTION_SCSI_IO_REQUEST;
+ Request->Data.Header.MessageContext = 1; // We handle one request at a time
+
+ Request->Data.Header.CDBLength = Packet->CdbLength;
+ CopyMem (Request->Data.Header.CDB, Packet->Cdb, Packet->CdbLength);
+
+ //
+ // SenseDataLength is UINT8, Sense[] is MAX_UINT8, so we can't overflow
+ //
+ ZeroMem (&Dev->Dma->Sense, Packet->SenseDataLength);
+ Request->Data.Header.SenseBufferLength = Packet->SenseDataLength;
+ Request->Data.Header.SenseBufferLowAddress = MPT_SCSI_DMA_ADDR (Dev, Sense);
+
+ Request->Data.Sg.EndOfList = 1;
+ Request->Data.Sg.EndOfBuffer = 1;
+ Request->Data.Sg.LastElement = 1;
+ Request->Data.Sg.ElementType = MPT_SG_ENTRY_TYPE_SIMPLE;
+ Request->Data.Sg.DataBufferAddress = MPT_SCSI_DMA_ADDR (Dev, Data);
+
+ switch (Packet->DataDirection)
+ {
+ case EFI_EXT_SCSI_DATA_DIRECTION_READ:
+ Request->Data.Header.DataLength = Packet->InTransferLength;
+ Request->Data.Sg.Length = Packet->InTransferLength;
+ Request->Data.Header.Control = MPT_SCSIIO_REQUEST_CONTROL_TXDIR_READ;
+ break;
+ case EFI_EXT_SCSI_DATA_DIRECTION_WRITE:
+ Request->Data.Header.DataLength = Packet->OutTransferLength;
+ Request->Data.Sg.Length = Packet->OutTransferLength;
+ Request->Data.Header.Control = MPT_SCSIIO_REQUEST_CONTROL_TXDIR_WRITE;
+
+ CopyMem (Dev->Dma->Data, Packet->OutDataBuffer, Packet->OutTransferLength);
+ Request->Data.Sg.BufferContainsData = 1;
+ break;
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MptScsiSendRequest (
+ IN MPT_SCSI_DEV *Dev,
+ IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Make sure Request is fully written
+ //
+ MemoryFence ();
+
+ Status = Out32 (Dev, MPT_REG_REQ_Q, MPT_SCSI_DMA_ADDR (Dev, IoRequest));
+ if (EFI_ERROR (Status)) {
+ //
+ // We couldn't enqueue the request, report it as an adapter error
+ //
+ Packet->InTransferLength = 0;
+ Packet->OutTransferLength = 0;
+ Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER;
+ Packet->TargetStatus = EFI_EXT_SCSI_STATUS_TARGET_GOOD;
+ Packet->SenseDataLength = 0;
+ return EFI_DEVICE_ERROR;
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MptScsiGetReply (
+ IN MPT_SCSI_DEV *Dev,
+ OUT UINT32 *Reply
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Istatus;
+ UINT32 EmptyReply;
+
+ for (;;) {
+ Status = In32 (Dev, MPT_REG_ISTATUS, &Istatus);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Interrupt raised
+ //
+ if (Istatus & MPT_IMASK_REPLY) {
+ break;
+ }
+
+ gBS->Stall (Dev->StallPerPollUsec);
+ }
+
+ Status = In32 (Dev, MPT_REG_REP_Q, Reply);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // The driver is supposed to fetch replies until 0xffffffff is returned, which
+ // will reset the interrupt status. We put only one request, so we expect the
+ // next read reply to be the last.
+ //
+ Status = In32 (Dev, MPT_REG_REP_Q, &EmptyReply);
+ if (EFI_ERROR (Status) || EmptyReply != MAX_UINT32) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MptScsiHandleReply (
+ IN MPT_SCSI_DEV *Dev,
+ IN UINT32 Reply,
+ OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
+ )
+{
+ EFI_STATUS Status;
+
+ CopyMem (Packet->SenseData, Dev->Dma->Sense, Packet->SenseDataLength);
+ if (Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_READ) {
+ CopyMem (Packet->InDataBuffer, Dev->Dma->Data, Packet->InTransferLength);
+ }
+
+ if (Reply == Dev->Dma->IoRequest.Data.Header.MessageContext) {
+ //
+ // Everything is good
+ //
+ Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OK;
+ Packet->TargetStatus = EFI_EXT_SCSI_STATUS_TARGET_GOOD;
+
+ } else if (Reply & (1 << 31)) {
+ DEBUG ((DEBUG_ERROR, "%a: request failed\n", __FUNCTION__));
+ //
+ // When reply MSB is set, it's an error frame.
+ //
+
+ switch (Dev->Dma->IoErrorReply.Data.IOCStatus) {
+ case MPT_SCSI_IO_ERROR_IOCSTATUS_DEVICE_NOT_THERE:
+ Packet->HostAdapterStatus =
+ EFI_EXT_SCSI_STATUS_HOST_ADAPTER_SELECTION_TIMEOUT;
+ break;
+ default:
+ Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER;
+ break;
+ }
+
+ //
+ // Resubmit the reply frame to the reply queue
+ //
+ Status = Out32 (Dev, MPT_REG_REP_Q, MPT_SCSI_DMA_ADDR (Dev, IoErrorReply));
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ } else {
+ DEBUG ((DEBUG_ERROR, "%a: unexpected reply\n", __FUNCTION__));
+ return EFI_DEVICE_ERROR;
+ }
+
return EFI_SUCCESS;
}
@@ -223,7 +454,49 @@ MptScsiPassThru (
IN EFI_EVENT Event OPTIONAL
)
{
- return EFI_UNSUPPORTED;
+ EFI_STATUS Status;
+ MPT_SCSI_DEV *Dev = MPT_SCSI_FROM_PASS_THRU (This);
+ UINT32 Reply;
+
+ Status = MptScsiPopulateRequest (Dev, *Target, Lun, Packet);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = MptScsiSendRequest (Dev, Packet);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OK;
+
+ Status = MptScsiGetReply (Dev, &Reply);
+ if (EFI_ERROR (Status)) {
+ goto Fatal;
+ }
+
+ Status = MptScsiHandleReply (Dev, Reply, Packet);
+ if (EFI_ERROR (Status)) {
+ goto Fatal;
+ }
+
+ return Status;
+
+Fatal:
+ //
+ // We erred in the middle of a transaction, a very serious problem has occured
+ // and it's not clear if it's possible to recover without leaving the hardware
+ // in an inconsistent state. Perhaps we would want to reset the device...
+ //
+ DEBUG ((DEBUG_ERROR, "%a: fatal error in scsi request\n", __FUNCTION__));
+ Packet->InTransferLength = 0;
+ Packet->OutTransferLength = 0;
+ if (Packet->HostAdapterStatus == EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OK) {
+ Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER;
+ }
+ Packet->TargetStatus = EFI_EXT_SCSI_STATUS_TARGET_TASK_ABORTED;
+ Packet->SenseDataLength = 0;
+ return EFI_DEVICE_ERROR;
}
STATIC
@@ -426,6 +699,7 @@ MptScsiControllerStart (
EFI_STATUS Status;
MPT_SCSI_DEV *Dev;
BOOLEAN PciAttributesChanged;
+ UINTN BytesMapped;
Dev = AllocateZeroPool (sizeof (*Dev));
if (Dev == NULL) {
@@ -472,6 +746,39 @@ MptScsiControllerStart (
}
PciAttributesChanged = TRUE;
+ //
+ // Create buffers for data transfer
+ //
+ Status = Dev->PciIo->AllocateBuffer (
+ Dev->PciIo,
+ AllocateAnyPages,
+ EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (sizeof (*Dev->Dma)),
+ (VOID **)&Dev->Dma,
+ EFI_PCI_ATTRIBUTE_MEMORY_CACHED
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ BytesMapped = sizeof (*Dev->Dma);
+ Status = Dev->PciIo->Map (
+ Dev->PciIo,
+ EfiPciIoOperationBusMasterCommonBuffer,
+ Dev->Dma,
+ &BytesMapped,
+ &Dev->DmaPhysical,
+ &Dev->DmaMapping
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ if (BytesMapped != sizeof (*Dev->Dma)) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
+
Status = MptScsiInit (Dev);
if (EFI_ERROR (Status)) {
goto Done;
@@ -506,6 +813,21 @@ MptScsiControllerStart (
Done:
if (EFI_ERROR (Status)) {
+ if (Dev->DmaMapping) {
+ Dev->PciIo->Unmap (
+ Dev->PciIo,
+ Dev->DmaMapping
+ );
+ }
+
+ if (Dev->Dma) {
+ Dev->PciIo->FreeBuffer (
+ Dev->PciIo,
+ EFI_SIZE_TO_PAGES (sizeof (*Dev->Dma)),
+ Dev->Dma
+ );
+ }
+
if (PciAttributesChanged) {
Dev->PciIo->Attributes (
Dev->PciIo,
@@ -566,6 +888,17 @@ MptScsiControllerStop (
MptScsiReset (Dev);
+ Dev->PciIo->Unmap (
+ Dev->PciIo,
+ Dev->DmaMapping
+ );
+
+ Dev->PciIo->FreeBuffer (
+ Dev->PciIo,
+ EFI_SIZE_TO_PAGES (sizeof (*Dev->Dma)),
+ Dev->Dma
+ );
+
Dev->PciIo->Attributes (
Dev->PciIo,
EfiPciIoAttributeOperationEnable,
diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
index 1cb5df4233..9b090921b6 100644
--- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
+++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
@@ -40,3 +40,6 @@
[Protocols]
gEfiPciIoProtocolGuid ## TO_START
gEfiExtScsiPassThruProtocolGuid ## BY_START
+
+[Pcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiStallPerPollUsec ## CONSUMES
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 4c5b6511cb..7e8097f995 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -228,6 +228,9 @@
## Number of page frames to use for storing grant table entries.
gUefiOvmfPkgTokenSpaceGuid.PcdXenGrantFrames|4|UINT32|0x33
+ ## Microseconds to stall between polling for MptScsi request result
+ gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiStallPerPollUsec|5|UINT32|0x36
+
[PcdsDynamic, PcdsDynamicEx]
gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 13/13] OvmfPkg/MptScsiDxe: Report multiple targets
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (11 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 12/13] OvmfPkg/MptScsiDxe: Implement the PassThru method Nikita Leshenko
@ 2020-02-26 16:41 ` Nikita Leshenko
2020-02-27 9:52 ` [edk2-devel] [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Laszlo Ersek
2020-02-28 7:51 ` Laszlo Ersek
14 siblings, 0 replies; 27+ messages in thread
From: Nikita Leshenko @ 2020-02-26 16:41 UTC (permalink / raw)
To: devel
Cc: liran.alon, aaron.young, jordan.l.justen, lersek, ard.biesheuvel,
Nikita Leshenko
The controller supports up to 8 targets (Not reported by the
controller, but based on the implementation of the virtual device),
report them in GetNextTarget and GetNextTargetLun. The firmware will
then try to communicate with them and create a block device for each
one that responds.
Support for multiple LUNs will be implemented in another series.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Aaron Young <aaron.young@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 26 ++++++++++++++++++--------
OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 1 +
OvmfPkg/OvmfPkg.dec | 4 ++++
3 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 6c70112bbc..b7f5ea1b8a 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -51,6 +51,7 @@ typedef struct {
EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 OriginalPciAttributes;
UINT32 StallPerPollUsec;
+ UINT8 MaxTarget;
MPT_SCSI_DMA_BUFFER *Dma;
EFI_PHYSICAL_ADDRESS DmaPhysical;
VOID *DmaMapping;
@@ -163,6 +164,7 @@ MptScsiInit (
UINT32 Reply32;
Dev->StallPerPollUsec = PcdGet32 (PcdMptScsiStallPerPollUsec);
+ Dev->MaxTarget = PcdGet8 (PcdMptScsiMaxTargetLimit);
Status = MptScsiReset (Dev);
if (EFI_ERROR (Status)) {
@@ -173,7 +175,7 @@ MptScsiInit (
ZeroMem (&Reply, sizeof (Reply));
Req.Data.WhoInit = MPT_IOC_WHOINIT_ROM_BIOS;
Req.Data.Function = MPT_MESSAGE_HDR_FUNCTION_IOC_INIT;
- Req.Data.MaxDevices = 1;
+ Req.Data.MaxDevices = Dev->MaxTarget + 1;
Req.Data.MaxBuses = 1;
Req.Data.ReplyFrameSize = sizeof (MPT_SCSI_IO_ERROR_REPLY);
@@ -252,7 +254,7 @@ MptScsiPopulateRequest (
return EFI_UNSUPPORTED;
}
- if (Target > 0 || Lun > 0) {
+ if (Target > Dev->MaxTarget || Lun > 0) {
return EFI_INVALID_PARAMETER;
}
@@ -523,16 +525,22 @@ MptScsiGetNextTargetLun (
IN OUT UINT64 *Lun
)
{
+ MPT_SCSI_DEV *Dev = MPT_SCSI_FROM_PASS_THRU (This);
+
//
- // Currently support only target 0 LUN 0, so hardcode it
+ // Currently support only LUN 0, so hardcode it
//
if (!IsTargetInitialized (*Target)) {
**Target = 0;
*Lun = 0;
- return EFI_SUCCESS;
+ } else if (**Target < Dev->MaxTarget) {
+ **Target += 1;
+ *Lun = 0;
} else {
return EFI_NOT_FOUND;
}
+
+ return EFI_SUCCESS;
}
STATIC
@@ -543,15 +551,17 @@ MptScsiGetNextTarget (
IN OUT UINT8 **Target
)
{
- //
- // Currently support only target 0 LUN 0, so hardcode it
- //
+ MPT_SCSI_DEV *Dev = MPT_SCSI_FROM_PASS_THRU (This);
+
if (!IsTargetInitialized (*Target)) {
**Target = 0;
- return EFI_SUCCESS;
+ } else if (**Target < Dev->MaxTarget) {
+ **Target += 1;
} else {
return EFI_NOT_FOUND;
}
+
+ return EFI_SUCCESS;
}
STATIC
diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
index 9b090921b6..8453c73e60 100644
--- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
+++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
@@ -43,3 +43,4 @@
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiStallPerPollUsec ## CONSUMES
+ gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiMaxTargetLimit ## CONSUMES
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 7e8097f995..1e17df0316 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -231,6 +231,10 @@
## Microseconds to stall between polling for MptScsi request result
gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiStallPerPollUsec|5|UINT32|0x36
+ ## Set the *inclusive* number of targets that MptScsi exposes for scan
+ # by ScsiBusDxe.
+ gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiMaxTargetLimit|7|UINT8|0x37
+
[PcdsDynamic, PcdsDynamicEx]
gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
--
2.20.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [edk2-devel] [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (12 preceding siblings ...)
2020-02-26 16:41 ` [PATCH v2 13/13] OvmfPkg/MptScsiDxe: Report multiple targets Nikita Leshenko
@ 2020-02-27 9:52 ` Laszlo Ersek
2020-02-28 7:51 ` Laszlo Ersek
14 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-27 9:52 UTC (permalink / raw)
To: devel, nikita.leshchenko
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
Hi Nikita,
On 02/26/20 17:41, Nikita Leshenko wrote:
> This series adds driver support for:
> - LSI53C1030
> - SAS1068
> - SAS1068E
>
> These controllers are widely supported by QEMU, VirtualBox and VMWare. This work
> is part of the more general agenda of enhancing OVMF boot device support to have
> feature parity with SeaBIOS.
>
> We have also developed support for PVSCSI which we will submit in a separate
> patch series.
>
> I pushed a copy of these patches to https://github.com/nikital/edk2/tree/mptscsi
>
> v1->v2:
> - Map() DMAed buffers
> - Fixed various code convention issues
> - Newer debug macros
> - Updated INF version
I'm confirming that this is in my queue. I'll get to it at some point. I
prefer to review patches as first thing in the morning, when my brain is
still "fresh". But that "freshness" generally doesn't last beyond 10
patches or so. So I'll likely need a few days to reach this.
Thanks
Laszlo
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [edk2-devel] [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers
2020-02-26 16:41 [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Nikita Leshenko
` (13 preceding siblings ...)
2020-02-27 9:52 ` [edk2-devel] [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers Laszlo Ersek
@ 2020-02-28 7:51 ` Laszlo Ersek
2020-02-28 8:06 ` Laszlo Ersek
14 siblings, 1 reply; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 7:51 UTC (permalink / raw)
To: devel, nikita.leshchenko
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/26/20 17:41, Nikita Leshenko wrote:
> This series adds driver support for:
> - LSI53C1030
> - SAS1068
> - SAS1068E
>
> These controllers are widely supported by QEMU, VirtualBox and VMWare. This work
> is part of the more general agenda of enhancing OVMF boot device support to have
> feature parity with SeaBIOS.
>
> We have also developed support for PVSCSI which we will submit in a separate
> patch series.
>
> I pushed a copy of these patches to https://github.com/nikital/edk2/tree/mptscsi
>
> v1->v2:
> - Map() DMAed buffers
> - Fixed various code convention issues
> - Newer debug macros
> - Updated INF version
General comments:
(1) In future cover letters, please include a cumulative diffstat. "git
format-patch --cover-letter" should generate one.
(2) Edk2 has migrated to using SPDX license identifiers, rather than
open-coded license blocks:
https://bugzilla.tianocore.org/show_bug.cgi?id=1373
Furthermore, the preferred license is "BSD-2-Clause-Patent":
https://spdx.org/licenses/BSD-2-Clause-Patent.html
Please see "Readme.md" in the project root, or at
<https://github.com/tianocore/edk2/#license-details>.
(2a) Therefore please *at least* replace the open-coded BSD license
blocks in the new files with SPDX tags.
(2b) Furthermore, if you can consider making this contribution under
"BSD-2-Clause-Patent", please change the license to that; it would be
more in-line with the rest of edk2.
(Otherwise, i.e. if you don't want to adopt "BSD-2-Clause-Patent", then
please extend "OvmfPkg/License.txt" with the 2-clause BSD license,
similarly to how "MIT" is treated there.)
(2c) The "Contributed-under" tags should now be removed from the commit
messages (see again TianoCore#1373).
(3) Before posting the next version, please run "PatchCheck.py" on the
series. For example:
$ python3 BaseTools/Scripts/PatchCheck.py master..nikita-mptscsi-v2
Currently, it mainly reports "Contributed-under", but there's at least
one other warning: "Line 3 of commit message is too long (78 >= 76)".
Please try to fix warnings too.
(4) Future versions should not be force-pushed to your repo, but pushed
under a new topic branch whose name includes the version (i.e., the next
version should have "v3" in the name). A topic branch, once published
for review, should remain read-only.
(5) Please do not include Reviewed-by and similar feedback tags that
have not been given on the mailing list.
For example, consider patch#4:
"OvmfPkg/MptScsiDxe: Probe PCI devices and look for MptScsi"
Version 1 is archived (for example) at:
http://mid.mail-archive.com/20190131100724.20907-5-nikita.leshchenko@oracle.com
If I remember correctly, that was the very first posting, and it already
contained R-b's from Konrad, Aaron and Liran. For upstream reviews, such
tags (i.e. those that originate off-list) are not useful -- they have to
be given on the list, in response to the posting. (I'm pointing this out
with v1 in order to show that v2 has not picked up the R-b's from the
list either.)
So please ask your colleagues to repost their R-b tags on the list (in
response to the individual patches, or in response to the cover letter,
if they approve the whole set).
I'll continue with reviewing the individual patches now.
Thanks!
Laszlo
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [edk2-devel] [PATCH v2 00/13] OvmfPkg: Support booting from Fusion-MPT SCSI controllers
2020-02-28 7:51 ` Laszlo Ersek
@ 2020-02-28 8:06 ` Laszlo Ersek
0 siblings, 0 replies; 27+ messages in thread
From: Laszlo Ersek @ 2020-02-28 8:06 UTC (permalink / raw)
To: devel, nikita.leshchenko
Cc: liran.alon, aaron.young, jordan.l.justen, ard.biesheuvel
On 02/28/20 08:51, Laszlo Ersek wrote:
> On 02/26/20 17:41, Nikita Leshenko wrote:
>> This series adds driver support for:
>> - LSI53C1030
>> - SAS1068
>> - SAS1068E
>>
>> These controllers are widely supported by QEMU, VirtualBox and VMWare. This work
>> is part of the more general agenda of enhancing OVMF boot device support to have
>> feature parity with SeaBIOS.
>>
>> We have also developed support for PVSCSI which we will submit in a separate
>> patch series.
>>
>> I pushed a copy of these patches to https://github.com/nikital/edk2/tree/mptscsi
>>
>> v1->v2:
>> - Map() DMAed buffers
>> - Fixed various code convention issues
>> - Newer debug macros
>> - Updated INF version
>
> General comments:
>
> [...]
(6) Please run "BaseTools/Scripts/SetupGit.py" in your local edk2 clone,
before future postings. That will help for example with:
- generating diff hunks in the preferred file order (based on
"BaseTools/Conf/diff.order"),
- generating function names and section names into the @@ hunk headers
(based on "BaseTools/Conf/gitattributes" and the xfuncname setting).
Thanks
Laszlo
^ permalink raw reply [flat|nested] 27+ messages in thread