4 * @author Intel Corporation
7 * @brief This file contains the implementation of the public API for the
8 * IXP425 NPE Message Handler component.
12 * IXP400 SW Release version 2.0
14 * -- Copyright Notice --
17 * Copyright 2001-2005, Intel Corporation.
18 * All rights reserved.
21 * SPDX-License-Identifier: BSD-3-Clause
23 * -- End of Copyright Notice --
27 * Put the system defined include files required.
31 * Put the user defined include files required.
35 #include "IxNpeMhMacros_p.h"
39 #include "IxNpeMhConfig_p.h"
40 #include "IxNpeMhReceive_p.h"
41 #include "IxNpeMhSend_p.h"
42 #include "IxNpeMhSolicitedCbMgr_p.h"
43 #include "IxNpeMhUnsolicitedCbMgr_p.h"
46 * #defines and macros used in this file.
50 * Typedefs whose scope is limited to this file.
54 * Variable declarations global to this file only. Externs are followed by
58 PRIVATE BOOL ixNpeMhInitialized = false;
61 * Extern function prototypes.
65 * Static function prototypes.
69 * Function definition: ixNpeMhInitialize
72 PUBLIC IX_STATUS ixNpeMhInitialize (
73 IxNpeMhNpeInterrupts npeInterrupts)
75 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
76 "ixNpeMhInitialize\n");
78 /* check the npeInterrupts parameter */
79 if ((npeInterrupts != IX_NPEMH_NPEINTERRUPTS_NO) &&
80 (npeInterrupts != IX_NPEMH_NPEINTERRUPTS_YES))
82 IX_NPEMH_ERROR_REPORT ("Illegal npeInterrupts parameter value\n");
86 /* parameters are ok ... */
88 /* initialize the Receive module */
89 ixNpeMhReceiveInitialize ();
91 /* initialize the Solicited Callback Manager module */
92 ixNpeMhSolicitedCbMgrInitialize ();
94 /* initialize the Unsolicited Callback Manager module */
95 ixNpeMhUnsolicitedCbMgrInitialize ();
97 /* initialize the Configuration module
99 * NOTE: This module was originally configured before the
100 * others, but the sequence was changed so that interrupts
101 * would only be enabled after the handler functions were
102 * set up. The above modules need to be initialised to
103 * handle the NPE interrupts. See SCR #2231.
105 ixNpeMhConfigInitialize (npeInterrupts);
107 ixNpeMhInitialized = true;
109 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
110 "ixNpeMhInitialize\n");
116 * Function definition: ixNpeMhUnload
119 PUBLIC IX_STATUS ixNpeMhUnload (void)
121 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
124 if (!ixNpeMhInitialized)
129 /* Uninitialize the Configuration module */
130 ixNpeMhConfigUninit ();
132 ixNpeMhInitialized = false;
134 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
142 * Function definition: ixNpeMhUnsolicitedCallbackRegister
145 PUBLIC IX_STATUS ixNpeMhUnsolicitedCallbackRegister (
147 IxNpeMhMessageId messageId,
148 IxNpeMhCallback unsolicitedCallback)
150 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
151 "ixNpeMhUnsolicitedCallbackRegister\n");
153 /* check that we are initialized */
154 if (!ixNpeMhInitialized)
156 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
160 /* check the npeId parameter */
161 if (!ixNpeMhConfigNpeIdIsValid (npeId))
163 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
167 /* check the messageId parameter */
168 if ((messageId < IX_NPEMH_MIN_MESSAGE_ID)
169 || (messageId > IX_NPEMH_MAX_MESSAGE_ID))
171 IX_NPEMH_ERROR_REPORT ("Message ID is out of range\n");
175 /* the unsolicitedCallback parameter is allowed to be NULL */
177 /* parameters are ok ... */
179 /* get the lock to prevent other clients from entering */
180 ixNpeMhConfigLockGet (npeId);
182 /* save the unsolicited callback for the message ID */
183 ixNpeMhUnsolicitedCbMgrCallbackSave (
184 npeId, messageId, unsolicitedCallback);
186 /* release the lock to allow other clients back in */
187 ixNpeMhConfigLockRelease (npeId);
189 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
190 "ixNpeMhUnsolicitedCallbackRegister\n");
196 * Function definition: ixNpeMhUnsolicitedCallbackForRangeRegister
199 PUBLIC IX_STATUS ixNpeMhUnsolicitedCallbackForRangeRegister (
201 IxNpeMhMessageId minMessageId,
202 IxNpeMhMessageId maxMessageId,
203 IxNpeMhCallback unsolicitedCallback)
205 IxNpeMhMessageId messageId;
207 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
208 "ixNpeMhUnsolicitedCallbackForRangeRegister\n");
210 /* check that we are initialized */
211 if (!ixNpeMhInitialized)
213 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
217 /* check the npeId parameter */
218 if (!ixNpeMhConfigNpeIdIsValid (npeId))
220 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
224 /* check the minMessageId parameter */
225 if ((minMessageId < IX_NPEMH_MIN_MESSAGE_ID)
226 || (minMessageId > IX_NPEMH_MAX_MESSAGE_ID))
228 IX_NPEMH_ERROR_REPORT ("Min message ID is out of range\n");
232 /* check the maxMessageId parameter */
233 if ((maxMessageId < IX_NPEMH_MIN_MESSAGE_ID)
234 || (maxMessageId > IX_NPEMH_MAX_MESSAGE_ID))
236 IX_NPEMH_ERROR_REPORT ("Max message ID is out of range\n");
240 /* check the semantics of the message range parameters */
241 if (minMessageId > maxMessageId)
243 IX_NPEMH_ERROR_REPORT ("Min message ID greater than max message "
248 /* the unsolicitedCallback parameter is allowed to be NULL */
250 /* parameters are ok ... */
252 /* get the lock to prevent other clients from entering */
253 ixNpeMhConfigLockGet (npeId);
255 /* for each message ID in the range ... */
256 for (messageId = minMessageId; messageId <= maxMessageId; messageId++)
258 /* save the unsolicited callback for the message ID */
259 ixNpeMhUnsolicitedCbMgrCallbackSave (
260 npeId, messageId, unsolicitedCallback);
263 /* release the lock to allow other clients back in */
264 ixNpeMhConfigLockRelease (npeId);
266 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
267 "ixNpeMhUnsolicitedCallbackForRangeRegister\n");
273 * Function definition: ixNpeMhMessageSend
276 PUBLIC IX_STATUS ixNpeMhMessageSend (
278 IxNpeMhMessage message,
279 UINT32 maxSendRetries)
281 IX_STATUS status = IX_SUCCESS;
283 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
284 "ixNpeMhMessageSend\n");
286 /* check that we are initialized */
287 if (!ixNpeMhInitialized)
289 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
293 /* check the npeId parameter */
294 if (!ixNpeMhConfigNpeIdIsValid (npeId))
296 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
300 /* parameters are ok ... */
302 /* get the lock to prevent other clients from entering */
303 ixNpeMhConfigLockGet (npeId);
305 /* send the message */
306 status = ixNpeMhSendMessageSend (npeId, message, maxSendRetries);
307 if (status != IX_SUCCESS)
309 IX_NPEMH_ERROR_REPORT ("Failed to send message\n");
312 /* release the lock to allow other clients back in */
313 ixNpeMhConfigLockRelease (npeId);
315 IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
317 " : status = %d\n", status);
323 * Function definition: ixNpeMhMessageWithResponseSend
326 PUBLIC IX_STATUS ixNpeMhMessageWithResponseSend (
328 IxNpeMhMessage message,
329 IxNpeMhMessageId solicitedMessageId,
330 IxNpeMhCallback solicitedCallback,
331 UINT32 maxSendRetries)
333 IX_STATUS status = IX_SUCCESS;
334 IxNpeMhCallback unsolicitedCallback = NULL;
336 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
337 "ixNpeMhMessageWithResponseSend\n");
339 /* check that we are initialized */
340 if (!ixNpeMhInitialized)
342 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
346 /* the solicitecCallback parameter is allowed to be NULL. this */
347 /* signifies the client is not interested in the response message */
349 /* check the npeId parameter */
350 if (!ixNpeMhConfigNpeIdIsValid (npeId))
352 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
356 /* check the solicitedMessageId parameter */
357 if ((solicitedMessageId < IX_NPEMH_MIN_MESSAGE_ID)
358 || (solicitedMessageId > IX_NPEMH_MAX_MESSAGE_ID))
360 IX_NPEMH_ERROR_REPORT ("Solicited message ID is out of range\n");
364 /* check the solicitedMessageId parameter. if an unsolicited */
365 /* callback has been registered for the specified message ID then */
366 /* report an error and return failure */
367 ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
368 npeId, solicitedMessageId, &unsolicitedCallback);
369 if (unsolicitedCallback != NULL)
371 IX_NPEMH_ERROR_REPORT ("Solicited message ID conflicts with "
372 "unsolicited message ID\n");
376 /* parameters are ok ... */
378 /* get the lock to prevent other clients from entering */
379 ixNpeMhConfigLockGet (npeId);
381 /* send the message */
382 status = ixNpeMhSendMessageWithResponseSend (
383 npeId, message, solicitedMessageId, solicitedCallback,
385 if (status != IX_SUCCESS)
387 IX_NPEMH_ERROR_REPORT ("Failed to send message\n");
390 /* release the lock to allow other clients back in */
391 ixNpeMhConfigLockRelease (npeId);
393 IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
394 "ixNpeMhMessageWithResponseSend"
395 " : status = %d\n", status);
401 * Function definition: ixNpeMhMessagesReceive
404 PUBLIC IX_STATUS ixNpeMhMessagesReceive (
407 IX_STATUS status = IX_SUCCESS;
409 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
410 "ixNpeMhMessagesReceive\n");
412 /* check that we are initialized */
413 if (!ixNpeMhInitialized)
415 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
419 /* check the npeId parameter */
420 if (!ixNpeMhConfigNpeIdIsValid (npeId))
422 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
426 /* parameters are ok ... */
428 /* get the lock to prevent other clients from entering */
429 ixNpeMhConfigLockGet (npeId);
431 /* receive messages from the NPE */
432 status = ixNpeMhReceiveMessagesReceive (npeId);
434 if (status != IX_SUCCESS)
436 IX_NPEMH_ERROR_REPORT ("Failed to receive message\n");
439 /* release the lock to allow other clients back in */
440 ixNpeMhConfigLockRelease (npeId);
442 IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
443 "ixNpeMhMessagesReceive"
444 " : status = %d\n", status);
450 * Function definition: ixNpeMhShow
453 PUBLIC IX_STATUS ixNpeMhShow (
456 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
459 /* check that we are initialized */
460 if (!ixNpeMhInitialized)
462 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
466 /* check the npeId parameter */
467 if (!ixNpeMhConfigNpeIdIsValid (npeId))
469 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
473 /* parameters are ok ... */
475 /* note we don't get the lock here as printing the statistics */
476 /* to a console may take some time and we don't want to impact */
477 /* system performance. this means that the statistics displayed */
478 /* may be in a state of flux and make not represent a consistent */
481 /* display a header */
482 ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT,
483 "Current state of NPE ID %d:\n\n", npeId, 0, 0, 0, 0, 0);
485 /* show the current state of each module */
487 /* show the current state of the Configuration module */
488 ixNpeMhConfigShow (npeId);
490 /* show the current state of the Receive module */
491 ixNpeMhReceiveShow (npeId);
493 /* show the current state of the Send module */
494 ixNpeMhSendShow (npeId);
496 /* show the current state of the Solicited Callback Manager module */
497 ixNpeMhSolicitedCbMgrShow (npeId);
499 /* show the current state of the Unsolicited Callback Manager module */
500 ixNpeMhUnsolicitedCbMgrShow (npeId);
502 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
509 * Function definition: ixNpeMhShowReset
512 PUBLIC IX_STATUS ixNpeMhShowReset (
515 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
516 "ixNpeMhShowReset\n");
518 /* check that we are initialized */
519 if (!ixNpeMhInitialized)
521 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
525 /* check the npeId parameter */
526 if (!ixNpeMhConfigNpeIdIsValid (npeId))
528 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
532 /* parameters are ok ... */
534 /* note we don't get the lock here as resetting the statistics */
535 /* shouldn't impact system performance. */
537 /* reset the current state of each module */
539 /* reset the current state of the Configuration module */
540 ixNpeMhConfigShowReset (npeId);
542 /* reset the current state of the Receive module */
543 ixNpeMhReceiveShowReset (npeId);
545 /* reset the current state of the Send module */
546 ixNpeMhSendShowReset (npeId);
548 /* reset the current state of the Solicited Callback Manager module */
549 ixNpeMhSolicitedCbMgrShowReset (npeId);
551 /* reset the current state of the Unsolicited Callback Manager module */
552 ixNpeMhUnsolicitedCbMgrShowReset (npeId);
554 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
555 "ixNpeMhShowReset\n");