]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/SnpDxe/Get_status.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / SnpDxe / Get_status.c
1 /** @file
2 Implementation of reading the current interrupt status and recycled transmit
3 buffer status from a network interface.
4
5 Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "Snp.h"
11
12 /**
13 Call undi to get the status of the interrupts, get the list of recycled transmit
14 buffers that completed transmitting. The recycled transmit buffer address will
15 be saved into Snp->RecycledTxBuf. This function will also update the MediaPresent
16 field of EFI_SIMPLE_NETWORK_MODE if UNDI support it.
17
18 @param[in] Snp Pointer to snp driver structure.
19 @param[out] InterruptStatusPtr A non null pointer to contain the interrupt
20 status.
21 @param[in] GetTransmittedBuf Set to TRUE to retrieve the recycled transmit
22 buffer address.
23
24 @retval EFI_SUCCESS The status of the network interface was retrieved.
25 @retval EFI_DEVICE_ERROR The command could not be sent to the network
26 interface.
27
28 **/
29 EFI_STATUS
30 PxeGetStatus (
31 IN SNP_DRIVER *Snp,
32 OUT UINT32 *InterruptStatusPtr,
33 IN BOOLEAN GetTransmittedBuf
34 )
35 {
36 PXE_DB_GET_STATUS *Db;
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
97 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_RECEIVE) == PXE_STATFLAGS_GET_STATUS_RECEIVE) {
98 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
99 }
100
101 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_TRANSMIT) == PXE_STATFLAGS_GET_STATUS_TRANSMIT) {
102 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
103 }
104
105 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_COMMAND) == PXE_STATFLAGS_GET_STATUS_COMMAND) {
106 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;
107 }
108
109 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_SOFTWARE) == PXE_STATFLAGS_GET_STATUS_SOFTWARE) {
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
159 /**
160 Reads the current interrupt status and recycled transmit buffer status from a
161 network interface.
162
163 This function gets the current interrupt and recycled transmit buffer status
164 from the network interface. The interrupt status is returned as a bit mask in
165 InterruptStatus. If InterruptStatus is NULL, the interrupt status will not be
166 read. If TxBuf is not NULL, a recycled transmit buffer address will be retrieved.
167 If a recycled transmit buffer address is returned in TxBuf, then the buffer has
168 been successfully transmitted, and the status for that buffer is cleared. If
169 the status of the network interface is successfully collected, EFI_SUCCESS
170 will be returned. If the driver has not been initialized, EFI_DEVICE_ERROR will
171 be returned.
172
173 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
174 @param InterruptStatus A pointer to the bit mask of the currently active
175 interrupts (see "Related Definitions"). If this is NULL,
176 the interrupt status will not be read from the device.
177 If this is not NULL, the interrupt status will be read
178 from the device. When the interrupt status is read, it
179 will also be cleared. Clearing the transmit interrupt does
180 not empty the recycled transmit buffer array.
181 @param TxBuf Recycled transmit buffer address. The network interface
182 will not transmit if its internal recycled transmit
183 buffer array is full. Reading the transmit buffer does
184 not clear the transmit interrupt. If this is NULL, then
185 the transmit buffer status will not be read. If there
186 are no transmit buffers to recycle and TxBuf is not NULL,
187 TxBuf will be set to NULL.
188
189 @retval EFI_SUCCESS The status of the network interface was retrieved.
190 @retval EFI_NOT_STARTED The network interface has not been started.
191 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
192 EFI_SIMPLE_NETWORK_PROTOCOL structure.
193 @retval EFI_DEVICE_ERROR The command could not be sent to the network
194 interface.
195
196 **/
197 EFI_STATUS
198 EFIAPI
199 SnpUndi32GetStatus (
200 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
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
256 ON_EXIT:
257 gBS->RestoreTPL (OldTpl);
258
259 return Status;
260 }