IxNpeMhReceive.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /**
  2. * @file IxNpeMhReceive.c
  3. *
  4. * @author Intel Corporation
  5. * @date 18 Jan 2002
  6. *
  7. * @brief This file contains the implementation of the private API for the
  8. * Receive 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 "IxNpeMhConfig_p.h"
  34. #include "IxNpeMhReceive_p.h"
  35. #include "IxNpeMhSolicitedCbMgr_p.h"
  36. #include "IxNpeMhUnsolicitedCbMgr_p.h"
  37. /*
  38. * #defines and macros used in this file.
  39. */
  40. /*
  41. * Typedefs whose scope is limited to this file.
  42. */
  43. /**
  44. * @struct IxNpeMhReceiveStats
  45. *
  46. * @brief This structure is used to maintain statistics for the Receive
  47. * module.
  48. */
  49. typedef struct
  50. {
  51. UINT32 isrs; /**< receive ISR invocations */
  52. UINT32 receives; /**< receive messages invocations */
  53. UINT32 messages; /**< messages received */
  54. UINT32 solicited; /**< solicited messages received */
  55. UINT32 unsolicited; /**< unsolicited messages received */
  56. UINT32 callbacks; /**< callbacks invoked */
  57. } IxNpeMhReceiveStats;
  58. /*
  59. * Variable declarations global to this file only. Externs are followed by
  60. * static variables.
  61. */
  62. PRIVATE IxNpeMhReceiveStats ixNpeMhReceiveStats[IX_NPEMH_NUM_NPES];
  63. /*
  64. * Extern function prototypes.
  65. */
  66. /*
  67. * Static function prototypes.
  68. */
  69. PRIVATE
  70. void ixNpeMhReceiveIsr (int npeId);
  71. PRIVATE
  72. void ixNpeMhReceiveIsr (int npeId)
  73. {
  74. int lockKey;
  75. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  76. "ixNpeMhReceiveIsr\n");
  77. lockKey = ixOsalIrqLock ();
  78. /* invoke the message receive routine to get messages from the NPE */
  79. ixNpeMhReceiveMessagesReceive (npeId);
  80. /* update statistical info */
  81. ixNpeMhReceiveStats[npeId].isrs++;
  82. ixOsalIrqUnlock (lockKey);
  83. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  84. "ixNpeMhReceiveIsr\n");
  85. }
  86. /*
  87. * Function definition: ixNpeMhReceiveInitialize
  88. */
  89. void ixNpeMhReceiveInitialize (void)
  90. {
  91. IxNpeMhNpeId npeId = 0;
  92. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  93. "ixNpeMhReceiveInitialize\n");
  94. /* for each NPE ... */
  95. for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
  96. {
  97. /* register our internal ISR for the NPE to handle "outFIFO not */
  98. /* empty" interrupts */
  99. ixNpeMhConfigIsrRegister (npeId, ixNpeMhReceiveIsr);
  100. }
  101. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  102. "ixNpeMhReceiveInitialize\n");
  103. }
  104. /*
  105. * Function definition: ixNpeMhReceiveMessagesReceive
  106. */
  107. IX_STATUS ixNpeMhReceiveMessagesReceive (
  108. IxNpeMhNpeId npeId)
  109. {
  110. IxNpeMhMessage message = { { 0, 0 } };
  111. IxNpeMhMessageId messageId = 0;
  112. IxNpeMhCallback callback = NULL;
  113. IX_STATUS status;
  114. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  115. "ixNpeMhReceiveMessagesReceive\n");
  116. /* update statistical info */
  117. ixNpeMhReceiveStats[npeId].receives++;
  118. /* while the NPE has messages in its outFIFO */
  119. while (!ixNpeMhConfigOutFifoIsEmpty (npeId))
  120. {
  121. /* read a message from the NPE's outFIFO */
  122. status = ixNpeMhConfigOutFifoRead (npeId, &message);
  123. if (IX_SUCCESS != status)
  124. {
  125. return status;
  126. }
  127. /* get the ID of the message */
  128. messageId = ixNpeMhConfigMessageIdGet (message);
  129. IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG,
  130. "Received message from NPE %d with ID 0x%02X\n",
  131. npeId, messageId);
  132. /* update statistical info */
  133. ixNpeMhReceiveStats[npeId].messages++;
  134. /* try to find a matching unsolicited callback for this message. */
  135. /* we assume the message is unsolicited. only if there is no */
  136. /* unsolicited callback for this message type do we assume the */
  137. /* message is solicited. it is much faster to check for an */
  138. /* unsolicited callback, so doing this check first should result */
  139. /* in better performance. */
  140. ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
  141. npeId, messageId, &callback);
  142. if (callback != NULL)
  143. {
  144. IX_NPEMH_TRACE0 (IX_NPEMH_DEBUG,
  145. "Found matching unsolicited callback\n");
  146. /* update statistical info */
  147. ixNpeMhReceiveStats[npeId].unsolicited++;
  148. }
  149. /* if no unsolicited callback was found try to find a matching */
  150. /* solicited callback for this message */
  151. if (callback == NULL)
  152. {
  153. ixNpeMhSolicitedCbMgrCallbackRetrieve (
  154. npeId, messageId, &callback);
  155. if (callback != NULL)
  156. {
  157. IX_NPEMH_TRACE0 (IX_NPEMH_DEBUG,
  158. "Found matching solicited callback\n");
  159. /* update statistical info */
  160. ixNpeMhReceiveStats[npeId].solicited++;
  161. }
  162. }
  163. /* if a callback (either unsolicited or solicited) was found */
  164. if (callback != NULL)
  165. {
  166. /* invoke the callback to pass the message back to the client */
  167. callback (npeId, message);
  168. /* update statistical info */
  169. ixNpeMhReceiveStats[npeId].callbacks++;
  170. }
  171. else /* no callback (neither unsolicited nor solicited) was found */
  172. {
  173. IX_NPEMH_TRACE2 (IX_NPEMH_WARNING,
  174. "No matching callback for NPE %d"
  175. " and ID 0x%02X, discarding message\n",
  176. npeId, messageId);
  177. /* the message will be discarded. this is normal behaviour */
  178. /* if the client passes a NULL solicited callback when */
  179. /* sending a message. this indicates that the client is not */
  180. /* interested in receiving the response. alternatively a */
  181. /* NULL callback here may signify an unsolicited message */
  182. /* with no appropriate registered callback. */
  183. }
  184. }
  185. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  186. "ixNpeMhReceiveMessagesReceive\n");
  187. return IX_SUCCESS;
  188. }
  189. /*
  190. * Function definition: ixNpeMhReceiveShow
  191. */
  192. void ixNpeMhReceiveShow (
  193. IxNpeMhNpeId npeId)
  194. {
  195. /* show the ISR invocation counter */
  196. IX_NPEMH_SHOW ("Receive ISR invocations",
  197. ixNpeMhReceiveStats[npeId].isrs);
  198. /* show the receive message invocation counter */
  199. IX_NPEMH_SHOW ("Receive messages invocations",
  200. ixNpeMhReceiveStats[npeId].receives);
  201. /* show the message received counter */
  202. IX_NPEMH_SHOW ("Messages received",
  203. ixNpeMhReceiveStats[npeId].messages);
  204. /* show the solicited message counter */
  205. IX_NPEMH_SHOW ("Solicited messages received",
  206. ixNpeMhReceiveStats[npeId].solicited);
  207. /* show the unsolicited message counter */
  208. IX_NPEMH_SHOW ("Unsolicited messages received",
  209. ixNpeMhReceiveStats[npeId].unsolicited);
  210. /* show the callback invoked counter */
  211. IX_NPEMH_SHOW ("Callbacks invoked",
  212. ixNpeMhReceiveStats[npeId].callbacks);
  213. /* show the message discarded counter */
  214. IX_NPEMH_SHOW ("Received messages discarded",
  215. (ixNpeMhReceiveStats[npeId].messages -
  216. ixNpeMhReceiveStats[npeId].callbacks));
  217. }
  218. /*
  219. * Function definition: ixNpeMhReceiveShowReset
  220. */
  221. void ixNpeMhReceiveShowReset (
  222. IxNpeMhNpeId npeId)
  223. {
  224. /* reset the ISR invocation counter */
  225. ixNpeMhReceiveStats[npeId].isrs = 0;
  226. /* reset the receive message invocation counter */
  227. ixNpeMhReceiveStats[npeId].receives = 0;
  228. /* reset the message received counter */
  229. ixNpeMhReceiveStats[npeId].messages = 0;
  230. /* reset the solicited message counter */
  231. ixNpeMhReceiveStats[npeId].solicited = 0;
  232. /* reset the unsolicited message counter */
  233. ixNpeMhReceiveStats[npeId].unsolicited = 0;
  234. /* reset the callback invoked counter */
  235. ixNpeMhReceiveStats[npeId].callbacks = 0;
  236. }