IxNpeMhSend.c 8.6 KB

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