]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Statistics.c
rename
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Statistics.c
1 /** @file
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
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
22 #include "Snp.h"
23
24
25 /**
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
29
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
34
35
36 **/
37 EFI_STATUS
38 EFIAPI
39 snp_undi32_statistics (
40 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
41 IN BOOLEAN ResetFlag,
42 IN OUT UINTN *StatTableSizePtr OPTIONAL,
43 IN OUT EFI_NETWORK_STATISTICS * StatTablePtr OPTIONAL
44 )
45 {
46 SNP_DRIVER *snp;
47 PXE_DB_STATISTICS *db;
48 UINT64 *stp;
49 UINT64 mask;
50 UINTN size;
51 UINTN n;
52 EFI_TPL OldTpl;
53 EFI_STATUS Status;
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 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
65
66 //
67 // Return error if the SNP is not initialized.
68 //
69 switch (snp->mode.State) {
70 case EfiSimpleNetworkInitialized:
71 break;
72
73 case EfiSimpleNetworkStopped:
74 Status = EFI_NOT_STARTED;
75 goto ON_EXIT;
76
77 default:
78 Status = EFI_DEVICE_ERROR;
79 goto ON_EXIT;
80 }
81 //
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.
84 //
85 if (!ResetFlag && StatTableSizePtr == NULL) {
86 Status = StatTablePtr ? EFI_INVALID_PARAMETER : EFI_SUCCESS;
87 goto ON_EXIT;
88 }
89 //
90 // Initialize UNDI Statistics CDB
91 //
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;
99
100 if (ResetFlag) {
101 snp->cdb.OpFlags = PXE_OPFLAGS_STATISTICS_RESET;
102 snp->cdb.DBsize = PXE_DBSIZE_NOT_USED;
103 snp->cdb.DBaddr = PXE_DBADDR_NOT_USED;
104 db = snp->db;
105 } else {
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);
109 }
110 //
111 // Issue UNDI command and check result.
112 //
113 DEBUG ((EFI_D_NET, "\nsnp->undi.statistics() "));
114
115 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);
116
117 switch (snp->cdb.StatCode) {
118 case PXE_STATCODE_SUCCESS:
119 break;
120
121 case PXE_STATCODE_UNSUPPORTED:
122 DEBUG (
123 (EFI_D_ERROR,
124 "\nsnp->undi.statistics() %xh:%xh\n",
125 snp->cdb.StatFlags,
126 snp->cdb.StatCode)
127 );
128
129 Status = EFI_UNSUPPORTED;
130 goto ON_EXIT;
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 Status = EFI_DEVICE_ERROR;
141 goto ON_EXIT;
142 }
143
144 if (ResetFlag) {
145 Status = EFI_SUCCESS;
146 goto ON_EXIT;
147 }
148
149 if (StatTablePtr == NULL) {
150 *StatTableSizePtr = sizeof (EFI_NETWORK_STATISTICS);
151 Status = EFI_BUFFER_TOO_SMALL;
152 goto ON_EXIT;
153 }
154 //
155 // Convert the UNDI statistics information to SNP statistics
156 // information.
157 //
158 ZeroMem (StatTablePtr, *StatTableSizePtr);
159 stp = (UINT64 *) StatTablePtr;
160 size = 0;
161
162 for (n = 0, mask = 1; n < 64; n++, mask = LShiftU64 (mask, 1), stp++) {
163 //
164 // There must be room for a full UINT64. Partial
165 // numbers will not be stored.
166 //
167 if ((n + 1) * sizeof (UINT64) > *StatTableSizePtr) {
168 break;
169 }
170
171 if (db->Supported & mask) {
172 *stp = db->Data[n];
173 size = n + 1;
174 } else {
175 SetMem (stp, sizeof (UINT64), 0xFF);
176 }
177 }
178 //
179 // Compute size up to last supported statistic.
180 //
181 while (++n < 64) {
182 if (db->Supported & (mask = LShiftU64 (mask, 1))) {
183 size = n;
184 }
185 }
186
187 size *= sizeof (UINT64);
188
189 if (*StatTableSizePtr >= size) {
190 *StatTableSizePtr = size;
191 Status = EFI_SUCCESS;
192 } else {
193 *StatTableSizePtr = size;
194 Status = EFI_BUFFER_TOO_SMALL;
195 }
196
197 ON_EXIT:
198 gBS->RestoreTPL (OldTpl);
199
200 return Status;
201 }