]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Network/SnpDxe/Get_status.c
SecurityPkg : Tpm2DeviceLibDTpm : Rename TisTpmCommand to avoid name collision
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Get_status.c
... / ...
CommitLineData
1/** @file\r
2 Implementation of reading the current interrupt status and recycled transmit\r
3 buffer status from a network interface.\r
4\r
5Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials are licensed\r
7and made available under the terms and conditions of the BSD License which\r
8accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "Snp.h"\r
17\r
18/**\r
19 Call undi to get the status of the interrupts, get the list of transmit\r
20 buffers that completed transmitting.\r
21\r
22 @param Snp Pointer to snp driver structure.\r
23 @param InterruptStatusPtr A non null pointer to contain the interrupt\r
24 status.\r
25 @param TransmitBufferListPtrs A non null pointer to contain the list of\r
26 pointers of previous transmitted buffers whose\r
27 transmission was completed asynchrnously.\r
28\r
29 @retval EFI_SUCCESS The status of the network interface was retrieved.\r
30 @retval EFI_DEVICE_ERROR The command could not be sent to the network\r
31 interface.\r
32\r
33**/\r
34EFI_STATUS\r
35PxeGetStatus (\r
36 SNP_DRIVER *Snp,\r
37 UINT32 *InterruptStatusPtr,\r
38 VOID **TransmitBufferListPtr\r
39 )\r
40{\r
41 PXE_DB_GET_STATUS *Db;\r
42 UINT16 InterruptFlags;\r
43\r
44 Db = Snp->Db;\r
45 Snp->Cdb.OpCode = PXE_OPCODE_GET_STATUS;\r
46\r
47 Snp->Cdb.OpFlags = 0;\r
48\r
49 if (TransmitBufferListPtr != NULL) {\r
50 Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS;\r
51 }\r
52\r
53 if (InterruptStatusPtr != NULL) {\r
54 Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_INTERRUPT_STATUS;\r
55 }\r
56\r
57 if (Snp->MediaStatusSupported) {\r
58 Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_MEDIA_STATUS;\r
59 }\r
60\r
61 Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
62 Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
63\r
64 //\r
65 // size DB for return of one buffer\r
66 //\r
67 Snp->Cdb.DBsize = (UINT16) ((sizeof (PXE_DB_GET_STATUS) - sizeof (Db->TxBuffer)) + sizeof (Db->TxBuffer[0]));\r
68\r
69 Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;\r
70\r
71 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
72 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
73 Snp->Cdb.IFnum = Snp->IfNum;\r
74 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
75\r
76 //\r
77 // Issue UNDI command and check result.\r
78 //\r
79 DEBUG ((EFI_D_NET, "\nSnp->undi.get_status() "));\r
80\r
81 (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);\r
82\r
83 if (Snp->Cdb.StatCode != EFI_SUCCESS) {\r
84 DEBUG (\r
85 (EFI_D_NET,\r
86 "\nSnp->undi.get_status() %xh:%xh\n",\r
87 Snp->Cdb.StatFlags,\r
88 Snp->Cdb.StatFlags)\r
89 );\r
90\r
91 return EFI_DEVICE_ERROR;\r
92 }\r
93 //\r
94 // report the values back..\r
95 //\r
96 if (InterruptStatusPtr != NULL) {\r
97 InterruptFlags = (UINT16) (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK);\r
98\r
99 *InterruptStatusPtr = 0;\r
100\r
101 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_RECEIVE) == PXE_STATFLAGS_GET_STATUS_RECEIVE) {\r
102 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;\r
103 }\r
104\r
105 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_TRANSMIT) == PXE_STATFLAGS_GET_STATUS_TRANSMIT) {\r
106 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;\r
107 }\r
108\r
109 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_COMMAND) == PXE_STATFLAGS_GET_STATUS_COMMAND) {\r
110 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;\r
111 }\r
112\r
113 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_SOFTWARE) == PXE_STATFLAGS_GET_STATUS_SOFTWARE) {\r
114 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;\r
115 }\r
116\r
117 }\r
118\r
119 if (TransmitBufferListPtr != NULL) {\r
120 *TransmitBufferListPtr =\r
121 (\r
122 ((Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN) != 0) ||\r
123 ((Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY) != 0)\r
124 ) ? 0 : (VOID *) (UINTN) Db->TxBuffer[0];\r
125\r
126 }\r
127\r
128 //\r
129 // Update MediaPresent field of EFI_SIMPLE_NETWORK_MODE if the UNDI support\r
130 // returning media status from GET_STATUS command\r
131 //\r
132 if (Snp->MediaStatusSupported) {\r
133 Snp->Snp.Mode->MediaPresent =\r
134 (BOOLEAN) (((Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_MEDIA) != 0) ? FALSE : TRUE);\r
135 }\r
136\r
137 return EFI_SUCCESS;\r
138}\r
139\r
140/**\r
141 Reads the current interrupt status and recycled transmit buffer status from a\r
142 network interface.\r
143\r
144 This function gets the current interrupt and recycled transmit buffer status\r
145 from the network interface. The interrupt status is returned as a bit mask in\r
146 InterruptStatus. If InterruptStatus is NULL, the interrupt status will not be\r
147 read. If TxBuf is not NULL, a recycled transmit buffer address will be retrieved.\r
148 If a recycled transmit buffer address is returned in TxBuf, then the buffer has\r
149 been successfully transmitted, and the status for that buffer is cleared. If\r
150 the status of the network interface is successfully collected, EFI_SUCCESS\r
151 will be returned. If the driver has not been initialized, EFI_DEVICE_ERROR will\r
152 be returned.\r
153\r
154 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
155 @param InterruptStatus A pointer to the bit mask of the currently active\r
156 interrupts (see "Related Definitions"). If this is NULL,\r
157 the interrupt status will not be read from the device.\r
158 If this is not NULL, the interrupt status will be read\r
159 from the device. When the interrupt status is read, it\r
160 will also be cleared. Clearing the transmit interrupt does\r
161 not empty the recycled transmit buffer array.\r
162 @param TxBuf Recycled transmit buffer address. The network interface\r
163 will not transmit if its internal recycled transmit\r
164 buffer array is full. Reading the transmit buffer does\r
165 not clear the transmit interrupt. If this is NULL, then\r
166 the transmit buffer status will not be read. If there\r
167 are no transmit buffers to recycle and TxBuf is not NULL,\r
168 TxBuf will be set to NULL.\r
169\r
170 @retval EFI_SUCCESS The status of the network interface was retrieved.\r
171 @retval EFI_NOT_STARTED The network interface has not been started.\r
172 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid\r
173 EFI_SIMPLE_NETWORK_PROTOCOL structure.\r
174 @retval EFI_DEVICE_ERROR The command could not be sent to the network\r
175 interface.\r
176\r
177**/\r
178EFI_STATUS\r
179EFIAPI\r
180SnpUndi32GetStatus (\r
181 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
182 OUT UINT32 *InterruptStatus, OPTIONAL\r
183 OUT VOID **TxBuf OPTIONAL\r
184 )\r
185{\r
186 SNP_DRIVER *Snp;\r
187 EFI_TPL OldTpl;\r
188 EFI_STATUS Status;\r
189\r
190 if (This == NULL) {\r
191 return EFI_INVALID_PARAMETER;\r
192 }\r
193\r
194 if (InterruptStatus == NULL && TxBuf == NULL) {\r
195 return EFI_INVALID_PARAMETER;\r
196 }\r
197\r
198 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r
199\r
200 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
201\r
202 if (Snp == NULL) {\r
203 return EFI_DEVICE_ERROR;\r
204 }\r
205\r
206 switch (Snp->Mode.State) {\r
207 case EfiSimpleNetworkInitialized:\r
208 break;\r
209\r
210 case EfiSimpleNetworkStopped:\r
211 Status = EFI_NOT_STARTED;\r
212 goto ON_EXIT;\r
213\r
214 default:\r
215 Status = EFI_DEVICE_ERROR;\r
216 goto ON_EXIT;\r
217 }\r
218\r
219 Status = PxeGetStatus (Snp, InterruptStatus, TxBuf);\r
220\r
221ON_EXIT:\r
222 gBS->RestoreTPL (OldTpl);\r
223\r
224 return Status;\r
225}\r