IxNpeMh.c 16 KB

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