3 Implementation of the SNP.GetStatus() function and its private helpers if
6 Copyright (C) 2013, Red Hat, Inc.
7 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
9 This program and the accompanying materials are licensed and made available
10 under the terms and conditions of the BSD License which accompanies this
11 distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
15 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Library/BaseLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
22 #include "VirtioNet.h"
25 Reads the current interrupt status and recycled transmit buffer status from
28 @param This The protocol instance pointer.
29 @param InterruptStatus A pointer to the bit mask of the currently active
30 interrupts If this is NULL, the interrupt status will
31 not be read from the device. If this is not NULL, the
32 interrupt status will be read from the device. When
33 the interrupt status is read, it will also be
34 cleared. Clearing the transmit interrupt does not
35 empty the recycled transmit buffer array.
36 @param TxBuf Recycled transmit buffer address. The network
37 interface will not transmit if its internal recycled
38 transmit buffer array is full. Reading the transmit
39 buffer does not clear the transmit interrupt. If this
40 is NULL, then the transmit buffer status will not be
41 read. If there are no transmit buffers to recycle and
42 TxBuf is not NULL, * TxBuf will be set to NULL.
44 @retval EFI_SUCCESS The status of the network interface was
46 @retval EFI_NOT_STARTED The network interface has not been started.
47 @retval EFI_INVALID_PARAMETER One or more of the parameters has an
49 @retval EFI_DEVICE_ERROR The command could not be sent to the network
51 @retval EFI_UNSUPPORTED This function is not supported by the network
59 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
60 OUT UINT32
*InterruptStatus OPTIONAL
,
61 OUT VOID
**TxBuf OPTIONAL
71 return EFI_INVALID_PARAMETER
;
74 Dev
= VIRTIO_NET_FROM_SNP (This
);
75 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
76 switch (Dev
->Snm
.State
) {
77 case EfiSimpleNetworkStopped
:
78 Status
= EFI_NOT_STARTED
;
80 case EfiSimpleNetworkStarted
:
81 Status
= EFI_DEVICE_ERROR
;
90 if (Dev
->Snm
.MediaPresentSupported
) {
93 Status
= VIRTIO_CFG_READ (Dev
, LinkStatus
, &LinkStatus
);
94 if (EFI_ERROR (Status
)) {
97 Dev
->Snm
.MediaPresent
=
98 (BOOLEAN
) ((LinkStatus
& VIRTIO_NET_S_LINK_UP
) != 0);
102 // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device
105 RxCurUsed
= *Dev
->RxRing
.Used
.Idx
;
106 TxCurUsed
= *Dev
->TxRing
.Used
.Idx
;
109 if (InterruptStatus
!= NULL
) {
111 // report the receive interrupt if there is data available for reception,
112 // report the transmit interrupt if we have transmitted at least one buffer
114 *InterruptStatus
= 0;
115 if (Dev
->RxLastUsed
!= RxCurUsed
) {
116 *InterruptStatus
|= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
;
118 if (Dev
->TxLastUsed
!= TxCurUsed
) {
119 ASSERT (Dev
->TxCurPending
> 0);
120 *InterruptStatus
|= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
;
125 if (Dev
->TxLastUsed
== TxCurUsed
) {
133 // fetch the first descriptor among those that the hypervisor reports
136 ASSERT (Dev
->TxCurPending
> 0);
137 ASSERT (Dev
->TxCurPending
<= Dev
->TxMaxPending
);
139 UsedElemIdx
= Dev
->TxLastUsed
++ % Dev
->TxRing
.QueueSize
;
140 DescIdx
= Dev
->TxRing
.Used
.UsedElem
[UsedElemIdx
].Id
;
141 ASSERT (DescIdx
< (UINT32
) (2 * Dev
->TxMaxPending
- 1));
144 // report buffer address to caller that has been enqueued by caller
146 *TxBuf
= (VOID
*)(UINTN
) Dev
->TxRing
.Desc
[DescIdx
+ 1].Addr
;
149 // now this descriptor can be used again to enqueue a transmit buffer
151 Dev
->TxFreeStack
[--Dev
->TxCurPending
] = (UINT16
) DescIdx
;
155 Status
= EFI_SUCCESS
;
158 gBS
->RestoreTPL (OldTpl
);