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.

262 lines
6.0 KiB

  1. /*****************************************************************************
  2. ** **
  3. ** COPYRIGHT (C) 2000, 2001 MKNET CORPORATION **
  4. ** DEVELOPED FOR THE MK7100-BASED VFIR PCI CONTROLLER. **
  5. ** **
  6. *****************************************************************************/
  7. /**********************************************************************
  8. Module Name:
  9. DBG.C
  10. Routines:
  11. MyLogEvent
  12. MyLogPhysEvent
  13. DbgInterPktTimeGap
  14. DbgTestInit
  15. MK7DbgTestIntTmo
  16. **********************************************************************/
  17. #include "precomp.h"
  18. #pragma hdrstop
  19. #include "protot.h"
  20. #define LOG_LENGTH 1000
  21. #if DBG
  22. UINT DbgLogIndex = 0;
  23. char *DbgLogMsg[LOG_LENGTH] = {0};
  24. ULONG DbgLogVal[LOG_LENGTH] = {0};
  25. // This to keep track of the phy buffs
  26. ULONG DbgLogTxPhysBuffs[DEF_TCB_CNT];
  27. ULONG DbgLogRxPhysBuffs[CalRpdSize(DEF_RCB_CNT)];
  28. UINT DbgLogTxPhysBuffsIndex = 0;
  29. UINT DbgLogRxPhysBuffsIndex = 0;
  30. // Globals to ease debugging
  31. UINT GDbgDataSize=0;
  32. MK7DBG_STAT GDbgStat;
  33. ULONG GDbgSleep=0;
  34. LONGLONG GDbgTACmdTime[1000];
  35. LONGLONG GDbgTARspTime[1000];
  36. LONGLONG GDbgTATime[1000];
  37. UINT GDbgTATimeIdx;
  38. //----------------------------------------------------------------------
  39. // Procedure: [MyLogEvent]
  40. //
  41. // Description: Log to our arrary.
  42. //
  43. //----------------------------------------------------------------------
  44. VOID MyLogEvent(char *msg, ULONG val)
  45. {
  46. // NdisGetCurrentSystemTime((PLARGE_INTEGER)&DbgLog[DbgLogIndex].usec);
  47. DbgLogMsg[DbgLogIndex] = msg;
  48. DbgLogVal[DbgLogIndex] = val;
  49. DbgLogIndex++;
  50. DbgLogIndex %= LOG_LENGTH;
  51. }
  52. //----------------------------------------------------------------------
  53. // Procedure: [MyLogPhysEvent]
  54. //
  55. // Description: Log to our arrary.
  56. //----------------------------------------------------------------------
  57. VOID MyLogPhysEvent(ULONG *logarray, UINT *index, ULONG val)
  58. {
  59. logarray[*index] = val;
  60. (*index)++;
  61. }
  62. //----------------------------------------------------------------------
  63. // Procedure: Time gap between successive sends.
  64. //----------------------------------------------------------------------
  65. VOID DbgInterPktTimeGap()
  66. {
  67. NdisMSleep(GDbgSleep);
  68. }
  69. //----------------------------------------------------------------------
  70. // Procedure: [DbgTestInit]
  71. //
  72. // Description: Initialized the test context.
  73. //
  74. //-----------------------------------------------------------------------
  75. VOID DbgTestInit(PMK7_ADAPTER Adapter)
  76. {
  77. UINT i;
  78. //************************************************************
  79. // The start of this routine is to facilitate debugging. We create
  80. // canned debug/test settings so we don't have to manually change
  81. // variables in debugger. However, tests not covered by the hardcoded
  82. // settings still need to be manually set.
  83. //
  84. // 2 main functions happen here to help w/ test/debug:
  85. // 1. Desired fields in the Adapter struct are extracted here and
  86. // displayed so we don't have to manually look at these fields.
  87. // 2. Setup debug/test fields in Adapter.
  88. //************************************************************
  89. //************************************************************
  90. //
  91. // Set DbgTest here to run canned tests.
  92. //
  93. //************************************************************
  94. //++++++++++++++++++++++++++++++
  95. // Hardcode something to ease debug.
  96. Adapter->DbgTest = 0;
  97. //++++++++++++++++++++++++++++++
  98. if (Adapter->DbgTest == 0)
  99. return;
  100. switch(Adapter->DbgTest) {
  101. //
  102. // Tests 1-5 all need Loopback turned on at startup.
  103. //
  104. case 1:
  105. Adapter->LBPktLevel = 1;
  106. Adapter->DbgTestDataCnt = GDbgDataSize;
  107. break;
  108. case 2:
  109. Adapter->LBPktLevel = 4;
  110. break;
  111. case 3:
  112. Adapter->LBPktLevel = 15;
  113. break;
  114. case 4:
  115. Adapter->LBPktLevel = 32;
  116. break;
  117. case 5:
  118. Adapter->LBPktLevel = 4;
  119. break;
  120. case 6:
  121. Adapter->LBPktLevel = 1;
  122. Adapter->DbgTestDataCnt = GDbgDataSize;
  123. break;
  124. case 7:
  125. Adapter->LBPktLevel = 0;
  126. Adapter->DbgTestDataCnt = GDbgDataSize;
  127. break;
  128. default:
  129. // anything else we're not running any tests
  130. break;
  131. }
  132. NdisZeroMemory(&GDbgStat, sizeof(MK7DBG_STAT));
  133. // Use our timer to simulate TX/RX (this to basically tests
  134. // my interrupt handling logic while hw interrupt is not yet
  135. // working. (May be used for other tests.)
  136. // Always set it up but we may not use it.
  137. // NdisMInitializeTimer(&Adapter->MK7DbgTestIntTimer,
  138. // Adapter->MK7AdapterHandle,
  139. // (PNDIS_TIMER_FUNCTION) MK7DbgTestIntTmo,
  140. // (PVOID) Adapter);
  141. for (i=0; i<1000; i++) {
  142. GDbgTACmdTime[i] = 0;
  143. GDbgTARspTime[i] = 0;
  144. GDbgTATime[i] = 0;
  145. }
  146. GDbgTATimeIdx = 0;
  147. }
  148. //----------------------------------------------------------------------
  149. // Procedure: [MK7DbgTestIntTmo]
  150. //
  151. // Description: Process a test interrupt time out.
  152. //
  153. // (NOTE: This was used to test the TEST_Int bit when hw interrupt was
  154. // not fully working. This function is no longer needed. It's here as
  155. // as example on how to process an NDIS timer.)
  156. //-----------------------------------------------------------------------
  157. VOID MK7DbgTestIntTmo(PVOID sysspiff1,
  158. NDIS_HANDLE MiniportAdapterContext,
  159. PVOID sysspiff2,
  160. PVOID sysspiff3)
  161. {
  162. PMK7_ADAPTER Adapter;
  163. UINT tcbidx;
  164. PTCB tcb;
  165. PRCB rcb;
  166. UINT testsize;
  167. PUCHAR dst, src;
  168. Adapter = PMK7_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);
  169. MK7DisableInterrupt(Adapter);
  170. NdisAcquireSpinLock(&Adapter->Lock);
  171. // Find the tcb-trd being sent. We just go back one becuase after
  172. // the send this gets incremented.
  173. if (Adapter->nextAvailTcbIdx == 0) {
  174. tcbidx = Adapter->NumTcb - 1;
  175. }
  176. else {
  177. tcbidx = Adapter->nextAvailTcbIdx - 1;
  178. }
  179. tcb = Adapter->pTcbArray[tcbidx];
  180. rcb = Adapter->pRcbArray[Adapter->nextRxRcbIdx];
  181. // Copy from TX buff to RX buff
  182. src = tcb->buff;
  183. dst = rcb->rpd->databuff;
  184. testsize = tcb->PacketLength;
  185. NdisMoveMemory(dst, src, testsize);
  186. // now the RX ring buffer fields -- count
  187. rcb->rrd->count = tcb->trd->count;
  188. // now make sure the ownerships go to the drv
  189. GrantTrdToDrv(tcb->trd);
  190. GrantRrdToDrv(rcb->rrd);
  191. NdisReleaseSpinLock(&Adapter->Lock);
  192. MK7Reg_Write(Adapter, R_INTS, 0x0004);
  193. }
  194. #endif // DBG end bracket