1 | /** @file
|
---|
2 |
|
---|
3 | Implementation of the SNP.GetStatus() function and its private helpers if
|
---|
4 | any.
|
---|
5 |
|
---|
6 | Copyright (c) 2021 - 2024, Oracle and/or its affiliates.
|
---|
7 | Copyright (C) 2013, Red Hat, Inc.
|
---|
8 | Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
|
---|
9 |
|
---|
10 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
11 |
|
---|
12 | **/
|
---|
13 |
|
---|
14 | #include <Library/BaseLib.h>
|
---|
15 | #include <Library/UefiBootServicesTableLib.h>
|
---|
16 |
|
---|
17 | #include "E1kNet.h"
|
---|
18 |
|
---|
19 | /**
|
---|
20 | Reads the current interrupt status and recycled transmit buffer status from
|
---|
21 | a network interface.
|
---|
22 |
|
---|
23 | @param This The protocol instance pointer.
|
---|
24 | @param InterruptStatus A pointer to the bit mask of the currently active
|
---|
25 | interrupts If this is NULL, the interrupt status will
|
---|
26 | not be read from the device. If this is not NULL, the
|
---|
27 | interrupt status will be read from the device. When
|
---|
28 | the interrupt status is read, it will also be
|
---|
29 | cleared. Clearing the transmit interrupt does not
|
---|
30 | empty the recycled transmit buffer array.
|
---|
31 | @param TxBuf Recycled transmit buffer address. The network
|
---|
32 | interface will not transmit if its internal recycled
|
---|
33 | transmit buffer array is full. Reading the transmit
|
---|
34 | buffer does not clear the transmit interrupt. If this
|
---|
35 | is NULL, then the transmit buffer status will not be
|
---|
36 | read. If there are no transmit buffers to recycle and
|
---|
37 | TxBuf is not NULL, * TxBuf will be set to NULL.
|
---|
38 |
|
---|
39 | @retval EFI_SUCCESS The status of the network interface was
|
---|
40 | retrieved.
|
---|
41 | @retval EFI_NOT_STARTED The network interface has not been started.
|
---|
42 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an
|
---|
43 | unsupported value.
|
---|
44 | @retval EFI_DEVICE_ERROR The command could not be sent to the network
|
---|
45 | interface.
|
---|
46 | @retval EFI_UNSUPPORTED This function is not supported by the network
|
---|
47 | interface.
|
---|
48 |
|
---|
49 | **/
|
---|
50 |
|
---|
51 | EFI_STATUS
|
---|
52 | EFIAPI
|
---|
53 | E1kNetGetStatus (
|
---|
54 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
55 | OUT UINT32 *InterruptStatus OPTIONAL,
|
---|
56 | OUT VOID **TxBuf OPTIONAL
|
---|
57 | )
|
---|
58 | {
|
---|
59 | E1K_NET_DEV *Dev;
|
---|
60 | EFI_TPL OldTpl;
|
---|
61 | EFI_STATUS Status;
|
---|
62 | UINT32 TdhCur;
|
---|
63 | UINT32 RdhCur;
|
---|
64 | EFI_PHYSICAL_ADDRESS DeviceAddress;
|
---|
65 |
|
---|
66 | if (This == NULL) {
|
---|
67 | return EFI_INVALID_PARAMETER;
|
---|
68 | }
|
---|
69 |
|
---|
70 | Dev = E1K_NET_FROM_SNP (This);
|
---|
71 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
72 | switch (Dev->Snm.State) {
|
---|
73 | case EfiSimpleNetworkStopped:
|
---|
74 | Status = EFI_NOT_STARTED;
|
---|
75 | goto Exit;
|
---|
76 | case EfiSimpleNetworkStarted:
|
---|
77 | Status = EFI_DEVICE_ERROR;
|
---|
78 | goto Exit;
|
---|
79 | default:
|
---|
80 | break;
|
---|
81 | }
|
---|
82 |
|
---|
83 | //
|
---|
84 | // update link status
|
---|
85 | //
|
---|
86 | if (Dev->Snm.MediaPresentSupported) {
|
---|
87 | UINT32 RegSts;
|
---|
88 |
|
---|
89 | Status = E1kNetRegRead32(Dev, E1K_REG_STATUS, &RegSts);
|
---|
90 | if (EFI_ERROR (Status)) {
|
---|
91 | goto Exit;
|
---|
92 | }
|
---|
93 |
|
---|
94 | Dev->Snm.MediaPresent = (BOOLEAN)((RegSts & E1K_REG_STATUS_LU) != 0);
|
---|
95 | }
|
---|
96 |
|
---|
97 | E1kNetRegRead32(Dev, E1K_REG_TDH, &TdhCur);
|
---|
98 | E1kNetRegRead32(Dev, E1K_REG_RDH, &RdhCur);
|
---|
99 |
|
---|
100 |
|
---|
101 | if (InterruptStatus != NULL) {
|
---|
102 | //
|
---|
103 | // report the receive interrupt if there is data available for reception,
|
---|
104 | // report the transmit interrupt if we have transmitted at least one buffer
|
---|
105 | //
|
---|
106 | *InterruptStatus = 0;
|
---|
107 | if (Dev->RdhLastSeen != RdhCur) {
|
---|
108 | *InterruptStatus |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
|
---|
109 | }
|
---|
110 | if (Dev->TdhLastSeen != TdhCur) {
|
---|
111 | ASSERT (Dev->TxCurPending > 0);
|
---|
112 | *InterruptStatus |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | if (TxBuf != NULL) {
|
---|
117 | if (Dev->TdhLastSeen == TdhCur) {
|
---|
118 | *TxBuf = NULL;
|
---|
119 | }
|
---|
120 | else {
|
---|
121 | ASSERT (Dev->TxCurPending > 0);
|
---|
122 | ASSERT (Dev->TxCurPending <= Dev->TxMaxPending);
|
---|
123 |
|
---|
124 | //
|
---|
125 | // get the device address that has been enqueued for the caller's
|
---|
126 | // transmit buffer
|
---|
127 | //
|
---|
128 | DeviceAddress = Dev->TxRing[Dev->TdhLastSeen].AddrBufferLow;
|
---|
129 | DeviceAddress |= LShiftU64(Dev->TxRing[Dev->TdhLastSeen].AddrBufferHigh, 32);
|
---|
130 |
|
---|
131 | Dev->TdhLastSeen = (Dev->TdhLastSeen + 1) % E1K_NET_MAX_PENDING;
|
---|
132 | Dev->TxCurPending--;
|
---|
133 |
|
---|
134 | //
|
---|
135 | // Unmap the device address and perform the reverse mapping to find the
|
---|
136 | // caller buffer address.
|
---|
137 | //
|
---|
138 | Status = E1kNetUnmapTxBuf (
|
---|
139 | Dev,
|
---|
140 | TxBuf,
|
---|
141 | DeviceAddress
|
---|
142 | );
|
---|
143 | if (EFI_ERROR (Status)) {
|
---|
144 | //
|
---|
145 | // E1kNetUnmapTxBuf should never fail, if we have reached here
|
---|
146 | // that means our internal state has been corrupted
|
---|
147 | //
|
---|
148 | ASSERT (FALSE);
|
---|
149 | Status = EFI_DEVICE_ERROR;
|
---|
150 | goto Exit;
|
---|
151 | }
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | Status = EFI_SUCCESS;
|
---|
156 |
|
---|
157 | Exit:
|
---|
158 | gBS->RestoreTPL (OldTpl);
|
---|
159 | return Status;
|
---|
160 | }
|
---|