2 Copyright (c) 2004 - 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 2000-Feb-17 M(f)J Genesis.
26 This is the SNP interface routine for getting the NIC's statistics.
27 This routine basically retrieves snp structure, checks the SNP state and
28 calls the pxe_ routine to actually do the
30 @param this context pointer
31 @param ResetFlag true to reset the NIC's statistics counters to zero.
32 @param StatTableSizePtr pointer to the statistics table size
33 @param StatTablePtr pointer to the statistics table
39 snp_undi32_statistics (
40 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
42 IN OUT UINTN
*StatTableSizePtr OPTIONAL
,
43 IN OUT EFI_NETWORK_STATISTICS
* StatTablePtr OPTIONAL
47 PXE_DB_STATISTICS
*db
;
56 // Get pointer to SNP driver instance for *this.
59 return EFI_INVALID_PARAMETER
;
62 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
64 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
67 // Return error if the SNP is not initialized.
69 switch (snp
->mode
.State
) {
70 case EfiSimpleNetworkInitialized
:
73 case EfiSimpleNetworkStopped
:
74 Status
= EFI_NOT_STARTED
;
78 Status
= EFI_DEVICE_ERROR
;
82 // if we are not resetting the counters, we have to have a valid stat table
83 // with >0 size. if no reset, no table and no size, return success.
85 if (!ResetFlag
&& StatTableSizePtr
== NULL
) {
86 Status
= StatTablePtr
? EFI_INVALID_PARAMETER
: EFI_SUCCESS
;
90 // Initialize UNDI Statistics CDB
92 snp
->cdb
.OpCode
= PXE_OPCODE_STATISTICS
;
93 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
94 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
95 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
96 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
97 snp
->cdb
.IFnum
= snp
->if_num
;
98 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
101 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATISTICS_RESET
;
102 snp
->cdb
.DBsize
= PXE_DBSIZE_NOT_USED
;
103 snp
->cdb
.DBaddr
= PXE_DBADDR_NOT_USED
;
106 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATISTICS_READ
;
107 snp
->cdb
.DBsize
= sizeof (PXE_DB_STATISTICS
);
108 snp
->cdb
.DBaddr
= (UINT64
)(UINTN
) (db
= snp
->db
);
111 // Issue UNDI command and check result.
113 DEBUG ((EFI_D_NET
, "\nsnp->undi.statistics() "));
115 (*snp
->issue_undi32_command
) ((UINT64
)(UINTN
) &snp
->cdb
);
117 switch (snp
->cdb
.StatCode
) {
118 case PXE_STATCODE_SUCCESS
:
121 case PXE_STATCODE_UNSUPPORTED
:
124 "\nsnp->undi.statistics() %xh:%xh\n",
129 Status
= EFI_UNSUPPORTED
;
135 "\nsnp->undi.statistics() %xh:%xh\n",
140 Status
= EFI_DEVICE_ERROR
;
145 Status
= EFI_SUCCESS
;
149 if (StatTablePtr
== NULL
) {
150 *StatTableSizePtr
= sizeof (EFI_NETWORK_STATISTICS
);
151 Status
= EFI_BUFFER_TOO_SMALL
;
155 // Convert the UNDI statistics information to SNP statistics
158 ZeroMem (StatTablePtr
, *StatTableSizePtr
);
159 stp
= (UINT64
*) StatTablePtr
;
162 for (n
= 0, mask
= 1; n
< 64; n
++, mask
= LShiftU64 (mask
, 1), stp
++) {
164 // There must be room for a full UINT64. Partial
165 // numbers will not be stored.
167 if ((n
+ 1) * sizeof (UINT64
) > *StatTableSizePtr
) {
171 if (db
->Supported
& mask
) {
175 SetMem (stp
, sizeof (UINT64
), 0xFF);
179 // Compute size up to last supported statistic.
182 if (db
->Supported
& (mask
= LShiftU64 (mask
, 1))) {
187 size
*= sizeof (UINT64
);
189 if (*StatTableSizePtr
>= size
) {
190 *StatTableSizePtr
= size
;
191 Status
= EFI_SUCCESS
;
193 *StatTableSizePtr
= size
;
194 Status
= EFI_BUFFER_TOO_SMALL
;
198 gBS
->RestoreTPL (OldTpl
);