TianoCore EDK2 master
Loading...
Searching...
No Matches
Get_status.c
Go to the documentation of this file.
1
10#include "Snp.h"
11
31 IN SNP_DRIVER *Snp,
32 OUT UINT32 *InterruptStatusPtr,
33 IN BOOLEAN GetTransmittedBuf
34 )
35{
37 UINT16 InterruptFlags;
38 UINT32 Index;
39 UINT64 *Tmp;
40
41 Tmp = NULL;
42 Db = Snp->Db;
43 Snp->Cdb.OpCode = PXE_OPCODE_GET_STATUS;
44
45 Snp->Cdb.OpFlags = 0;
46
47 if (GetTransmittedBuf) {
48 Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS;
49 ZeroMem (Db->TxBuffer, sizeof (Db->TxBuffer));
50 }
51
52 if (InterruptStatusPtr != NULL) {
53 Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_INTERRUPT_STATUS;
54 }
55
56 if (Snp->MediaStatusSupported) {
57 Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_MEDIA_STATUS;
58 }
59
60 Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
61 Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
62
63 Snp->Cdb.DBsize = (UINT16)sizeof (PXE_DB_GET_STATUS);
64 Snp->Cdb.DBaddr = (UINT64)(UINTN)Db;
65
66 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
67 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
68 Snp->Cdb.IFnum = Snp->IfNum;
69 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
70
71 //
72 // Issue UNDI command and check result.
73 //
74 DEBUG ((DEBUG_NET, "\nSnp->undi.get_status() "));
75
76 (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);
77
78 if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {
79 DEBUG (
80 (DEBUG_NET,
81 "\nSnp->undi.get_status() %xh:%xh\n",
82 Snp->Cdb.StatFlags,
83 Snp->Cdb.StatCode)
84 );
85
86 return EFI_DEVICE_ERROR;
87 }
88
89 //
90 // report the values back..
91 //
92 if (InterruptStatusPtr != NULL) {
93 InterruptFlags = (UINT16)(Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK);
94
95 *InterruptStatusPtr = 0;
96
98 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
99 }
100
102 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
103 }
104
106 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;
107 }
108
110 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;
111 }
112 }
113
114 if (GetTransmittedBuf) {
115 if ((Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN) == 0) {
116 //
117 // UNDI has written some transmitted buffer addresses into the DB. Store them into Snp->RecycledTxBuf.
118 //
119 for (Index = 0; Index < MAX_XMIT_BUFFERS; Index++) {
120 if (Db->TxBuffer[Index] != 0) {
121 if (Snp->RecycledTxBufCount == Snp->MaxRecycledTxBuf) {
122 //
123 // Snp->RecycledTxBuf is full, reallocate a new one.
124 //
125 if ((Snp->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >= SNP_MAX_TX_BUFFER_NUM) {
126 return EFI_DEVICE_ERROR;
127 }
128
129 Tmp = AllocatePool (sizeof (UINT64) * (Snp->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT));
130 if (Tmp == NULL) {
131 return EFI_DEVICE_ERROR;
132 }
133
134 CopyMem (Tmp, Snp->RecycledTxBuf, sizeof (UINT64) * Snp->RecycledTxBufCount);
135 FreePool (Snp->RecycledTxBuf);
136 Snp->RecycledTxBuf = Tmp;
137 Snp->MaxRecycledTxBuf += SNP_TX_BUFFER_INCREASEMENT;
138 }
139
140 Snp->RecycledTxBuf[Snp->RecycledTxBufCount] = Db->TxBuffer[Index];
141 Snp->RecycledTxBufCount++;
142 }
143 }
144 }
145 }
146
147 //
148 // Update MediaPresent field of EFI_SIMPLE_NETWORK_MODE if the UNDI support
149 // returning media status from GET_STATUS command
150 //
151 if (Snp->MediaStatusSupported) {
152 Snp->Snp.Mode->MediaPresent =
153 (BOOLEAN)(((Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_MEDIA) != 0) ? FALSE : TRUE);
154 }
155
156 return EFI_SUCCESS;
157}
158
198EFIAPI
201 OUT UINT32 *InterruptStatus OPTIONAL,
202 OUT VOID **TxBuf OPTIONAL
203 )
204{
205 SNP_DRIVER *Snp;
206 EFI_TPL OldTpl;
207 EFI_STATUS Status;
208
209 if (This == NULL) {
210 return EFI_INVALID_PARAMETER;
211 }
212
213 if ((InterruptStatus == NULL) && (TxBuf == NULL)) {
214 return EFI_INVALID_PARAMETER;
215 }
216
217 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
218
219 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
220
221 if (Snp == NULL) {
222 return EFI_DEVICE_ERROR;
223 }
224
225 switch (Snp->Mode.State) {
226 case EfiSimpleNetworkInitialized:
227 break;
228
229 case EfiSimpleNetworkStopped:
230 Status = EFI_NOT_STARTED;
231 goto ON_EXIT;
232
233 default:
234 Status = EFI_DEVICE_ERROR;
235 goto ON_EXIT;
236 }
237
238 if ((Snp->RecycledTxBufCount == 0) && (TxBuf != NULL)) {
239 Status = PxeGetStatus (Snp, InterruptStatus, TRUE);
240 } else {
241 Status = PxeGetStatus (Snp, InterruptStatus, FALSE);
242 }
243
244 if (TxBuf != NULL) {
245 //
246 // Get a recycled buf from Snp->RecycledTxBuf
247 //
248 if (Snp->RecycledTxBufCount == 0) {
249 *TxBuf = NULL;
250 } else {
251 Snp->RecycledTxBufCount--;
252 *TxBuf = (VOID *)(UINTN)Snp->RecycledTxBuf[Snp->RecycledTxBufCount];
253 }
254 }
255
256ON_EXIT:
257 gBS->RestoreTPL (OldTpl);
258
259 return Status;
260}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS PxeGetStatus(IN SNP_DRIVER *Snp, OUT UINT32 *InterruptStatusPtr, IN BOOLEAN GetTransmittedBuf)
Definition: Get_status.c:30
EFI_STATUS EFIAPI SnpUndi32GetStatus(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, OUT UINT32 *InterruptStatus OPTIONAL, OUT VOID **TxBuf OPTIONAL)
Definition: Get_status.c:199
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define PXE_CPBSIZE_NOT_USED
zero
Definition: UefiPxe.h:57
#define PXE_STATFLAGS_GET_STATUS_TRANSMIT
Definition: UefiPxe.h:547
#define PXE_OPCODE_GET_STATUS
Definition: UefiPxe.h:155
#define PXE_STATFLAGS_GET_STATUS_RECEIVE
Definition: UefiPxe.h:542
#define PXE_STATFLAGS_GET_STATUS_NO_MEDIA
Definition: UefiPxe.h:574
#define PXE_STATFLAGS_GET_STATUS_SOFTWARE
Definition: UefiPxe.h:557
#define PXE_OPFLAGS_GET_INTERRUPT_STATUS
Definition: UefiPxe.h:352
#define MAX_XMIT_BUFFERS
recycling Q length for xmit_done.
Definition: UefiPxe.h:919
#define PXE_OPFLAGS_GET_MEDIA_STATUS
Definition: UefiPxe.h:367
#define PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS
Definition: UefiPxe.h:362
#define PXE_CPBADDR_NOT_USED
zero
Definition: UefiPxe.h:59
#define PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN
Definition: UefiPxe.h:569
#define PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK
/ UNDI MCast IP to MAC. / / No additional StatFlags.
Definition: UefiPxe.h:536
#define PXE_STATCODE_SUCCESS
Definition: UefiPxe.h:602
#define PXE_STATFLAGS_GET_STATUS_COMMAND
Definition: UefiPxe.h:552
Definition: Snp.h:55
PXE_UINT64 TxBuffer[MAX_XMIT_BUFFERS]
Definition: UefiPxe.h:1565