]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Network/Snp32_64/Dxe/statistics.c
Make variable names for protocol GUIDs consistent
[mirror_edk2.git] / EdkModulePkg / Universal / Network / Snp32_64 / Dxe / statistics.c
1 /*++
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
7
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.
10
11 Module name:
12 statistics.c
13
14 Abstract:
15
16 Revision history:
17 2000-Feb-17 M(f)J Genesis.
18 --*/
19
20
21 #include "Snp.h"
22
23 EFI_STATUS
24 EFIAPI
25 snp_undi32_statistics (
26 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
27 IN BOOLEAN ResetFlag,
28 IN OUT UINTN *StatTableSizePtr OPTIONAL,
29 IN OUT EFI_NETWORK_STATISTICS * StatTablePtr OPTIONAL
30 )
31 /*++
32
33 Routine Description:
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
37
38 Arguments:
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
43
44 Returns:
45
46 --*/
47 {
48 SNP_DRIVER *snp;
49 PXE_DB_STATISTICS *db;
50 UINT64 *stp;
51 UINT64 mask;
52 UINTN size;
53 UINTN n;
54
55 //
56 // Get pointer to SNP driver instance for *this.
57 //
58 if (this == NULL) {
59 return EFI_INVALID_PARAMETER;
60 }
61
62 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
63
64 if (snp == NULL) {
65 return EFI_DEVICE_ERROR;
66 }
67 //
68 // Return error if the SNP is not initialized.
69 //
70 switch (snp->mode.State) {
71 case EfiSimpleNetworkInitialized:
72 break;
73
74 case EfiSimpleNetworkStopped:
75 return EFI_NOT_STARTED;
76
77 case EfiSimpleNetworkStarted:
78 return EFI_DEVICE_ERROR;
79
80 default:
81 return EFI_DEVICE_ERROR;
82 }
83 //
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.
86 //
87 if (!ResetFlag && StatTableSizePtr == NULL) {
88 return StatTablePtr ? EFI_INVALID_PARAMETER : EFI_SUCCESS;
89 }
90 //
91 // Initialize UNDI Statistics CDB
92 //
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;
100
101 if (ResetFlag) {
102 snp->cdb.OpFlags = PXE_OPFLAGS_STATISTICS_RESET;
103 snp->cdb.DBsize = PXE_DBSIZE_NOT_USED;
104 snp->cdb.DBaddr = PXE_DBADDR_NOT_USED;
105 db = snp->db;
106 } else {
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);
110 }
111 //
112 // Issue UNDI command and check result.
113 //
114 DEBUG ((EFI_D_NET, "\nsnp->undi.statistics() "));
115
116 (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);
117
118 switch (snp->cdb.StatCode) {
119 case PXE_STATCODE_SUCCESS:
120 break;
121
122 case PXE_STATCODE_UNSUPPORTED:
123 DEBUG (
124 (EFI_D_ERROR,
125 "\nsnp->undi.statistics() %xh:%xh\n",
126 snp->cdb.StatFlags,
127 snp->cdb.StatCode)
128 );
129
130 return EFI_UNSUPPORTED;
131
132 default:
133 DEBUG (
134 (EFI_D_ERROR,
135 "\nsnp->undi.statistics() %xh:%xh\n",
136 snp->cdb.StatFlags,
137 snp->cdb.StatCode)
138 );
139
140 return EFI_DEVICE_ERROR;
141 }
142
143 if (ResetFlag) {
144 return EFI_SUCCESS;
145 }
146
147 if (StatTablePtr == NULL) {
148 *StatTableSizePtr = sizeof (EFI_NETWORK_STATISTICS);
149 return EFI_BUFFER_TOO_SMALL;
150 }
151 //
152 // Convert the UNDI statistics information to SNP statistics
153 // information.
154 //
155 ZeroMem (StatTablePtr, *StatTableSizePtr);
156 stp = (UINT64 *) StatTablePtr;
157 size = 0;
158
159 for (n = 0, mask = 1; n < 64; n++, mask = LShiftU64 (mask, 1), stp++) {
160 //
161 // There must be room for a full UINT64. Partial
162 // numbers will not be stored.
163 //
164 if ((n + 1) * sizeof (UINT64) > *StatTableSizePtr) {
165 break;
166 }
167
168 if (db->Supported & mask) {
169 *stp = db->Data[n];
170 size = n + 1;
171 } else {
172 SetMem (stp, sizeof (UINT64), 0xFF);
173 }
174 }
175 //
176 // Compute size up to last supported statistic.
177 //
178 while (++n < 64) {
179 if (db->Supported & (mask = LShiftU64 (mask, 1))) {
180 size = n;
181 }
182 }
183
184 size *= sizeof (UINT64);
185
186 if (*StatTableSizePtr >= size) {
187 *StatTableSizePtr = size;
188 return EFI_SUCCESS;
189 } else {
190 *StatTableSizePtr = size;
191 return EFI_BUFFER_TOO_SMALL;
192 }
193 }