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