/** @file\r
-Copyright (c) 2004 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
+ Implementation of collecting the statistics on a network interface.\r
+ \r
+Copyright (c) 2004 - 2007, Intel Corporation. <BR> \r
+All rights reserved. This program and the accompanying materials are licensed \r
+and made available under the terms and conditions of the BSD License which \r
+accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
\r
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
-Module name:\r
- statistics.c\r
-\r
-Abstract:\r
-\r
-Revision history:\r
- 2000-Feb-17 M(f)J Genesis.\r
-\r
**/\r
\r
\r
\r
\r
/**\r
- This is the SNP interface routine for getting the NIC's statistics.\r
- This routine basically retrieves snp structure, checks the SNP state and\r
- calls the pxe_ routine to actually do the\r
-\r
- @param this context pointer\r
- @param ResetFlag true to reset the NIC's statistics counters to zero.\r
- @param StatTableSizePtr pointer to the statistics table size\r
- @param StatTablePtr pointer to the statistics table\r
-\r
+ Resets or collects the statistics on a network interface.\r
+ \r
+ This function resets or collects the statistics on a network interface. If the\r
+ size of the statistics table specified by StatisticsSize is not big enough for\r
+ all the statistics that are collected by the network interface, then a partial\r
+ buffer of statistics is returned in StatisticsTable, StatisticsSize is set to \r
+ the size required to collect all the available statistics, and \r
+ EFI_BUFFER_TOO_SMALL is returned.\r
+ If StatisticsSize is big enough for all the statistics, then StatisticsTable \r
+ will be filled, StatisticsSize will be set to the size of the returned \r
+ StatisticsTable structure, and EFI_SUCCESS is returned.\r
+ If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.\r
+ If Reset is FALSE, and both StatisticsSize and StatisticsTable are NULL, then\r
+ no operations will be performed, and EFI_SUCCESS will be returned.\r
+ If Reset is TRUE, then all of the supported statistics counters on this network\r
+ interface will be reset to zero.\r
+\r
+ @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
+ @param Reset Set to TRUE to reset the statistics for the network interface.\r
+ @param StatisticsSize On input the size, in bytes, of StatisticsTable. On output \r
+ the size, in bytes, of the resulting table of statistics.\r
+ @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that \r
+ contains the statistics. Type EFI_NETWORK_STATISTICS is \r
+ defined in "Related Definitions" below. \r
+ \r
+ @retval EFI_SUCCESS The requested operation succeeded.\r
+ @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been\r
+ started by calling Start().\r
+ @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is \r
+ NULL. The current buffer size that is needed to \r
+ hold all the statistics is returned in StatisticsSize.\r
+ @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is \r
+ not NULL. The current buffer size that is needed\r
+ to hold all the statistics is returned in \r
+ StatisticsSize. A partial set of statistics is \r
+ returned in StatisticsTable.\r
+ @retval EFI_INVALID_PARAMETER StatisticsSize is NULL and StatisticsTable is not \r
+ NULL.\r
+ @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not \r
+ been initialized by calling Initialize().\r
+ @retval EFI_DEVICE_ERROR An error was encountered collecting statistics \r
+ from the NIC.\r
+ @retval EFI_UNSUPPORTED The NIC does not support collecting statistics \r
+ from the network interface.\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
-snp_undi32_statistics (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL * this,\r
- IN BOOLEAN ResetFlag,\r
- IN OUT UINTN *StatTableSizePtr OPTIONAL,\r
- IN OUT EFI_NETWORK_STATISTICS * StatTablePtr OPTIONAL\r
+SnpUndi32Statistics (\r
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+ IN BOOLEAN Reset,\r
+ IN OUT UINTN *StatisticsSize, OPTIONAL\r
+ IN OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL\r
)\r
{\r
- SNP_DRIVER *snp;\r
- PXE_DB_STATISTICS *db;\r
- UINT64 *stp;\r
- UINT64 mask;\r
- UINTN size;\r
- UINTN n;\r
+ SNP_DRIVER *Snp;\r
+ PXE_DB_STATISTICS *Db;\r
+ UINT64 *Stp;\r
+ UINT64 Mask;\r
+ UINTN Size;\r
+ UINTN Index;\r
EFI_TPL OldTpl;\r
EFI_STATUS Status;\r
\r
//\r
- // Get pointer to SNP driver instance for *this.\r
+ // Get pointer to SNP driver instance for *This.\r
//\r
- if (this == NULL) {\r
+ if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r
+ Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r
\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
\r
//\r
// Return error if the SNP is not initialized.\r
//\r
- switch (snp->mode.State) {\r
+ switch (Snp->Mode.State) {\r
case EfiSimpleNetworkInitialized:\r
break;\r
\r
// if we are not resetting the counters, we have to have a valid stat table\r
// with >0 size. if no reset, no table and no size, return success.\r
//\r
- if (!ResetFlag && StatTableSizePtr == NULL) {\r
- Status = StatTablePtr ? EFI_INVALID_PARAMETER : EFI_SUCCESS;\r
+ if (!Reset && StatisticsSize == NULL) {\r
+ Status = (StatisticsTable != NULL) ? EFI_INVALID_PARAMETER : EFI_SUCCESS;\r
goto ON_EXIT;\r
}\r
//\r
// Initialize UNDI Statistics CDB\r
//\r
- snp->cdb.OpCode = PXE_OPCODE_STATISTICS;\r
- snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
- snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
- snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
- snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
- snp->cdb.IFnum = snp->if_num;\r
- snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
-\r
- if (ResetFlag) {\r
- snp->cdb.OpFlags = PXE_OPFLAGS_STATISTICS_RESET;\r
- snp->cdb.DBsize = PXE_DBSIZE_NOT_USED;\r
- snp->cdb.DBaddr = PXE_DBADDR_NOT_USED;\r
- db = snp->db;\r
+ Snp->Cdb.OpCode = PXE_OPCODE_STATISTICS;\r
+ Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
+ Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
+ Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
+ Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
+ Snp->Cdb.IFnum = Snp->IfNum;\r
+ Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
+\r
+ if (Reset) {\r
+ Snp->Cdb.OpFlags = PXE_OPFLAGS_STATISTICS_RESET;\r
+ Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED;\r
+ Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED;\r
+ Db = Snp->Db;\r
} else {\r
- snp->cdb.OpFlags = PXE_OPFLAGS_STATISTICS_READ;\r
- snp->cdb.DBsize = sizeof (PXE_DB_STATISTICS);\r
- snp->cdb.DBaddr = (UINT64)(UINTN) (db = snp->db);\r
+ Snp->Cdb.OpFlags = PXE_OPFLAGS_STATISTICS_READ;\r
+ Snp->Cdb.DBsize = sizeof (PXE_DB_STATISTICS);\r
+ Snp->Cdb.DBaddr = (UINT64)(UINTN) (Db = Snp->Db);\r
}\r
//\r
// Issue UNDI command and check result.\r
//\r
DEBUG ((EFI_D_NET, "\nsnp->undi.statistics() "));\r
\r
- (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r
+ (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);\r
\r
- switch (snp->cdb.StatCode) {\r
+ switch (Snp->Cdb.StatCode) {\r
case PXE_STATCODE_SUCCESS:\r
break;\r
\r
DEBUG (\r
(EFI_D_ERROR,\r
"\nsnp->undi.statistics() %xh:%xh\n",\r
- snp->cdb.StatFlags,\r
- snp->cdb.StatCode)\r
+ Snp->Cdb.StatFlags,\r
+ Snp->Cdb.StatCode)\r
);\r
\r
Status = EFI_UNSUPPORTED;\r
DEBUG (\r
(EFI_D_ERROR,\r
"\nsnp->undi.statistics() %xh:%xh\n",\r
- snp->cdb.StatFlags,\r
- snp->cdb.StatCode)\r
+ Snp->Cdb.StatFlags,\r
+ Snp->Cdb.StatCode)\r
);\r
\r
Status = EFI_DEVICE_ERROR;\r
goto ON_EXIT;\r
}\r
\r
- if (ResetFlag) {\r
+ if (Reset) {\r
Status = EFI_SUCCESS;\r
goto ON_EXIT;\r
}\r
\r
- if (StatTablePtr == NULL) {\r
- *StatTableSizePtr = sizeof (EFI_NETWORK_STATISTICS);\r
+ if (StatisticsTable == NULL) {\r
+ *StatisticsSize = sizeof (EFI_NETWORK_STATISTICS);\r
Status = EFI_BUFFER_TOO_SMALL;\r
goto ON_EXIT;\r
}\r
// Convert the UNDI statistics information to SNP statistics\r
// information.\r
//\r
- ZeroMem (StatTablePtr, *StatTableSizePtr);\r
- stp = (UINT64 *) StatTablePtr;\r
- size = 0;\r
+ ZeroMem (StatisticsTable, *StatisticsSize);\r
+ Stp = (UINT64 *) StatisticsTable;\r
+ Size = 0;\r
\r
- for (n = 0, mask = 1; n < 64; n++, mask = LShiftU64 (mask, 1), stp++) {\r
+ for (Index = 0, Mask = 1; Index < 64; Index++, Mask = LShiftU64 (Mask, 1), Stp++) {\r
//\r
// There must be room for a full UINT64. Partial\r
// numbers will not be stored.\r
//\r
- if ((n + 1) * sizeof (UINT64) > *StatTableSizePtr) {\r
+ if ((Index + 1) * sizeof (UINT64) > *StatisticsSize) {\r
break;\r
}\r
\r
- if (db->Supported & mask) {\r
- *stp = db->Data[n];\r
- size = n + 1;\r
+ if (Db->Supported & Mask) {\r
+ *Stp = Db->Data[Index];\r
+ Size = Index + 1;\r
} else {\r
- SetMem (stp, sizeof (UINT64), 0xFF);\r
+ SetMem (Stp, sizeof (UINT64), 0xFF);\r
}\r
}\r
//\r
// Compute size up to last supported statistic.\r
//\r
- while (++n < 64) {\r
- if (db->Supported & (mask = LShiftU64 (mask, 1))) {\r
- size = n;\r
+ while (++Index < 64) {\r
+ if (Db->Supported & (Mask = LShiftU64 (Mask, 1))) {\r
+ Size = Index;\r
}\r
}\r
\r
- size *= sizeof (UINT64);\r
+ Size *= sizeof (UINT64);\r
\r
- if (*StatTableSizePtr >= size) {\r
- *StatTableSizePtr = size;\r
+ if (*StatisticsSize >= Size) {\r
+ *StatisticsSize = Size;\r
Status = EFI_SUCCESS;\r
} else {\r
- *StatTableSizePtr = size;\r
+ *StatisticsSize = Size;\r
Status = EFI_BUFFER_TOO_SMALL;\r
}\r
\r