IxNpeMhUnsolicitedCbMgr.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions
  23. * are met:
  24. * 1. Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * 2. Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in the
  28. * documentation and/or other materials provided with the distribution.
  29. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  30. * may be used to endorse or promote products derived from this software
  31. * without specific prior written permission.
  32. *
  33. * @par
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  35. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  36. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  37. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  38. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  39. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  40. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  42. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  43. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  44. * SUCH DAMAGE.
  45. *
  46. * @par
  47. * -- End of Copyright Notice --
  48. */
  49. /*
  50. * Put the system defined include files required.
  51. */
  52. /*
  53. * Put the user defined include files required.
  54. */
  55. #include "IxOsal.h"
  56. #include "IxNpeMhMacros_p.h"
  57. #include "IxNpeMhUnsolicitedCbMgr_p.h"
  58. /*
  59. * #defines and macros used in this file.
  60. */
  61. /*
  62. * Typedefs whose scope is limited to this file.
  63. */
  64. /**
  65. * @struct IxNpeMhUnsolicitedCallbackTable
  66. *
  67. * @brief This structure is used to maintain the list of registered
  68. * callbacks. One entry exists for each message ID, and a NULL entry will
  69. * signify that no callback has been registered for that ID.
  70. */
  71. typedef struct
  72. {
  73. /** array of entries */
  74. IxNpeMhCallback entries[IX_NPEMH_MAX_MESSAGE_ID + 1];
  75. } IxNpeMhUnsolicitedCallbackTable;
  76. /**
  77. * @struct IxNpeMhUnsolicitedCbMgrStats
  78. *
  79. * @brief This structure is used to maintain statistics for the Unsolicited
  80. * Callback Manager module.
  81. */
  82. typedef struct
  83. {
  84. UINT32 saves; /**< callback table saves */
  85. UINT32 overwrites; /**< callback table overwrites */
  86. } IxNpeMhUnsolicitedCbMgrStats;
  87. /*
  88. * Variable declarations global to this file only. Externs are followed by
  89. * static variables.
  90. */
  91. PRIVATE IxNpeMhUnsolicitedCallbackTable
  92. ixNpeMhUnsolicitedCallbackTables[IX_NPEMH_NUM_NPES];
  93. PRIVATE IxNpeMhUnsolicitedCbMgrStats
  94. ixNpeMhUnsolicitedCbMgrStats[IX_NPEMH_NUM_NPES];
  95. /*
  96. * Extern function prototypes.
  97. */
  98. /*
  99. * Static function prototypes.
  100. */
  101. /*
  102. * Function definition: ixNpeMhUnsolicitedCbMgrInitialize
  103. */
  104. void ixNpeMhUnsolicitedCbMgrInitialize (void)
  105. {
  106. IxNpeMhNpeId npeId = 0;
  107. IxNpeMhUnsolicitedCallbackTable *table = NULL;
  108. IxNpeMhMessageId messageId = 0;
  109. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  110. "ixNpeMhUnsolicitedCbMgrInitialize\n");
  111. /* for each NPE ... */
  112. for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
  113. {
  114. /* initialise a pointer to the table for convenience */
  115. table = &ixNpeMhUnsolicitedCallbackTables[npeId];
  116. /* for each message ID ... */
  117. for (messageId = IX_NPEMH_MIN_MESSAGE_ID;
  118. messageId <= IX_NPEMH_MAX_MESSAGE_ID; messageId++)
  119. {
  120. /* initialise the callback for this message ID to NULL */
  121. table->entries[messageId] = NULL;
  122. }
  123. }
  124. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  125. "ixNpeMhUnsolicitedCbMgrInitialize\n");
  126. }
  127. /*
  128. * Function definition: ixNpeMhUnsolicitedCbMgrCallbackSave
  129. */
  130. void ixNpeMhUnsolicitedCbMgrCallbackSave (
  131. IxNpeMhNpeId npeId,
  132. IxNpeMhMessageId unsolicitedMessageId,
  133. IxNpeMhCallback unsolicitedCallback)
  134. {
  135. IxNpeMhUnsolicitedCallbackTable *table = NULL;
  136. /* initialise a pointer to the table for convenience */
  137. table = &ixNpeMhUnsolicitedCallbackTables[npeId];
  138. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  139. "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
  140. /* update statistical info */
  141. ixNpeMhUnsolicitedCbMgrStats[npeId].saves++;
  142. /* check if there is a callback already registered for this NPE and */
  143. /* message ID */
  144. if (table->entries[unsolicitedMessageId] != NULL)
  145. {
  146. /* if we are overwriting an existing callback */
  147. if (unsolicitedCallback != NULL)
  148. {
  149. IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "Unsolicited callback "
  150. "overwriting existing callback for NPE ID %d "
  151. "message ID 0x%02X\n", npeId, unsolicitedMessageId);
  152. }
  153. else /* if we are clearing an existing callback */
  154. {
  155. IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "NULL unsolicited callback "
  156. "clearing existing callback for NPE ID %d "
  157. "message ID 0x%02X\n", npeId, unsolicitedMessageId);
  158. }
  159. /* update statistical info */
  160. ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites++;
  161. }
  162. /* save the callback into the table */
  163. table->entries[unsolicitedMessageId] = unsolicitedCallback;
  164. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  165. "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
  166. }
  167. /*
  168. * Function definition: ixNpeMhUnsolicitedCbMgrCallbackRetrieve
  169. */
  170. void ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
  171. IxNpeMhNpeId npeId,
  172. IxNpeMhMessageId unsolicitedMessageId,
  173. IxNpeMhCallback *unsolicitedCallback)
  174. {
  175. IxNpeMhUnsolicitedCallbackTable *table = NULL;
  176. /* initialise a pointer to the table for convenience */
  177. table = &ixNpeMhUnsolicitedCallbackTables[npeId];
  178. /* retrieve the callback from the table */
  179. *unsolicitedCallback = table->entries[unsolicitedMessageId];
  180. }
  181. /*
  182. * Function definition: ixNpeMhUnsolicitedCbMgrShow
  183. */
  184. void ixNpeMhUnsolicitedCbMgrShow (
  185. IxNpeMhNpeId npeId)
  186. {
  187. /* show the unsolicited callback table save counter */
  188. IX_NPEMH_SHOW ("Unsolicited callback table saves",
  189. ixNpeMhUnsolicitedCbMgrStats[npeId].saves);
  190. /* show the unsolicited callback table overwrite counter */
  191. IX_NPEMH_SHOW ("Unsolicited callback table overwrites",
  192. ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites);
  193. }
  194. /*
  195. * Function definition: ixNpeMhUnsolicitedCbMgrShowReset
  196. */
  197. void ixNpeMhUnsolicitedCbMgrShowReset (
  198. IxNpeMhNpeId npeId)
  199. {
  200. /* reset the unsolicited callback table save counter */
  201. ixNpeMhUnsolicitedCbMgrStats[npeId].saves = 0;
  202. /* reset the unsolicited callback table overwrite counter */
  203. ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites = 0;
  204. }