Fix bug in unload function: Check if component name protocol exist, only uninstall...
authorFu Siyuan <siyuan.fu@intel.com>
Fri, 10 Jan 2014 08:24:29 +0000 (08:24 +0000)
committersfu5 <sfu5@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 10 Jan 2014 08:24:29 +0000 (08:24 +0000)
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Tian, Feng <feng.tian@intel.com>
Reviewed-by: Jin, Eric <eric.jin@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15092 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.c
MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h
NetworkPkg/IScsiDxe/IScsiDriver.c
NetworkPkg/IScsiDxe/IScsiMisc.c
NetworkPkg/IScsiDxe/IScsiMisc.h

index f4663d9f59c1837328ad45864f35a634cead7f23..b389610479561a829631aae7751aa80d937b35cb 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The entry point of IScsi driver.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -439,10 +439,12 @@ EfiIScsiUnload (
   IN EFI_HANDLE  ImageHandle\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINTN       DeviceHandleCount;\r
-  EFI_HANDLE  *DeviceHandleBuffer;\r
-  UINTN       Index;\r
+  EFI_STATUS                        Status;\r
+  UINTN                             DeviceHandleCount;\r
+  EFI_HANDLE                        *DeviceHandleBuffer;\r
+  UINTN                             Index;\r
+  EFI_COMPONENT_NAME_PROTOCOL       *ComponentName;\r
+  EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;\r
 \r
   //\r
   // Try to disonnect the driver from the devices it's controlling.\r
@@ -454,40 +456,89 @@ EfiIScsiUnload (
                   &DeviceHandleCount,\r
                   &DeviceHandleBuffer\r
                   );\r
-  if (!EFI_ERROR (Status)) {\r
-    for (Index = 0; Index < DeviceHandleCount; Index++) {\r
-      Status = gBS->DisconnectController (\r
-                      DeviceHandleBuffer[Index],\r
-                      ImageHandle,\r
-                      NULL\r
-                      );\r
-    }\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
-    if (DeviceHandleBuffer != NULL) {\r
-      FreePool (DeviceHandleBuffer);\r
+  for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+    Status = IScsiTestManagedDevice (\r
+               DeviceHandleBuffer[Index],\r
+               gIScsiDriverBinding.DriverBindingHandle,\r
+               &gEfiTcp4ProtocolGuid\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
     }\r
-  }\r
+    Status = gBS->DisconnectController (\r
+                    DeviceHandleBuffer[Index],\r
+                    gIScsiDriverBinding.DriverBindingHandle,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }  \r
+\r
   //\r
   // Unload the iSCSI configuration form.\r
   //\r
-  IScsiConfigFormUnload (gIScsiDriverBinding.DriverBindingHandle);\r
+  Status = IScsiConfigFormUnload (gIScsiDriverBinding.DriverBindingHandle);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
 \r
   //\r
-  // Uninstall the protocols installed by iSCSI driver.\r
+  // Uninstall the ComponentName and ComponentName2 protocol from iSCSI4 driver binding handle\r
+  // if it has been installed.\r
   //\r
+  Status = gBS->HandleProtocol (\r
+                  gIScsiDriverBinding.DriverBindingHandle,\r
+                  &gEfiComponentNameProtocolGuid,\r
+                  (VOID **) &ComponentName\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
+           gIScsiDriverBinding.DriverBindingHandle,\r
+           &gEfiComponentNameProtocolGuid,\r
+           ComponentName,\r
+           NULL\r
+           );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
+  \r
+  Status = gBS->HandleProtocol (\r
+                  gIScsiDriverBinding.DriverBindingHandle,\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  (VOID **) &ComponentName2\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+           gIScsiDriverBinding.DriverBindingHandle,\r
+           &gEfiComponentName2ProtocolGuid,\r
+           ComponentName2,\r
+           NULL\r
+           );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
+\r
   Status = gBS->UninstallMultipleProtocolInterfaces (\r
                   ImageHandle,\r
                   &gEfiDriverBindingProtocolGuid,\r
                   &gIScsiDriverBinding,\r
-                  &gEfiComponentName2ProtocolGuid,\r
-                  &gIScsiComponentName2,\r
-                  &gEfiComponentNameProtocolGuid,\r
-                  &gIScsiComponentName,\r
                   &gEfiIScsiInitiatorNameProtocolGuid,\r
                   &gIScsiInitiatorName,\r
                   NULL\r
                   );\r
+ON_EXIT:\r
 \r
+  if (DeviceHandleBuffer != NULL) {\r
+    FreePool (DeviceHandleBuffer);\r
+  }\r
+  \r
   return Status;\r
 }\r
 \r
index 2e43b415ec593b899d16426991d0aca73229805f..a00d805b84c4758363103dc4acc68750d9583a5b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous routines for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -852,3 +852,70 @@ IScsiOnExitBootService (
 \r
   IScsiSessionAbort (&Private->Session);\r
 }\r
+\r
+/**\r
+  Tests whether a controller handle is being managed by IScsi driver.\r
+\r
+  This function tests whether the driver specified by DriverBindingHandle is\r
+  currently managing the controller specified by ControllerHandle.  This test\r
+  is performed by evaluating if the the protocol specified by ProtocolGuid is\r
+  present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
+  Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
+  If ProtocolGuid is NULL, then ASSERT().\r
+\r
+  @param  ControllerHandle     A handle for a controller to test.\r
+  @param  DriverBindingHandle  Specifies the driver binding handle for the\r
+                               driver.\r
+  @param  ProtocolGuid         Specifies the protocol that the driver specified\r
+                               by DriverBindingHandle opens in its Start()\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS          ControllerHandle is managed by the driver\r
+                               specified by DriverBindingHandle.\r
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver\r
+                               specified by DriverBindingHandle.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IScsiTestManagedDevice (\r
+  IN  EFI_HANDLE       ControllerHandle,\r
+  IN  EFI_HANDLE       DriverBindingHandle,\r
+  IN  EFI_GUID         *ProtocolGuid\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  VOID           *ManagedInterface;\r
+  EFI_HANDLE     NicControllerHandle;\r
+\r
+  ASSERT (ProtocolGuid != NULL);\r
+\r
+  NicControllerHandle = NetLibGetNicHandle (ControllerHandle, ProtocolGuid);\r
+  if (NicControllerHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &ManagedInterface,\r
+                  DriverBindingHandle,\r
+                  NicControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           (EFI_GUID *) ProtocolGuid,\r
+           DriverBindingHandle,\r
+           NicControllerHandle\r
+           );\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
index b310c9c579aabcd39276be6a01780690709965ef..052a90f8d493d125b188b5a7ae47b55474e2bc48 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous definitions for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -275,6 +275,35 @@ IScsiOnExitBootService (
   IN VOID       *Context\r
   );\r
 \r
+/**\r
+  Tests whether a controller handle is being managed by IScsi driver.\r
+\r
+  This function tests whether the driver specified by DriverBindingHandle is\r
+  currently managing the controller specified by ControllerHandle.  This test\r
+  is performed by evaluating if the the protocol specified by ProtocolGuid is\r
+  present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
+  Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
+  If ProtocolGuid is NULL, then ASSERT().\r
+\r
+  @param  ControllerHandle     A handle for a controller to test.\r
+  @param  DriverBindingHandle  Specifies the driver binding handle for the\r
+                               driver.\r
+  @param  ProtocolGuid         Specifies the protocol that the driver specified\r
+                               by DriverBindingHandle opens in its Start()\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS          ControllerHandle is managed by the driver\r
+                               specified by DriverBindingHandle.\r
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver\r
+                               specified by DriverBindingHandle.\r
 \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IScsiTestManagedDevice (\r
+  IN  EFI_HANDLE       ControllerHandle,\r
+  IN  EFI_HANDLE       DriverBindingHandle,\r
+  IN  EFI_GUID         *ProtocolGuid\r
+  );\r
 \r
 #endif\r
index 6d6f9a13ed8b8f33059872bc1f1dd3b7b27682ca..42ac8f0fe778e8b80c8d3335a10c6de0061d5ea3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The entry point of IScsi driver.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1245,10 +1245,12 @@ IScsiUnload (
   IN EFI_HANDLE  ImageHandle\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINTN       DeviceHandleCount;\r
-  EFI_HANDLE  *DeviceHandleBuffer;\r
-  UINTN       Index;\r
+  EFI_STATUS                        Status;\r
+  UINTN                             DeviceHandleCount;\r
+  EFI_HANDLE                        *DeviceHandleBuffer;\r
+  UINTN                             Index;\r
+  EFI_COMPONENT_NAME_PROTOCOL       *ComponentName;\r
+  EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;\r
 \r
   //\r
   // Try to disonnect the driver from the devices it's controlling.\r
@@ -1264,64 +1266,184 @@ IScsiUnload (
     return Status;\r
   }\r
 \r
+  //\r
+  // Disconnect the iSCSI4 driver from the controlled device.\r
+  //\r
+  for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+    Status = IScsiTestManagedDevice (\r
+               DeviceHandleBuffer[Index],\r
+               gIScsiIp4DriverBinding.DriverBindingHandle,\r
+               &gEfiTcp4ProtocolGuid)\r
+               ;\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+    Status = gBS->DisconnectController (\r
+                    DeviceHandleBuffer[Index],\r
+                    gIScsiIp4DriverBinding.DriverBindingHandle,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Disconnect the iSCSI6 driver from the controlled device.\r
+  //\r
   for (Index = 0; Index < DeviceHandleCount; Index++) {\r
-    gBS->DisconnectController (\r
-           DeviceHandleBuffer[Index],\r
+    Status = IScsiTestManagedDevice (\r
+               DeviceHandleBuffer[Index],\r
+               gIScsiIp6DriverBinding.DriverBindingHandle,\r
+               &gEfiTcp6ProtocolGuid\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+    Status = gBS->DisconnectController (\r
+                    DeviceHandleBuffer[Index],\r
+                    gIScsiIp6DriverBinding.DriverBindingHandle,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Unload the iSCSI configuration form.\r
+  //\r
+  Status = IScsiConfigFormUnload (gIScsiIp4DriverBinding.DriverBindingHandle);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+  \r
+  //\r
+  // Uninstall the protocols installed by iSCSI driver.\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  ImageHandle,\r
+                  &gEfiAuthenticationInfoProtocolGuid,\r
+                  &gIScsiAuthenticationInfo,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+  \r
+  if (gIScsiControllerNameTable!= NULL) {\r
+    Status = FreeUnicodeStringTable (gIScsiControllerNameTable);\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+    gIScsiControllerNameTable = NULL;\r
+  }\r
+\r
+  //\r
+  // Uninstall the ComponentName and ComponentName2 protocol from iSCSI4 driver binding handle\r
+  // if it has been installed.\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+                  gIScsiIp4DriverBinding.DriverBindingHandle,\r
+                  &gEfiComponentNameProtocolGuid,\r
+                  (VOID **) &ComponentName\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
            gIScsiIp4DriverBinding.DriverBindingHandle,\r
+           &gEfiComponentNameProtocolGuid,\r
+           ComponentName,\r
            NULL\r
            );\r
-    gBS->DisconnectController (\r
-           DeviceHandleBuffer[Index],\r
-           gIScsiIp6DriverBinding.DriverBindingHandle,\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
+  \r
+  Status = gBS->HandleProtocol (\r
+                  gIScsiIp4DriverBinding.DriverBindingHandle,\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  (VOID **) &ComponentName2\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+           gIScsiIp4DriverBinding.DriverBindingHandle,\r
+           &gEfiComponentName2ProtocolGuid,\r
+           ComponentName2,\r
            NULL\r
            );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
   }\r
 \r
   //\r
-  // Unload the iSCSI configuration form.\r
+  // Uninstall the ComponentName and ComponentName2 protocol from iSCSI6 driver binding handle\r
+  // if it has been installed.\r
   //\r
-  IScsiConfigFormUnload (gIScsiIp4DriverBinding.DriverBindingHandle);\r
+  Status = gBS->HandleProtocol (\r
+                  gIScsiIp6DriverBinding.DriverBindingHandle,\r
+                  &gEfiComponentNameProtocolGuid,\r
+                  (VOID **) &ComponentName\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
+           gIScsiIp6DriverBinding.DriverBindingHandle,\r
+           &gEfiComponentNameProtocolGuid,\r
+           ComponentName,\r
+           NULL\r
+           );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
+  \r
+  Status = gBS->HandleProtocol (\r
+                  gIScsiIp6DriverBinding.DriverBindingHandle,\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  (VOID **) &ComponentName2\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+           gIScsiIp6DriverBinding.DriverBindingHandle,\r
+           &gEfiComponentName2ProtocolGuid,\r
+           ComponentName2,\r
+           NULL\r
+           );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
 \r
   //\r
-  // Uninstall the protocols installed by iSCSI driver.\r
+  // Uninstall the IScsiInitiatorNameProtocol and all the driver binding protocols.\r
   //\r
-  gBS->UninstallMultipleProtocolInterfaces (\r
-         ImageHandle,\r
-         &gEfiAuthenticationInfoProtocolGuid,\r
-         &gIScsiAuthenticationInfo,\r
-         NULL\r
-         );\r
-\r
-  if (gIScsiControllerNameTable!= NULL) {\r
-    FreeUnicodeStringTable (gIScsiControllerNameTable);\r
-    gIScsiControllerNameTable = NULL;\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  gIScsiIp4DriverBinding.DriverBindingHandle,\r
+                  &gEfiDriverBindingProtocolGuid,\r
+                  &gIScsiIp4DriverBinding,\r
+                  &gEfiIScsiInitiatorNameProtocolGuid,\r
+                  &gIScsiInitiatorName,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
   }\r
-  \r
-  gBS->UninstallMultipleProtocolInterfaces (\r
-         gIScsiIp4DriverBinding.DriverBindingHandle,\r
-         &gEfiDriverBindingProtocolGuid,\r
-         &gIScsiIp4DriverBinding,\r
-         &gEfiComponentName2ProtocolGuid,\r
-         &gIScsiComponentName2,\r
-         &gEfiComponentNameProtocolGuid,\r
-         &gIScsiComponentName,\r
-         &gEfiIScsiInitiatorNameProtocolGuid,\r
-         &gIScsiInitiatorName,\r
-         NULL\r
-         );\r
 \r
-  gBS->UninstallMultipleProtocolInterfaces (\r
-         gIScsiIp6DriverBinding.DriverBindingHandle,\r
-         &gEfiDriverBindingProtocolGuid,\r
-         &gIScsiIp6DriverBinding,\r
-         &gEfiComponentName2ProtocolGuid,\r
-         &gIScsiComponentName2,\r
-         &gEfiComponentNameProtocolGuid,\r
-         &gIScsiComponentName,\r
-         NULL\r
-         );\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  gIScsiIp6DriverBinding.DriverBindingHandle,\r
+                  &gEfiDriverBindingProtocolGuid,\r
+                  &gIScsiIp6DriverBinding,\r
+                  NULL\r
+                  );\r
 \r
-  return EFI_SUCCESS;\r
+ON_EXIT:\r
+\r
+  if (DeviceHandleBuffer != NULL) {\r
+    FreePool (DeviceHandleBuffer);\r
+  }\r
+  \r
+  return Status;\r
 }\r
 \r
 /**\r
index 6ed4974545fba7b35dfa17fab3ba4b5eef74c355..444d6f062e197dc58ccdfa4f7afc1378648b79bb 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous routines for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1436,3 +1436,70 @@ IScsiOnExitBootService (
     IScsiSessionAbort (Private->Session);\r
   }\r
 }\r
+\r
+/**\r
+  Tests whether a controller handle is being managed by IScsi driver.\r
+\r
+  This function tests whether the driver specified by DriverBindingHandle is\r
+  currently managing the controller specified by ControllerHandle.  This test\r
+  is performed by evaluating if the the protocol specified by ProtocolGuid is\r
+  present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
+  Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
+  If ProtocolGuid is NULL, then ASSERT().\r
+\r
+  @param  ControllerHandle     A handle for a controller to test.\r
+  @param  DriverBindingHandle  Specifies the driver binding handle for the\r
+                               driver.\r
+  @param  ProtocolGuid         Specifies the protocol that the driver specified\r
+                               by DriverBindingHandle opens in its Start()\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS          ControllerHandle is managed by the driver\r
+                               specified by DriverBindingHandle.\r
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver\r
+                               specified by DriverBindingHandle.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IScsiTestManagedDevice (\r
+  IN  EFI_HANDLE       ControllerHandle,\r
+  IN  EFI_HANDLE       DriverBindingHandle,\r
+  IN  EFI_GUID         *ProtocolGuid\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  VOID           *ManagedInterface;\r
+  EFI_HANDLE     NicControllerHandle;\r
+\r
+  ASSERT (ProtocolGuid != NULL);\r
+\r
+  NicControllerHandle = NetLibGetNicHandle (ControllerHandle, ProtocolGuid);\r
+  if (NicControllerHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &ManagedInterface,\r
+                  DriverBindingHandle,\r
+                  NicControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           (EFI_GUID *) ProtocolGuid,\r
+           DriverBindingHandle,\r
+           NicControllerHandle\r
+           );\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
index e2a27806ac8eccefcd362a696a98ba2d53f5c28f..fd9e3af764407b35dd89b2f1a1e61ae4feb0da91 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous definitions for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -357,4 +357,34 @@ IScsiOnExitBootService (
   IN VOID       *Context\r
   );\r
 \r
+/**\r
+  Tests whether a controller handle is being managed by IScsi driver.\r
+\r
+  This function tests whether the driver specified by DriverBindingHandle is\r
+  currently managing the controller specified by ControllerHandle.  This test\r
+  is performed by evaluating if the the protocol specified by ProtocolGuid is\r
+  present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
+  Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
+  If ProtocolGuid is NULL, then ASSERT().\r
+\r
+  @param  ControllerHandle     A handle for a controller to test.\r
+  @param  DriverBindingHandle  Specifies the driver binding handle for the\r
+                               driver.\r
+  @param  ProtocolGuid         Specifies the protocol that the driver specified\r
+                               by DriverBindingHandle opens in its Start()\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS          ControllerHandle is managed by the driver\r
+                               specified by DriverBindingHandle.\r
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver\r
+                               specified by DriverBindingHandle.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IScsiTestManagedDevice (\r
+  IN  EFI_HANDLE       ControllerHandle,\r
+  IN  EFI_HANDLE       DriverBindingHandle,\r
+  IN  EFI_GUID         *ProtocolGuid\r
+  );\r
 #endif\r