Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
3.0 KiB

  1. //
  2. // Copyright (c) 1998-1999, Microsoft Corporation, all rights reserved
  3. //
  4. // pktlog.c
  5. //
  6. // IEEE1394 mini-port/call-manager driver
  7. //
  8. // Packet logging utilities.
  9. //
  10. // 10/12/1999 JosephJ Created
  11. //
  12. #include <precomp.h>
  13. VOID
  14. nic1394InitPktLog(
  15. PNIC1394_PKTLOG pPktLog
  16. )
  17. /*++
  18. Routine Description:
  19. Initializes a packet log.
  20. Arguments:
  21. pPktLog - Pkt log to to be initialized.
  22. --*/
  23. {
  24. if (pPktLog == NULL)
  25. return;
  26. NdisZeroMemory(pPktLog, sizeof(*pPktLog));
  27. pPktLog->InitialTimestamp = KeQueryPerformanceCounter(
  28. &pPktLog->PerformanceFrequency);
  29. pPktLog->EntrySize = sizeof(pPktLog->Entries[0]);
  30. pPktLog->NumEntries = N1394_NUM_PKTLOG_ENTRIES;
  31. }
  32. VOID
  33. Nic1394LogPkt (
  34. PNIC1394_PKTLOG pPktLog,
  35. ULONG Flags,
  36. ULONG SourceID,
  37. ULONG DestID,
  38. PVOID pvData,
  39. ULONG cbData
  40. )
  41. /*++
  42. Routine Description:
  43. Adds a pkt log entry to the specified circular pkt log.
  44. The entry gets added at location
  45. (NdisInterlockedIncrement(&pPktLog->SequenceNo) % N1394_NUM_PKTLOG_ENTRIES)
  46. May be called at any IRQL. Does not use explicit locking -- relies on
  47. the serialization produced by NdisInterlockedIncrement.
  48. Arguments:
  49. pPktLog - Pkt log to log packet
  50. Flags - User-defined flags
  51. SourceID - User-defined source ID
  52. DestID - User-defined destination ID
  53. pvData - Data from packet // can be null
  54. cbData - size of this data (at most N1394_PKTLOG_DATA_SIZE bytes are logged)
  55. --*/
  56. {
  57. ULONG SequenceNo;
  58. PN1394_PKTLOG_ENTRY pEntry;
  59. SequenceNo = NdisInterlockedIncrement(&pPktLog->SequenceNo);
  60. pEntry = &pPktLog->Entries[SequenceNo % N1394_NUM_PKTLOG_ENTRIES];
  61. pEntry->SequenceNo = SequenceNo;
  62. pEntry->Flags = Flags;
  63. pEntry->TimeStamp = KeQueryPerformanceCounter(NULL);
  64. pEntry->SourceID = SourceID;
  65. pEntry->DestID = DestID;
  66. pEntry->OriginalDataSize = cbData;
  67. if (cbData > sizeof(pEntry->Data))
  68. {
  69. cbData = sizeof(pEntry->Data);
  70. }
  71. if (pvData != NULL && cbData != 0)
  72. {
  73. NdisMoveMemory(pEntry->Data, pvData, cbData);
  74. }
  75. }
  76. VOID
  77. nic1394AllocPktLog(
  78. IN ADAPTERCB* pAdapter
  79. )
  80. /*++
  81. Routine Description:
  82. Initialize the packet log
  83. Arguments:
  84. Return Value:
  85. --*/
  86. {
  87. ASSERT (pAdapter->pPktLog==NULL);
  88. pAdapter->pPktLog = ALLOC_NONPAGED(sizeof(*pAdapter->pPktLog), MTAG_PKTLOG);
  89. if (pAdapter->pPktLog == NULL)
  90. {
  91. TRACE( TL_A, TM_Misc, ( " Could not allocate packet log for Adapter %x",
  92. pAdapter ) );
  93. }
  94. }
  95. VOID
  96. nic1394DeallocPktLog(
  97. IN ADAPTERCB* pAdapter
  98. )
  99. /*++
  100. Routine Description:
  101. Free the packet log
  102. Arguments:
  103. Return Value:
  104. --*/
  105. {
  106. if (pAdapter->pPktLog != NULL)
  107. {
  108. FREE_NONPAGED(pAdapter->pPktLog);
  109. pAdapter->pPktLog = NULL;
  110. }
  111. }