/** @file\r
- The implementation of IScsi protocol based on RFC3720.\r
+ The implementation of iSCSI protocol based on RFC3720.\r
\r
Copyright (c) 2004 - 2008, Intel Corporation.<BR>\r
All rights reserved. This program and the accompanying materials\r
/**\r
Attach the iSCSI connection to the iSCSI session. \r
\r
- @param[in] Session The iSCSI session.\r
- @param[in] Conn The iSCSI connection.\r
+ @param[in, out] Session The iSCSI session.\r
+ @param[in, out] Conn The iSCSI connection.\r
**/\r
VOID\r
IScsiAttatchConnection (\r
- IN ISCSI_SESSION *Session,\r
- IN ISCSI_CONNECTION *Conn\r
+ IN OUT ISCSI_SESSION *Session,\r
+ IN OUT ISCSI_CONNECTION *Conn\r
)\r
{\r
InsertTailList (&Session->Conns, &Conn->Link);\r
/**\r
Detach the iSCSI connection from the session it belongs to. \r
\r
- @param[in] Conn The iSCSI connection.\r
+ @param[in, out] Conn The iSCSI connection.\r
**/\r
VOID\r
IScsiDetatchConnection (\r
- IN ISCSI_CONNECTION *Conn\r
+ IN OUT ISCSI_CONNECTION *Conn\r
)\r
{\r
RemoveEntryList (&Conn->Link);\r
/**\r
Check the sequence number according to RFC3720. \r
\r
- @param[in] ExpSN The currently expected sequence number.\r
- @param[in] NewSN The sequence number to check.\r
+ @param[in, out] ExpSN The currently expected sequence number.\r
+ @param[in] NewSN The sequence number to check.\r
\r
@retval EFI_SUCCESS The check passed and the ExpSN is increased.\r
@retval EFI_NOT_READY Response was sent due to a retransmission request.\r
**/\r
EFI_STATUS\r
IScsiCheckSN (\r
- IN UINT32 *ExpSN,\r
- IN UINT32 NewSN\r
+ IN OUT UINT32 *ExpSN,\r
+ IN UINT32 NewSN\r
)\r
{\r
if (!ISCSI_SEQ_EQ (NewSN, *ExpSN)) {\r
/**\r
Update the sequence numbers for the iSCSI command.\r
\r
- @param[in] Session The iSCSI session.\r
- @param[in] MaxCmdSN Maximum CmdSN from the target.\r
- @param[in] ExpCmdSN Next expected CmdSN from the target.\r
+ @param[in, out] Session The iSCSI session.\r
+ @param[in] MaxCmdSN Maximum CmdSN from the target.\r
+ @param[in] ExpCmdSN Next expected CmdSN from the target.\r
**/\r
VOID\r
IScsiUpdateCmdSN (\r
- IN ISCSI_SESSION *Session,\r
- IN UINT32 MaxCmdSN,\r
- IN UINT32 ExpCmdSN\r
+ IN OUT ISCSI_SESSION *Session,\r
+ IN UINT32 MaxCmdSN,\r
+ IN UINT32 ExpCmdSN\r
)\r
{\r
if (ISCSI_SEQ_LT (MaxCmdSN, ExpCmdSN - 1)) {\r
/**\r
This function does the iSCSI connection login.\r
\r
- @param[in] Conn The iSCSI connection to login.\r
+ @param[in, out] Conn The iSCSI connection to login.\r
\r
@retval EFI_SUCCESS The iSCSI connection is logged into the iSCSI target.\r
@retval EFI_TIMEOUT Timeout happened during the login procedure.\r
- @retval Others Some unexpected error happened. \r
+ @retval Others Other errors as indicated. \r
**/\r
EFI_STATUS\r
IScsiConnLogin (\r
- IN ISCSI_CONNECTION *Conn\r
+ IN OUT ISCSI_CONNECTION *Conn\r
)\r
{\r
EFI_STATUS Status;\r
/**\r
Reset the iSCSI connection.\r
\r
- @param[in] Conn The iSCSI connection to reset.\r
+ @param[in, out] Conn The iSCSI connection to reset.\r
**/\r
VOID\r
IScsiConnReset (\r
- IN ISCSI_CONNECTION *Conn\r
+ IN OUT ISCSI_CONNECTION *Conn\r
)\r
{\r
Tcp4IoReset (&Conn->Tcp4Io);\r
Conn->ExpStatSN = 0;\r
Conn->PartialReqSent = FALSE;\r
Conn->PartialRspRcvd = FALSE;\r
- Conn->CID = Session->NextCID++;\r
+ Conn->Cid = Session->NextCid++;\r
\r
Status = gBS->CreateEvent (\r
EVT_TIMER,\r
\r
@retval EFI_SUCCESS The iSCSI session login procedure finished.\r
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiSessionLogin (\r
@param[in] Conn The connection in the iSCSI login phase.\r
\r
@retval EFI_SUCCESS The iSCSI login response PDU is received and processed.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiReceiveLoginRsp (\r
The DataSegmentLength and the actual size of the net buffer containing this PDU will be\r
updated.\r
\r
- @param[in] Pdu The iSCSI PDU whose data segment the key-value pair will\r
+ @param[in, out] Pdu The iSCSI PDU whose data segment the key-value pair will\r
be added to.\r
- @param[in] Key The key name string.\r
- @param[in] Value The value string.\r
+ @param[in] Key The key name string.\r
+ @param[in] Value The value string.\r
\r
@retval EFI_SUCCESS The key-valu pair is added to the PDU's datasegment and\r
the correspondence length fields are updated.\r
**/\r
EFI_STATUS\r
IScsiAddKeyValuePair (\r
- IN NET_BUF *Pdu,\r
+ IN OUT NET_BUF *Pdu,\r
IN CHAR8 *Key,\r
IN CHAR8 *Value\r
)\r
/**\r
Prepare the iSCSI login request to be sent according to the current login status.\r
\r
- @param[in] Conn The connection in the iSCSI login phase.\r
+ @param[in, out] Conn The connection in the iSCSI login phase.\r
\r
@return The pointer to the net buffer containing the iSCSI login request built.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
NET_BUF *\r
IScsiPrepareLoginReq (\r
- IN ISCSI_CONNECTION *Conn\r
+ IN OUT ISCSI_CONNECTION *Conn\r
)\r
{\r
ISCSI_SESSION *Session;\r
ISCSI_SET_STAGES (LoginReq, Conn->CurrentStage, Conn->NextStage);\r
LoginReq->VersionMax = ISCSI_VERSION_MAX;\r
LoginReq->VersionMin = ISCSI_VERSION_MIN;\r
- LoginReq->TSIH = HTONS (Session->TSIH);\r
+ LoginReq->Tsih = HTONS (Session->Tsih);\r
LoginReq->InitiatorTaskTag = HTONL (Session->InitiatorTaskTag);\r
- LoginReq->CID = HTONS (Conn->CID);\r
+ LoginReq->Cid = HTONS (Conn->Cid);\r
LoginReq->CmdSN = HTONL (Session->CmdSN);\r
\r
//\r
// with their increasing StatSN values.\r
//\r
LoginReq->ExpStatSN = HTONL (Conn->ExpStatSN);\r
- CopyMem (LoginReq->ISID, Session->ISID, sizeof (LoginReq->ISID));\r
+ CopyMem (LoginReq->Isid, Session->Isid, sizeof (LoginReq->Isid));\r
\r
if (Conn->PartialRspRcvd) {\r
//\r
/**\r
Process the iSCSI Login Response.\r
\r
- @param[in] Conn The connection on which the iSCSI login response is received.\r
- @param[in] Pdu The iSCSI login response PDU.\r
+ @param[in, out] Conn The connection on which the iSCSI login response is received.\r
+ @param[in, out] Pdu The iSCSI login response PDU.\r
\r
@retval EFI_SUCCESS The iSCSI login response PDU is processed and all check are passed.\r
@retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened.\r
@retval EFI_MEDIA_CHANGED Target is redirected.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiProcessLoginRsp (\r
- IN ISCSI_CONNECTION *Conn,\r
- IN NET_BUF *Pdu\r
+ IN OUT ISCSI_CONNECTION *Conn,\r
+ IN OUT NET_BUF *Pdu\r
)\r
{\r
EFI_STATUS Status;\r
(CurrentStage != Conn->CurrentStage) ||\r
(!Conn->TransitInitiated && Transit) ||\r
(Transit && (NextStage != Conn->NextStage)) ||\r
- (CompareMem (Session->ISID, LoginRsp->ISID, sizeof (LoginRsp->ISID)) != 0) ||\r
+ (CompareMem (Session->Isid, LoginRsp->Isid, sizeof (LoginRsp->Isid)) != 0) ||\r
(LoginRsp->InitiatorTaskTag != Session->InitiatorTaskTag)\r
) {\r
//\r
//\r
// In security negotiation stage, let CHAP module handle it.\r
//\r
- Status = IScsiCHAPOnRspReceived (Conn, Transit);\r
+ Status = IScsiCHAPOnRspReceived (Conn);\r
break;\r
\r
case ISCSI_LOGIN_OPERATIONAL_NEGOTIATION:\r
//\r
// Response received with negotiation resonse on iSCSI parameters, check them.\r
//\r
- Status = IScsiCheckOpParams (Conn, Transit);\r
+ Status = IScsiCheckOpParams (Conn);\r
break;\r
\r
default:\r
// CurrentStage is iSCSI Full Feature, it's the Login-Final Response,\r
// get the TSIH from the Login Response.\r
//\r
- Session->TSIH = NTOHS (LoginRsp->TSIH);\r
+ Session->Tsih = NTOHS (LoginRsp->Tsih);\r
}\r
}\r
//\r
Updated the target information according the data received in the iSCSI\r
login response with an target redirection status.\r
\r
- @param[in] Session The iSCSI session.\r
- @param[in] Data The data segment which should contain the\r
- TargetAddress key-value list.\r
- @param[in] Len Length of the data.\r
+ @param[in, out] Session The iSCSI session.\r
+ @param[in] Data The data segment which should contain the\r
+ TargetAddress key-value list.\r
+ @param[in] Len Length of the data.\r
\r
@retval EFI_SUCCESS The target address is updated.\r
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
@retval EFI_NOT_FOUND The TargetAddress key is not found.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiUpdateTargetAddress (\r
- IN ISCSI_SESSION *Session,\r
- IN CHAR8 *Data,\r
- IN UINT32 Len\r
+ IN OUT ISCSI_SESSION *Session,\r
+ IN CHAR8 *Data,\r
+ IN UINT32 Len\r
)\r
{\r
LIST_ENTRY *KeyValueList;\r
@retval EFI_SUCCESS An iSCSI pdu is received.\r
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
@retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiReceivePdu (\r
Len = ISCSI_GET_DATASEG_LEN (Header);\r
if (Len == 0) {\r
//\r
- // No data segment.\r
+ // No data segment.Form the pdu from a list of pdu segments.\r
//\r
- goto FORM_PDU;\r
+ *Pdu = NetbufFromBufList (NbufList, 0, 0, IScsiFreeNbufList, NbufList);\r
+ if (*Pdu == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto ON_EXIT;\r
+ }\r
+ return Status;\r
}\r
//\r
// Get the length of the padding bytes of the data segment.\r
NetbufTrim (DataSeg, PadLen, NET_BUF_TAIL);\r
}\r
\r
-FORM_PDU:\r
//\r
// Form the pdu from a list of pdu segments.\r
//\r
/**\r
Check and get the result of the prameter negotiation.\r
\r
- @param[in] Conn The connection in iSCSI login.\r
- @param[in] Transit Whether need transit.\r
+ @param[in, out] Conn The connection in iSCSI login.\r
\r
@retval EFI_SUCCESS The parmeter check is passed and negotiation is finished.\r
@retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened.\r
**/\r
EFI_STATUS\r
IScsiCheckOpParams (\r
- IN ISCSI_CONNECTION *Conn,\r
- IN BOOLEAN Transit\r
+ IN OUT ISCSI_CONNECTION *Conn\r
)\r
{\r
EFI_STATUS Status;\r
Session->ImmediateData = (BOOLEAN) (Session->ImmediateData && (AsciiStrCmp (Value, "Yes") == 0));\r
\r
//\r
- // MaxRecvDataSegmentLength, result function is Mininum.\r
+ // MaxRecvDataSegmentLength is declarative.\r
//\r
Value = IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_MAX_RECV_DATA_SEGMENT_LENGTH);\r
if (Value != NULL) {\r
- //\r
- // MaxRecvDataSegmentLength is declarative.\r
- //\r
- NumericValue = AsciiStrDecimalToUintn (Value);\r
-\r
- Conn->MaxRecvDataSegmentLength = (UINT32) MIN (Conn->MaxRecvDataSegmentLength, NumericValue);\r
+ Conn->MaxRecvDataSegmentLength = (UINT32) AsciiStrDecimalToUintn (Value);\r
}\r
//\r
// MaxBurstLength, result funtion is Mininum.\r
/**\r
Fill the oprational prameters.\r
\r
- @param[in] Conn The connection in iSCSI login.\r
- @param[in] Pdu The iSCSI login request PDU to fill the parameters.\r
+ @param[in] Conn The connection in iSCSI login.\r
+ @param[in, out] Pdu The iSCSI login request PDU to fill the parameters.\r
\r
@retval EFI_SUCCESS The parmeters are filled into the iSCSI login request PDU.\r
**/\r
EFI_STATUS\r
IScsiFillOpParams (\r
IN ISCSI_CONNECTION *Conn,\r
- IN NET_BUF *Pdu\r
+ IN OUT NET_BUF *Pdu\r
)\r
{\r
ISCSI_SESSION *Session;\r
/**\r
Pad the iSCSI AHS or data segment to an integer number of 4 byte words.\r
\r
- @param[in] Pdu The iSCSI pdu which contains segments to pad.\r
- @param[in] Len The length of the last semgnet in the PDU.\r
+ @param[in, out] Pdu The iSCSI pdu which contains segments to pad.\r
+ @param[in] Len The length of the last semgnet in the PDU.\r
\r
@retval EFI_SUCCESS The segment is padded or no need to pad it.\r
@retval EFI_OUT_OF_RESOURCES There is not enough remaining free space to add the\r
**/\r
EFI_STATUS\r
IScsiPadSegment (\r
- IN NET_BUF *Pdu,\r
- IN UINT32 Len\r
+ IN OUT NET_BUF *Pdu,\r
+ IN UINT32 Len\r
)\r
{\r
UINT32 PadLen;\r
@param[in] Len Length of the data segment.\r
\r
@return The key-value list.\r
- @return NULL Some unexpected error happened.\r
+ @retval NULL Other errors as indicated.\r
**/\r
LIST_ENTRY *\r
IScsiBuildKeyValueList (\r
Get the value string by the key name from the key-value list. If found,\r
the key-value entry will be removed from the list.\r
\r
- @param[in] KeyValueList The key-value list.\r
- @param[in] Key The key name to find.\r
+ @param[in, out] KeyValueList The key-value list.\r
+ @param[in] Key The key name to find.\r
\r
@return The value string.\r
**/\r
CHAR8 *\r
IScsiGetValueByKeyFromList (\r
- IN LIST_ENTRY *KeyValueList,\r
+ IN OUT LIST_ENTRY *KeyValueList,\r
IN CHAR8 *Key\r
)\r
{\r
/**\r
Normalize the iSCSI name according to RFC.\r
\r
- @param[in] Name The iSCSI name.\r
- @param[in] Len length of the iSCSI name.\r
+ @param[in, out] Name The iSCSI name.\r
+ @param[in] Len length of the iSCSI name.\r
\r
@retval EFI_SUCCESS The iSCSI name is valid and normalized.\r
@retval EFI_PROTOCOL_ERROR The iSCSI name is mal-formatted or not in the IQN format.\r
**/\r
EFI_STATUS\r
IScsiNormalizeName (\r
- IN CHAR8 *Name,\r
- IN UINTN Len\r
+ IN OUT CHAR8 *Name,\r
+ IN UINTN Len\r
)\r
{\r
UINTN Index;\r
@param[in] Tcb The tcb assocated with this SCSI command.\r
\r
@return The created iSCSI SCSI command PDU.\r
- @return NULL Some unexpected error happened.\r
+ @retval NULL Other errors as indicated.\r
**/\r
NET_BUF *\r
IScsiNewScsiCmdPdu (\r
@param[in] Lun The LUN.\r
\r
@return The net buffer wrapping the Data Out PDU.\r
- @return NULL Some unexpected error happened.\r
+ @retval NULL Other errors as indicated.\r
**/\r
NET_BUF *\r
IScsiNewDataOutPdu (\r
@param[in] Lun The LUN the data will be sent to.\r
\r
@return A list of net buffers with each of them wraps an iSCSI SCSI Data Out PDU.\r
- @return NULL Some unexpected error happened.\r
+ @retval NULL Other errors as indicated.\r
**/\r
LIST_ENTRY *\r
IScsiGenerateDataOutPduSequence (\r
\r
@retval EFI_SUCCES The data is sent out to the LUN.\r
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiSendDataOutPduSequence (\r
actions are taken.\r
@retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened.\r
@retval EFI_BAD_BUFFER_SIZEE The buffer was not the proper size for the request.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiOnDataInRcvd (\r
\r
@retval EFI_SUCCES The R2T PDU is valid and the solicited data is sent out.\r
@retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiOnR2TRcvd (\r
@retval EFI_SUCCES The Response PDU is processed.\r
@retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened.\r
@retval EFI_BAD_BUFFER_SIZEE The buffer was not the proper size for the request.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiOnScsiRspRcvd (\r
\r
@retval EFI_SUCCES The SCSI command is executed and the result is updated to \r
the Packet.\r
- @retval EFI_DEVICE_ERROR Some unexpected error happened.\r
+ @retval EFI_DEVICE_ERROR Session state was not as required.\r
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
- @retval Others Some unexpected error happened.\r
+ @retval Others Other errors as indicated.\r
**/\r
EFI_STATUS\r
IScsiExecuteScsiCommand (\r
/**\r
Reinstate the session on some error.\r
\r
- @param[in] Private The iSCSI driver data.\r
+ @param[in, out] Private The iSCSI driver data.\r
\r
@retval EFI_SUCCES The session is reinstated from some error.\r
@retval Other Reinstatement failed.\r
**/\r
EFI_STATUS\r
IScsiSessionReinstatement (\r
- IN ISCSI_DRIVER_DATA *Private\r
+ IN OUT ISCSI_DRIVER_DATA *Private\r
)\r
{\r
ISCSI_SESSION *Session;\r
/**\r
Initialize some session parameters before login.\r
\r
- @param[in] Session The iSCSI session.\r
- @param[in] Recovery Whether the request is from a fresh new start or recovery.\r
+ @param[in, out] Session The iSCSI session.\r
+ @param[in] Recovery Whether the request is from a fresh new start or recovery.\r
**/\r
VOID\r
IScsiSessionInit (\r
- IN ISCSI_SESSION *Session,\r
- IN BOOLEAN Recovery\r
+ IN OUT ISCSI_SESSION *Session,\r
+ IN BOOLEAN Recovery\r
)\r
{\r
UINT32 Random;\r
\r
Random = NET_RANDOM (NetRandomInitSeed ());\r
\r
- Session->ISID[0] = ISID_BYTE_0;\r
- Session->ISID[1] = ISID_BYTE_1;\r
- Session->ISID[2] = ISID_BYTE_2;\r
- Session->ISID[3] = ISID_BYTE_3;\r
- Session->ISID[4] = (UINT8) Random;\r
- Session->ISID[5] = (UINT8) (Random >> 8);\r
+ Session->Isid[0] = ISID_BYTE_0;\r
+ Session->Isid[1] = ISID_BYTE_1;\r
+ Session->Isid[2] = ISID_BYTE_2;\r
+ Session->Isid[3] = ISID_BYTE_3;\r
+ Session->Isid[4] = (UINT8) Random;\r
+ Session->Isid[5] = (UINT8) (Random >> 8);\r
\r
InitializeListHead (&Session->Conns);\r
InitializeListHead (&Session->TcbList);\r
}\r
\r
- Session->TSIH = 0;\r
+ Session->Tsih = 0;\r
\r
Session->CmdSN = 1;\r
Session->InitiatorTaskTag = 1;\r
- Session->NextCID = 1;\r
+ Session->NextCid = 1;\r
\r
Session->TargetPortalGroupTag = 0;\r
Session->MaxConnections = ISCSI_MAX_CONNS_PER_SESSION;\r
Abort the iSCSI session, that is, reset all the connection and free the\r
resources.\r
\r
- @param[in] Session The iSCSI session.\r
+ @param[in, out] Session The iSCSI session.\r
\r
@retval EFI_SUCCES The session is aborted.\r
**/\r
EFI_STATUS\r
IScsiSessionAbort (\r
- IN ISCSI_SESSION *Session\r
+ IN OUT ISCSI_SESSION *Session\r
)\r
{\r
ISCSI_DRIVER_DATA *Private;\r