]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/Statistics.c
rename
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Statistics.c
diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Statistics.c b/MdeModulePkg/Universal/Network/SnpDxe/Statistics.c
new file mode 100644 (file)
index 0000000..19f2823
--- /dev/null
@@ -0,0 +1,201 @@
+/** @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
+\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
+#include "Snp.h"\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
+\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
+  )\r
+{\r
+  SNP_DRIVER        *snp;\r
+  PXE_DB_STATISTICS *db;\r
+  UINT64            *stp;\r
+  UINT64            mask;\r
+  UINTN             size;\r
+  UINTN             n;\r
+  EFI_TPL           OldTpl;\r
+  EFI_STATUS        Status;\r
+\r
+  //\r
+  // Get pointer to SNP driver instance for *this.\r
+  //\r
+  if (this == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\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
+  case EfiSimpleNetworkInitialized:\r
+    break;\r
+\r
+  case EfiSimpleNetworkStopped:\r
+    Status = EFI_NOT_STARTED;\r
+    goto ON_EXIT;\r
+\r
+  default:\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto ON_EXIT;\r
+  }\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
+    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
+  } 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
+  }\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
+\r
+  switch (snp->cdb.StatCode) {\r
+  case PXE_STATCODE_SUCCESS:\r
+    break;\r
+\r
+  case PXE_STATCODE_UNSUPPORTED:\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "\nsnp->undi.statistics()  %xh:%xh\n",\r
+      snp->cdb.StatFlags,\r
+      snp->cdb.StatCode)\r
+      );\r
+\r
+    Status = EFI_UNSUPPORTED;\r
+    goto ON_EXIT;\r
+\r
+  default:\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "\nsnp->undi.statistics()  %xh:%xh\n",\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
+    Status = EFI_SUCCESS;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (StatTablePtr == NULL) {\r
+    *StatTableSizePtr = sizeof (EFI_NETWORK_STATISTICS);\r
+    Status = EFI_BUFFER_TOO_SMALL;\r
+    goto ON_EXIT;\r
+  }\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
+\r
+  for (n = 0, mask = 1; n < 64; n++, 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
+      break;\r
+    }\r
+\r
+    if (db->Supported & mask) {\r
+      *stp  = db->Data[n];\r
+      size  = n + 1;\r
+    } else {\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
+    }\r
+  }\r
+\r
+  size *= sizeof (UINT64);\r
+\r
+  if (*StatTableSizePtr >= size) {\r
+    *StatTableSizePtr = size;\r
+    Status = EFI_SUCCESS;\r
+  } else {\r
+    *StatTableSizePtr = size;\r
+    Status = EFI_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+ON_EXIT:\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r