]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Get_status.c
edd2424c2cea5f8d7624df3ea490f223c4df04da
[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 - 2007, 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 Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
58 Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
59
60 //
61 // size DB for return of one buffer
62 //
63 Snp->Cdb.DBsize = (UINT16) ((sizeof (PXE_DB_GET_STATUS) - sizeof (Db->TxBuffer)) + sizeof (Db->TxBuffer[0]));
64
65 Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;
66
67 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
68 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
69 Snp->Cdb.IFnum = Snp->IfNum;
70 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
71
72 //
73 // Issue UNDI command and check result.
74 //
75 DEBUG ((EFI_D_NET, "\nSnp->undi.get_status() "));
76
77 (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
78
79 if (Snp->Cdb.StatCode != EFI_SUCCESS) {
80 DEBUG (
81 (EFI_D_NET,
82 "\nSnp->undi.get_status() %xh:%xh\n",
83 Snp->Cdb.StatFlags,
84 Snp->Cdb.StatFlags)
85 );
86
87 return EFI_DEVICE_ERROR;
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
115 if (TransmitBufferListPtr != NULL) {
116 *TransmitBufferListPtr =
117 (
118 (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN) ||
119 (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY)
120 ) ? 0 : (VOID *) (UINTN) Db->TxBuffer[0];
121
122 }
123
124 return EFI_SUCCESS;
125 }
126
127 /**
128 Reads the current interrupt status and recycled transmit buffer status from a
129 network interface.
130
131 This function gets the current interrupt and recycled transmit buffer status
132 from the network interface. The interrupt status is returned as a bit mask in
133 InterruptStatus. If InterruptStatus is NULL, the interrupt status will not be
134 read. If TxBuf is not NULL, a recycled transmit buffer address will be retrieved.
135 If a recycled transmit buffer address is returned in TxBuf, then the buffer has
136 been successfully transmitted, and the status for that buffer is cleared. If
137 the status of the network interface is successfully collected, EFI_SUCCESS
138 will be returned. If the driver has not been initialized, EFI_DEVICE_ERROR will
139 be returned.
140
141 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
142 @param InterruptStatus A pointer to the bit mask of the currently active
143 interrupts (see "Related Definitions"). If this is NULL,
144 the interrupt status will not be read from the device.
145 If this is not NULL, the interrupt status will be read
146 from the device. When the interrupt status is read, it
147 will also be cleared. Clearing the transmit interrupt does
148 not empty the recycled transmit buffer array.
149 @param TxBuf Recycled transmit buffer address. The network interface
150 will not transmit if its internal recycled transmit
151 buffer array is full. Reading the transmit buffer does
152 not clear the transmit interrupt. If this is NULL, then
153 the transmit buffer status will not be read. If there
154 are no transmit buffers to recycle and TxBuf is not NULL,
155 TxBuf will be set to NULL.
156
157 @retval EFI_SUCCESS The status of the network interface was retrieved.
158 @retval EFI_NOT_STARTED The network interface has not been started.
159 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
160 EFI_SIMPLE_NETWORK_PROTOCOL structure.
161 @retval EFI_DEVICE_ERROR The command could not be sent to the network
162 interface.
163
164 **/
165 EFI_STATUS
166 EFIAPI
167 SnpUndi32GetStatus (
168 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
169 OUT UINT32 *InterruptStatus, OPTIONAL
170 OUT VOID **TxBuf OPTIONAL
171 )
172 {
173 SNP_DRIVER *Snp;
174 EFI_TPL OldTpl;
175 EFI_STATUS Status;
176
177 if (This == NULL) {
178 return EFI_INVALID_PARAMETER;
179 }
180
181 if (InterruptStatus == NULL && TxBuf == NULL) {
182 return EFI_INVALID_PARAMETER;
183 }
184
185 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
186
187 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
188
189 if (Snp == NULL) {
190 return EFI_DEVICE_ERROR;
191 }
192
193 switch (Snp->Mode.State) {
194 case EfiSimpleNetworkInitialized:
195 break;
196
197 case EfiSimpleNetworkStopped:
198 Status = EFI_NOT_STARTED;
199 goto ON_EXIT;
200
201 default:
202 Status = EFI_DEVICE_ERROR;
203 goto ON_EXIT;
204 }
205
206 Status = PxeGetStatus (Snp, InterruptStatus, TxBuf);
207
208 ON_EXIT:
209 gBS->RestoreTPL (OldTpl);
210
211 return Status;
212 }