2 Copyright (c) 2006, 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.
25 snp_undi32_statistics (
26 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
28 IN OUT UINTN
*StatTableSizePtr OPTIONAL
,
29 IN OUT EFI_NETWORK_STATISTICS
* StatTablePtr OPTIONAL
34 This is the SNP interface routine for getting the NIC's statistics.
35 This routine basically retrieves snp structure, checks the SNP state and
36 calls the pxe_ routine to actually do the
39 this - context pointer
40 ResetFlag - true to reset the NIC's statistics counters to zero.
41 StatTableSizePtr - pointer to the statistics table size
42 StatTablePtr - pointer to the statistics table
49 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);
65 return EFI_DEVICE_ERROR
;
68 // Return error if the SNP is not initialized.
70 switch (snp
->mode
.State
) {
71 case EfiSimpleNetworkInitialized
:
74 case EfiSimpleNetworkStopped
:
75 return EFI_NOT_STARTED
;
77 case EfiSimpleNetworkStarted
:
78 return EFI_DEVICE_ERROR
;
81 return EFI_DEVICE_ERROR
;
84 // if we are not resetting the counters, we have to have a valid stat table
85 // with >0 size. if no reset, no table and no size, return success.
87 if (!ResetFlag
&& StatTableSizePtr
== NULL
) {
88 return StatTablePtr
? EFI_INVALID_PARAMETER
: EFI_SUCCESS
;
91 // Initialize UNDI Statistics CDB
93 snp
->cdb
.OpCode
= PXE_OPCODE_STATISTICS
;
94 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
95 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
96 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
97 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
98 snp
->cdb
.IFnum
= snp
->if_num
;
99 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
102 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATISTICS_RESET
;
103 snp
->cdb
.DBsize
= PXE_DBSIZE_NOT_USED
;
104 snp
->cdb
.DBaddr
= PXE_DBADDR_NOT_USED
;
107 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATISTICS_READ
;
108 snp
->cdb
.DBsize
= sizeof (PXE_DB_STATISTICS
);
109 snp
->cdb
.DBaddr
= (UINT64
) (UINTN
) (db
= snp
->db
);
112 // Issue UNDI command and check result.
114 DEBUG ((EFI_D_NET
, "\nsnp->undi.statistics() "));
116 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
118 switch (snp
->cdb
.StatCode
) {
119 case PXE_STATCODE_SUCCESS
:
122 case PXE_STATCODE_UNSUPPORTED
:
125 "\nsnp->undi.statistics() %xh:%xh\n",
130 return EFI_UNSUPPORTED
;
135 "\nsnp->undi.statistics() %xh:%xh\n",
140 return EFI_DEVICE_ERROR
;
147 if (StatTablePtr
== NULL
) {
148 *StatTableSizePtr
= sizeof (EFI_NETWORK_STATISTICS
);
149 return EFI_BUFFER_TOO_SMALL
;
152 // Convert the UNDI statistics information to SNP statistics
155 ZeroMem (StatTablePtr
, *StatTableSizePtr
);
156 stp
= (UINT64
*) StatTablePtr
;
159 for (n
= 0, mask
= 1; n
< 64; n
++, mask
= LShiftU64 (mask
, 1), stp
++) {
161 // There must be room for a full UINT64. Partial
162 // numbers will not be stored.
164 if ((n
+ 1) * sizeof (UINT64
) > *StatTableSizePtr
) {
168 if (db
->Supported
& mask
) {
172 SetMem (stp
, sizeof (UINT64
), 0xFF);
176 // Compute size up to last supported statistic.
179 if (db
->Supported
& (mask
= LShiftU64 (mask
, 1))) {
184 size
*= sizeof (UINT64
);
186 if (*StatTableSizePtr
>= size
) {
187 *StatTableSizePtr
= size
;
190 *StatTableSizePtr
= size
;
191 return EFI_BUFFER_TOO_SMALL
;