IxNpeMh.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /**
  2. * @file IxNpeMh.c
  3. *
  4. * @author Intel Corporation
  5. * @date 18 Jan 2002
  6. *
  7. * @brief This file contains the implementation of the public API for the
  8. * IXP425 NPE Message Handler component.
  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 "IxNpeMh.h"
  34. #include "IxNpeMhConfig_p.h"
  35. #include "IxNpeMhReceive_p.h"
  36. #include "IxNpeMhSend_p.h"
  37. #include "IxNpeMhSolicitedCbMgr_p.h"
  38. #include "IxNpeMhUnsolicitedCbMgr_p.h"
  39. /*
  40. * #defines and macros used in this file.
  41. */
  42. /*
  43. * Typedefs whose scope is limited to this file.
  44. */
  45. /*
  46. * Variable declarations global to this file only. Externs are followed by
  47. * static variables.
  48. */
  49. PRIVATE BOOL ixNpeMhInitialized = false;
  50. /*
  51. * Extern function prototypes.
  52. */
  53. /*
  54. * Static function prototypes.
  55. */
  56. /*
  57. * Function definition: ixNpeMhInitialize
  58. */
  59. PUBLIC IX_STATUS ixNpeMhInitialize (
  60. IxNpeMhNpeInterrupts npeInterrupts)
  61. {
  62. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  63. "ixNpeMhInitialize\n");
  64. /* check the npeInterrupts parameter */
  65. if ((npeInterrupts != IX_NPEMH_NPEINTERRUPTS_NO) &&
  66. (npeInterrupts != IX_NPEMH_NPEINTERRUPTS_YES))
  67. {
  68. IX_NPEMH_ERROR_REPORT ("Illegal npeInterrupts parameter value\n");
  69. return IX_FAIL;
  70. }
  71. /* parameters are ok ... */
  72. /* initialize the Receive module */
  73. ixNpeMhReceiveInitialize ();
  74. /* initialize the Solicited Callback Manager module */
  75. ixNpeMhSolicitedCbMgrInitialize ();
  76. /* initialize the Unsolicited Callback Manager module */
  77. ixNpeMhUnsolicitedCbMgrInitialize ();
  78. /* initialize the Configuration module
  79. *
  80. * NOTE: This module was originally configured before the
  81. * others, but the sequence was changed so that interrupts
  82. * would only be enabled after the handler functions were
  83. * set up. The above modules need to be initialised to
  84. * handle the NPE interrupts. See SCR #2231.
  85. */
  86. ixNpeMhConfigInitialize (npeInterrupts);
  87. ixNpeMhInitialized = true;
  88. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  89. "ixNpeMhInitialize\n");
  90. return IX_SUCCESS;
  91. }
  92. /*
  93. * Function definition: ixNpeMhUnload
  94. */
  95. PUBLIC IX_STATUS ixNpeMhUnload (void)
  96. {
  97. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  98. "ixNpeMhUnload\n");
  99. if (!ixNpeMhInitialized)
  100. {
  101. return IX_FAIL;
  102. }
  103. /* Uninitialize the Configuration module */
  104. ixNpeMhConfigUninit ();
  105. ixNpeMhInitialized = false;
  106. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  107. "ixNpeMhUnload\n");
  108. return IX_SUCCESS;
  109. }
  110. /*
  111. * Function definition: ixNpeMhUnsolicitedCallbackRegister
  112. */
  113. PUBLIC IX_STATUS ixNpeMhUnsolicitedCallbackRegister (
  114. IxNpeMhNpeId npeId,
  115. IxNpeMhMessageId messageId,
  116. IxNpeMhCallback unsolicitedCallback)
  117. {
  118. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  119. "ixNpeMhUnsolicitedCallbackRegister\n");
  120. /* check that we are initialized */
  121. if (!ixNpeMhInitialized)
  122. {
  123. IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
  124. return IX_FAIL;
  125. }
  126. /* check the npeId parameter */
  127. if (!ixNpeMhConfigNpeIdIsValid (npeId))
  128. {
  129. IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
  130. return IX_FAIL;
  131. }
  132. /* check the messageId parameter */
  133. if ((messageId < IX_NPEMH_MIN_MESSAGE_ID)
  134. || (messageId > IX_NPEMH_MAX_MESSAGE_ID))
  135. {
  136. IX_NPEMH_ERROR_REPORT ("Message ID is out of range\n");
  137. return IX_FAIL;
  138. }
  139. /* the unsolicitedCallback parameter is allowed to be NULL */
  140. /* parameters are ok ... */
  141. /* get the lock to prevent other clients from entering */
  142. ixNpeMhConfigLockGet (npeId);
  143. /* save the unsolicited callback for the message ID */
  144. ixNpeMhUnsolicitedCbMgrCallbackSave (
  145. npeId, messageId, unsolicitedCallback);
  146. /* release the lock to allow other clients back in */
  147. ixNpeMhConfigLockRelease (npeId);
  148. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  149. "ixNpeMhUnsolicitedCallbackRegister\n");
  150. return IX_SUCCESS;
  151. }
  152. /*
  153. * Function definition: ixNpeMhUnsolicitedCallbackForRangeRegister
  154. */
  155. PUBLIC IX_STATUS ixNpeMhUnsolicitedCallbackForRangeRegister (
  156. IxNpeMhNpeId npeId,
  157. IxNpeMhMessageId minMessageId,
  158. IxNpeMhMessageId maxMessageId,
  159. IxNpeMhCallback unsolicitedCallback)
  160. {
  161. IxNpeMhMessageId messageId;
  162. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  163. "ixNpeMhUnsolicitedCallbackForRangeRegister\n");
  164. /* check that we are initialized */
  165. if (!ixNpeMhInitialized)
  166. {
  167. IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
  168. return IX_FAIL;
  169. }
  170. /* check the npeId parameter */
  171. if (!ixNpeMhConfigNpeIdIsValid (npeId))
  172. {
  173. IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
  174. return IX_FAIL;
  175. }
  176. /* check the minMessageId parameter */
  177. if ((minMessageId < IX_NPEMH_MIN_MESSAGE_ID)
  178. || (minMessageId > IX_NPEMH_MAX_MESSAGE_ID))
  179. {
  180. IX_NPEMH_ERROR_REPORT ("Min message ID is out of range\n");
  181. return IX_FAIL;
  182. }
  183. /* check the maxMessageId parameter */
  184. if ((maxMessageId < IX_NPEMH_MIN_MESSAGE_ID)
  185. || (maxMessageId > IX_NPEMH_MAX_MESSAGE_ID))
  186. {
  187. IX_NPEMH_ERROR_REPORT ("Max message ID is out of range\n");
  188. return IX_FAIL;
  189. }
  190. /* check the semantics of the message range parameters */
  191. if (minMessageId > maxMessageId)
  192. {
  193. IX_NPEMH_ERROR_REPORT ("Min message ID greater than max message "
  194. "ID\n");
  195. return IX_FAIL;
  196. }
  197. /* the unsolicitedCallback parameter is allowed to be NULL */
  198. /* parameters are ok ... */
  199. /* get the lock to prevent other clients from entering */
  200. ixNpeMhConfigLockGet (npeId);
  201. /* for each message ID in the range ... */
  202. for (messageId = minMessageId; messageId <= maxMessageId; messageId++)
  203. {
  204. /* save the unsolicited callback for the message ID */
  205. ixNpeMhUnsolicitedCbMgrCallbackSave (
  206. npeId, messageId, unsolicitedCallback);
  207. }
  208. /* release the lock to allow other clients back in */
  209. ixNpeMhConfigLockRelease (npeId);
  210. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  211. "ixNpeMhUnsolicitedCallbackForRangeRegister\n");
  212. return IX_SUCCESS;
  213. }
  214. /*
  215. * Function definition: ixNpeMhMessageSend
  216. */
  217. PUBLIC IX_STATUS ixNpeMhMessageSend (
  218. IxNpeMhNpeId npeId,
  219. IxNpeMhMessage message,
  220. UINT32 maxSendRetries)
  221. {
  222. IX_STATUS status = IX_SUCCESS;
  223. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  224. "ixNpeMhMessageSend\n");
  225. /* check that we are initialized */
  226. if (!ixNpeMhInitialized)
  227. {
  228. IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
  229. return IX_FAIL;
  230. }
  231. /* check the npeId parameter */
  232. if (!ixNpeMhConfigNpeIdIsValid (npeId))
  233. {
  234. IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
  235. return IX_FAIL;
  236. }
  237. /* parameters are ok ... */
  238. /* get the lock to prevent other clients from entering */
  239. ixNpeMhConfigLockGet (npeId);
  240. /* send the message */
  241. status = ixNpeMhSendMessageSend (npeId, message, maxSendRetries);
  242. if (status != IX_SUCCESS)
  243. {
  244. IX_NPEMH_ERROR_REPORT ("Failed to send message\n");
  245. }
  246. /* release the lock to allow other clients back in */
  247. ixNpeMhConfigLockRelease (npeId);
  248. IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  249. "ixNpeMhMessageSend"
  250. " : status = %d\n", status);
  251. return status;
  252. }
  253. /*
  254. * Function definition: ixNpeMhMessageWithResponseSend
  255. */
  256. PUBLIC IX_STATUS ixNpeMhMessageWithResponseSend (
  257. IxNpeMhNpeId npeId,
  258. IxNpeMhMessage message,
  259. IxNpeMhMessageId solicitedMessageId,
  260. IxNpeMhCallback solicitedCallback,
  261. UINT32 maxSendRetries)
  262. {
  263. IX_STATUS status = IX_SUCCESS;
  264. IxNpeMhCallback unsolicitedCallback = NULL;
  265. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  266. "ixNpeMhMessageWithResponseSend\n");
  267. /* check that we are initialized */
  268. if (!ixNpeMhInitialized)
  269. {
  270. IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
  271. return IX_FAIL;
  272. }
  273. /* the solicitecCallback parameter is allowed to be NULL. this */
  274. /* signifies the client is not interested in the response message */
  275. /* check the npeId parameter */
  276. if (!ixNpeMhConfigNpeIdIsValid (npeId))
  277. {
  278. IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
  279. return IX_FAIL;
  280. }
  281. /* check the solicitedMessageId parameter */
  282. if ((solicitedMessageId < IX_NPEMH_MIN_MESSAGE_ID)
  283. || (solicitedMessageId > IX_NPEMH_MAX_MESSAGE_ID))
  284. {
  285. IX_NPEMH_ERROR_REPORT ("Solicited message ID is out of range\n");
  286. return IX_FAIL;
  287. }
  288. /* check the solicitedMessageId parameter. if an unsolicited */
  289. /* callback has been registered for the specified message ID then */
  290. /* report an error and return failure */
  291. ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
  292. npeId, solicitedMessageId, &unsolicitedCallback);
  293. if (unsolicitedCallback != NULL)
  294. {
  295. IX_NPEMH_ERROR_REPORT ("Solicited message ID conflicts with "
  296. "unsolicited message ID\n");
  297. return IX_FAIL;
  298. }
  299. /* parameters are ok ... */
  300. /* get the lock to prevent other clients from entering */
  301. ixNpeMhConfigLockGet (npeId);
  302. /* send the message */
  303. status = ixNpeMhSendMessageWithResponseSend (
  304. npeId, message, solicitedMessageId, solicitedCallback,
  305. maxSendRetries);
  306. if (status != IX_SUCCESS)
  307. {
  308. IX_NPEMH_ERROR_REPORT ("Failed to send message\n");
  309. }
  310. /* release the lock to allow other clients back in */
  311. ixNpeMhConfigLockRelease (npeId);
  312. IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  313. "ixNpeMhMessageWithResponseSend"
  314. " : status = %d\n", status);
  315. return status;
  316. }
  317. /*
  318. * Function definition: ixNpeMhMessagesReceive
  319. */
  320. PUBLIC IX_STATUS ixNpeMhMessagesReceive (
  321. IxNpeMhNpeId npeId)
  322. {
  323. IX_STATUS status = IX_SUCCESS;
  324. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  325. "ixNpeMhMessagesReceive\n");
  326. /* check that we are initialized */
  327. if (!ixNpeMhInitialized)
  328. {
  329. IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
  330. return IX_FAIL;
  331. }
  332. /* check the npeId parameter */
  333. if (!ixNpeMhConfigNpeIdIsValid (npeId))
  334. {
  335. IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
  336. return IX_FAIL;
  337. }
  338. /* parameters are ok ... */
  339. /* get the lock to prevent other clients from entering */
  340. ixNpeMhConfigLockGet (npeId);
  341. /* receive messages from the NPE */
  342. status = ixNpeMhReceiveMessagesReceive (npeId);
  343. if (status != IX_SUCCESS)
  344. {
  345. IX_NPEMH_ERROR_REPORT ("Failed to receive message\n");
  346. }
  347. /* release the lock to allow other clients back in */
  348. ixNpeMhConfigLockRelease (npeId);
  349. IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  350. "ixNpeMhMessagesReceive"
  351. " : status = %d\n", status);
  352. return status;
  353. }
  354. /*
  355. * Function definition: ixNpeMhShow
  356. */
  357. PUBLIC IX_STATUS ixNpeMhShow (
  358. IxNpeMhNpeId npeId)
  359. {
  360. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  361. "ixNpeMhShow\n");
  362. /* check that we are initialized */
  363. if (!ixNpeMhInitialized)
  364. {
  365. IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
  366. return IX_FAIL;
  367. }
  368. /* check the npeId parameter */
  369. if (!ixNpeMhConfigNpeIdIsValid (npeId))
  370. {
  371. IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
  372. return IX_FAIL;
  373. }
  374. /* parameters are ok ... */
  375. /* note we don't get the lock here as printing the statistics */
  376. /* to a console may take some time and we don't want to impact */
  377. /* system performance. this means that the statistics displayed */
  378. /* may be in a state of flux and make not represent a consistent */
  379. /* snapshot. */
  380. /* display a header */
  381. ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT,
  382. "Current state of NPE ID %d:\n\n", npeId, 0, 0, 0, 0, 0);
  383. /* show the current state of each module */
  384. /* show the current state of the Configuration module */
  385. ixNpeMhConfigShow (npeId);
  386. /* show the current state of the Receive module */
  387. ixNpeMhReceiveShow (npeId);
  388. /* show the current state of the Send module */
  389. ixNpeMhSendShow (npeId);
  390. /* show the current state of the Solicited Callback Manager module */
  391. ixNpeMhSolicitedCbMgrShow (npeId);
  392. /* show the current state of the Unsolicited Callback Manager module */
  393. ixNpeMhUnsolicitedCbMgrShow (npeId);
  394. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  395. "ixNpeMhShow\n");
  396. return IX_SUCCESS;
  397. }
  398. /*
  399. * Function definition: ixNpeMhShowReset
  400. */
  401. PUBLIC IX_STATUS ixNpeMhShowReset (
  402. IxNpeMhNpeId npeId)
  403. {
  404. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
  405. "ixNpeMhShowReset\n");
  406. /* check that we are initialized */
  407. if (!ixNpeMhInitialized)
  408. {
  409. IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
  410. return IX_FAIL;
  411. }
  412. /* check the npeId parameter */
  413. if (!ixNpeMhConfigNpeIdIsValid (npeId))
  414. {
  415. IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
  416. return IX_FAIL;
  417. }
  418. /* parameters are ok ... */
  419. /* note we don't get the lock here as resetting the statistics */
  420. /* shouldn't impact system performance. */
  421. /* reset the current state of each module */
  422. /* reset the current state of the Configuration module */
  423. ixNpeMhConfigShowReset (npeId);
  424. /* reset the current state of the Receive module */
  425. ixNpeMhReceiveShowReset (npeId);
  426. /* reset the current state of the Send module */
  427. ixNpeMhSendShowReset (npeId);
  428. /* reset the current state of the Solicited Callback Manager module */
  429. ixNpeMhSolicitedCbMgrShowReset (npeId);
  430. /* reset the current state of the Unsolicited Callback Manager module */
  431. ixNpeMhUnsolicitedCbMgrShowReset (npeId);
  432. IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
  433. "ixNpeMhShowReset\n");
  434. return IX_SUCCESS;
  435. }