]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Get_status.c
sync comments, fix function header, rename variable name to follow coding style.
[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 this routine calls undi to get the status of the interrupts, get the list of
20 transmit buffers that completed transmitting!
21
22 @param Snp pointer to snp driver structure
23 @param InterruptStatusPtr a non null pointer gets the interrupt status
24 @param TransmitBufferListPtrs a non null ointer gets the list of pointers of
25 previously transmitted buffers whose
26 transmission was completed asynchrnously.
27
28
29 **/
30 EFI_STATUS
31 PxeGetStatus (
32 SNP_DRIVER *Snp,
33 UINT32 *InterruptStatusPtr,
34 VOID **TransmitBufferListPtr
35 )
36 {
37 PXE_DB_GET_STATUS *Db;
38 UINT16 InterruptFlags;
39
40 Db = Snp->Db;
41 Snp->Cdb.OpCode = PXE_OPCODE_GET_STATUS;
42
43 Snp->Cdb.OpFlags = 0;
44
45 if (TransmitBufferListPtr != NULL) {
46 Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS;
47 }
48
49 if (InterruptStatusPtr != NULL) {
50 Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_INTERRUPT_STATUS;
51 }
52
53 Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
54 Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
55
56 //
57 // size DB for return of one buffer
58 //
59 Snp->Cdb.DBsize = (UINT16) ((sizeof (PXE_DB_GET_STATUS) - sizeof (Db->TxBuffer)) + sizeof (Db->TxBuffer[0]));
60
61 Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;
62
63 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
64 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
65 Snp->Cdb.IFnum = Snp->IfNum;
66 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
67
68 //
69 // Issue UNDI command and check result.
70 //
71 DEBUG ((EFI_D_NET, "\nSnp->undi.get_status() "));
72
73 (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
74
75 if (Snp->Cdb.StatCode != EFI_SUCCESS) {
76 DEBUG (
77 (EFI_D_NET,
78 "\nSnp->undi.get_status() %xh:%xh\n",
79 Snp->Cdb.StatFlags,
80 Snp->Cdb.StatFlags)
81 );
82
83 return EFI_DEVICE_ERROR;
84 }
85 //
86 // report the values back..
87 //
88 if (InterruptStatusPtr != NULL) {
89 InterruptFlags = (UINT16) (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK);
90
91 *InterruptStatusPtr = 0;
92
93 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_RECEIVE) == PXE_STATFLAGS_GET_STATUS_RECEIVE) {
94 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
95 }
96
97 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_TRANSMIT) == PXE_STATFLAGS_GET_STATUS_TRANSMIT) {
98 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
99 }
100
101 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_COMMAND) == PXE_STATFLAGS_GET_STATUS_COMMAND) {
102 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;
103 }
104
105 if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_SOFTWARE) == PXE_STATFLAGS_GET_STATUS_SOFTWARE) {
106 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;
107 }
108
109 }
110
111 if (TransmitBufferListPtr != NULL) {
112 *TransmitBufferListPtr =
113 (
114 (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN) ||
115 (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY)
116 ) ? 0 : (VOID *) (UINTN) Db->TxBuffer[0];
117
118 }
119
120 return EFI_SUCCESS;
121 }
122
123 /**
124 Reads the current interrupt status and recycled transmit buffer status from a
125 network interface.
126
127 This function gets the current interrupt and recycled transmit buffer status
128 from the network interface. The interrupt status is returned as a bit mask in
129 InterruptStatus. If InterruptStatus is NULL, the interrupt status will not be
130 read. If TxBuf is not NULL, a recycled transmit buffer address will be retrieved.
131 If a recycled transmit buffer address is returned in TxBuf, then the buffer has
132 been successfully transmitted, and the status for that buffer is cleared. If
133 the status of the network interface is successfully collected, EFI_SUCCESS
134 will be returned. If the driver has not been initialized, EFI_DEVICE_ERROR will
135 be returned.
136
137 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
138 @param InterruptStatus A pointer to the bit mask of the currently active
139 interrupts (see "Related Definitions"). If this is NULL,
140 the interrupt status will not be read from the device.
141 If this is not NULL, the interrupt status will be read
142 from the device. When the interrupt status is read, it
143 will also be cleared. Clearing the transmit interrupt does
144 not empty the recycled transmit buffer array.
145 @param TxBuf Recycled transmit buffer address. The network interface
146 will not transmit if its internal recycled transmit
147 buffer array is full. Reading the transmit buffer does
148 not clear the transmit interrupt. If this is NULL, then
149 the transmit buffer status will not be read. If there
150 are no transmit buffers to recycle and TxBuf is not NULL,
151 TxBuf will be set to NULL.
152
153 @retval EFI_SUCCESS The status of the network interface was retrieved.
154 @retval EFI_NOT_STARTED The network interface has not been started.
155 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
156 EFI_SIMPLE_NETWORK_PROTOCOL structure.
157 @retval EFI_DEVICE_ERROR The command could not be sent to the network
158 interface.
159
160 **/
161 EFI_STATUS
162 EFIAPI
163 SnpUndi32GetStatus (
164 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
165 OUT UINT32 *InterruptStatus, OPTIONAL
166 OUT VOID **TxBuf OPTIONAL
167 )
168 {
169 SNP_DRIVER *Snp;
170 EFI_TPL OldTpl;
171 EFI_STATUS Status;
172
173 if (This == NULL) {
174 return EFI_INVALID_PARAMETER;
175 }
176
177 if (InterruptStatus == NULL && TxBuf == NULL) {
178 return EFI_INVALID_PARAMETER;
179 }
180
181 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
182
183 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
184
185 if (Snp == NULL) {
186 return EFI_DEVICE_ERROR;
187 }
188
189 switch (Snp->Mode.State) {
190 case EfiSimpleNetworkInitialized:
191 break;
192
193 case EfiSimpleNetworkStopped:
194 Status = EFI_NOT_STARTED;
195 goto ON_EXIT;
196
197 default:
198 Status = EFI_DEVICE_ERROR;
199 goto ON_EXIT;
200 }
201
202 Status = PxeGetStatus (Snp, InterruptStatus, TxBuf);
203
204 ON_EXIT:
205 gBS->RestoreTPL (OldTpl);
206
207 return Status;
208 }