1. Add DPC protocol and DpcLib library in MdeModulePkg.

2. Add DpcDxe module and DxeDpcLib module in MdeModulePkg
3. Port network stack module to use DPC.
4. Use MIN, and MAX defined in MdePkg to replace NET_MIN and NET_MAX.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4307 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
vanjeff
2007-11-20 05:42:23 +00:00
parent 04e12c2147
commit 36ee91ca36
48 changed files with 1835 additions and 543 deletions

View File

@@ -208,6 +208,7 @@ Ip4CreateService (
IpSb->Ip4Config = NULL;
IpSb->DoneEvent = NULL;
IpSb->ReconfigEvent = NULL;
IpSb->ActiveEvent = NULL;
//
// Create various resources. First create the route table, timer
@@ -223,7 +224,7 @@ Ip4CreateService (
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL | EVT_TIMER,
TPL_CALLBACK,
NET_TPL_TIMER,
Ip4TimerTicking,
IpSb,
&IpSb->Timer
@@ -375,6 +376,7 @@ Ip4CleanService (
gBS->CloseEvent (IpSb->DoneEvent);
gBS->CloseEvent (IpSb->ReconfigEvent);
IpSb->ActiveEvent = NULL;
IpSb->Ip4Config = NULL;
}

View File

@@ -29,6 +29,13 @@ Abstract:
//
STATIC EFI_MAC_ADDRESS mZeroMacAddress;
STATIC
VOID
EFIAPI
Ip4OnFrameSentDpc (
IN VOID *Context
);
STATIC
VOID
EFIAPI
@@ -37,6 +44,13 @@ Ip4OnFrameSent (
IN VOID *Context
);
STATIC
VOID
EFIAPI
Ip4OnArpResolvedDpc (
IN VOID *Context
);
STATIC
VOID
EFIAPI
@@ -45,6 +59,13 @@ Ip4OnArpResolved (
IN VOID *Context
);
STATIC
VOID
EFIAPI
Ip4OnFrameReceivedDpc (
IN VOID *Context
);
STATIC
VOID
EFIAPI
@@ -116,7 +137,7 @@ Ip4WrapLinkTxToken (
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
NET_TPL_EVENT,
Ip4OnFrameSent,
Token,
&MnpToken->Event
@@ -201,7 +222,7 @@ Ip4CreateArpQue (
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
NET_TPL_EVENT,
Ip4OnArpResolved,
ArpQue,
&ArpQue->OnResolved
@@ -289,7 +310,7 @@ Ip4CreateLinkRxToken (
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
NET_TPL_EVENT,
Ip4OnFrameReceived,
Token,
&MnpToken->Event
@@ -404,10 +425,7 @@ Ip4CancelFrames (
Ip4CancelFrameArp (ArpQue, IoStatus, FrameToCancel, Context);
if (NetListIsEmpty (&ArpQue->Frames)) {
NetListRemoveEntry (Entry);
Interface->Arp->Cancel (Interface->Arp, &ArpQue->Ip, ArpQue->OnResolved);
Ip4FreeArpQue (ArpQue, EFI_ABORTED);
}
}
@@ -419,11 +437,7 @@ Ip4CancelFrames (
Token = NET_LIST_USER_STRUCT (Entry, IP4_LINK_TX_TOKEN, Link);
if ((FrameToCancel == NULL) || FrameToCancel (Token, Context)) {
NetListRemoveEntry (Entry);
Interface->Mnp->Cancel (Interface->Mnp, &Token->MnpToken);
Token->CallBack (Token->IpInstance, Token->Packet, IoStatus, 0, Token->Context);
Ip4FreeLinkTxToken (Token);
}
}
}
@@ -540,7 +554,7 @@ Ip4SetAddress (
Type = NetGetIpClass (IpAddr);
Len = NetGetMaskLength (SubnetMask);
Netmask = mIp4AllMasks[NET_MIN (Len, Type << 3)];
Netmask = mIp4AllMasks[MIN (Len, Type << 3)];
Interface->NetBrdcast = (IpAddr | ~Netmask);
//
@@ -747,7 +761,6 @@ Ip4FreeInterface (
all the queued frame if the ARP requests failed. Or transmit them
if the request succeed.
@param Event The Arp request event
@param Context The context of the callback, a point to the ARP
queue
@@ -757,8 +770,7 @@ Ip4FreeInterface (
STATIC
VOID
EFIAPI
Ip4OnArpResolved (
IN EFI_EVENT Event,
Ip4OnArpResolvedDpc (
IN VOID *Context
)
{
@@ -798,27 +810,64 @@ Ip4OnArpResolved (
Token = NET_LIST_USER_STRUCT (Entry, IP4_LINK_TX_TOKEN, Link);
CopyMem (&Token->DstMac, &ArpQue->Mac, sizeof (Token->DstMac));
Status = Interface->Mnp->Transmit (Interface->Mnp, &Token->MnpToken);
//
// Insert the tx token before transmitting it via MNP as the FrameSentDpc
// may be called before Mnp->Transmit returns which will remove this tx
// token from the SentFrames list. Remove it from the list if the returned
// Status of Mnp->Transmit is not EFI_SUCCESS as in this case the
// FrameSentDpc won't be queued.
//
NetListInsertTail (&Interface->SentFrames, &Token->Link);
Status = Interface->Mnp->Transmit (Interface->Mnp, &Token->MnpToken);
if (EFI_ERROR (Status)) {
NetListRemoveEntry (Entry);
Token->CallBack (Token->IpInstance, Token->Packet, Status, 0, Token->Context);
Ip4FreeLinkTxToken (Token);
continue;
}
NetListInsertTail (&Interface->SentFrames, &Token->Link);
}
Ip4FreeArpQue (ArpQue, EFI_SUCCESS);
}
STATIC
VOID
EFIAPI
Ip4OnArpResolved (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Request Ip4OnArpResolvedDpc as a DPC at TPL_CALLBACK
Arguments:
Event - The Arp request event
Context - The context of the callback, a point to the ARP queue
Returns:
None
--*/
{
//
// Request Ip4OnArpResolvedDpc as a DPC at TPL_CALLBACK
//
NetLibQueueDpc (TPL_CALLBACK, Ip4OnArpResolvedDpc, Context);
}
/**
Callback funtion when frame transmission is finished. It will
call the frame owner's callback function to tell it the result.
@param Event The transmit token's event
@param Context Context which is point to the token.
@return None.
@@ -827,8 +876,7 @@ Ip4OnArpResolved (
STATIC
VOID
EFIAPI
Ip4OnFrameSent (
IN EFI_EVENT Event,
Ip4OnFrameSentDpc (
IN VOID *Context
)
{
@@ -850,6 +898,36 @@ Ip4OnFrameSent (
Ip4FreeLinkTxToken (Token);
}
STATIC
VOID
EFIAPI
Ip4OnFrameSent (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Request Ip4OnFrameSentDpc as a DPC at TPL_CALLBACK
Arguments:
Event - The transmit token's event
Context - Context which is point to the token.
Returns:
None.
--*/
{
//
// Request Ip4OnFrameSentDpc as a DPC at TPL_CALLBACK
//
NetLibQueueDpc (TPL_CALLBACK, Ip4OnFrameSentDpc, Context);
}
/**
@@ -983,13 +1061,17 @@ Ip4SendFrame (
return EFI_SUCCESS;
SEND_NOW:
//
// Insert the tx token into the SentFrames list before calling Mnp->Transmit.
// Remove it if the returned status is not EFI_SUCCESS.
//
NetListInsertTail (&Interface->SentFrames, &Token->Link);
Status = Interface->Mnp->Transmit (Interface->Mnp, &Token->MnpToken);
if (EFI_ERROR (Status)) {
NetListRemoveEntry (&Interface->SentFrames);
goto ON_ERROR;
}
NetListInsertTail (&Interface->SentFrames, &Token->Link);
return EFI_SUCCESS;
ON_ERROR:
@@ -1031,7 +1113,6 @@ Ip4RecycleFrame (
again call the Ip4RecycleFrame to signal MNP's event and free
the token used.
@param Event The receive event delivered to MNP for receive.
@param Context Context for the callback.
@return None.
@@ -1040,8 +1121,7 @@ Ip4RecycleFrame (
STATIC
VOID
EFIAPI
Ip4OnFrameReceived (
IN EFI_EVENT Event,
Ip4OnFrameReceivedDpc (
IN VOID *Context
)
{
@@ -1096,6 +1176,36 @@ Ip4OnFrameReceived (
Token->CallBack (Token->IpInstance, Packet, EFI_SUCCESS, Flag, Token->Context);
}
STATIC
VOID
EFIAPI
Ip4OnFrameReceived (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Request Ip4OnFrameReceivedDpc as a DPC at TPL_CALLBACK
Arguments:
Event - The receive event delivered to MNP for receive.
Context - Context for the callback.
Returns:
None.
--*/
{
//
// Request Ip4OnFrameReceivedDpc as a DPC at TPL_CALLBACK
//
NetLibQueueDpc (TPL_CALLBACK, Ip4OnFrameReceivedDpc, Context);
}
/**
Request to receive the packet from the interface.
@@ -1134,13 +1244,12 @@ Ip4ReceiveFrame (
return EFI_OUT_OF_RESOURCES;
}
Interface->RecvRequest = Token;
Status = Interface->Mnp->Receive (Interface->Mnp, &Token->MnpToken);
if (EFI_ERROR (Status)) {
Interface->RecvRequest = NULL;
Ip4FreeFrameRxToken (Token);
return Status;
}
Interface->RecvRequest = Token;
return EFI_SUCCESS;
}

View File

@@ -482,7 +482,7 @@ Ip4IgmpHandle (
// is longer than the MaxRespTime. TODO: randomize the DelayTime.
//
if ((Group->DelayTime == 0) || (Group->DelayTime > Igmp.MaxRespTime)) {
Group->DelayTime = NET_MAX (1, Igmp.MaxRespTime);
Group->DelayTime = MAX (1, Igmp.MaxRespTime);
}
}
}

View File

@@ -214,7 +214,6 @@ Ip4ServiceConfigMnp (
it will configure the default interface and default route table
with the configuration information retrieved by IP4_CONFIGURE.
@param Event The event that is signalled.
@param Context The IP4 service binding instance.
@return None
@@ -222,8 +221,7 @@ Ip4ServiceConfigMnp (
**/
VOID
EFIAPI
Ip4AutoConfigCallBack (
IN EFI_EVENT Event,
Ip4AutoConfigCallBackDpc (
IN VOID *Context
)
{
@@ -252,7 +250,7 @@ Ip4AutoConfigCallBack (
// frames on the default address, and when the default interface is
// freed, Ip4AcceptFrame won't be informed.
//
if (Event == IpSb->ReconfigEvent) {
if (IpSb->ActiveEvent == IpSb->ReconfigEvent) {
if (IpSb->DefaultInterface->Configured) {
IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image);
@@ -360,6 +358,40 @@ ON_EXIT:
NetFreePool (Data);
}
VOID
EFIAPI
Ip4AutoConfigCallBack (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK
Arguments:
Event - The event that is signalled.
Context - The IP4 service binding instance.
Returns:
None
--*/
{
IP4_SERVICE *IpSb;
IpSb = (IP4_SERVICE *) Context;
IpSb->ActiveEvent = Event;
//
// Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK
//
NetLibQueueDpc (TPL_CALLBACK, Ip4AutoConfigCallBackDpc, Context);
}
/**
Start the auto configuration for this IP service instance.
@@ -401,7 +433,7 @@ Ip4StartAutoConfig (
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
NET_TPL_EVENT,
Ip4AutoConfigCallBack,
IpSb,
&IpSb->ReconfigEvent
@@ -764,7 +796,7 @@ Ip4StationAddressValid (
return FALSE;
}
NetBrdcastMask = mIp4AllMasks[NET_MIN (Len, Type << 3)];
NetBrdcastMask = mIp4AllMasks[MIN (Len, Type << 3)];
if (Ip == (Ip | ~NetBrdcastMask)) {
return FALSE;
@@ -1356,6 +1388,11 @@ Ip4FreeTxToken (
if (Wrap->Sent) {
gBS->SignalEvent (Wrap->Token->Event);
//
// Dispatch the DPC queued by the NotifyFunction of Token->Event.
//
NetLibDispatchDpc ();
}
NetFreePool (Wrap);
@@ -1562,6 +1599,12 @@ EfiIp4Transmit (
goto ON_EXIT;
}
//
// Mark the packet sent before output it. Mark it not sent again if the
// returned status is not EFI_SUCCESS;
//
Wrap->Sent = TRUE;
Status = Ip4Output (
IpSb,
IpInstance,
@@ -1575,16 +1618,10 @@ EfiIp4Transmit (
);
if (EFI_ERROR (Status)) {
Wrap->Sent = FALSE;
NetbufFree (Wrap->Packet);
goto ON_EXIT;
}
//
// Mark the packet sent, so when Ip4FreeTxToken is called, it
// will signal the upper layer.
//
Wrap->Sent = TRUE;
ON_EXIT:
NET_RESTORE_TPL (OldTpl);
return Status;
@@ -1668,6 +1705,12 @@ EfiIp4Receive (
Status = Ip4InstanceDeliverPacket (IpInstance);
//
// Dispatch the DPC queued by the NotifyFunction of this instane's receive
// event.
//
NetLibDispatchDpc ();
ON_EXIT:
NET_RESTORE_TPL (OldTpl);
return Status;
@@ -1820,7 +1863,11 @@ Ip4Cancel (
// for Token!=NULL and it is cancelled.
//
Status = NetMapIterate (&IpInstance->RxTokens, Ip4CancelRxTokens, Token);
//
// Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
// events.
//
NetLibDispatchDpc ();
if (EFI_ERROR (Status)) {
if ((Token != NULL) && (Status == EFI_ABORTED)) {
return EFI_SUCCESS;

View File

@@ -194,6 +194,7 @@ struct _IP4_SERVICE {
EFI_IP4_CONFIG_PROTOCOL *Ip4Config;
EFI_EVENT DoneEvent;
EFI_EVENT ReconfigEvent;
EFI_EVENT ActiveEvent;
//
// The string representation of the current mac address of the

View File

@@ -607,6 +607,12 @@ Ip4AccpetFrame (
Packet = NULL;
//
// Dispatch the DPCs queued by the NotifyFunction of the rx token's events
// which are signaled with received data.
//
NetLibDispatchDpc ();
RESTART:
Ip4ReceiveFrame (IpSb->DefaultInterface, NULL, Ip4AccpetFrame, IpSb);