IxNpeMhSend.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /**
  2. * @file IxNpeMhSend.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. * Send 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 "IxNpeMhMacros_p.h"
  32. #include "IxNpeMhConfig_p.h"
  33. #include "IxNpeMhSend_p.h"
  34. #include "IxNpeMhSolicitedCbMgr_p.h"
  35. /*
  36. * #defines and macros used in this file.
  37. */
  38. /**
  39. * @def IX_NPEMH_INFIFO_RETRY_DELAY_US
  40. *
  41. * @brief Amount of time (uSecs) to delay between retries
  42. * while inFIFO is Full when attempting to send a message
  43. */
  44. #define IX_NPEMH_INFIFO_RETRY_DELAY_US (1)
  45. /*
  46. * Typedefs whose scope is limited to this file.
  47. */
  48. /**
  49. * @struct IxNpeMhSendStats
  50. *
  51. * @brief This structure is used to maintain statistics for the Send
  52. * module.
  53. */
  54. typedef struct
  55. {
  56. UINT32 sends; /**< send invocations */
  57. UINT32 sendWithResponses; /**< send with response invocations */
  58. UINT32 queueFulls; /**< fifo queue full occurrences */
  59. UINT32 queueFullRetries; /**< fifo queue full retry occurrences */
  60. UINT32 maxQueueFullRetries; /**< max fifo queue full retries */
  61. UINT32 callbackFulls; /**< callback list full occurrences */
  62. } IxNpeMhSendStats;
  63. /*
  64. * Variable declarations global to this file only. Externs are followed by
  65. * static variables.
  66. */
  67. PRIVATE IxNpeMhSendStats ixNpeMhSendStats[IX_NPEMH_NUM_NPES];
  68. /*
  69. * Extern function prototypes.
  70. */
  71. /*
  72. * Static function prototypes.
  73. */
  74. PRIVATE
  75. BOOL ixNpeMhSendInFifoIsFull(
  76. IxNpeMhNpeId npeId,
  77. UINT32 maxSendRetries);
  78. /*
  79. * Function definition: ixNpeMhSendInFifoIsFull
  80. */
  81. PRIVATE
  82. BOOL ixNpeMhSendInFifoIsFull(
  83. IxNpeMhNpeId npeId,
  84. UINT32 maxSendRetries)
  85. {
  86. BOOL isFull = false;
  87. UINT32 numRetries = 0;
  88. /* check the NPE's inFIFO */
  89. isFull = ixNpeMhConfigInFifoIsFull (npeId);
  90. /* we retry a few times, just to give the NPE a chance to read from */
  91. /* the FIFO if the FIFO is currently full */
  92. while (isFull && (numRetries++ < maxSendRetries))
  93. {
  94. if (numRetries >= IX_NPEMH_SEND_RETRIES_DEFAULT)
  95. {
  96. /* Delay here for as short a time as possible (1 us). */
  97. /* Adding a delay here should ensure we are not hogging */
  98. /* the AHB bus while we are retrying */
  99. ixOsalBusySleep (IX_NPEMH_INFIFO_RETRY_DELAY_US);
  100. }
  101. /* re-check the NPE's inFIFO */
  102. isFull = ixNpeMhConfigInFifoIsFull (npeId);
  103. /* update statistical info */
  104. ixNpeMhSendStats[npeId].queueFullRetries++;
  105. }
  106. /* record the highest number of retries that occurred */
  107. if (ixNpeMhSendStats[npeId].maxQueueFullRetries < numRetries)
  108. {
  109. ixNpeMhSendStats[npeId].maxQueueFullRetries = numRetries;
  110. }
  111. if (isFull)
  112. {
  113. /* update statistical info */
  114. ixNpeMhSendStats[npeId].queueFulls++;
  115. }
  116. return isFull;
  117. }
  118. /*
  119. * Function definition: ixNpeMhSendMessageSend
  120. */
  121. IX_STATUS ixNpeMhSendMessageSend (
  122. IxNpeMhNpeId npeId,
  123. IxNpeMhMessage message,
  124. UINT32 maxSendRetries)
  125. {
  126. IX_STATUS status;
  127. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  128. "ixNpeMhSendMessageSend\n");
  129. /* update statistical info */
  130. ixNpeMhSendStats[npeId].sends++;
  131. /* check if the NPE's inFIFO is full - if so return an error */
  132. if (ixNpeMhSendInFifoIsFull (npeId, maxSendRetries))
  133. {
  134. IX_NPEMH_TRACE0 (IX_NPEMH_WARNING, "NPE's inFIFO is full\n");
  135. return IX_FAIL;
  136. }
  137. /* write the message to the NPE's inFIFO */
  138. status = ixNpeMhConfigInFifoWrite (npeId, message);
  139. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  140. "ixNpeMhSendMessageSend\n");
  141. return status;
  142. }
  143. /*
  144. * Function definition: ixNpeMhSendMessageWithResponseSend
  145. */
  146. IX_STATUS ixNpeMhSendMessageWithResponseSend (
  147. IxNpeMhNpeId npeId,
  148. IxNpeMhMessage message,
  149. IxNpeMhMessageId solicitedMessageId,
  150. IxNpeMhCallback solicitedCallback,
  151. UINT32 maxSendRetries)
  152. {
  153. IX_STATUS status = IX_SUCCESS;
  154. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  155. "ixNpeMhSendMessageWithResponseSend\n");
  156. /* update statistical info */
  157. ixNpeMhSendStats[npeId].sendWithResponses++;
  158. /* sr: this sleep will call the receive routine (no interrupts used!!!) */
  159. ixOsalSleep (IX_NPEMH_INFIFO_RETRY_DELAY_US);
  160. /* check if the NPE's inFIFO is full - if so return an error */
  161. if (ixNpeMhSendInFifoIsFull (npeId, maxSendRetries))
  162. {
  163. IX_NPEMH_TRACE0 (IX_NPEMH_WARNING, "NPE's inFIFO is full\n");
  164. return IX_FAIL;
  165. }
  166. /* save the solicited callback */
  167. status = ixNpeMhSolicitedCbMgrCallbackSave (
  168. npeId, solicitedMessageId, solicitedCallback);
  169. if (status != IX_SUCCESS)
  170. {
  171. IX_NPEMH_ERROR_REPORT ("Failed to save solicited callback\n");
  172. /* update statistical info */
  173. ixNpeMhSendStats[npeId].callbackFulls++;
  174. return status;
  175. }
  176. /* write the message to the NPE's inFIFO */
  177. status = ixNpeMhConfigInFifoWrite (npeId, message);
  178. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  179. "ixNpeMhSendMessageWithResponseSend\n");
  180. return status;
  181. }
  182. /*
  183. * Function definition: ixNpeMhSendShow
  184. */
  185. void ixNpeMhSendShow (
  186. IxNpeMhNpeId npeId)
  187. {
  188. /* show the message send invocation counter */
  189. IX_NPEMH_SHOW ("Send invocations",
  190. ixNpeMhSendStats[npeId].sends);
  191. /* show the message send with response invocation counter */
  192. IX_NPEMH_SHOW ("Send with response invocations",
  193. ixNpeMhSendStats[npeId].sendWithResponses);
  194. /* show the fifo queue full occurrence counter */
  195. IX_NPEMH_SHOW ("Fifo queue full occurrences",
  196. ixNpeMhSendStats[npeId].queueFulls);
  197. /* show the fifo queue full retry occurrence counter */
  198. IX_NPEMH_SHOW ("Fifo queue full retry occurrences",
  199. ixNpeMhSendStats[npeId].queueFullRetries);
  200. /* show the fifo queue full maximum retries counter */
  201. IX_NPEMH_SHOW ("Maximum fifo queue full retries",
  202. ixNpeMhSendStats[npeId].maxQueueFullRetries);
  203. /* show the callback list full occurrence counter */
  204. IX_NPEMH_SHOW ("Solicited callback list full occurrences",
  205. ixNpeMhSendStats[npeId].callbackFulls);
  206. }
  207. /*
  208. * Function definition: ixNpeMhSendShowReset
  209. */
  210. void ixNpeMhSendShowReset (
  211. IxNpeMhNpeId npeId)
  212. {
  213. /* reset the message send invocation counter */
  214. ixNpeMhSendStats[npeId].sends = 0;
  215. /* reset the message send with response invocation counter */
  216. ixNpeMhSendStats[npeId].sendWithResponses = 0;
  217. /* reset the fifo queue full occurrence counter */
  218. ixNpeMhSendStats[npeId].queueFulls = 0;
  219. /* reset the fifo queue full retry occurrence counter */
  220. ixNpeMhSendStats[npeId].queueFullRetries = 0;
  221. /* reset the max fifo queue full retries counter */
  222. ixNpeMhSendStats[npeId].maxQueueFullRetries = 0;
  223. /* reset the callback list full occurrence counter */
  224. ixNpeMhSendStats[npeId].callbackFulls = 0;
  225. }