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 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
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.
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
47 * -- End of Copyright Notice --
51 * Put the system defined include files required.
55 * Put the user defined include files required.
59 #include "IxNpeMhMacros_p.h"
63 #include "IxNpeMhConfig_p.h"
64 #include "IxNpeMhReceive_p.h"
65 #include "IxNpeMhSend_p.h"
66 #include "IxNpeMhSolicitedCbMgr_p.h"
67 #include "IxNpeMhUnsolicitedCbMgr_p.h"
70 * #defines and macros used in this file.
74 * Typedefs whose scope is limited to this file.
78 * Variable declarations global to this file only. Externs are followed by
82 PRIVATE BOOL ixNpeMhInitialized
= FALSE
;
85 * Extern function prototypes.
89 * Static function prototypes.
93 * Function definition: ixNpeMhInitialize
96 PUBLIC IX_STATUS
ixNpeMhInitialize (
97 IxNpeMhNpeInterrupts npeInterrupts
)
99 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Entering "
100 "ixNpeMhInitialize\n");
102 /* check the npeInterrupts parameter */
103 if ((npeInterrupts
!= IX_NPEMH_NPEINTERRUPTS_NO
) &&
104 (npeInterrupts
!= IX_NPEMH_NPEINTERRUPTS_YES
))
106 IX_NPEMH_ERROR_REPORT ("Illegal npeInterrupts parameter value\n");
110 /* parameters are ok ... */
112 /* initialize the Receive module */
113 ixNpeMhReceiveInitialize ();
115 /* initialize the Solicited Callback Manager module */
116 ixNpeMhSolicitedCbMgrInitialize ();
118 /* initialize the Unsolicited Callback Manager module */
119 ixNpeMhUnsolicitedCbMgrInitialize ();
121 /* initialize the Configuration module
123 * NOTE: This module was originally configured before the
124 * others, but the sequence was changed so that interrupts
125 * would only be enabled after the handler functions were
126 * set up. The above modules need to be initialised to
127 * handle the NPE interrupts. See SCR #2231.
129 ixNpeMhConfigInitialize (npeInterrupts
);
131 ixNpeMhInitialized
= TRUE
;
133 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Exiting "
134 "ixNpeMhInitialize\n");
140 * Function definition: ixNpeMhUnload
143 PUBLIC IX_STATUS
ixNpeMhUnload (void)
145 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Entering "
148 if (!ixNpeMhInitialized
)
153 /* Uninitialize the Configuration module */
154 ixNpeMhConfigUninit ();
156 ixNpeMhInitialized
= FALSE
;
158 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Exiting "
166 * Function definition: ixNpeMhUnsolicitedCallbackRegister
169 PUBLIC IX_STATUS
ixNpeMhUnsolicitedCallbackRegister (
171 IxNpeMhMessageId messageId
,
172 IxNpeMhCallback unsolicitedCallback
)
174 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Entering "
175 "ixNpeMhUnsolicitedCallbackRegister\n");
177 /* check that we are initialized */
178 if (!ixNpeMhInitialized
)
180 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
184 /* check the npeId parameter */
185 if (!ixNpeMhConfigNpeIdIsValid (npeId
))
187 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
191 /* check the messageId parameter */
192 if ((messageId
< IX_NPEMH_MIN_MESSAGE_ID
)
193 || (messageId
> IX_NPEMH_MAX_MESSAGE_ID
))
195 IX_NPEMH_ERROR_REPORT ("Message ID is out of range\n");
199 /* the unsolicitedCallback parameter is allowed to be NULL */
201 /* parameters are ok ... */
203 /* get the lock to prevent other clients from entering */
204 ixNpeMhConfigLockGet (npeId
);
206 /* save the unsolicited callback for the message ID */
207 ixNpeMhUnsolicitedCbMgrCallbackSave (
208 npeId
, messageId
, unsolicitedCallback
);
210 /* release the lock to allow other clients back in */
211 ixNpeMhConfigLockRelease (npeId
);
213 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Exiting "
214 "ixNpeMhUnsolicitedCallbackRegister\n");
220 * Function definition: ixNpeMhUnsolicitedCallbackForRangeRegister
223 PUBLIC IX_STATUS
ixNpeMhUnsolicitedCallbackForRangeRegister (
225 IxNpeMhMessageId minMessageId
,
226 IxNpeMhMessageId maxMessageId
,
227 IxNpeMhCallback unsolicitedCallback
)
229 IxNpeMhMessageId messageId
;
231 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Entering "
232 "ixNpeMhUnsolicitedCallbackForRangeRegister\n");
234 /* check that we are initialized */
235 if (!ixNpeMhInitialized
)
237 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
241 /* check the npeId parameter */
242 if (!ixNpeMhConfigNpeIdIsValid (npeId
))
244 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
248 /* check the minMessageId parameter */
249 if ((minMessageId
< IX_NPEMH_MIN_MESSAGE_ID
)
250 || (minMessageId
> IX_NPEMH_MAX_MESSAGE_ID
))
252 IX_NPEMH_ERROR_REPORT ("Min message ID is out of range\n");
256 /* check the maxMessageId parameter */
257 if ((maxMessageId
< IX_NPEMH_MIN_MESSAGE_ID
)
258 || (maxMessageId
> IX_NPEMH_MAX_MESSAGE_ID
))
260 IX_NPEMH_ERROR_REPORT ("Max message ID is out of range\n");
264 /* check the semantics of the message range parameters */
265 if (minMessageId
> maxMessageId
)
267 IX_NPEMH_ERROR_REPORT ("Min message ID greater than max message "
272 /* the unsolicitedCallback parameter is allowed to be NULL */
274 /* parameters are ok ... */
276 /* get the lock to prevent other clients from entering */
277 ixNpeMhConfigLockGet (npeId
);
279 /* for each message ID in the range ... */
280 for (messageId
= minMessageId
; messageId
<= maxMessageId
; messageId
++)
282 /* save the unsolicited callback for the message ID */
283 ixNpeMhUnsolicitedCbMgrCallbackSave (
284 npeId
, messageId
, unsolicitedCallback
);
287 /* release the lock to allow other clients back in */
288 ixNpeMhConfigLockRelease (npeId
);
290 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Exiting "
291 "ixNpeMhUnsolicitedCallbackForRangeRegister\n");
297 * Function definition: ixNpeMhMessageSend
300 PUBLIC IX_STATUS
ixNpeMhMessageSend (
302 IxNpeMhMessage message
,
303 UINT32 maxSendRetries
)
305 IX_STATUS status
= IX_SUCCESS
;
307 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Entering "
308 "ixNpeMhMessageSend\n");
310 /* check that we are initialized */
311 if (!ixNpeMhInitialized
)
313 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
317 /* check the npeId parameter */
318 if (!ixNpeMhConfigNpeIdIsValid (npeId
))
320 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
324 /* parameters are ok ... */
326 /* get the lock to prevent other clients from entering */
327 ixNpeMhConfigLockGet (npeId
);
329 /* send the message */
330 status
= ixNpeMhSendMessageSend (npeId
, message
, maxSendRetries
);
331 if (status
!= IX_SUCCESS
)
333 IX_NPEMH_ERROR_REPORT ("Failed to send message\n");
336 /* release the lock to allow other clients back in */
337 ixNpeMhConfigLockRelease (npeId
);
339 IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT
, "Exiting "
341 " : status = %d\n", status
);
347 * Function definition: ixNpeMhMessageWithResponseSend
350 PUBLIC IX_STATUS
ixNpeMhMessageWithResponseSend (
352 IxNpeMhMessage message
,
353 IxNpeMhMessageId solicitedMessageId
,
354 IxNpeMhCallback solicitedCallback
,
355 UINT32 maxSendRetries
)
357 IX_STATUS status
= IX_SUCCESS
;
358 IxNpeMhCallback unsolicitedCallback
= NULL
;
360 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Entering "
361 "ixNpeMhMessageWithResponseSend\n");
363 /* check that we are initialized */
364 if (!ixNpeMhInitialized
)
366 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
370 /* the solicitecCallback parameter is allowed to be NULL. this */
371 /* signifies the client is not interested in the response message */
373 /* check the npeId parameter */
374 if (!ixNpeMhConfigNpeIdIsValid (npeId
))
376 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
380 /* check the solicitedMessageId parameter */
381 if ((solicitedMessageId
< IX_NPEMH_MIN_MESSAGE_ID
)
382 || (solicitedMessageId
> IX_NPEMH_MAX_MESSAGE_ID
))
384 IX_NPEMH_ERROR_REPORT ("Solicited message ID is out of range\n");
388 /* check the solicitedMessageId parameter. if an unsolicited */
389 /* callback has been registered for the specified message ID then */
390 /* report an error and return failure */
391 ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
392 npeId
, solicitedMessageId
, &unsolicitedCallback
);
393 if (unsolicitedCallback
!= NULL
)
395 IX_NPEMH_ERROR_REPORT ("Solicited message ID conflicts with "
396 "unsolicited message ID\n");
400 /* parameters are ok ... */
402 /* get the lock to prevent other clients from entering */
403 ixNpeMhConfigLockGet (npeId
);
405 /* send the message */
406 status
= ixNpeMhSendMessageWithResponseSend (
407 npeId
, message
, solicitedMessageId
, solicitedCallback
,
409 if (status
!= IX_SUCCESS
)
411 IX_NPEMH_ERROR_REPORT ("Failed to send message\n");
414 /* release the lock to allow other clients back in */
415 ixNpeMhConfigLockRelease (npeId
);
417 IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT
, "Exiting "
418 "ixNpeMhMessageWithResponseSend"
419 " : status = %d\n", status
);
425 * Function definition: ixNpeMhMessagesReceive
428 PUBLIC IX_STATUS
ixNpeMhMessagesReceive (
431 IX_STATUS status
= IX_SUCCESS
;
433 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Entering "
434 "ixNpeMhMessagesReceive\n");
436 /* check that we are initialized */
437 if (!ixNpeMhInitialized
)
439 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
443 /* check the npeId parameter */
444 if (!ixNpeMhConfigNpeIdIsValid (npeId
))
446 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
450 /* parameters are ok ... */
452 /* get the lock to prevent other clients from entering */
453 ixNpeMhConfigLockGet (npeId
);
455 /* receive messages from the NPE */
456 status
= ixNpeMhReceiveMessagesReceive (npeId
);
458 if (status
!= IX_SUCCESS
)
460 IX_NPEMH_ERROR_REPORT ("Failed to receive message\n");
463 /* release the lock to allow other clients back in */
464 ixNpeMhConfigLockRelease (npeId
);
466 IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT
, "Exiting "
467 "ixNpeMhMessagesReceive"
468 " : status = %d\n", status
);
474 * Function definition: ixNpeMhShow
477 PUBLIC IX_STATUS
ixNpeMhShow (
480 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Entering "
483 /* check that we are initialized */
484 if (!ixNpeMhInitialized
)
486 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
490 /* check the npeId parameter */
491 if (!ixNpeMhConfigNpeIdIsValid (npeId
))
493 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
497 /* parameters are ok ... */
499 /* note we don't get the lock here as printing the statistics */
500 /* to a console may take some time and we don't want to impact */
501 /* system performance. this means that the statistics displayed */
502 /* may be in a state of flux and make not represent a consistent */
505 /* display a header */
506 ixOsalLog (IX_OSAL_LOG_LVL_USER
, IX_OSAL_LOG_DEV_STDOUT
,
507 "Current state of NPE ID %d:\n\n", npeId
, 0, 0, 0, 0, 0);
509 /* show the current state of each module */
511 /* show the current state of the Configuration module */
512 ixNpeMhConfigShow (npeId
);
514 /* show the current state of the Receive module */
515 ixNpeMhReceiveShow (npeId
);
517 /* show the current state of the Send module */
518 ixNpeMhSendShow (npeId
);
520 /* show the current state of the Solicited Callback Manager module */
521 ixNpeMhSolicitedCbMgrShow (npeId
);
523 /* show the current state of the Unsolicited Callback Manager module */
524 ixNpeMhUnsolicitedCbMgrShow (npeId
);
526 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Exiting "
533 * Function definition: ixNpeMhShowReset
536 PUBLIC IX_STATUS
ixNpeMhShowReset (
539 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Entering "
540 "ixNpeMhShowReset\n");
542 /* check that we are initialized */
543 if (!ixNpeMhInitialized
)
545 IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
549 /* check the npeId parameter */
550 if (!ixNpeMhConfigNpeIdIsValid (npeId
))
552 IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
556 /* parameters are ok ... */
558 /* note we don't get the lock here as resetting the statistics */
559 /* shouldn't impact system performance. */
561 /* reset the current state of each module */
563 /* reset the current state of the Configuration module */
564 ixNpeMhConfigShowReset (npeId
);
566 /* reset the current state of the Receive module */
567 ixNpeMhReceiveShowReset (npeId
);
569 /* reset the current state of the Send module */
570 ixNpeMhSendShowReset (npeId
);
572 /* reset the current state of the Solicited Callback Manager module */
573 ixNpeMhSolicitedCbMgrShowReset (npeId
);
575 /* reset the current state of the Unsolicited Callback Manager module */
576 ixNpeMhUnsolicitedCbMgrShowReset (npeId
);
578 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT
, "Exiting "
579 "ixNpeMhShowReset\n");