IxNpeMhReceive.c 9.4 KB

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