]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/SnpDxe/WaitForPacket.c
NetworkPkg: Move Network library and drivers from MdeModulePkg to NetworkPkg
[mirror_edk2.git] / NetworkPkg / SnpDxe / WaitForPacket.c
1 /** @file
2 Event handler to check for available packet.
3
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "Snp.h"
10
11
12 /**
13 Nofication call back function for WaitForPacket event.
14
15 @param Event EFI Event.
16 @param SnpPtr Pointer to SNP_DRIVER structure.
17
18 **/
19 VOID
20 EFIAPI
21 SnpWaitForPacketNotify (
22 EFI_EVENT Event,
23 VOID *SnpPtr
24 )
25 {
26 PXE_DB_GET_STATUS PxeDbGetStatus;
27
28 //
29 // Do nothing if either parameter is a NULL pointer.
30 //
31 if (Event == NULL || SnpPtr == NULL) {
32 return ;
33 }
34 //
35 // Do nothing if the SNP interface is not initialized.
36 //
37 switch (((SNP_DRIVER *) SnpPtr)->Mode.State) {
38 case EfiSimpleNetworkInitialized:
39 break;
40
41 case EfiSimpleNetworkStopped:
42 case EfiSimpleNetworkStarted:
43 default:
44 return ;
45 }
46 //
47 // Fill in CDB for UNDI GetStatus().
48 //
49 ((SNP_DRIVER *) SnpPtr)->Cdb.OpCode = PXE_OPCODE_GET_STATUS;
50 ((SNP_DRIVER *) SnpPtr)->Cdb.OpFlags = 0;
51 ((SNP_DRIVER *) SnpPtr)->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
52 ((SNP_DRIVER *) SnpPtr)->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
53 ((SNP_DRIVER *) SnpPtr)->Cdb.DBsize = (UINT16) (sizeof (UINT32) * 2);
54 ((SNP_DRIVER *) SnpPtr)->Cdb.DBaddr = (UINT64)(UINTN) (((SNP_DRIVER *) SnpPtr)->Db);
55 ((SNP_DRIVER *) SnpPtr)->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
56 ((SNP_DRIVER *) SnpPtr)->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
57 ((SNP_DRIVER *) SnpPtr)->Cdb.IFnum = ((SNP_DRIVER *) SnpPtr)->IfNum;
58 ((SNP_DRIVER *) SnpPtr)->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
59
60 //
61 // Clear contents of DB buffer.
62 //
63 ZeroMem (((SNP_DRIVER *) SnpPtr)->Db, sizeof (UINT32) * 2);
64
65 //
66 // Issue UNDI command and check result.
67 //
68 (*((SNP_DRIVER *) SnpPtr)->IssueUndi32Command) ((UINT64)(UINTN) &((SNP_DRIVER *) SnpPtr)->Cdb);
69
70 if (((SNP_DRIVER *) SnpPtr)->Cdb.StatCode != EFI_SUCCESS) {
71 return ;
72 }
73 //
74 // We might have a packet. Check the receive length and signal
75 // the event if the length is not zero.
76 //
77 CopyMem (
78 &PxeDbGetStatus,
79 ((SNP_DRIVER *) SnpPtr)->Db,
80 sizeof (UINT32) * 2
81 );
82
83 if (PxeDbGetStatus.RxFrameLen != 0) {
84 gBS->SignalEvent (Event);
85 }
86 }