2 Implementation of collecting the statistics on a network interface.
4 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 Resets or collects the statistics on a network interface.
14 This function resets or collects the statistics on a network interface. If the
15 size of the statistics table specified by StatisticsSize is not big enough for
16 all the statistics that are collected by the network interface, then a partial
17 buffer of statistics is returned in StatisticsTable, StatisticsSize is set to
18 the size required to collect all the available statistics, and
19 EFI_BUFFER_TOO_SMALL is returned.
20 If StatisticsSize is big enough for all the statistics, then StatisticsTable
21 will be filled, StatisticsSize will be set to the size of the returned
22 StatisticsTable structure, and EFI_SUCCESS is returned.
23 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
24 If Reset is FALSE, and both StatisticsSize and StatisticsTable are NULL, then
25 no operations will be performed, and EFI_SUCCESS will be returned.
26 If Reset is TRUE, then all of the supported statistics counters on this network
27 interface will be reset to zero.
29 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
30 @param Reset Set to TRUE to reset the statistics for the network interface.
31 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On output
32 the size, in bytes, of the resulting table of statistics.
33 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
34 contains the statistics. Type EFI_NETWORK_STATISTICS is
35 defined in "Related Definitions" below.
37 @retval EFI_SUCCESS The requested operation succeeded.
38 @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been
39 started by calling Start().
40 @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is
41 NULL. The current buffer size that is needed to
42 hold all the statistics is returned in StatisticsSize.
43 @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is
44 not NULL. The current buffer size that is needed
45 to hold all the statistics is returned in
46 StatisticsSize. A partial set of statistics is
47 returned in StatisticsTable.
48 @retval EFI_INVALID_PARAMETER StatisticsSize is NULL and StatisticsTable is not
50 @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
51 been initialized by calling Initialize().
52 @retval EFI_DEVICE_ERROR An error was encountered collecting statistics
54 @retval EFI_UNSUPPORTED The NIC does not support collecting statistics
55 from the network interface.
61 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
63 IN OUT UINTN
*StatisticsSize OPTIONAL
,
64 IN OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
68 PXE_DB_STATISTICS
*Db
;
77 // Get pointer to SNP driver instance for *This.
80 return EFI_INVALID_PARAMETER
;
83 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
85 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
88 // Return error if the SNP is not initialized.
90 switch (Snp
->Mode
.State
) {
91 case EfiSimpleNetworkInitialized
:
94 case EfiSimpleNetworkStopped
:
95 Status
= EFI_NOT_STARTED
;
99 Status
= EFI_DEVICE_ERROR
;
104 // if we are not resetting the counters, we have to have a valid stat table
105 // with >0 size. if no reset, no table and no size, return success.
107 if (!Reset
&& (StatisticsSize
== NULL
)) {
108 Status
= (StatisticsTable
!= NULL
) ? EFI_INVALID_PARAMETER
: EFI_SUCCESS
;
113 // Initialize UNDI Statistics CDB
115 Snp
->Cdb
.OpCode
= PXE_OPCODE_STATISTICS
;
116 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
117 Snp
->Cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
118 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
119 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
120 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
121 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
124 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_STATISTICS_RESET
;
125 Snp
->Cdb
.DBsize
= PXE_DBSIZE_NOT_USED
;
126 Snp
->Cdb
.DBaddr
= PXE_DBADDR_NOT_USED
;
129 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_STATISTICS_READ
;
130 Snp
->Cdb
.DBsize
= (UINT16
)sizeof (PXE_DB_STATISTICS
);
131 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
)(Db
= Snp
->Db
);
135 // Issue UNDI command and check result.
137 DEBUG ((DEBUG_NET
, "\nsnp->undi.statistics() "));
139 (*Snp
->IssueUndi32Command
)((UINT64
)(UINTN
)&Snp
->Cdb
);
141 switch (Snp
->Cdb
.StatCode
) {
142 case PXE_STATCODE_SUCCESS
:
145 case PXE_STATCODE_UNSUPPORTED
:
148 "\nsnp->undi.statistics() %xh:%xh\n",
153 Status
= EFI_UNSUPPORTED
;
159 "\nsnp->undi.statistics() %xh:%xh\n",
164 Status
= EFI_DEVICE_ERROR
;
169 Status
= EFI_SUCCESS
;
173 if (StatisticsTable
== NULL
) {
174 *StatisticsSize
= sizeof (EFI_NETWORK_STATISTICS
);
175 Status
= EFI_BUFFER_TOO_SMALL
;
180 // Convert the UNDI statistics information to SNP statistics
183 ZeroMem (StatisticsTable
, *StatisticsSize
);
184 Stp
= (UINT64
*)StatisticsTable
;
187 for (Index
= 0, Mask
= 1; Index
< 64; Index
++, Mask
= LShiftU64 (Mask
, 1), Stp
++) {
189 // There must be room for a full UINT64. Partial
190 // numbers will not be stored.
192 if ((Index
+ 1) * sizeof (UINT64
) > *StatisticsSize
) {
196 if ((Db
->Supported
& Mask
) != 0) {
197 *Stp
= Db
->Data
[Index
];
200 SetMem (Stp
, sizeof (UINT64
), 0xFF);
205 // Compute size up to last supported statistic.
207 while (++Index
< 64) {
208 if ((Db
->Supported
& (Mask
= LShiftU64 (Mask
, 1))) != 0) {
213 Size
*= sizeof (UINT64
);
215 if (*StatisticsSize
>= Size
) {
216 *StatisticsSize
= Size
;
217 Status
= EFI_SUCCESS
;
219 *StatisticsSize
= Size
;
220 Status
= EFI_BUFFER_TOO_SMALL
;
224 gBS
->RestoreTPL (OldTpl
);