/** @file\r
+ Implementation of Managed Network Protocol I/O functions.\r
\r
-Copyright (c) 2005 - 2007, Intel Corporation\r
-All rights reserved. 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
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution. The full\r
+text of the license may be found at<BR>\r
http://opensource.org/licenses/bsd-license.php\r
\r
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
- MnpIo.c\r
-\r
-Abstract:\r
-\r
- Implementation of Managed Network Protocol I/O functions.\r
-\r
-\r
**/\r
\r
-#include <Library/NetLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
#include "MnpImpl.h"\r
-\r
+#include "MnpVlan.h"\r
\r
/**\r
Validates the Mnp transmit token.\r
\r
- @param Instance Pointer to the Mnp instance context data.\r
- @param Token Pointer to the transmit token to check.\r
+ @param[in] Instance Pointer to the Mnp instance context data.\r
+ @param[in] Token Pointer to the transmit token to check.\r
\r
@return The Token is valid or not.\r
\r
**/\r
BOOLEAN\r
MnpIsValidTxToken (\r
- IN MNP_INSTANCE_DATA *Instance,\r
- IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
+ IN MNP_INSTANCE_DATA *Instance,\r
+ IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
)\r
{\r
MNP_SERVICE_DATA *MnpServiceData;\r
MnpServiceData = Instance->MnpServiceData;\r
NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
\r
- TxData = Token->Packet.TxData;\r
+ TxData = Token->Packet.TxData;\r
\r
if ((Token->Event == NULL) || (TxData == NULL) || (TxData->FragmentCount == 0)) {\r
//\r
return TRUE;\r
}\r
\r
-\r
/**\r
Build the packet to transmit from the TxData passed in.\r
\r
- @param MnpServiceData Pointer to the mnp service context data.\r
- @param TxData Pointer to the transmit data containing the\r
- information to build the packet.\r
- @param PktBuf Pointer to record the address of the packet.\r
- @param PktLen Pointer to a UINT32 variable used to record the\r
- packet's length.\r
+ @param[in] MnpServiceData Pointer to the mnp service context data.\r
+ @param[in] TxData Pointer to the transmit data containing the information\r
+ to build the packet.\r
+ @param[out] PktBuf Pointer to record the address of the packet.\r
+ @param[out] PktLen Pointer to a UINT32 variable used to record the packet's\r
+ length.\r
\r
- @return None.\r
+ @retval EFI_SUCCESS TxPackage is built.\r
+ @retval EFI_OUT_OF_RESOURCES The deliver fails due to lack of memory resource.\r
\r
**/\r
-VOID\r
+EFI_STATUS\r
MnpBuildTxPacket (\r
- IN MNP_SERVICE_DATA *MnpServiceData,\r
- IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData,\r
- OUT UINT8 **PktBuf,\r
- OUT UINT32 *PktLen\r
+ IN MNP_SERVICE_DATA *MnpServiceData,\r
+ IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData,\r
+ OUT UINT8 **PktBuf,\r
+ OUT UINT32 *PktLen\r
)\r
{\r
EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
UINT8 *DstPos;\r
UINT16 Index;\r
-\r
+ MNP_DEVICE_DATA *MnpDeviceData;\r
+ UINT8 *TxBuf;\r
+ \r
+ MnpDeviceData = MnpServiceData->MnpDeviceData;\r
+ \r
+ TxBuf = MnpAllocTxBuf (MnpDeviceData);\r
+ if (TxBuf == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ \r
+ //\r
+ // Reserve space for vlan tag if needed.\r
+ //\r
+ if (MnpServiceData->VlanId != 0) {\r
+ *PktBuf = TxBuf + NET_VLAN_TAG_LEN;\r
+ } else {\r
+ *PktBuf = TxBuf;\r
+ }\r
+ \r
if ((TxData->DestinationAddress == NULL) && (TxData->FragmentCount == 1)) {\r
- //\r
- // Media header is in FragmentTable and there is only one fragment,\r
- // use fragment buffer directly.\r
- //\r
- *PktBuf = TxData->FragmentTable[0].FragmentBuffer;\r
+ CopyMem (\r
+ *PktBuf,\r
+ TxData->FragmentTable[0].FragmentBuffer,\r
+ TxData->FragmentTable[0].FragmentLength\r
+ );\r
+ \r
*PktLen = TxData->FragmentTable[0].FragmentLength;\r
} else {\r
//\r
// one fragment, copy the data into the packet buffer. Reserve the\r
// media header space if necessary.\r
//\r
- SnpMode = MnpServiceData->Snp->Mode;\r
- DstPos = MnpServiceData->TxBuf;\r
-\r
+ SnpMode = MnpDeviceData->Snp->Mode; \r
+ DstPos = *PktBuf;\r
*PktLen = 0;\r
if (TxData->DestinationAddress != NULL) {\r
//\r
}\r
\r
//\r
- // Set the buffer pointer and the buffer length.\r
+ // Set the buffer length.\r
//\r
- *PktBuf = MnpServiceData->TxBuf;\r
*PktLen += TxData->DataLength + TxData->HeaderLength;\r
}\r
+\r
+ return EFI_SUCCESS;\r
}\r
\r
\r
/**\r
- Synchronously send out the packet.\r
+ Synchronously send out the packet. \r
+\r
+ This functon places the packet buffer to SNP driver's tansmit queue. The packet\r
+ can be considered successfully sent out once SNP acccetp the packet, while the\r
+ packet buffer recycle is deferred for better performance.\r
\r
- @param MnpServiceData Pointer to the mnp service context data.\r
- @param Packet Pointer to the pakcet buffer.\r
- @param Length The length of the packet.\r
- @param Token Pointer to the token the packet generated from.\r
+ @param[in] MnpServiceData Pointer to the mnp service context data.\r
+ @param[in] Packet Pointer to the pakcet buffer.\r
+ @param[in] Length The length of the packet.\r
+ @param[in, out] Token Pointer to the token the packet generated from.\r
\r
- @retval EFI_SUCCESS The packet is sent out.\r
- @retval EFI_TIMEOUT Time out occurs, the packet isn't sent.\r
- @retval EFI_DEVICE_ERROR An unexpected network error occurs.\r
+ @retval EFI_SUCCESS The packet is sent out.\r
+ @retval EFI_TIMEOUT Time out occurs, the packet isn't sent.\r
+ @retval EFI_DEVICE_ERROR An unexpected network error occurs.\r
\r
**/\r
EFI_STATUS\r
MnpSyncSendPacket (\r
- IN MNP_SERVICE_DATA *MnpServiceData,\r
- IN UINT8 *Packet,\r
- IN UINT32 Length,\r
- IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
+ IN MNP_SERVICE_DATA *MnpServiceData,\r
+ IN UINT8 *Packet,\r
+ IN UINT32 Length,\r
+ IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
)\r
{\r
EFI_STATUS Status;\r
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData;\r
UINT32 HeaderSize;\r
- UINT8 *TxBuf;\r
+ MNP_DEVICE_DATA *MnpDeviceData;\r
+ UINT16 ProtocolType;\r
\r
- Snp = MnpServiceData->Snp;\r
- TxData = Token->Packet.TxData;\r
-\r
- HeaderSize = Snp->Mode->MediaHeaderSize - TxData->HeaderLength;\r
+ MnpDeviceData = MnpServiceData->MnpDeviceData;\r
+ Snp = MnpDeviceData->Snp;\r
+ TxData = Token->Packet.TxData;\r
+ Token->Status = EFI_SUCCESS;\r
+ HeaderSize = Snp->Mode->MediaHeaderSize - TxData->HeaderLength;\r
\r
//\r
- // Start the timeout event.\r
+ // Check media status before transmit packet.\r
+ // Note: media status will be updated by periodic timer MediaDetectTimer.\r
//\r
- Status = gBS->SetTimer (\r
- MnpServiceData->TxTimeoutEvent,\r
- TimerRelative,\r
- MNP_TX_TIMEOUT_TIME\r
- );\r
- if (EFI_ERROR (Status)) {\r
-\r
+ if (Snp->Mode->MediaPresentSupported && !Snp->Mode->MediaPresent) {\r
+ //\r
+ // Media not present, skip packet transmit and report EFI_NO_MEDIA\r
+ //\r
+ DEBUG ((EFI_D_WARN, "MnpSyncSendPacket: No network cable detected.\n"));\r
+ Token->Status = EFI_NO_MEDIA;\r
goto SIGNAL_TOKEN;\r
}\r
\r
- for (;;) {\r
+ \r
+ if (MnpServiceData->VlanId != 0) {\r
//\r
- // Transmit the packet through SNP.\r
+ // Insert VLAN tag\r
//\r
+ MnpInsertVlanTag (MnpServiceData, TxData, &ProtocolType, &Packet, &Length);\r
+ } else {\r
+ ProtocolType = TxData->ProtocolType;\r
+ }\r
+\r
+ //\r
+ // Transmit the packet through SNP.\r
+ //\r
+ Status = Snp->Transmit (\r
+ Snp,\r
+ HeaderSize,\r
+ Length,\r
+ Packet,\r
+ TxData->SourceAddress,\r
+ TxData->DestinationAddress,\r
+ &ProtocolType\r
+ );\r
+ if (Status == EFI_NOT_READY) {\r
+ Status = MnpRecycleTxBuf (MnpDeviceData);\r
+ if (EFI_ERROR (Status)) {\r
+ Token->Status = EFI_DEVICE_ERROR;\r
+ goto SIGNAL_TOKEN;\r
+ }\r
+\r
Status = Snp->Transmit (\r
Snp,\r
HeaderSize,\r
Packet,\r
TxData->SourceAddress,\r
TxData->DestinationAddress,\r
- &TxData->ProtocolType\r
- );\r
- if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_READY)) {\r
-\r
- Status = EFI_DEVICE_ERROR;\r
- break;\r
- }\r
-\r
- //\r
- // If Status is EFI_SUCCESS, the packet is put in the transmit queue.\r
- // if Status is EFI_NOT_READY, the transmit engine of the network interface is busy.\r
- // Both need to sync SNP.\r
- //\r
- TxBuf = NULL;\r
- do {\r
- //\r
- // Get the recycled transmit buffer status.\r
- //\r
- Snp->GetStatus (Snp, NULL, (VOID **) &TxBuf);\r
-\r
- if (!EFI_ERROR (gBS->CheckEvent (MnpServiceData->TxTimeoutEvent))) {\r
-\r
- Status = EFI_TIMEOUT;\r
- break;\r
- }\r
- } while (TxBuf == NULL);\r
-\r
- if ((Status == EFI_SUCCESS) || (Status == EFI_TIMEOUT)) {\r
-\r
- break;\r
- } else {\r
- //\r
- // Status is EFI_NOT_READY. Restart the timer event and call Snp->Transmit again.\r
- //\r
- gBS->SetTimer (\r
- MnpServiceData->TxTimeoutEvent,\r
- TimerRelative,\r
- MNP_TX_TIMEOUT_TIME\r
- );\r
- }\r
+ &ProtocolType\r
+ ); \r
+ }\r
+ \r
+ if (EFI_ERROR (Status)) {\r
+ Token->Status = EFI_DEVICE_ERROR;\r
}\r
-\r
- //\r
- // Cancel the timer event.\r
- //\r
- gBS->SetTimer (MnpServiceData->TxTimeoutEvent, TimerCancel, 0);\r
\r
SIGNAL_TOKEN:\r
\r
- Token->Status = Status;\r
gBS->SignalEvent (Token->Event);\r
\r
//\r
// Dispatch the DPC queued by the NotifyFunction of Token->Event.\r
//\r
- NetLibDispatchDpc ();\r
+ DispatchDpc ();\r
\r
return EFI_SUCCESS;\r
}\r
/**\r
Try to deliver the received packet to the instance.\r
\r
- @param Instance Pointer to the mnp instance context data.\r
+ @param[in, out] Instance Pointer to the mnp instance context data.\r
\r
@retval EFI_SUCCESS The received packet is delivered, or there is no\r
packet to deliver, or there is no available receive\r
**/\r
EFI_STATUS\r
MnpInstanceDeliverPacket (\r
- IN MNP_INSTANCE_DATA *Instance\r
+ IN OUT MNP_INSTANCE_DATA *Instance\r
)\r
{\r
- MNP_SERVICE_DATA *MnpServiceData;\r
+ MNP_DEVICE_DATA *MnpDeviceData;\r
MNP_RXDATA_WRAP *RxDataWrap;\r
NET_BUF *DupNbuf;\r
EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData;\r
EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
EFI_MANAGED_NETWORK_COMPLETION_TOKEN *RxToken;\r
\r
- MnpServiceData = Instance->MnpServiceData;\r
- NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+ MnpDeviceData = Instance->MnpServiceData->MnpDeviceData;\r
+ NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
\r
if (NetMapIsEmpty (&Instance->RxTokenMap) || IsListEmpty (&Instance->RcvdPacketQueue)) {\r
//\r
// There are other instances share this Nbuf, duplicate to get a\r
// copy to allow the instance to do R/W operations.\r
//\r
- DupNbuf = MnpAllocNbuf (MnpServiceData);\r
+ DupNbuf = MnpAllocNbuf (MnpDeviceData);\r
if (DupNbuf == NULL) {\r
DEBUG ((EFI_D_WARN, "MnpDeliverPacket: Failed to allocate a free Nbuf.\n"));\r
\r
// Duplicate the net buffer.\r
//\r
NetbufDuplicate (RxDataWrap->Nbuf, DupNbuf, 0);\r
- MnpFreeNbuf (MnpServiceData, RxDataWrap->Nbuf);\r
+ MnpFreeNbuf (MnpDeviceData, RxDataWrap->Nbuf);\r
RxDataWrap->Nbuf = DupNbuf;\r
}\r
\r
Instance->RcvdPacketQueueSize--;\r
\r
RxData = &RxDataWrap->RxData;\r
- SnpMode = MnpServiceData->Snp->Mode;\r
+ SnpMode = MnpDeviceData->Snp->Mode;\r
\r
//\r
// Set all the buffer pointers.\r
/**\r
Deliver the received packet for the instances belonging to the MnpServiceData.\r
\r
- @param MnpServiceData Pointer to the mnp service context data.\r
-\r
- @return None.\r
+ @param[in] MnpServiceData Pointer to the mnp service context data.\r
\r
**/\r
-STATIC\r
VOID\r
MnpDeliverPacket (\r
- IN MNP_SERVICE_DATA *MnpServiceData\r
+ IN MNP_SERVICE_DATA *MnpServiceData\r
)\r
{\r
LIST_ENTRY *Entry;\r
Recycle the RxData and other resources used to hold and deliver the received\r
packet.\r
\r
- @param Event The event this notify function registered to.\r
- @param Context Pointer to the context data registerd to the Event.\r
-\r
- @return None.\r
+ @param[in] Event The event this notify function registered to.\r
+ @param[in] Context Pointer to the context data registerd to the Event.\r
\r
**/\r
VOID\r
EFIAPI\r
MnpRecycleRxData (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
)\r
{\r
- MNP_RXDATA_WRAP *RxDataWrap;\r
- MNP_SERVICE_DATA *MnpServiceData;\r
+ MNP_RXDATA_WRAP *RxDataWrap;\r
+ MNP_DEVICE_DATA *MnpDeviceData;\r
\r
ASSERT (Context != NULL);\r
\r
\r
ASSERT (RxDataWrap->Nbuf != NULL);\r
\r
- MnpServiceData = RxDataWrap->Instance->MnpServiceData;\r
- NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+ MnpDeviceData = RxDataWrap->Instance->MnpServiceData->MnpDeviceData;\r
+ NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
\r
//\r
// Free this Nbuf.\r
//\r
- MnpFreeNbuf (MnpServiceData, RxDataWrap->Nbuf);\r
+ MnpFreeNbuf (MnpDeviceData, RxDataWrap->Nbuf);\r
RxDataWrap->Nbuf = NULL;\r
\r
//\r
//\r
RemoveEntryList (&RxDataWrap->WrapEntry);\r
\r
- gBS->FreePool (RxDataWrap);\r
+ FreePool (RxDataWrap);\r
}\r
\r
\r
/**\r
Queue the received packet into instance's receive queue.\r
\r
- @param Instance Pointer to the mnp instance context data.\r
- @param RxDataWrap Pointer to the Wrap structure containing the\r
- received data and other information.\r
-\r
- @return None.\r
-\r
+ @param[in, out] Instance Pointer to the mnp instance context data.\r
+ @param[in, out] RxDataWrap Pointer to the Wrap structure containing the\r
+ received data and other information.\r
**/\r
-STATIC\r
VOID\r
MnpQueueRcvdPacket (\r
- IN MNP_INSTANCE_DATA *Instance,\r
- IN MNP_RXDATA_WRAP *RxDataWrap\r
+ IN OUT MNP_INSTANCE_DATA *Instance,\r
+ IN OUT MNP_RXDATA_WRAP *RxDataWrap\r
)\r
{\r
MNP_RXDATA_WRAP *OldRxDataWrap;\r
/**\r
Match the received packet with the instance receive filters.\r
\r
- @param Instance Pointer to the mnp instance context data.\r
- @param RxData Pointer to the EFI_MANAGED_NETWORK_RECEIVE_DATA.\r
- @param GroupAddress Pointer to the GroupAddress, the GroupAddress is\r
+ @param[in] Instance Pointer to the mnp instance context data.\r
+ @param[in] RxData Pointer to the EFI_MANAGED_NETWORK_RECEIVE_DATA.\r
+ @param[in] GroupAddress Pointer to the GroupAddress, the GroupAddress is\r
non-NULL and it contains the destination multicast\r
mac address of the received packet if the packet\r
destinated to a multicast mac address.\r
- @param PktAttr The received packets attribute.\r
+ @param[in] PktAttr The received packets attribute.\r
\r
@return The received packet matches the instance's receive filters or not.\r
\r
**/\r
-STATIC\r
BOOLEAN\r
MnpMatchPacket (\r
- IN MNP_INSTANCE_DATA *Instance,\r
- IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData,\r
- IN MNP_GROUP_ADDRESS *GroupAddress OPTIONAL,\r
- IN UINT8 PktAttr\r
+ IN MNP_INSTANCE_DATA *Instance,\r
+ IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData,\r
+ IN MNP_GROUP_ADDRESS *GroupAddress OPTIONAL,\r
+ IN UINT8 PktAttr\r
)\r
{\r
EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData;\r
/**\r
Analyse the received packets.\r
\r
- @param MnpServiceData Pointer to the mnp service context data.\r
- @param Nbuf Pointer to the net buffer holding the received\r
- packet.\r
- @param RxData Pointer to the buffer used to save the analysed\r
- result in EFI_MANAGED_NETWORK_RECEIVE_DATA.\r
- @param GroupAddress Pointer to pointer to a MNP_GROUP_ADDRESS used to\r
- pass out the address of the multicast address the\r
- received packet destinated to.\r
- @param PktAttr Pointer to the buffer used to save the analysed\r
- packet attribute.\r
-\r
- @return None.\r
+ @param[in] MnpServiceData Pointer to the mnp service context data.\r
+ @param[in] Nbuf Pointer to the net buffer holding the received\r
+ packet.\r
+ @param[in, out] RxData Pointer to the buffer used to save the analysed\r
+ result in EFI_MANAGED_NETWORK_RECEIVE_DATA.\r
+ @param[out] GroupAddress Pointer to pointer to a MNP_GROUP_ADDRESS used to\r
+ pass out the address of the multicast address the\r
+ received packet destinated to.\r
+ @param[out] PktAttr Pointer to the buffer used to save the analysed\r
+ packet attribute.\r
\r
**/\r
-STATIC\r
VOID\r
MnpAnalysePacket (\r
- IN MNP_SERVICE_DATA *MnpServiceData,\r
- IN NET_BUF *Nbuf,\r
- IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData,\r
- OUT MNP_GROUP_ADDRESS **GroupAddress,\r
- OUT UINT8 *PktAttr\r
+ IN MNP_SERVICE_DATA *MnpServiceData,\r
+ IN NET_BUF *Nbuf,\r
+ IN OUT EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData,\r
+ OUT MNP_GROUP_ADDRESS **GroupAddress,\r
+ OUT UINT8 *PktAttr\r
)\r
{\r
EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
+ MNP_DEVICE_DATA *MnpDeviceData;\r
UINT8 *BufPtr;\r
LIST_ENTRY *Entry;\r
\r
- SnpMode = MnpServiceData->Snp->Mode;\r
+ MnpDeviceData = MnpServiceData->MnpDeviceData;\r
+ SnpMode = MnpDeviceData->Snp->Mode;\r
\r
//\r
// Get the packet buffer.\r
//\r
// It's multicast, try to match the multicast filters.\r
//\r
- NET_LIST_FOR_EACH (Entry, &MnpServiceData->GroupAddressList) {\r
+ NET_LIST_FOR_EACH (Entry, &MnpDeviceData->GroupAddressList) {\r
\r
*GroupAddress = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);\r
if (NET_MAC_EQUAL (BufPtr, &((*GroupAddress)->Address), SnpMode->HwAddressSize)) {\r
*GroupAddress = NULL;\r
RxData->PromiscuousFlag = TRUE;\r
\r
- if (MnpServiceData->PromiscuousCount == 0) {\r
+ if (MnpDeviceData->PromiscuousCount == 0) {\r
//\r
// Skip the below code, there is no receiver of this packet.\r
//\r
/**\r
Wrap the RxData.\r
\r
- @param Instance Pointer to the mnp instance context data.\r
- @param RxData Pointer to the receive data to wrap.\r
+ @param[in] Instance Pointer to the mnp instance context data.\r
+ @param[in] RxData Pointer to the receive data to wrap.\r
\r
@return Pointer to a MNP_RXDATA_WRAP which wraps the RxData.\r
\r
**/\r
-STATIC\r
MNP_RXDATA_WRAP *\r
MnpWrapRxData (\r
- IN MNP_INSTANCE_DATA *Instance,\r
- IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData\r
+ IN MNP_INSTANCE_DATA *Instance,\r
+ IN EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData\r
)\r
{\r
EFI_STATUS Status;\r
&RxDataWrap->RxData.RecycleEvent\r
);\r
if (EFI_ERROR (Status)) {\r
-\r
DEBUG ((EFI_D_ERROR, "MnpDispatchPacket: gBS->CreateEvent failed, %r.\n", Status));\r
- gBS->FreePool (RxDataWrap);\r
+\r
+ FreePool (RxDataWrap);\r
return NULL;\r
}\r
\r
Enqueue the received the packets to the instances belonging to the\r
MnpServiceData.\r
\r
- @param MnpServiceData Pointer to the mnp service context data.\r
- @param Nbuf Pointer to the net buffer representing the received\r
+ @param[in] MnpServiceData Pointer to the mnp service context data.\r
+ @param[in] Nbuf Pointer to the net buffer representing the received\r
packet.\r
\r
- @return None.\r
-\r
**/\r
-STATIC\r
VOID\r
MnpEnqueuePacket (\r
- IN MNP_SERVICE_DATA *MnpServiceData,\r
- IN NET_BUF *Nbuf\r
+ IN MNP_SERVICE_DATA *MnpServiceData,\r
+ IN NET_BUF *Nbuf\r
)\r
{\r
LIST_ENTRY *Entry;\r
//\r
MnpAnalysePacket (MnpServiceData, Nbuf, &RxData, &GroupAddress, &PktAttr);\r
\r
- if (RxData.PromiscuousFlag && (MnpServiceData->PromiscuousCount == 0)) {\r
+ if (RxData.PromiscuousFlag && (MnpServiceData->MnpDeviceData->PromiscuousCount == 0)) {\r
//\r
// No receivers, no more action need.\r
//\r
// Check the packet against the instance receive filters.\r
//\r
if (MnpMatchPacket (Instance, &RxData, GroupAddress, PktAttr)) {\r
-\r
//\r
// Wrap the RxData.\r
//\r
/**\r
Try to receive a packet and deliver it.\r
\r
- @param MnpServiceData Pointer to the mnp service context data.\r
+ @param[in, out] MnpDeviceData Pointer to the mnp device context data.\r
\r
@retval EFI_SUCCESS add return value to function comment\r
@retval EFI_NOT_STARTED The simple network protocol is not started.\r
**/\r
EFI_STATUS\r
MnpReceivePacket (\r
- IN MNP_SERVICE_DATA *MnpServiceData\r
+ IN OUT MNP_DEVICE_DATA *MnpDeviceData\r
)\r
{\r
EFI_STATUS Status;\r
UINTN BufLen;\r
UINTN HeaderSize;\r
UINT32 Trimmed;\r
+ MNP_SERVICE_DATA *MnpServiceData;\r
+ UINT16 VlanId;\r
+ BOOLEAN IsVlanPacket;\r
\r
- NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+ NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
\r
- Snp = MnpServiceData->Snp;\r
+ Snp = MnpDeviceData->Snp;\r
if (Snp->Mode->State != EfiSimpleNetworkInitialized) {\r
//\r
// The simple network protocol is not started.\r
return EFI_NOT_STARTED;\r
}\r
\r
- if (IsListEmpty (&MnpServiceData->ChildrenList)) {\r
- //\r
- // There is no child, no need to receive packets.\r
- //\r
- return EFI_SUCCESS;\r
- }\r
-\r
- if (MnpServiceData->RxNbufCache == NULL) {\r
+ if (MnpDeviceData->RxNbufCache == NULL) {\r
//\r
// Try to get a new buffer as there may be buffers recycled.\r
//\r
- MnpServiceData->RxNbufCache = MnpAllocNbuf (MnpServiceData);\r
+ MnpDeviceData->RxNbufCache = MnpAllocNbuf (MnpDeviceData);\r
\r
- if (MnpServiceData->RxNbufCache == NULL) {\r
+ if (MnpDeviceData->RxNbufCache == NULL) {\r
//\r
- // No availabe buffer in the buffer pool.\r
+ // No available buffer in the buffer pool.\r
//\r
return EFI_DEVICE_ERROR;\r
}\r
\r
NetbufAllocSpace (\r
- MnpServiceData->RxNbufCache,\r
- MnpServiceData->BufferLength,\r
+ MnpDeviceData->RxNbufCache,\r
+ MnpDeviceData->BufferLength,\r
NET_BUF_TAIL\r
);\r
}\r
\r
- Nbuf = MnpServiceData->RxNbufCache;\r
+ Nbuf = MnpDeviceData->RxNbufCache;\r
BufLen = Nbuf->TotalSize;\r
BufPtr = NetbufGetByte (Nbuf, 0, NULL);\r
ASSERT (BufPtr != NULL);\r
//\r
Status = Snp->Receive (Snp, &HeaderSize, &BufLen, BufPtr, NULL, NULL, NULL);\r
if (EFI_ERROR (Status)) {\r
-\r
DEBUG_CODE (\r
if (Status != EFI_NOT_READY) {\r
DEBUG ((EFI_D_WARN, "MnpReceivePacket: Snp->Receive() = %r.\n", Status));\r
// Sanity check.\r
//\r
if ((HeaderSize != Snp->Mode->MediaHeaderSize) || (BufLen < HeaderSize)) {\r
-\r
DEBUG (\r
(EFI_D_WARN,\r
"MnpReceivePacket: Size error, HL:TL = %d:%d.\n",\r
ASSERT (Nbuf->TotalSize == BufLen);\r
}\r
\r
+ VlanId = 0;\r
+ if (MnpDeviceData->NumberOfVlan != 0) {\r
+ //\r
+ // VLAN is configured, remove the VLAN tag if any\r
+ //\r
+ IsVlanPacket = MnpRemoveVlanTag (MnpDeviceData, Nbuf, &VlanId);\r
+ } else {\r
+ IsVlanPacket = FALSE;\r
+ }\r
+\r
+ MnpServiceData = MnpFindServiceData (MnpDeviceData, VlanId);\r
+ if (MnpServiceData == NULL) {\r
+ //\r
+ // VLAN is not set for this tagged frame, ignore this packet\r
+ //\r
+ if (Trimmed > 0) {\r
+ NetbufAllocSpace (Nbuf, Trimmed, NET_BUF_TAIL);\r
+ }\r
+\r
+ if (IsVlanPacket) {\r
+ NetbufAllocSpace (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_HEAD);\r
+ }\r
+\r
+ goto EXIT;\r
+ }\r
+\r
//\r
// Enqueue the packet to the matched instances.\r
//\r
// RefCnt > 2 indicates there is at least one receiver of this packet.\r
// Free the current RxNbufCache and allocate a new one.\r
//\r
- MnpFreeNbuf (MnpServiceData, Nbuf);\r
+ MnpFreeNbuf (MnpDeviceData, Nbuf);\r
\r
- Nbuf = MnpAllocNbuf (MnpServiceData);\r
- MnpServiceData->RxNbufCache = Nbuf;\r
+ Nbuf = MnpAllocNbuf (MnpDeviceData);\r
+ MnpDeviceData->RxNbufCache = Nbuf;\r
if (Nbuf == NULL) {\r
DEBUG ((EFI_D_ERROR, "MnpReceivePacket: Alloc packet for receiving cache failed.\n"));\r
return EFI_DEVICE_ERROR;\r
}\r
\r
- NetbufAllocSpace (Nbuf, MnpServiceData->BufferLength, NET_BUF_TAIL);\r
+ NetbufAllocSpace (Nbuf, MnpDeviceData->BufferLength, NET_BUF_TAIL);\r
} else {\r
//\r
// No receiver for this packet.\r
if (Trimmed > 0) {\r
NetbufAllocSpace (Nbuf, Trimmed, NET_BUF_TAIL);\r
}\r
+ if (IsVlanPacket) {\r
+ NetbufAllocSpace (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_HEAD);\r
+ }\r
\r
goto EXIT;\r
}\r
//\r
MnpDeliverPacket (MnpServiceData);\r
\r
- //\r
- // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r
- //\r
- NetLibDispatchDpc ();\r
-\r
EXIT:\r
\r
- ASSERT (Nbuf->TotalSize == MnpServiceData->BufferLength);\r
+ ASSERT (Nbuf->TotalSize == MnpDeviceData->BufferLength);\r
\r
return Status;\r
}\r
/**\r
Remove the received packets if timeout occurs.\r
\r
- @param Event The event this notify function registered to.\r
- @param Context Pointer to the context data registered to the\r
- event.\r
-\r
- @return None.\r
+ @param[in] Event The event this notify function registered to.\r
+ @param[in] Context Pointer to the context data registered to the event.\r
\r
**/\r
VOID\r
EFIAPI\r
MnpCheckPacketTimeout (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
)\r
{\r
+ MNP_DEVICE_DATA *MnpDeviceData;\r
MNP_SERVICE_DATA *MnpServiceData;\r
LIST_ENTRY *Entry;\r
+ LIST_ENTRY *ServiceEntry;\r
LIST_ENTRY *RxEntry;\r
LIST_ENTRY *NextEntry;\r
MNP_INSTANCE_DATA *Instance;\r
MNP_RXDATA_WRAP *RxDataWrap;\r
EFI_TPL OldTpl;\r
\r
- MnpServiceData = (MNP_SERVICE_DATA *) Context;\r
- NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+ MnpDeviceData = (MNP_DEVICE_DATA *) Context;\r
+ NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
\r
- NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {\r
+ NET_LIST_FOR_EACH (ServiceEntry, &MnpDeviceData->ServiceList) {\r
+ MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (ServiceEntry);\r
\r
- Instance = NET_LIST_USER_STRUCT (Entry, MNP_INSTANCE_DATA, InstEntry);\r
- NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
+ NET_LIST_FOR_EACH (Entry, &MnpServiceData->ChildrenList) {\r
\r
- if (!Instance->Configured || (Instance->ConfigData.ReceivedQueueTimeoutValue == 0)) {\r
- //\r
- // This instance is not configured or there is no receive time out,\r
- // just skip to the next instance.\r
- //\r
- continue;\r
- }\r
+ Instance = NET_LIST_USER_STRUCT (Entry, MNP_INSTANCE_DATA, InstEntry);\r
+ NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
\r
- OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+ if (!Instance->Configured || (Instance->ConfigData.ReceivedQueueTimeoutValue == 0)) {\r
+ //\r
+ // This instance is not configured or there is no receive time out,\r
+ // just skip to the next instance.\r
+ //\r
+ continue;\r
+ }\r
\r
- NET_LIST_FOR_EACH_SAFE (RxEntry, NextEntry, &Instance->RcvdPacketQueue) {\r
+ OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
\r
- RxDataWrap = NET_LIST_USER_STRUCT (RxEntry, MNP_RXDATA_WRAP, WrapEntry);\r
+ NET_LIST_FOR_EACH_SAFE (RxEntry, NextEntry, &Instance->RcvdPacketQueue) {\r
\r
- if (RxDataWrap->TimeoutTick >= MNP_TIMEOUT_CHECK_INTERVAL) {\r
+ RxDataWrap = NET_LIST_USER_STRUCT (RxEntry, MNP_RXDATA_WRAP, WrapEntry);\r
\r
- RxDataWrap->TimeoutTick -= MNP_TIMEOUT_CHECK_INTERVAL;\r
- } else {\r
//\r
- // Drop the timeout packet.\r
+ // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.\r
//\r
- DEBUG ((EFI_D_WARN, "MnpCheckPacketTimeout: Received packet timeout.\n"));\r
- MnpRecycleRxData (NULL, RxDataWrap);\r
- Instance->RcvdPacketQueueSize--;\r
+ if (RxDataWrap->TimeoutTick >= (MNP_TIMEOUT_CHECK_INTERVAL / 10)) {\r
+ RxDataWrap->TimeoutTick -= (MNP_TIMEOUT_CHECK_INTERVAL / 10);\r
+ } else {\r
+ //\r
+ // Drop the timeout packet.\r
+ //\r
+ DEBUG ((EFI_D_WARN, "MnpCheckPacketTimeout: Received packet timeout.\n"));\r
+ MnpRecycleRxData (NULL, RxDataWrap);\r
+ Instance->RcvdPacketQueueSize--;\r
+ }\r
}\r
- }\r
\r
- gBS->RestoreTPL (OldTpl);\r
+ gBS->RestoreTPL (OldTpl);\r
+ }\r
}\r
}\r
\r
+/**\r
+ Poll to update MediaPresent field in SNP ModeData by Snp->GetStatus().\r
+\r
+ @param[in] Event The event this notify function registered to.\r
+ @param[in] Context Pointer to the context data registered to the event.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+MnpCheckMediaStatus (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+{\r
+ MNP_DEVICE_DATA *MnpDeviceData;\r
+ EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
+ UINT32 InterruptStatus;\r
+\r
+ MnpDeviceData = (MNP_DEVICE_DATA *) Context;\r
+ NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
+\r
+ Snp = MnpDeviceData->Snp;\r
+ if (Snp->Mode->MediaPresentSupported) {\r
+ //\r
+ // Upon successful return of GetStatus(), the MediaPresent field of\r
+ // EFI_SIMPLE_NETWORK_MODE will be updated to reflect any change of media status\r
+ //\r
+ Snp->GetStatus (Snp, &InterruptStatus, NULL);\r
+ }\r
+}\r
\r
/**\r
Poll to receive the packets from Snp. This function is either called by upperlayer\r
protocols/applications or the system poll timer notify mechanism.\r
\r
- @param Event The event this notify function registered to.\r
- @param Context Pointer to the context data registered to the\r
- event.\r
-\r
- @return None.\r
+ @param[in] Event The event this notify function registered to.\r
+ @param[in] Context Pointer to the context data registered to the event.\r
\r
**/\r
VOID\r
EFIAPI\r
MnpSystemPoll (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
)\r
{\r
- MNP_SERVICE_DATA *MnpServiceData;\r
+ MNP_DEVICE_DATA *MnpDeviceData;\r
\r
- MnpServiceData = (MNP_SERVICE_DATA *) Context;\r
- NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
+ MnpDeviceData = (MNP_DEVICE_DATA *) Context;\r
+ NET_CHECK_SIGNATURE (MnpDeviceData, MNP_DEVICE_DATA_SIGNATURE);\r
\r
//\r
// Try to receive packets from Snp.\r
//\r
- MnpReceivePacket (MnpServiceData);\r
+ MnpReceivePacket (MnpDeviceData);\r
\r
- NetLibDispatchDpc ();\r
+ //\r
+ // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r
+ //\r
+ DispatchDpc ();\r
}\r