IxNpeMhUnsolicitedCbMgr.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. * @file IxNpeMhUnsolicitedCbMgr.c
  3. *
  4. * @author Intel Corporation
  5. * @date 18 Jan 2002
  6. *
  7. * @brief This file contains the implementation of the private API for
  8. * the Unsolicited Callback Manager module.
  9. *
  10. *
  11. * @par
  12. * IXP400 SW Release version 2.0
  13. *
  14. * -- Copyright Notice --
  15. *
  16. * @par
  17. * Copyright 2001-2005, Intel Corporation.
  18. * All rights reserved.
  19. *
  20. * @par
  21. * SPDX-License-Identifier: BSD-3-Clause
  22. * @par
  23. * -- End of Copyright Notice --
  24. */
  25. /*
  26. * Put the system defined include files required.
  27. */
  28. /*
  29. * Put the user defined include files required.
  30. */
  31. #include "IxOsal.h"
  32. #include "IxNpeMhMacros_p.h"
  33. #include "IxNpeMhUnsolicitedCbMgr_p.h"
  34. /*
  35. * #defines and macros used in this file.
  36. */
  37. /*
  38. * Typedefs whose scope is limited to this file.
  39. */
  40. /**
  41. * @struct IxNpeMhUnsolicitedCallbackTable
  42. *
  43. * @brief This structure is used to maintain the list of registered
  44. * callbacks. One entry exists for each message ID, and a NULL entry will
  45. * signify that no callback has been registered for that ID.
  46. */
  47. typedef struct
  48. {
  49. /** array of entries */
  50. IxNpeMhCallback entries[IX_NPEMH_MAX_MESSAGE_ID + 1];
  51. } IxNpeMhUnsolicitedCallbackTable;
  52. /**
  53. * @struct IxNpeMhUnsolicitedCbMgrStats
  54. *
  55. * @brief This structure is used to maintain statistics for the Unsolicited
  56. * Callback Manager module.
  57. */
  58. typedef struct
  59. {
  60. UINT32 saves; /**< callback table saves */
  61. UINT32 overwrites; /**< callback table overwrites */
  62. } IxNpeMhUnsolicitedCbMgrStats;
  63. /*
  64. * Variable declarations global to this file only. Externs are followed by
  65. * static variables.
  66. */
  67. PRIVATE IxNpeMhUnsolicitedCallbackTable
  68. ixNpeMhUnsolicitedCallbackTables[IX_NPEMH_NUM_NPES];
  69. PRIVATE IxNpeMhUnsolicitedCbMgrStats
  70. ixNpeMhUnsolicitedCbMgrStats[IX_NPEMH_NUM_NPES];
  71. /*
  72. * Extern function prototypes.
  73. */
  74. /*
  75. * Static function prototypes.
  76. */
  77. /*
  78. * Function definition: ixNpeMhUnsolicitedCbMgrInitialize
  79. */
  80. void ixNpeMhUnsolicitedCbMgrInitialize (void)
  81. {
  82. IxNpeMhNpeId npeId = 0;
  83. IxNpeMhUnsolicitedCallbackTable *table = NULL;
  84. IxNpeMhMessageId messageId = 0;
  85. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  86. "ixNpeMhUnsolicitedCbMgrInitialize\n");
  87. /* for each NPE ... */
  88. for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
  89. {
  90. /* initialise a pointer to the table for convenience */
  91. table = &ixNpeMhUnsolicitedCallbackTables[npeId];
  92. /* for each message ID ... */
  93. for (messageId = IX_NPEMH_MIN_MESSAGE_ID;
  94. messageId <= IX_NPEMH_MAX_MESSAGE_ID; messageId++)
  95. {
  96. /* initialise the callback for this message ID to NULL */
  97. table->entries[messageId] = NULL;
  98. }
  99. }
  100. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  101. "ixNpeMhUnsolicitedCbMgrInitialize\n");
  102. }
  103. /*
  104. * Function definition: ixNpeMhUnsolicitedCbMgrCallbackSave
  105. */
  106. void ixNpeMhUnsolicitedCbMgrCallbackSave (
  107. IxNpeMhNpeId npeId,
  108. IxNpeMhMessageId unsolicitedMessageId,
  109. IxNpeMhCallback unsolicitedCallback)
  110. {
  111. IxNpeMhUnsolicitedCallbackTable *table = NULL;
  112. /* initialise a pointer to the table for convenience */
  113. table = &ixNpeMhUnsolicitedCallbackTables[npeId];
  114. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  115. "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
  116. /* update statistical info */
  117. ixNpeMhUnsolicitedCbMgrStats[npeId].saves++;
  118. /* check if there is a callback already registered for this NPE and */
  119. /* message ID */
  120. if (table->entries[unsolicitedMessageId] != NULL)
  121. {
  122. /* if we are overwriting an existing callback */
  123. if (unsolicitedCallback != NULL)
  124. {
  125. IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "Unsolicited callback "
  126. "overwriting existing callback for NPE ID %d "
  127. "message ID 0x%02X\n", npeId, unsolicitedMessageId);
  128. }
  129. else /* if we are clearing an existing callback */
  130. {
  131. IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "NULL unsolicited callback "
  132. "clearing existing callback for NPE ID %d "
  133. "message ID 0x%02X\n", npeId, unsolicitedMessageId);
  134. }
  135. /* update statistical info */
  136. ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites++;
  137. }
  138. /* save the callback into the table */
  139. table->entries[unsolicitedMessageId] = unsolicitedCallback;
  140. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  141. "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
  142. }
  143. /*
  144. * Function definition: ixNpeMhUnsolicitedCbMgrCallbackRetrieve
  145. */
  146. void ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
  147. IxNpeMhNpeId npeId,
  148. IxNpeMhMessageId unsolicitedMessageId,
  149. IxNpeMhCallback *unsolicitedCallback)
  150. {
  151. IxNpeMhUnsolicitedCallbackTable *table = NULL;
  152. /* initialise a pointer to the table for convenience */
  153. table = &ixNpeMhUnsolicitedCallbackTables[npeId];
  154. /* retrieve the callback from the table */
  155. *unsolicitedCallback = table->entries[unsolicitedMessageId];
  156. }
  157. /*
  158. * Function definition: ixNpeMhUnsolicitedCbMgrShow
  159. */
  160. void ixNpeMhUnsolicitedCbMgrShow (
  161. IxNpeMhNpeId npeId)
  162. {
  163. /* show the unsolicited callback table save counter */
  164. IX_NPEMH_SHOW ("Unsolicited callback table saves",
  165. ixNpeMhUnsolicitedCbMgrStats[npeId].saves);
  166. /* show the unsolicited callback table overwrite counter */
  167. IX_NPEMH_SHOW ("Unsolicited callback table overwrites",
  168. ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites);
  169. }
  170. /*
  171. * Function definition: ixNpeMhUnsolicitedCbMgrShowReset
  172. */
  173. void ixNpeMhUnsolicitedCbMgrShowReset (
  174. IxNpeMhNpeId npeId)
  175. {
  176. /* reset the unsolicited callback table save counter */
  177. ixNpeMhUnsolicitedCbMgrStats[npeId].saves = 0;
  178. /* reset the unsolicited callback table overwrite counter */
  179. ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites = 0;
  180. }