]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiExtScsiPassThru.c
index e1d2bc0e3c540af59c0c55e3e6275c9edc89686f..db2d6d19366ec460c70e66cb8cb767f3b16ede2e 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
-  The IScsi's EFI_EXT_SCSI_PASS_THRU_PROTOCOL driver\r
+  The IScsi's EFI_EXT_SCSI_PASS_THRU_PROTOCOL driver.\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2018, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -10,33 +10,50 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-  IScsiExtScsiPassThru.c\r
-\r
-Abstract:\r
-  The IScsi's EFI_EXT_SCSI_PASS_THRU_PROTOCOL driver\r
-\r
 **/\r
 \r
 #include "IScsiImpl.h"\r
 \r
 /**\r
-  This function sends out the SCSI command via iSCSI transport layer and returned\r
-  back the data received from the iSCSI target. \r
-\r
-  @param  This[in]        The EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
-\r
-  @param  Target[in]      The Target ID of device to send the SCSI Request Packet. \r
-\r
-  @param  Lun[in]         The LUN of the device to send the SCSI Request Packet.\r
-\r
-  @param  Packet[in][out] The SCSI Request Packet to send to the device.\r
-\r
-  @param  Event[in]       The event used in non-blocking mode, it should be always NULL.\r
-\r
-  @retval EFI_STATUS\r
-\r
+  Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function\r
+  supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the\r
+  nonblocking I/O functionality is optional.\r
+\r
+  @param[in]      This    A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
+  @param[in]      Target  The Target is an array of size TARGET_MAX_BYTES and it represents\r
+                          the id of the SCSI device to send the SCSI Request Packet. Each\r
+                          transport driver may chose to utilize a subset of this size to suit the needs\r
+                          of transport target representation. For example, a Fibre Channel driver\r
+                          may use only 8 bytes (WWN) to represent an FC target.\r
+  @param[in]       Lun    The LUN of the SCSI device to send the SCSI Request Packet.\r
+  @param[in, out]  Packet A pointer to the SCSI Request Packet to send to the SCSI device\r
+                          specified by Target and Lun.\r
+  @param[in]       Event  If nonblocking I/O is not supported then Event is ignored, and blocking\r
+                          I/O is performed. If Event is NULL, then blocking I/O is performed. If\r
+                          Event is not NULL and non blocking I/O is supported, then\r
+                          nonblocking I/O is performed, and Event will be signaled when the\r
+                          SCSI Request Packet completes.\r
+\r
+  @retval EFI_SUCCESS           The SCSI Request Packet was sent by the host. For bi-directional\r
+                                commands, InTransferLength bytes were transferred from\r
+                                InDataBuffer. For write and bi-directional commands,\r
+                                OutTransferLength bytes were transferred by\r
+                                OutDataBuffer.\r
+  @retval EFI_BAD_BUFFER_SIZE   The SCSI Request Packet was not executed. The number of bytes that\r
+                                could be transferred is returned in InTransferLength. For write\r
+                                and bi-directional commands, OutTransferLength bytes were\r
+                                transferred by OutDataBuffer. Currently not implemeted.\r
+  @retval EFI_NOT_READY         The SCSI Request Packet could not be sent because there are too many\r
+                                SCSI Request Packets already queued. The caller may retry again later.\r
+  @retval EFI_DEVICE_ERROR      A device error occurred while attempting to send the SCSI Request\r
+                                Packet.\r
+  @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.\r
+  @retval EFI_UNSUPPORTED       The command described by the SCSI Request Packet is not supported\r
+                                by the host adapter. This includes the case of Bi-directional SCSI\r
+                                commands not supported by the implementation. The SCSI Request\r
+                                Packet was not sent, so no additional status information is available.\r
+                                Currently not implemeted.\r
+  @retval EFI_TIMEOUT           A timeout occurred while waiting for the SCSI Request Packet to execute.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -48,7 +65,14 @@ IScsiExtScsiPassThruFunction (
   IN EFI_EVENT                                                Event     OPTIONAL\r
   )\r
 {\r
-  if (Target[0] != 0) {\r
+  ISCSI_DRIVER_DATA           *Private;\r
+  ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
+  EFI_STATUS                  Status;\r
+\r
+  Private       = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
+  ConfigNvData  = &Private->Session.ConfigData.NvData;\r
+\r
+  if (Target[0] != 0 || (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) != 0)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -56,31 +80,45 @@ IScsiExtScsiPassThruFunction (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  return IScsiExecuteScsiCommand (This, Target, Lun, Packet);\r
-}\r
-\r
-/**\r
-  Retrieve the list of legal Target IDs for SCSI devices on a SCSI channel.\r
-\r
-  @param  This[in]              The EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
-\r
-  @param  Target[in][out]       On input, a pointer to the Target ID of a SCSI device present on the\r
-                                SCSI channel. On output, a pointer to the Target ID of the next SCSI\r
-                                device present on a SCSI channel. An input value of 0xFFFFFFFF retrieves\r
-                                the Target ID of the first SCSI device present on a SCSI channel.\r
+  Status = IScsiExecuteScsiCommand (This, Target, Lun, Packet);\r
+  if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_READY)) {\r
+    //\r
+    // Try to reinstate the session and re-execute the Scsi command.\r
+    //\r
+    if (EFI_ERROR (IScsiSessionReinstatement (Private))) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
 \r
-  @param  Lun[in][out]          On input, a pointer to the LUN of a SCSI device present on the SCSI\r
-                                channel. On output, a pointer to the LUN of the next SCSI device\r
-                                present on a SCSI channel.\r
+    Status = IScsiExecuteScsiCommand (This, Target, Lun, Packet);\r
+  }\r
 \r
-  @retval EFI_SUCCESS           The Target ID and Lun of the next SCSI device \r
-                                on the SCSI channel was returned in Target and Lun.\r
+  return Status;\r
+}\r
 \r
+/**\r
+  Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These\r
+  can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal\r
+  Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the\r
+  Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI\r
+  channel.\r
+\r
+  @param[in]       This    A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
+  @param[in, out]  Target  On input, a pointer to the Target ID (an array of size\r
+                           TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
+                           On output, a pointer to the Target ID (an array of\r
+                           TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
+                           channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
+                           Target array retrieves the Target ID of the first SCSI device present on a\r
+                           SCSI channel.\r
+  @param[in, out]  Lun     On input, a pointer to the LUN of a SCSI device present on the SCSI\r
+                           channel. On output, a pointer to the LUN of the next SCSI device present\r
+                           on a SCSI channel.\r
+\r
+  @retval EFI_SUCCESS           The Target ID and LUN of the next SCSI device on the SCSI\r
+                                channel was returned in Target and Lun.\r
+  @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were\r
+                                not returned on a previous call to GetNextTargetLun().\r
   @retval EFI_NOT_FOUND         There are no more SCSI devices on this SCSI channel.\r
-\r
-  @retval EFI_INVALID_PARAMETER Target is not 0xFFFFFFFF,and Target and Lun were not\r
-                                returned on a previous call to GetNextDevice().\r
-\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -116,35 +154,30 @@ IScsiExtScsiPassThruGetNextTargetLun (
 }\r
 \r
 /**\r
-  Allocate and build a device path node for a SCSI device on a SCSI channel.\r
-\r
-  @param  This[in]              Protocol instance pointer.\r
-\r
-  @param  Target[in]            The Target ID of the SCSI device for which\r
-                                a device path node is to be allocated and built.\r
-\r
-  @param  Lun[in]               The LUN of the SCSI device for which a device \r
-                                path node is to be allocated and built.\r
-\r
-  @param  DevicePath[in][out]   A pointer to a single device path node that \r
-                                describes the SCSI device specified by \r
-                                Target and Lun. This function is responsible \r
-                                for allocating the buffer DevicePath with the boot\r
-                                service AllocatePool().  It is the caller's \r
-                                responsibility to free DevicePath when the caller\r
-                                is finished with DevicePath.    \r
-\r
-  @retval EFI_SUCCESS           The device path node that describes the SCSI device\r
-                                specified by Target and Lun was allocated and \r
-                                returned in DevicePath.\r
-\r
-  @retval EFI_NOT_FOUND         The SCSI devices specified by Target and Lun does\r
-                                not exist on the SCSI channel.\r
-\r
-  @retval EFI_INVALID_PARAMETER DevicePath is NULL.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES  There are not enough resources to allocate \r
+  Used to allocate and build a device path node for a SCSI device on a SCSI channel.\r
+\r
+  @param[in]      This        A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
+  @param[in]      Target      The Target is an array of size TARGET_MAX_BYTES and it specifies the\r
+                              Target ID of the SCSI device for which a device path node is to be\r
+                              allocated and built. Transport drivers may chose to utilize a subset of\r
+                              this size to suit the representation of targets. For example, a Fibre\r
+                              Channel driver may use only 8 bytes (WWN) in the array to represent a\r
+                              FC target.\r
+  @param[in]       Lun        The LUN of the SCSI device for which a device path node is to be\r
+                              allocated and built.\r
+  @param[in, out]  DevicePath A pointer to a single device path node that describes the SCSI device\r
+                              specified by Target and Lun. This function is responsible for\r
+                              allocating the buffer DevicePath with the boot service\r
+                              AllocatePool(). It is the caller's responsibility to free\r
+                              DevicePath when the caller is finished with DevicePath.\r
+\r
+  @retval EFI_SUCCESS           The device path node that describes the SCSI device specified by\r
+                                Target and Lun was allocated and returned in\r
                                 DevicePath.\r
+  @retval EFI_INVALID_PARAMETER DevicePath is NULL.\r
+  @retval EFI_NOT_FOUND         The SCSI devices specified by Target and Lun does not exist\r
+                                on the SCSI channel.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough resources to allocate DevicePath.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -163,7 +196,7 @@ IScsiExtScsiPassThruBuildDevicePath (
   EFI_DEV_PATH                  *Node;\r
   UINTN                         DevPathNodeLen;\r
 \r
-  if ((DevicePath == NULL)) {\r
+  if (DevicePath == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -211,7 +244,7 @@ IScsiExtScsiPassThruBuildDevicePath (
 \r
   CopyMem (&Node->Iscsi.Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
   Node->Iscsi.TargetPortalGroupTag = Session->TargetPortalGroupTag;\r
-  AsciiStrCpy ((CHAR8 *) Node + sizeof (ISCSI_DEVICE_PATH), ConfigNvData->TargetName);\r
+  AsciiStrCpyS ((CHAR8 *) Node + sizeof (ISCSI_DEVICE_PATH), AsciiStrLen (ConfigNvData->TargetName) + 1, ConfigNvData->TargetName);\r
 \r
   *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r
 \r
@@ -219,31 +252,22 @@ IScsiExtScsiPassThruBuildDevicePath (
 }\r
 \r
 /**\r
-  Translate a device path node to a Target ID and LUN.\r
-\r
-  @param  This[in]              Protocol instance pointer.\r
-\r
-  @param  DevicePath[in]        A pointer to the device path node that \r
-                                describes a SCSI device on the SCSI channel.\r
-\r
-  @param  Target[out]           A pointer to the Target ID of a SCSI device \r
-                                on the SCSI channel. \r
-\r
-  @param  Lun[out]              A pointer to the LUN of a SCSI device on \r
-                                the SCSI channel.    \r
-\r
-  @retval EFI_SUCCESS           DevicePath was successfully translated to a \r
-                                Target ID and LUN, and they were returned \r
-                                in Target and Lun.\r
-\r
-  @retval EFI_INVALID_PARAMETER DevicePath/Target/Lun is NULL.\r
-\r
-  @retval EFI_UNSUPPORTED       This driver does not support the device path \r
-                                node type in DevicePath.\r
-\r
-  @retval EFI_NOT_FOUND         A valid translation from DevicePath to a \r
-                                Target ID and LUN does not exist.\r
-\r
+  Used to translate a device path node to a Target ID and LUN.\r
+\r
+  @param[in]  This       A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
+  @param[in]  DevicePath A pointer to a single device path node that describes the SCSI device\r
+                         on the SCSI channel.\r
+  @param[out] Target     A pointer to the Target Array which represents the ID of a SCSI device\r
+                         on the SCSI channel.\r
+  @param[out]  Lun       A pointer to the LUN of a SCSI device on the SCSI channel.\r
+\r
+  @retval EFI_SUCCESS           DevicePath was successfully translated to a Target ID and\r
+                                LUN, and they were returned in Target and Lun.\r
+  @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.\r
+  @retval EFI_NOT_FOUND         A valid translation from DevicePath to a Target ID and LUN\r
+                                does not exist.Currently not implemented.\r
+  @retval EFI_UNSUPPORTED       This driver does not support the device path node type in\r
+                                DevicePath.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -271,7 +295,8 @@ IScsiExtScsiPassThruGetTargetLun (
   Private       = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
   ConfigNvData  = &Private->Session.ConfigData.NvData;\r
 \r
-  ZeroMem (*Target, TARGET_MAX_BYTES);\r
+  SetMem (*Target, TARGET_MAX_BYTES, 0xFF);\r
+  (*Target)[0] = 0;\r
 \r
   if (AsciiStrCmp (ConfigNvData->TargetName, (CHAR8 *) DevicePath + sizeof (ISCSI_DEVICE_PATH)) != 0) {\r
     return EFI_UNSUPPORTED;\r
@@ -283,13 +308,15 @@ IScsiExtScsiPassThruGetTargetLun (
 }\r
 \r
 /**\r
-  Resets a SCSI channel.This operation resets all the SCSI devices connected to\r
-  the SCSI channel.\r
+  Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.\r
+  Currently not implemented.\r
 \r
-  @param  This[in]        Protocol instance pointer.\r
-\r
-  @retval EFI_UNSUPPORTED It's not supported.\r
+  @param[in]  This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
 \r
+  @retval EFI_SUCCESS      The SCSI channel was reset.\r
+  @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.\r
+  @retval EFI_TIMEOUT      A timeout occurred while attempting to reset the SCSI channel.\r
+  @retval EFI_UNSUPPORTED  The SCSI channel does not support a channel reset operation.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -301,15 +328,22 @@ IScsiExtScsiPassThruResetChannel (
 }\r
 \r
 /**\r
-  Resets a SCSI device that is connected to a SCSI channel.\r
-\r
-  @param  This[in]        Protocol instance pointer.\r
-\r
-  @param  Target[in]      The Target ID of the SCSI device to reset.\r
-\r
-  @param  Lun[in]         The LUN of the SCSI device to reset.\r
-\r
-  @retval EFI_UNSUPPORTED It's not supported.\r
+  Resets a SCSI logical unit that is connected to a SCSI channel. Currently not implemented.\r
+\r
+  @param[in]  This   A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
+  @param[in]  Target The Target is an array of size TARGET_MAX_BYTE and it represents the\r
+                     target port ID of the SCSI device containing the SCSI logical unit to\r
+                     reset. Transport drivers may chose to utilize a subset of this array to suit\r
+                     the representation of their targets.\r
+  @param[in]  Lun    The LUN of the SCSI device to reset.\r
+\r
+  @retval EFI_SUCCESS           The SCSI device specified by Target and Lun was reset.\r
+  @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
+  @retval EFI_TIMEOUT           A timeout occurred while attempting to reset the SCSI device\r
+                                specified by Target and Lun.\r
+  @retval EFI_UNSUPPORTED       The SCSI channel does not support a target reset operation.\r
+  @retval EFI_DEVICE_ERROR      A device error occurred while attempting to reset the SCSI device\r
+                                specified by Target and Lun.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -324,25 +358,26 @@ IScsiExtScsiPassThruResetTargetLun (
 }\r
 \r
 /**\r
-  Retrieve the list of legal Target IDs for SCSI devices on a SCSI channel.\r
-\r
-  @param  This[in]              Protocol instance pointer.\r
-\r
-  @param  Target[in]            On input, a pointer to the Target ID of a SCSI \r
-                                device present on the SCSI channel.  On output, \r
-                                a pointer to the Target ID of the next SCSI device\r
-                                present on a SCSI channel.  An input value of \r
-                                0xFFFFFFFF retrieves the Target ID of the first \r
-                                SCSI device present on a SCSI channel.\r
-\r
-  @retval EFI_SUCCESS           The Target ID and Lun of the next SCSI device \r
-                                on the SCSI channel was returned in Target and Lun.\r
-\r
+  Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either\r
+  be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs\r
+  for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to\r
+  see if a SCSI device is actually present at that location on the SCSI channel.\r
+\r
+  @param[in]       This    A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
+  @param[in, out]  Target  (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
+                           On output, a pointer to the Target ID (an array of\r
+                           TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
+                           channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
+                           Target array retrieves the Target ID of the first SCSI device present on a\r
+                           SCSI channel.\r
+\r
+  @retval EFI_SUCCESS           The Target ID of the next SCSI device on the SCSI\r
+                                channel was returned in Target.\r
+  @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
+  @retval EFI_TIMEOUT           Target array is not all 0xF, and Target were not\r
+                                returned on a previous call to GetNextTarget().\r
+                                Currently not implemented.\r
   @retval EFI_NOT_FOUND         There are no more SCSI devices on this SCSI channel.\r
-\r
-  @retval EFI_INVALID_PARAMETER Target is not 0xFFFFFFFF,and Target and Lun were not\r
-                                returned on a previous call to GetNextDevice().\r
-\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r