X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIScsiDxe%2FIScsiProto.c;h=7db57506b9ba28f89f4610c673c21bf4d1e44462;hp=93e03b0fef6e6bef993c47dc3abdabd68b10cb2e;hb=fe1e36e550c6ffcd2561903d434683d3939e1942;hpb=7a444476b4ffb405006ee36d0f2cec80c2d4b348 diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.c index 93e03b0fef..7db57506b9 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.c @@ -1,6 +1,7 @@ -/*++ +/** @file + The implementation of IScsi protocol based on RFC3720 -Copyright (c) 2004 - 2007, Intel Corporation +Copyright (c) 2004 - 2008, Intel Corporation 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 @@ -14,86 +15,68 @@ Module Name: IScsiProto.c Abstract: + The implementation of IScsi protocol based on RFC3720 ---*/ +**/ #include "IScsiImpl.h" -static UINT32 mDataSegPad = 0; - -VOID -IScsiAttatchConnection ( - IN ISCSI_SESSION *Session, - IN ISCSI_CONNECTION *Conn - ) -/*++ - -Routine Description: +UINT32 mDataSegPad = 0; +/** Attach the iSCSI connection to the iSCSI session. -Arguments: - - Session - The iSCSI session. - Conn - The iSCSI connection. + @param Session[in] The iSCSI session. -Returns: + @param Conn[in] The iSCSI connection. - None. + @retval None. ---*/ +**/ +VOID +IScsiAttatchConnection ( + IN ISCSI_SESSION *Session, + IN ISCSI_CONNECTION *Conn + ) { - NetListInsertTail (&Session->Conns, &Conn->Link); + InsertTailList (&Session->Conns, &Conn->Link); Conn->Session = Session; Session->NumConns++; } -VOID -IScsiDetatchConnection ( - IN ISCSI_CONNECTION *Conn - ) -/*++ - -Routine Description: - +/** Detach the iSCSI connection from the session it belongs to. -Arguments: - - Conn - The iSCSI connection. + @param Conn[in] The iSCSI connection. -Returns: + @retval None. - None. - ---*/ +**/ +VOID +IScsiDetatchConnection ( + IN ISCSI_CONNECTION *Conn + ) { - NetListRemoveEntry (&Conn->Link); + RemoveEntryList (&Conn->Link); Conn->Session->NumConns--; Conn->Session = NULL; } -EFI_STATUS -IScsiCheckSN ( - IN UINT32 *ExpSN, - IN UINT32 NewSN - ) -/*++ - -Routine Description: - +/** Check the sequence number according to RFC3720. -Arguments: + @param ExpSN[in] The currently expected sequence number. - ExpSN - The currently expected sequence number. - NewSN - The sequence number to check. + @param NewSN[in] The sequence number to check. -Returns: + @retval EFI_SUCCESS The check passed and the ExpSN is increased. - EFI_SUCCESS - The check passed and the ExpSN is increased. - ---*/ +**/ +EFI_STATUS +IScsiCheckSN ( + IN UINT32 *ExpSN, + IN UINT32 NewSN + ) { if (!ISCSI_SEQ_EQ (NewSN, *ExpSN)) { if (ISCSI_SEQ_LT (NewSN, *ExpSN)) { @@ -113,29 +96,24 @@ Returns: } } -VOID -IScsiUpdateCmdSN ( - IN ISCSI_SESSION *Session, - IN UINT32 MaxCmdSN, - IN UINT32 ExpCmdSN - ) -/*++ - -Routine Description: - +/** Update the sequence numbers for the iSCSI command. -Arguments: + @param Session[in] The iSCSI session. - Session - The iSCSI session. - MaxCmdSN - Maximum CmdSN from the target. - ExpCmdSN - Next expected CmdSN from the target. + @param MaxCmdSN[in] Maximum CmdSN from the target. -Returns: + @param ExpCmdSN[in] Next expected CmdSN from the target. - None. + @retval None. ---*/ +**/ +VOID +IScsiUpdateCmdSN ( + IN ISCSI_SESSION *Session, + IN UINT32 MaxCmdSN, + IN UINT32 ExpCmdSN + ) { if (ISCSI_SEQ_LT (MaxCmdSN, ExpCmdSN - 1)) { return ; @@ -150,27 +128,22 @@ Returns: } } -EFI_STATUS -IScsiConnLogin ( - IN ISCSI_CONNECTION *Conn - ) -/*++ - -Routine Description: - +/** This function does the iSCSI connection login. -Arguments: + @param Conn[in] The iSCSI connection to login. - Conn - The iSCSI connection to login. + @retval EFI_SUCCESS The iSCSI connection is logged into the iSCSI target. -Returns: + @retval EFI_TIMEOUT Timeout happened during the login procedure. - EFI_SUCCESS - The iSCSI connection is logged into the iSCSI target. - EFI_TIMEOUT - Timeout happened during the login procedure. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol error happened. + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. ---*/ +**/ +EFI_STATUS +IScsiConnLogin ( + IN ISCSI_CONNECTION *Conn + ) { EFI_STATUS Status; @@ -210,56 +183,43 @@ Returns: return Status; } +/** + Reset the iSCSI connection. + + @param Conn[in] The iSCSI connection to reset. + + @retval None. + +**/ VOID IScsiConnReset ( IN ISCSI_CONNECTION *Conn ) -/*++ - -Routine Description: - - Reset the iSCSI connection. - -Arguments: +{ + Tcp4IoReset (&Conn->Tcp4Io); +} - Conn - The iSCSI connection to reset. +/** + Create a TCP connection for the iSCSI session. -Returns: + @param Private[in] The iSCSI driver data. - None. + @param Session[in] Maximum CmdSN from the target. ---*/ -{ - Tcp4IoReset (&Conn->Tcp4Io); -} + @retval The newly created iSCSI connection. +**/ ISCSI_CONNECTION * IScsiCreateConnection ( IN ISCSI_DRIVER_DATA *Private, IN ISCSI_SESSION *Session ) -/*++ - -Routine Description: - - Create a TCP connection for the iSCSI session. - -Arguments: - - Private - The iSCSI driver data. - Session - Maximum CmdSN from the target. - -Returns: - - The newly created iSCSI connection. - ---*/ { ISCSI_CONNECTION *Conn; TCP4_IO_CONFIG_DATA Tcp4IoConfig; EFI_STATUS Status; - Conn = NetAllocatePool (sizeof (ISCSI_CONNECTION)); + Conn = AllocatePool (sizeof (ISCSI_CONNECTION)); if (Conn == NULL) { return NULL; } @@ -275,14 +235,14 @@ Returns: Conn->CID = Session->NextCID++; Status = gBS->CreateEvent ( - EFI_EVENT_TIMER, - NET_TPL_TIMER, + EVT_TIMER, + TPL_CALLBACK, NULL, NULL, &Conn->TimeoutEvent ); if (EFI_ERROR (Status)) { - NetFreePool (Conn); + gBS->FreePool (Conn); return NULL; } @@ -295,10 +255,10 @@ Returns: Conn->HeaderDigest = ISCSI_DIGEST_NONE; Conn->DataDigest = ISCSI_DIGEST_NONE; - NetCopyMem (&Tcp4IoConfig.LocalIp, &Session->ConfigData.NvData.LocalIp, sizeof (EFI_IPv4_ADDRESS)); - NetCopyMem (&Tcp4IoConfig.SubnetMask, &Session->ConfigData.NvData.SubnetMask, sizeof (EFI_IPv4_ADDRESS)); - NetCopyMem (&Tcp4IoConfig.Gateway, &Session->ConfigData.NvData.Gateway, sizeof (EFI_IPv4_ADDRESS)); - NetCopyMem (&Tcp4IoConfig.RemoteIp, &Session->ConfigData.NvData.TargetIp, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Tcp4IoConfig.LocalIp, &Session->ConfigData.NvData.LocalIp, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Tcp4IoConfig.SubnetMask, &Session->ConfigData.NvData.SubnetMask, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Tcp4IoConfig.Gateway, &Session->ConfigData.NvData.Gateway, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Tcp4IoConfig.RemoteIp, &Session->ConfigData.NvData.TargetIp, sizeof (EFI_IPv4_ADDRESS)); Tcp4IoConfig.RemotePort = Session->ConfigData.NvData.TargetPort; @@ -313,60 +273,48 @@ Returns: ); if (EFI_ERROR (Status)) { gBS->CloseEvent (Conn->TimeoutEvent); - NetFreePool (Conn); + gBS->FreePool (Conn); Conn = NULL; } return Conn; } -VOID -IScsiDestroyConnection ( - IN ISCSI_CONNECTION *Conn - ) -/*++ - -Routine Description: - +/** Destroy an iSCSI connection. -Arguments: - - Conn - The connection to destroy. + @param Conn[in] The connection to destroy. -Returns: + @retval None. - None. - ---*/ +**/ +VOID +IScsiDestroyConnection ( + IN ISCSI_CONNECTION *Conn + ) { Tcp4IoDestroySocket (&Conn->Tcp4Io); NetbufQueFlush (&Conn->RspQue); gBS->CloseEvent (Conn->TimeoutEvent); - NetFreePool (Conn); + gBS->FreePool (Conn); } -EFI_STATUS -IScsiSessionLogin ( - IN ISCSI_DRIVER_DATA *Private - ) -/*++ - -Routine Description: - +/** Login the iSCSI session. -Arguments: + @param Private[in] The iSCSI driver data. - Private - The iSCSI driver data. + @retval EFI_SUCCESS The iSCSI session login procedure finished. -Returns: + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - EFI_SUCCESS - The iSCSI session login procedure finished. - EFI_OUT_OF_RESOURCES - Failed to allocate memory. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol error happened. + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. ---*/ +**/ +EFI_STATUS +IScsiSessionLogin ( + IN ISCSI_DRIVER_DATA *Private + ) { EFI_STATUS Status; ISCSI_SESSION *Session; @@ -409,29 +357,24 @@ Returns: return Status; } -EFI_STATUS -IScsiSendLoginReq ( - IN ISCSI_CONNECTION *Conn - ) -/*++ - -Routine Description: - +/** Build and send the iSCSI login request to the iSCSI target according to the current login stage. -Arguments: + @param Conn[in] The connection in the iSCSI login phase. - Conn - The connection in the iSCSI login phase. + @retval EFI_SUCCESS The iSCSI login request PDU is built and sent on this + connection. -Returns: + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - EFI_SUCCESS - The iSCSI login request PDU is built and sent on this - connection. - EFI_OUT_OF_RESOURCES - Failed to allocate memory. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol error happened. + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. ---*/ +**/ +EFI_STATUS +IScsiSendLoginReq ( + IN ISCSI_CONNECTION *Conn + ) { NET_BUF *Pdu; EFI_STATUS Status; @@ -453,27 +396,22 @@ Returns: return Status; } -EFI_STATUS -IScsiReceiveLoginRsp ( - IN ISCSI_CONNECTION *Conn - ) -/*++ - -Routine Description: - +/** Receive and process the iSCSI login response. -Arguments: + @param Conn[in] The connection in the iSCSI login phase. - Conn - The connection in the iSCSI login phase. + @retval EFI_SUCCESS The iSCSI login response PDU is received and processed. -Returns: + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - EFI_SUCCESS - The iSCSI login response PDU is received and processed. - EFI_OUT_OF_RESOURCES - Failed to allocate memory. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol error happened. + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. ---*/ +**/ +EFI_STATUS +IScsiReceiveLoginRsp ( + IN ISCSI_CONNECTION *Conn + ) { EFI_STATUS Status; NET_BUF *Pdu; @@ -495,34 +433,31 @@ Returns: return Status; } -EFI_STATUS -IScsiAddKeyValuePair ( - IN NET_BUF *Pdu, - IN CHAR8 *Key, - IN CHAR8 *Value - ) -/*++ - -Routine Description: - +/** Add an iSCSI key-value pair as a string into the data segment of the Login Request PDU. The DataSegmentLength and the actual size of the net buffer containing this PDU will be updated. -Arguments: + @param Pdu[in] The iSCSI PDU whose data segment the key-value pair will + be added to. + + @param Key[in] The key name string. - Pdu - The iSCSI PDU whose data segment the key-value pair will be added to. - Key - The key name string. - Value - The value string. + @param Value[in] The value string. -Returns: + @retval EFI_SUCCESS The key-valu pair is added to the PDU's datasegment and + the correspondence length fields are updated. - EFI_SUCCESS - The key-valu pair is added to the PDU's datasegment and - the correspondence length fields are updated. - EFI_OUT_OF_RESOURCES - There is not enough space in the PDU to add the key-value - pair. + @retval EFI_OUT_OF_RESOURCES There is not enough space in the PDU to add the key-value + pair. ---*/ +**/ +EFI_STATUS +IScsiAddKeyValuePair ( + IN NET_BUF *Pdu, + IN CHAR8 *Key, + IN CHAR8 *Value + ) { UINT32 DataSegLen; UINT32 KeyLen; @@ -553,7 +488,7 @@ Returns: // // Add the key. // - NetCopyMem (Data, Key, KeyLen); + CopyMem (Data, Key, KeyLen); Data += KeyLen; *Data = '='; @@ -562,7 +497,7 @@ Returns: // // Add the value. // - NetCopyMem (Data, Value, ValueLen); + CopyMem (Data, Value, ValueLen); Data += ValueLen; *Data = '\0'; @@ -575,25 +510,18 @@ Returns: return EFI_SUCCESS; } -NET_BUF * -IScsiPrepareLoginReq ( - IN ISCSI_CONNECTION *Conn - ) -/*++ - -Routine Description: - +/** Prepare the iSCSI login request to be sent according to the current login status. -Arguments: + @param Conn[in] The connection in the iSCSI login phase. - Conn - The connection in the iSCSI login phase. + @retval The pointer to the net buffer containing the iSCSI login request built. -Returns: - - The pointer to the net buffer containing the iSCSI login request built. - ---*/ +**/ +NET_BUF * +IScsiPrepareLoginReq ( + IN ISCSI_CONNECTION *Conn + ) { ISCSI_SESSION *Session; NET_BUF *Nbuf; @@ -608,7 +536,7 @@ Returns: } LoginReq = (ISCSI_LOGIN_REQUEST *) NetbufAllocSpace (Nbuf, sizeof (ISCSI_LOGIN_REQUEST), NET_BUF_TAIL); - NetZeroMem (LoginReq, sizeof (ISCSI_LOGIN_REQUEST)); + ZeroMem (LoginReq, sizeof (ISCSI_LOGIN_REQUEST)); // // Init the login request pdu @@ -630,7 +558,7 @@ Returns: // with their increasing StatSN values. // LoginReq->ExpStatSN = HTONL (Conn->ExpStatSN); - NetCopyMem (LoginReq->ISID, Session->ISID, sizeof (LoginReq->ISID)); + CopyMem (LoginReq->ISID, Session->ISID, sizeof (LoginReq->ISID)); if (Conn->PartialRspRcvd) { // @@ -674,28 +602,23 @@ Returns: return Nbuf; } -EFI_STATUS -IScsiProcessLoginRsp ( - IN ISCSI_CONNECTION *Conn, - IN NET_BUF *Pdu - ) -/*++ - -Routine Description: - +/** Process the iSCSI Login Response. -Arguments: + @param Conn[in] The connection on which the iSCSI login response is received. - Conn - The connection on which the iSCSI login response is received. - Pdu - The iSCSI login response PDU. + @param Pdu[in] The iSCSI login response PDU. -Returns: + @retval EFI_SUCCESS The iSCSI login response PDU is processed and all check are passed. - EFI_SUCCESS - The iSCSI login response PDU is processed and all check are passed. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol error happened. + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. ---*/ +**/ +EFI_STATUS +IScsiProcessLoginRsp ( + IN ISCSI_CONNECTION *Conn, + IN NET_BUF *Pdu + ) { EFI_STATUS Status; ISCSI_SESSION *Session; @@ -777,7 +700,7 @@ Returns: (CurrentStage != Conn->CurrentStage) || (!Conn->TransitInitiated && Transit) || (Transit && (NextStage != Conn->NextStage)) || - (NetCompareMem (Session->ISID, LoginRsp->ISID, sizeof (LoginRsp->ISID)) != 0) || + (CompareMem (Session->ISID, LoginRsp->ISID, sizeof (LoginRsp->ISID)) != 0) || (LoginRsp->InitiatorTaskTag != Session->InitiatorTaskTag) ) { // @@ -886,34 +809,32 @@ Returns: return Status; } -EFI_STATUS -IScsiUpdateTargetAddress ( - IN ISCSI_SESSION *Session, - IN CHAR8 *Data, - IN UINT32 Len - ) -/*++ - -Routine Description: - +/** Updated the target information according the data received in the iSCSI login response with an target redirection status. -Arguments: + @param Session[in] The iSCSI session. + + @param Data[in] The data segment which should contain the + TargetAddress key-value list. + + @param Len[in] Length of the data. - Session - The iSCSI session. - Data - The data segment which should contain the TargetAddress key-value list. - Len - Length of the data. + @retval EFI_SUCCESS The target address is updated. -Returns: + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - EFI_SUCCESS - The target address is updated. - EFI_OUT_OF_RESOURCES - Failed to allocate memory. - EFI_NOT_FOUND - The TargetAddress key is not found. + @retval EFI_NOT_FOUND The TargetAddress key is not found. ---*/ +**/ +EFI_STATUS +IScsiUpdateTargetAddress ( + IN ISCSI_SESSION *Session, + IN CHAR8 *Data, + IN UINT32 Len + ) { - NET_LIST_ENTRY *KeyValueList; + LIST_ENTRY *KeyValueList; CHAR8 *TargetAddress; CHAR8 *IpStr; EFI_STATUS Status; @@ -989,54 +910,64 @@ Returns: return Status; } -VOID -IScsiFreeNbufList ( - VOID *Arg - ) -/*++ - -Routine Description: - +/** The callback function to free the net buffer list. -Arguments: + @param Arg[in] The opaque parameter. - Arg - The opaque parameter. + @retval None. -Returns: - - None. - ---*/ +**/ +VOID +IScsiFreeNbufList ( + VOID *Arg + ) { ASSERT (Arg != NULL); - NetbufFreeList ((NET_LIST_ENTRY *) Arg); - NetFreePool (Arg); + NetbufFreeList ((LIST_ENTRY *) Arg); + gBS->FreePool (Arg); } +/** + The callback function called in NetBufFree, it does nothing. + + @param Arg[in] The opaque parameter. + + @retval None. + +**/ VOID IScsiNbufExtFree ( VOID *Arg ) -/*++ +{ +} -Routine Description: +/** + Receive an iSCSI response PDU. An iSCSI response PDU contains an iSCSI PDU header and + an optional data segment. The two parts will be put into two blocks of buffers in the + net buffer. The digest check will be conducted in this function if needed and the digests + will be trimmed from the PDU buffer. - The callback function called in NetBufFree, it does nothing. + @param Conn[in] The iSCSI connection to receive data from. -Arguments: + @param Pdu[out] The received iSCSI pdu. - Arg - The opaque parameter. + @param Context[in] The context used to describe information on the caller provided + buffer to receive data segment of the iSCSI pdu, it's optional. -Returns: + @param HeaderDigest[in] Whether there will be header digest received. - None. + @param DataDigest[in] Whether there will be data digest. ---*/ -{ -} + @param TimeoutEvent[in] The timeout event, it's optional. + + @retval EFI_SUCCESS An iSCSI pdu is received. + @retval EFI_TIMEOUT Timeout happenend. + +**/ EFI_STATUS IScsiReceivePdu ( IN ISCSI_CONNECTION *Conn, @@ -1046,33 +977,8 @@ IScsiReceivePdu ( IN BOOLEAN DataDigest, IN EFI_EVENT TimeoutEvent OPTIONAL ) -/*++ - -Routine Description: - - Receive an iSCSI response PDU. An iSCSI response PDU contains an iSCSI PDU header and - an optional data segment. The two parts will be put into two blocks of buffers in the - net buffer. The digest check will be conducted in this function if needed and the digests - will be trimmed from the PDU buffer. - -Arguments: - - Conn - The iSCSI connection to receive data from. - Pdu - The received iSCSI pdu. - Context - The context used to describe information on the caller provided - buffer to receive data segment of the iSCSI pdu, it's optional. - HeaderDigest - Whether there will be header digest received. - DataDigest - Whether there will be data digest. - TimeoutEvent - The timeout event, it's optional. - -Returns: - - EFI_SUCCESS - An iSCSI pdu is received. - EFI_TIMEOUT - Timeout happenend. - ---*/ { - NET_LIST_ENTRY *NbufList; + LIST_ENTRY *NbufList; UINT32 Len; NET_BUF *PduHdr; UINT8 *Header; @@ -1084,12 +990,12 @@ Returns: NET_BUF *DataSeg; UINT32 PadAndCRC32[2]; - NbufList = NetAllocatePool (sizeof (NET_LIST_ENTRY)); + NbufList = AllocatePool (sizeof (LIST_ENTRY )); if (NbufList == NULL) { return EFI_OUT_OF_RESOURCES; } - NetListInit (NbufList); + InitializeListHead (NbufList); // // The header digest will be received together with the PDU header if exists. @@ -1102,7 +1008,7 @@ Returns: } Header = NetbufAllocSpace (PduHdr, Len, NET_BUF_TAIL); - NetListInsertTail (NbufList, &PduHdr->List); + InsertTailList (NbufList, &PduHdr->List); // // First step, receive the BHS of the PDU. @@ -1197,7 +1103,7 @@ Returns: goto ON_EXIT; } - NetListInsertTail (NbufList, &DataSeg->List); + InsertTailList (NbufList, &DataSeg->List); // // Receive the data segment with the data digest if any. @@ -1242,31 +1148,26 @@ ON_EXIT: return Status; } -EFI_STATUS -IScsiCheckOpParams ( - IN ISCSI_CONNECTION *Conn, - IN BOOLEAN Transit - ) -/*++ - -Routine Description: - +/** Check and get the result of the prameter negotiation. -Arguments: + @param Conn[in] The connection in iSCSI login. - Conn - The connection in iSCSI login. - Pdu - The iSCSI response PDU containing the parameter list. + @param Pdu[in] The iSCSI response PDU containing the parameter list. -Returns: + @retval EFI_SUCCESS The parmeter check is passed and negotiation is finished. - EFI_SUCCESS - The parmeter check is passed and negotiation is finished. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol error happened. + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. ---*/ +**/ +EFI_STATUS +IScsiCheckOpParams ( + IN ISCSI_CONNECTION *Conn, + IN BOOLEAN Transit + ) { EFI_STATUS Status; - NET_LIST_ENTRY *KeyValueList; + LIST_ENTRY *KeyValueList; CHAR8 *Data; UINT32 Len; ISCSI_SESSION *Session; @@ -1278,7 +1179,7 @@ Returns: Session = Conn->Session; Len = Conn->RspQue.BufSize; - Data = NetAllocatePool (Len); + Data = AllocatePool (Len); if (Data == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -1292,7 +1193,7 @@ Returns: // KeyValueList = IScsiBuildKeyValueList (Data, Len); if (KeyValueList == NULL) { - NetFreePool (Data); + gBS->FreePool (Data); return Status; } // @@ -1488,7 +1389,7 @@ Returns: IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_ALIAS); IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_PORTAL_GROUP_TAG); - if (NetListIsEmpty (KeyValueList)) { + if (IsListEmpty (KeyValueList)) { // // Succeed if no more keys in the list. // @@ -1499,33 +1400,28 @@ ON_ERROR: IScsiFreeKeyValueList (KeyValueList); - NetFreePool (Data); + gBS->FreePool (Data); return Status; } -EFI_STATUS -IScsiFillOpParams ( - IN ISCSI_CONNECTION *Conn, - IN NET_BUF *Pdu - ) -/*++ - -Routine Description: - +/** Fill the oprational prameters. -Arguments: + @param Conn[in] The connection in iSCSI login. - Conn - The connection in iSCSI login. - Pdu - The iSCSI login request PDU to fill the parameters. + @param Pdu[in] The iSCSI login request PDU to fill the parameters. -Returns: + @retval EFI_SUCCESS The parmeters are filled into the iSCSI login request PDU. - EFI_SUCCESS - The parmeters are filled into the iSCSI login request PDU. - EFI_OUT_OF_RESOURCES - There is not enough space in the PDU to hold the parameters. + @retval EFI_OUT_OF_RESOURCES There is not enough space in the PDU to hold the parameters. ---*/ +**/ +EFI_STATUS +IScsiFillOpParams ( + IN ISCSI_CONNECTION *Conn, + IN NET_BUF *Pdu + ) { ISCSI_SESSION *Session; CHAR8 Value[256]; @@ -1577,29 +1473,24 @@ Returns: return EFI_SUCCESS; } -EFI_STATUS -IScsiPadSegment ( - IN NET_BUF *Pdu, - IN UINT32 Len - ) -/*++ - -Routine Description: - +/** Pad the iSCSI AHS or data segment to an integer number of 4 byte words. -Arguments: + @param Pdu[in] The iSCSI pdu which contains segments to pad. - Pdu - The iSCSI pdu which contains segments to pad. - Len - The length of the last semgnet in the PDU. + @param Len[in] The length of the last semgnet in the PDU. -Returns: + @retval EFI_SUCCESS The segment is padded or no need to pad it. - EFI_SUCCESS - The segment is padded or no need to pad it. - EFI_OUT_OF_RESOURCES - There is not enough remaining free space to add the - padding bytes. + @retval EFI_OUT_OF_RESOURCES There is not enough remaining free space to add the + padding bytes. ---*/ +**/ +EFI_STATUS +IScsiPadSegment ( + IN NET_BUF *Pdu, + IN UINT32 Len + ) { UINT32 PadLen; UINT8 *Data; @@ -1612,51 +1503,45 @@ Returns: return EFI_OUT_OF_RESOURCES; } - NetZeroMem (Data, PadLen); + ZeroMem (Data, PadLen); } return EFI_SUCCESS; } -NET_LIST_ENTRY * -IScsiBuildKeyValueList ( - IN CHAR8 *Data, - IN UINT32 Len - ) -/*++ - -Routine Description: - +/** Build a key-value list from the data segment. -Arguments: - - Data - The data segment containing the key-value pairs. - Len - Length of the data segment. + @param Data[in] The data segment containing the key-value pairs. -Returns: + @param Len[in] Length of the data segment. - The key-value list. + @retval The key-value list. ---*/ +**/ +LIST_ENTRY * +IScsiBuildKeyValueList ( + IN CHAR8 *Data, + IN UINT32 Len + ) { - NET_LIST_ENTRY *ListHead; + LIST_ENTRY *ListHead; ISCSI_KEY_VALUE_PAIR *KeyValuePair; - ListHead = NetAllocatePool (sizeof (NET_LIST_ENTRY)); + ListHead = AllocatePool (sizeof (LIST_ENTRY )); if (ListHead == NULL) { return NULL; } - NetListInit (ListHead); + InitializeListHead (ListHead); while (Len > 0) { - KeyValuePair = NetAllocatePool (sizeof (ISCSI_KEY_VALUE_PAIR)); + KeyValuePair = AllocatePool (sizeof (ISCSI_KEY_VALUE_PAIR)); if (KeyValuePair == NULL) { goto ON_ERROR; } - NetListInit (&KeyValuePair->List); + InitializeListHead (&KeyValuePair->List); KeyValuePair->Key = Data; @@ -1671,13 +1556,13 @@ Returns: Data++; Len--; } else { - NetFreePool (KeyValuePair); + gBS->FreePool (KeyValuePair); goto ON_ERROR; } KeyValuePair->Value = Data; - NetListInsertTail (ListHead, &KeyValuePair->List);; + InsertTailList (ListHead, &KeyValuePair->List);; Data += AsciiStrLen (KeyValuePair->Value) + 1; Len -= (UINT32) AsciiStrLen (KeyValuePair->Value) + 1; @@ -1692,30 +1577,24 @@ ON_ERROR: return NULL; } -CHAR8 * -IScsiGetValueByKeyFromList ( - IN NET_LIST_ENTRY *KeyValueList, - IN CHAR8 *Key - ) -/*++ - -Routine Description: - +/** Get the value string by the key name from the key-value list. If found, the key-value entry will be removed from the list. -Arguments: - - KeyValueList - The key-value list. - Key - The key name to find. + @param KeyValueList[in] The key-value list. -Returns: + @param Key[in] The key name to find. - The value string. + @retval The value string. ---*/ +**/ +CHAR8 * +IScsiGetValueByKeyFromList ( + IN LIST_ENTRY *KeyValueList, + IN CHAR8 *Key + ) { - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; ISCSI_KEY_VALUE_PAIR *KeyValuePair; CHAR8 *Value; @@ -1727,8 +1606,8 @@ Returns: if (AsciiStrCmp (KeyValuePair->Key, Key) == 0) { Value = KeyValuePair->Value; - NetListRemoveEntry (&KeyValuePair->List); - NetFreePool (KeyValuePair); + RemoveEntryList (&KeyValuePair->List); + gBS->FreePool (KeyValuePair); break; } } @@ -1736,61 +1615,49 @@ Returns: return Value; } -VOID -IScsiFreeKeyValueList ( - IN NET_LIST_ENTRY *KeyValueList - ) -/*++ - -Routine Description: - +/** Free the key-value list. -Arguments: + @param KeyValueList[in] The key-value list. + + @retval None. - KeyValueList - The key-value list. - -Returns: - - None. - ---*/ +**/ +VOID +IScsiFreeKeyValueList ( + IN LIST_ENTRY *KeyValueList + ) { - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; ISCSI_KEY_VALUE_PAIR *KeyValuePair; - while (!NetListIsEmpty (KeyValueList)) { + while (!IsListEmpty (KeyValueList)) { Entry = NetListRemoveHead (KeyValueList); KeyValuePair = NET_LIST_USER_STRUCT (Entry, ISCSI_KEY_VALUE_PAIR, List); - NetFreePool (KeyValuePair); + gBS->FreePool (KeyValuePair); } - NetFreePool (KeyValueList); + gBS->FreePool (KeyValueList); } -EFI_STATUS -IScsiNormalizeName ( - IN CHAR8 *Name, - IN UINTN Len - ) -/*++ - -Routine Description: - +/** Normalize the iSCSI name according to RFC. -Arguments: + @param Name[in] The iSCSI name. - Name - The iSCSI name. - Len - length of the iSCSI name. + @param Len[in] length of the iSCSI name. -Returns: + @retval EFI_SUCCESS The iSCSI name is valid and normalized. - EFI_SUCCESS - The iSCSI name is valid and normalized. - EFI_PROTOCOL_ERROR - The iSCSI name is mal-formatted or not in the IQN format. + @retval EFI_PROTOCOL_ERROR The iSCSI name is mal-formatted or not in the IQN format. ---*/ +**/ +EFI_STATUS +IScsiNormalizeName ( + IN CHAR8 *Name, + IN UINTN Len + ) { UINTN Index; @@ -1816,7 +1683,7 @@ Returns: } } - if ((Len < 4) || (NetCompareMem (Name, "iqn.", 4) != 0)) { + if ((Len < 4) || (CompareMem (Name, "iqn.", 4) != 0)) { // // Only IQN format is accepted now. // @@ -1826,28 +1693,23 @@ Returns: return EFI_SUCCESS; } -EFI_STATUS -IScsiNewTcb ( - IN ISCSI_CONNECTION *Conn, - OUT ISCSI_TCB **Tcb - ) -/*++ - -Routine Description: - +/** Create an iSCSI task control block. -Arguments: + @param Conn[in] The connection on which the task control block will be created. - Conn - The connection on which the task control block will be created. - Tcb - The newly created task control block. + @param Tcb[out] The newly created task control block. -Returns: + @retval EFI_SUCCESS The task control block is created. - EFI_SUCCESS - The task control block is created. - EFI_OUT_OF_RESOURCES - Failed to allocate memory. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. ---*/ +**/ +EFI_STATUS +IScsiNewTcb ( + IN ISCSI_CONNECTION *Conn, + OUT ISCSI_TCB **Tcb + ) { ISCSI_SESSION *Session; ISCSI_TCB *NewTcb; @@ -1860,19 +1722,19 @@ Returns: return EFI_NOT_READY; } - NewTcb = NetAllocateZeroPool (sizeof (ISCSI_TCB)); + NewTcb = AllocateZeroPool (sizeof (ISCSI_TCB)); if (NewTcb == NULL) { return EFI_OUT_OF_RESOURCES; } - NetListInit (&NewTcb->Link); + InitializeListHead (&NewTcb->Link); NewTcb->SoFarInOrder = TRUE; NewTcb->InitiatorTaskTag = Session->InitiatorTaskTag; NewTcb->CmdSN = Session->CmdSN; NewTcb->Conn = Conn; - NetListInsertTail (&Session->TcbList, &NewTcb->Link); + InsertTailList (&Session->TcbList, &NewTcb->Link); // // Advance the initiator task tag. @@ -1885,55 +1747,42 @@ Returns: return EFI_SUCCESS; } +/** + Delete the tcb from the connection and destroy it. + + @param Tcb The tcb to delete. + + @retval None. + +**/ VOID IScsiDelTcb ( IN ISCSI_TCB *Tcb ) -/*++ - -Routine Description: - - Delete the tcb from the connection and destroy it. +{ + RemoveEntryList (&Tcb->Link); -Arguments: + gBS->FreePool (Tcb); +} - Tcb - The tcb to delete. +/** + Find the task control block by the initator task tag. -Returns: + @param TcbList[in] The tcb list. - None. + @param InitiatorTaskTag[in] The initiator task tag. ---*/ -{ - NetListRemoveEntry (&Tcb->Link); - - NetFreePool (Tcb); -} + @retval The task control block found. +**/ ISCSI_TCB * IScsiFindTcbByITT ( - IN NET_LIST_ENTRY *TcbList, + IN LIST_ENTRY *TcbList, IN UINT32 InitiatorTaskTag ) -/*++ - -Routine Description: - - Find the task control block by the initator task tag. - -Arguments: - - TcbList - The tcb list. - InitiatorTaskTag - The initiator task tag. - -Returns: - - The task control block found. - ---*/ { ISCSI_TCB *Tcb; - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; Tcb = NULL; @@ -1950,29 +1799,24 @@ Returns: return Tcb; } -NET_BUF * -IScsiNewDataSegment ( - IN UINT8 *Data, - IN UINT32 Len, - IN BOOLEAN DataDigest - ) -/*++ - -Routine Description: - +/** Create a data segment, pad it and calculate the CRC if needed. -Arguments: + @param Data[in] The data to fill into the data segment. - Data - The data to fill into the data segment. - Len - Length of the data. - DataDigest - Whether to calculate CRC for this data segment. + @param Len[in] Length of the data. -Returns: + @param DataDigest[in] Whether to calculate CRC for this data segment. - The net buffer wrapping the data segment. + @retval The net buffer wrapping the data segment. ---*/ +**/ +NET_BUF * +IScsiNewDataSegment ( + IN UINT8 *Data, + IN UINT32 Len, + IN BOOLEAN DataDigest + ) { NET_FRAGMENT Fragment[2]; UINT32 FragmentCount; @@ -1997,32 +1841,27 @@ Returns: return DataSeg; } -NET_BUF * -IScsiNewScsiCmdPdu ( - IN EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, - IN UINT64 Lun, - IN ISCSI_TCB *Tcb - ) -/*++ - -Routine Description: - +/** Create a iSCSI SCSI command PDU to encapsulate the command issued by SCSI through the EXT SCSI PASS THRU Protocol. -Arguments: + @param Packet[in] The EXT SCSI PASS THRU request packet containing the SCSI command. - Packet - The EXT SCSI PASS THRU request packet containing the SCSI command. - Lun - The LUN. - Tcb - The tcb assocated with this SCSI command. + @param Lun[in] The LUN. -Returns: + @param Tcb[in] The tcb assocated with this SCSI command. - The created iSCSI SCSI command PDU. + @retval The created iSCSI SCSI command PDU. ---*/ +**/ +NET_BUF * +IScsiNewScsiCmdPdu ( + IN EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, + IN UINT64 Lun, + IN ISCSI_TCB *Tcb + ) { - NET_LIST_ENTRY *NbufList; + LIST_ENTRY *NbufList; NET_BUF *Pdu; NET_BUF *PduHeader; NET_BUF *DataSeg; @@ -2060,7 +1899,7 @@ Returns: ScsiCmd = (SCSI_COMMAND *) NetbufAllocSpace (PduHeader, Length, NET_BUF_TAIL); Header = (ISCSI_ADDITIONAL_HEADER *) (ScsiCmd + 1); - NetZeroMem (ScsiCmd, Length); + ZeroMem (ScsiCmd, Length); ISCSI_SET_OPCODE (ScsiCmd, ISCSI_OPCODE_SCSI_CMD, 0); ISCSI_SET_FLAG (ScsiCmd, ISCSI_TASK_ATTR_SIMPLE); @@ -2097,18 +1936,18 @@ Returns: } ScsiCmd->TotalAHSLength = AHSLength; - NetCopyMem (ScsiCmd->Lun, &Lun, sizeof (ScsiCmd->Lun)); + CopyMem (ScsiCmd->Lun, &Lun, sizeof (ScsiCmd->Lun)); ScsiCmd->InitiatorTaskTag = NTOHL (Tcb->InitiatorTaskTag); ScsiCmd->CmdSN = NTOHL (Tcb->CmdSN); ScsiCmd->ExpStatSN = NTOHL (Tcb->Conn->ExpStatSN); - NetCopyMem (ScsiCmd->CDB, Packet->Cdb, sizeof (ScsiCmd->CDB)); + CopyMem (ScsiCmd->CDB, Packet->Cdb, sizeof (ScsiCmd->CDB)); if (Packet->CdbLength > 16) { Header->Length = NTOHS (Packet->CdbLength - 15); Header->Type = ISCSI_AHS_TYPE_EXT_CDB; - NetCopyMem (Header + 1, (UINT8 *) Packet->Cdb + 16, Packet->CdbLength - 16); + CopyMem (Header + 1, (UINT8 *) Packet->Cdb + 16, Packet->CdbLength - 16); } Pdu = PduHeader; @@ -2139,7 +1978,7 @@ Returns: goto ON_EXIT; } - NbufList = NetAllocatePool (sizeof (NET_LIST_ENTRY)); + NbufList = AllocatePool (sizeof (LIST_ENTRY )); if (NbufList == NULL) { NetbufFree (PduHeader); NetbufFree (DataSeg); @@ -2148,9 +1987,9 @@ Returns: goto ON_EXIT; } - NetListInit (NbufList); - NetListInsertTail (NbufList, &PduHeader->List); - NetListInsertTail (NbufList, &DataSeg->List); + InitializeListHead (NbufList); + InsertTailList (NbufList, &PduHeader->List); + InsertTailList (NbufList, &DataSeg->List); Pdu = NetbufFromBufList (NbufList, 0, 0, IScsiFreeNbufList, NbufList); if (Pdu == NULL) { @@ -2177,6 +2016,22 @@ ON_EXIT: return Pdu; } +/** + Create a new iSCSI SCSI Data Out PDU. + + @param Data[in] The data to put into the Data Out PDU. + + @param Len[in] Length of the data. + + @param DataSN[in] The DataSN of the Data Out PDU. + + @param Tcb[in] The task control block of this Data Out PDU. + + @param Lun[in] The LUN. + + @retval The net buffer wrapping the Data Out PDU. + +**/ NET_BUF * IScsiNewDataOutPdu ( IN UINT8 *Data, @@ -2185,57 +2040,38 @@ IScsiNewDataOutPdu ( IN ISCSI_TCB *Tcb, IN UINT64 Lun ) -/*++ - -Routine Description: - - Create a new iSCSI SCSI Data Out PDU. - -Arguments: - - Data - The data to put into the Data Out PDU. - Len - Length of the data. - DataSN - The DataSN of the Data Out PDU. - Tcb - The task control block of this Data Out PDU. - Lun - The LUN. - -Returns: - - The net buffer wrapping the Data Out PDU. - ---*/ { - NET_LIST_ENTRY *NbufList; + LIST_ENTRY *NbufList; NET_BUF *PduHdr; NET_BUF *DataSeg; NET_BUF *Pdu; ISCSI_SCSI_DATA_OUT *DataOutHdr; ISCSI_XFER_CONTEXT *XferContext; - NbufList = NetAllocatePool (sizeof (NET_LIST_ENTRY)); + NbufList = AllocatePool (sizeof (LIST_ENTRY )); if (NbufList == NULL) { return NULL; } - NetListInit (NbufList); + InitializeListHead (NbufList); // // Allocate memory for the BHS. // PduHdr = NetbufAlloc (sizeof (ISCSI_SCSI_DATA_OUT)); if (PduHdr == NULL) { - NetFreePool (NbufList); + gBS->FreePool (NbufList); return NULL; } // // Insert the BHS into the buffer list. // - NetListInsertTail (NbufList, &PduHdr->List); + InsertTailList (NbufList, &PduHdr->List); DataOutHdr = (ISCSI_SCSI_DATA_OUT *) NetbufAllocSpace (PduHdr, sizeof (ISCSI_SCSI_DATA_OUT), NET_BUF_TAIL); XferContext = &Tcb->XferContext; - NetZeroMem (DataOutHdr, sizeof (ISCSI_SCSI_DATA_OUT)); + ZeroMem (DataOutHdr, sizeof (ISCSI_SCSI_DATA_OUT)); // // Set the flags and fields of the Data Out PDU BHS. @@ -2250,7 +2086,7 @@ Returns: DataOutHdr->BufferOffset = HTONL (XferContext->Offset); if (XferContext->TargetTransferTag != ISCSI_RESERVED_TAG) { - NetCopyMem (&DataOutHdr->Lun, &Lun, sizeof (DataOutHdr->Lun)); + CopyMem (&DataOutHdr->Lun, &Lun, sizeof (DataOutHdr->Lun)); } // // Build the data segment for this Data Out PDU. @@ -2264,7 +2100,7 @@ Returns: // Put the data segment into the buffer list and combine it with the BHS // into a full Data Out PDU. // - NetListInsertTail (NbufList, &DataSeg->List); + InsertTailList (NbufList, &DataSeg->List); Pdu = NetbufFromBufList (NbufList, 0, 0, IScsiFreeNbufList, NbufList); if (Pdu == NULL) { IScsiFreeNbufList (NbufList); @@ -2273,43 +2109,38 @@ Returns: return Pdu; } -NET_LIST_ENTRY * -IScsiGenerateDataOutPduSequence ( - IN UINT8 *Data, - IN ISCSI_TCB *Tcb, - IN UINT64 Lun - ) -/*++ - -Routine Description: - +/** Generate a consecutive sequence of iSCSI SCSI Data Out PDUs. -Arguments: + @param Data[in] The data which will be carried by the sequence of iSCSI SCSI Data Out PDUs. - Data - The data which will be carried by the sequence of iSCSI SCSI Data Out PDUs. - Tcb - The task control block of the data to send out. - Lun - The LUN the data will be sent to. + @param Tcb[in] The task control block of the data to send out. -Returns: + @param Lun[in] The LUN the data will be sent to. - A list of net buffers with each of them wraps an iSCSI SCSI Data Out PDU. + @retval A list of net buffers with each of them wraps an iSCSI SCSI Data Out PDU. ---*/ +**/ +LIST_ENTRY * +IScsiGenerateDataOutPduSequence ( + IN UINT8 *Data, + IN ISCSI_TCB *Tcb, + IN UINT64 Lun + ) { - NET_LIST_ENTRY *PduList; + LIST_ENTRY *PduList; UINT32 DataSN; UINT32 DataLen; NET_BUF *DataOutPdu; ISCSI_CONNECTION *Conn; ISCSI_XFER_CONTEXT *XferContext; - PduList = NetAllocatePool (sizeof (NET_LIST_ENTRY)); + PduList = AllocatePool (sizeof (LIST_ENTRY )); if (PduList == NULL) { return NULL; } - NetListInit (PduList); + InitializeListHead (PduList); DataSN = 0; Conn = Tcb->Conn; @@ -2321,7 +2152,6 @@ Returns: // Determine the length of data this Data Out PDU can carry. // DataLen = MIN (XferContext->DesiredLength, Conn->MaxRecvDataSegmentLength); - Data += DataLen; // // Create a Data Out PDU. @@ -2334,7 +2164,7 @@ Returns: goto ON_EXIT; } - NetListInsertTail (PduList, &DataOutPdu->List); + InsertTailList (PduList, &DataOutPdu->List); // // Update the context and DataSN. @@ -2342,6 +2172,7 @@ Returns: XferContext->Offset += DataLen; XferContext->DesiredLength -= DataLen; DataSN++; + Data += DataLen; } // // Set the F bit for the last data out PDU in this sequence. @@ -2353,33 +2184,29 @@ ON_EXIT: return PduList; } -EFI_STATUS -IScsiSendDataOutPduSequence ( - IN UINT8 *Data, - IN UINT64 Lun, - IN ISCSI_TCB *Tcb - ) -/*++ - -Routine Description: - +/** Send the Data in a sequence of Data Out PDUs one by one. -Arguments: + @param Data[in] The data to carry by Data Out PDUs. - Data - The data to carry by Data Out PDUs. - Lun - The LUN the data will be sent to. - Tcb - The task control block. + @param Lun[in] The LUN the data will be sent to. -Returns: + @param Tcb[in] The task control block. - EFI_SUCCES - The data is sent out to the LUN. - EFI_OUT_OF_RESOURCES - Failed to allocate memory. + @retval EFI_SUCCES The data is sent out to the LUN. ---*/ + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + +**/ +EFI_STATUS +IScsiSendDataOutPduSequence ( + IN UINT8 *Data, + IN UINT64 Lun, + IN ISCSI_TCB *Tcb + ) { - NET_LIST_ENTRY *DataOutPduList; - NET_LIST_ENTRY *Entry; + LIST_ENTRY *DataOutPduList; + LIST_ENTRY *Entry; NET_BUF *Pdu; EFI_STATUS Status; @@ -2410,31 +2237,27 @@ Returns: return Status; } -EFI_STATUS -IScsiOnDataInRcvd ( - IN NET_BUF *Pdu, - IN ISCSI_TCB *Tcb, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet - ) -/*++ - -Routine Description: - +/** Process the received iSCSI SCSI Data In PDU. -Arguments: + @param Pdu[in] The Data In PDU received. - Pdu - The Data In PDU received. - Tcb - The task control block. - Packet - The EXT SCSI PASS THRU request packet. + @param Tcb[in] The task control block. -Returns: + @param Packet[in][out] The EXT SCSI PASS THRU request packet. - EFI_SUCCES - The check on the Data IN PDU is passed and some update - actions are taken. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol errror happened. + @retval EFI_SUCCES The check on the Data IN PDU is passed and some update + actions are taken. ---*/ + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened. + +**/ +EFI_STATUS +IScsiOnDataInRcvd ( + IN NET_BUF *Pdu, + IN ISCSI_TCB *Tcb, + IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet + ) { ISCSI_SCSI_DATA_IN *DataInHdr; EFI_STATUS Status; @@ -2502,32 +2325,29 @@ Returns: return Status; } -EFI_STATUS -IScsiOnR2TRcvd ( - IN NET_BUF *Pdu, - IN ISCSI_TCB *Tcb, - IN UINT64 Lun, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet - ) -/*++ +/** + Process the received iSCSI R2T PDU. -Routine Description: + @param Pdu[in] The R2T PDU received. - Process the received iSCSI R2T PDU. + @param Tcb[in] The task control block. -Arguments: + @param Lun[in] The Lun. - Pdu - The R2T PDU received. - Tcb - The task control block. - Lun - The Lun. - Packet - The EXT SCSI PASS THRU request packet. + @param Packet[in][out] The EXT SCSI PASS THRU request packet. -Returns: + @retval EFI_SUCCES The R2T PDU is valid and the solicited data is sent out. - EFI_SUCCES - The R2T PDU is valid and the solicited data is sent out. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol errror happened. + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened. ---*/ +**/ +EFI_STATUS +IScsiOnR2TRcvd ( + IN NET_BUF *Pdu, + IN ISCSI_TCB *Tcb, + IN UINT64 Lun, + IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet + ) { ISCSI_READY_TO_TRANSFER *R2THdr; EFI_STATUS Status; @@ -2573,30 +2393,26 @@ Returns: return Status; } -EFI_STATUS -IScsiOnScsiRspRcvd ( - IN NET_BUF *Pdu, - IN ISCSI_TCB *Tcb, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet - ) -/*++ - -Routine Description: - +/** Process the received iSCSI SCSI Response PDU. -Arguments: + @param Pdu[in] The Response PDU received. + + @param Tcb[in] The task control block. - Pdu - The Response PDU received. - Tcb - The task control block. - Packet - The EXT SCSI PASS THRU request packet. + @param Packet[in][out] The EXT SCSI PASS THRU request packet. -Returns: + @retval EFI_SUCCES The Response PDU is processed. - EFI_SUCCES - The Response PDU is processed. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol errror happened. + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened. ---*/ +**/ +EFI_STATUS +IScsiOnScsiRspRcvd ( + IN NET_BUF *Pdu, + IN ISCSI_TCB *Tcb, + IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet + ) { SCSI_RESPONSE *ScsiRspHdr; ISCSI_SENSE_DATA *SenseData; @@ -2671,7 +2487,7 @@ Returns: Packet->SenseDataLength = (UINT8) MIN (SenseData->Length, Packet->SenseDataLength); if (Packet->SenseDataLength != 0) { - NetCopyMem (Packet->SenseData, &SenseData->Data[0], Packet->SenseDataLength); + CopyMem (Packet->SenseData, &SenseData->Data[0], Packet->SenseDataLength); } } else { Packet->SenseDataLength = 0; @@ -2680,29 +2496,24 @@ Returns: return Status; } -EFI_STATUS -IScsiOnNopInRcvd ( - IN NET_BUF *Pdu, - IN ISCSI_TCB *Tcb - ) -/*++ - -Routine Description: - +/** Process the received NOP In PDU. -Arguments: + @param Pdu[in] The NOP In PDU received. - Pdu - The NOP In PDU received. - Tcb - The task control block. + @param Tcb[in] The task control block. -Returns: + @retval EFI_SUCCES The NOP In PDU is processed and the related sequence + numbers are updated. - EFI_SUCCES - The NOP In PDU is processed and the related sequence - numbers are updated. - EFI_PROTOCOL_ERROR - Some kind of iSCSI protocol errror happened. + @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened. ---*/ +**/ +EFI_STATUS +IScsiOnNopInRcvd ( + IN NET_BUF *Pdu, + IN ISCSI_TCB *Tcb + ) { ISCSI_NOP_IN *NopInHdr; EFI_STATUS Status; @@ -2729,34 +2540,31 @@ Returns: return EFI_SUCCESS; } -EFI_STATUS -IScsiExecuteScsiCommand ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru, - IN UINT8 *Target, - IN UINT64 Lun, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet - ) -/*++ +/** + Execute the SCSI command issued through the EXT SCSI PASS THRU protocol. -Routine Description: + @param PassThru[in] The EXT SCSI PASS THRU protocol. - Execute the SCSI command issued through the EXT SCSI PASS THRU protocol. + @param Target[in] The target ID. -Arguments: + @param Lun[in] The LUN. - PassThru - The EXT SCSI PASS THRU protocol. - Target - The target ID. - Lun - The LUN. - Packet - The request packet containing IO request, SCSI command buffer and - buffers to read/write. + @param Packet[in][out] The request packet containing IO request, SCSI command + buffer and buffers to read/write. -Returns: + @retval EFI_SUCCES The SCSI command is executed and the result is updated to + the Packet. - EFI_SUCCES - The SCSI command is executed and the result is updated to - the Packet. - EFI_DEVICE_ERROR - Some unexpected error happened. + @retval EFI_DEVICE_ERROR Some unexpected error happened. ---*/ +**/ +EFI_STATUS +IScsiExecuteScsiCommand ( + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru, + IN UINT8 *Target, + IN UINT64 Lun, + IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet + ) { EFI_STATUS Status; ISCSI_DRIVER_DATA *Private; @@ -2776,6 +2584,7 @@ Returns: Status = EFI_SUCCESS; Tcb = NULL; TimeoutEvent = NULL; + Timeout = 0; if (Session->State != SESSION_STATE_LOGGED_IN) { return EFI_DEVICE_ERROR; @@ -2790,15 +2599,6 @@ Returns: if (Packet->Timeout != 0) { Timeout = MultU64x32 (Packet->Timeout, 2); - // - // Start the timeout timer. - // - Status = gBS->SetTimer (Conn->TimeoutEvent, TimerRelative, Timeout); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - TimeoutEvent = Conn->TimeoutEvent; } Status = IScsiNewTcb (Conn, &Tcb); @@ -2854,6 +2654,16 @@ Returns: InBufferContext.InDataLen = Packet->InTransferLength; while (!Tcb->StatusXferd) { + // + // Start the timeout timer. + // + if (Timeout) { + Status = gBS->SetTimer (Conn->TimeoutEvent, TimerRelative, Timeout); + if (EFI_ERROR (Status)) { + goto ON_EXIT; + } + TimeoutEvent = Conn->TimeoutEvent; + } // // try to receive PDU from target. // @@ -2921,26 +2731,20 @@ ON_EXIT: return Status; } -EFI_STATUS -IScsiSessionReinstatement ( - IN ISCSI_DRIVER_DATA *Private - ) -/*++ - -Routine Description: - +/** Reinstate the session on some error. -Arguments: - - Private - The iSCSI driver data. + @param Private[in] The iSCSI driver data. -Returns: + @retval EFI_SUCCES The session is reinstated from some error. - EFI_SUCCES - The session is reinstated from some error. - other - Reinstatement failed. + @retval other Reinstatement failed. ---*/ +**/ +EFI_STATUS +IScsiSessionReinstatement ( + IN ISCSI_DRIVER_DATA *Private + ) { ISCSI_SESSION *Session; EFI_STATUS Status; @@ -2962,27 +2766,21 @@ Returns: return Status; } -VOID -IScsiSessionInit ( - IN ISCSI_SESSION *Session, - IN BOOLEAN Recovery - ) -/*++ - -Routine Description: - +/** Initialize some session parameters before login. -Arguments: - - Session - The iSCSI session. - Recovery - Whether the request is from a fresh new start or recovery. + @param Session[in] The iSCSI session. -Returns: + @param Recovery[in] Whether the request is from a fresh new start or recovery. - None. + @retval None. ---*/ +**/ +VOID +IScsiSessionInit ( + IN ISCSI_SESSION *Session, + IN BOOLEAN Recovery + ) { UINT32 Random; @@ -2999,8 +2797,8 @@ Returns: Session->ISID[4] = (UINT8) Random; Session->ISID[5] = (UINT8) (Random >> 8); - NetListInit (&Session->Conns); - NetListInit (&Session->TcbList); + InitializeListHead (&Session->Conns); + InitializeListHead (&Session->TcbList); } Session->TSIH = 0; @@ -3023,26 +2821,19 @@ Returns: Session->ErrorRecoveryLevel = 0; } -EFI_STATUS -IScsiSessionAbort ( - IN ISCSI_SESSION *Session - ) -/*++ - -Routine Description: - +/** Abort the iSCSI session, that is, reset all the connection and free the resources. -Arguments: - - Session - The iSCSI session. - -Returns: + @param Session[in] The iSCSI session. - EFI_SUCCES - The session is aborted. + @retval EFI_SUCCES The session is aborted. ---*/ +**/ +EFI_STATUS +IScsiSessionAbort ( + IN ISCSI_SESSION *Session + ) { ISCSI_DRIVER_DATA *Private; ISCSI_CONNECTION *Conn; @@ -3051,11 +2842,11 @@ Returns: return EFI_SUCCESS; } - ASSERT (!NetListIsEmpty (&Session->Conns)); + ASSERT (!IsListEmpty (&Session->Conns)); Private = ISCSI_DRIVER_DATA_FROM_SESSION (Session); - while (!NetListIsEmpty (&Session->Conns)) { + while (!IsListEmpty (&Session->Conns)) { Conn = NET_LIST_USER_STRUCT_S ( Session->Conns.ForwardLink, ISCSI_CONNECTION,