2 Implementation of reading the current interrupt status and recycled transmit
3 buffer status from a network interface.
5 Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
6 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
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.
19 Call undi to get the status of the interrupts, get the list of recycled transmit
20 buffers that completed transmitting. The recycled transmit buffer address will
21 be saved into Snp->RecycledTxBuf.
23 @param Snp Pointer to snp driver structure.
24 @param InterruptStatusPtr A non null pointer to contain the interrupt
26 @param GetTransmittedBuf Set to TRUE to retrieve the recycled transmit
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
37 UINT32
*InterruptStatusPtr
,
38 BOOLEAN GetTransmittedBuf
41 PXE_DB_GET_STATUS
*Db
;
42 UINT16 InterruptFlags
;
48 Snp
->Cdb
.OpCode
= PXE_OPCODE_GET_STATUS
;
52 if (GetTransmittedBuf
) {
53 Snp
->Cdb
.OpFlags
|= PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS
;
54 ZeroMem (Db
->TxBuffer
, sizeof (Db
->TxBuffer
));
57 if (InterruptStatusPtr
!= NULL
) {
58 Snp
->Cdb
.OpFlags
|= PXE_OPFLAGS_GET_INTERRUPT_STATUS
;
61 if (Snp
->MediaStatusSupported
) {
62 Snp
->Cdb
.OpFlags
|= PXE_OPFLAGS_GET_MEDIA_STATUS
;
65 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
66 Snp
->Cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
68 Snp
->Cdb
.DBsize
= (UINT16
) sizeof (PXE_DB_GET_STATUS
);
69 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
) Db
;
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
;
77 // Issue UNDI command and check result.
79 DEBUG ((EFI_D_NET
, "\nSnp->undi.get_status() "));
81 (*Snp
->IssueUndi32Command
) ((UINT64
)(UINTN
) &Snp
->Cdb
);
83 if (Snp
->Cdb
.StatCode
!= EFI_SUCCESS
) {
86 "\nSnp->undi.get_status() %xh:%xh\n",
91 return EFI_DEVICE_ERROR
;
94 // report the values back..
96 if (InterruptStatusPtr
!= NULL
) {
97 InterruptFlags
= (UINT16
) (Snp
->Cdb
.StatFlags
& PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK
);
99 *InterruptStatusPtr
= 0;
101 if ((InterruptFlags
& PXE_STATFLAGS_GET_STATUS_RECEIVE
) == PXE_STATFLAGS_GET_STATUS_RECEIVE
) {
102 *InterruptStatusPtr
|= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
;
105 if ((InterruptFlags
& PXE_STATFLAGS_GET_STATUS_TRANSMIT
) == PXE_STATFLAGS_GET_STATUS_TRANSMIT
) {
106 *InterruptStatusPtr
|= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
;
109 if ((InterruptFlags
& PXE_STATFLAGS_GET_STATUS_COMMAND
) == PXE_STATFLAGS_GET_STATUS_COMMAND
) {
110 *InterruptStatusPtr
|= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT
;
113 if ((InterruptFlags
& PXE_STATFLAGS_GET_STATUS_SOFTWARE
) == PXE_STATFLAGS_GET_STATUS_SOFTWARE
) {
114 *InterruptStatusPtr
|= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT
;
119 if (GetTransmittedBuf
) {
120 if ((Snp
->Cdb
.StatFlags
& PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN
) == 0) {
122 // UNDI has written some transmitted buffer addresses into the DB. Store them into Snp->RecycledTxBuf.
124 for (Index
= 0; Index
< MAX_XMIT_BUFFERS
; Index
++) {
125 if (Db
->TxBuffer
[Index
] != 0) {
126 if (Snp
->RecycledTxBufCount
== Snp
->MaxRecycledTxBuf
) {
128 // Snp->RecycledTxBuf is full, reallocate a new one.
130 if ((Snp
->MaxRecycledTxBuf
+ SNP_TX_BUFFER_INCREASEMENT
) >= SNP_MAX_TX_BUFFER_NUM
) {
131 return EFI_DEVICE_ERROR
;
133 Tmp
= AllocatePool (sizeof (UINT64
) * (Snp
->MaxRecycledTxBuf
+ SNP_TX_BUFFER_INCREASEMENT
));
135 return EFI_DEVICE_ERROR
;
137 CopyMem (Tmp
, Snp
->RecycledTxBuf
, sizeof (UINT64
) * Snp
->RecycledTxBufCount
);
138 FreePool (Snp
->RecycledTxBuf
);
139 Snp
->RecycledTxBuf
= Tmp
;
140 Snp
->MaxRecycledTxBuf
+= SNP_TX_BUFFER_INCREASEMENT
;
142 Snp
->RecycledTxBuf
[Snp
->RecycledTxBufCount
] = Db
->TxBuffer
[Index
];
143 Snp
->RecycledTxBufCount
++;
150 // Update MediaPresent field of EFI_SIMPLE_NETWORK_MODE if the UNDI support
151 // returning media status from GET_STATUS command
153 if (Snp
->MediaStatusSupported
) {
154 Snp
->Snp
.Mode
->MediaPresent
=
155 (BOOLEAN
) (((Snp
->Cdb
.StatFlags
& PXE_STATFLAGS_GET_STATUS_NO_MEDIA
) != 0) ? FALSE
: TRUE
);
162 Reads the current interrupt status and recycled transmit buffer status from a
165 This function gets the current interrupt and recycled transmit buffer status
166 from the network interface. The interrupt status is returned as a bit mask in
167 InterruptStatus. If InterruptStatus is NULL, the interrupt status will not be
168 read. If TxBuf is not NULL, a recycled transmit buffer address will be retrieved.
169 If a recycled transmit buffer address is returned in TxBuf, then the buffer has
170 been successfully transmitted, and the status for that buffer is cleared. If
171 the status of the network interface is successfully collected, EFI_SUCCESS
172 will be returned. If the driver has not been initialized, EFI_DEVICE_ERROR will
175 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
176 @param InterruptStatus A pointer to the bit mask of the currently active
177 interrupts (see "Related Definitions"). If this is NULL,
178 the interrupt status will not be read from the device.
179 If this is not NULL, the interrupt status will be read
180 from the device. When the interrupt status is read, it
181 will also be cleared. Clearing the transmit interrupt does
182 not empty the recycled transmit buffer array.
183 @param TxBuf Recycled transmit buffer address. The network interface
184 will not transmit if its internal recycled transmit
185 buffer array is full. Reading the transmit buffer does
186 not clear the transmit interrupt. If this is NULL, then
187 the transmit buffer status will not be read. If there
188 are no transmit buffers to recycle and TxBuf is not NULL,
189 TxBuf will be set to NULL.
191 @retval EFI_SUCCESS The status of the network interface was retrieved.
192 @retval EFI_NOT_STARTED The network interface has not been started.
193 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
194 EFI_SIMPLE_NETWORK_PROTOCOL structure.
195 @retval EFI_DEVICE_ERROR The command could not be sent to the network
202 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
203 OUT UINT32
*InterruptStatus
, OPTIONAL
204 OUT VOID
**TxBuf OPTIONAL
212 return EFI_INVALID_PARAMETER
;
215 if (InterruptStatus
== NULL
&& TxBuf
== NULL
) {
216 return EFI_INVALID_PARAMETER
;
219 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
221 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
224 return EFI_DEVICE_ERROR
;
227 switch (Snp
->Mode
.State
) {
228 case EfiSimpleNetworkInitialized
:
231 case EfiSimpleNetworkStopped
:
232 Status
= EFI_NOT_STARTED
;
236 Status
= EFI_DEVICE_ERROR
;
240 if (Snp
->RecycledTxBufCount
== 0 && TxBuf
!= NULL
) {
241 Status
= PxeGetStatus (Snp
, InterruptStatus
, TRUE
);
243 Status
= PxeGetStatus (Snp
, InterruptStatus
, FALSE
);
248 // Get a recycled buf from Snp->RecycledTxBuf
250 if (Snp
->RecycledTxBufCount
== 0) {
253 Snp
->RecycledTxBufCount
--;
254 *TxBuf
= (VOID
*) (UINTN
) Snp
->RecycledTxBuf
[Snp
->RecycledTxBufCount
];
259 gBS
->RestoreTPL (OldTpl
);