source: SVN/cambria/redboot/packages/devs/eth/intel/npe/npeMh/current/src/IxNpeMh.c @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 16.3 KB
Line 
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 * IXP NPE Message Handler component.
9 *
10 *
11 * @par
12 * IXP400 SW Release version 2.3
13 *
14 * -- Copyright Notice --
15 *
16 * @par
17 * Copyright (c) 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 *
34 * @par
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
36 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 *
47 *
48 * @par
49 * -- End of Copyright Notice --
50*/
51
52/*
53 * Put the system defined include files required.
54 */
55
56/*
57 * Put the user defined include files required.
58 */
59
60#include "IxOsal.h"
61#include "IxNpeMhMacros_p.h"
62
63#include "IxNpeMh.h"
64
65#include "IxNpeMhConfig_p.h"
66#include "IxNpeMhReceive_p.h"
67#include "IxNpeMhSend_p.h"
68#include "IxNpeMhSolicitedCbMgr_p.h"
69#include "IxNpeMhUnsolicitedCbMgr_p.h"
70
71/*
72 * #defines and macros used in this file.
73 */
74
75/*
76 * Typedefs whose scope is limited to this file.
77 */
78
79/*
80 * Variable declarations global to this file only.  Externs are followed by
81 * static variables.
82 */
83
84PRIVATE BOOL ixNpeMhInitialized = FALSE;
85
86/*
87 * Extern function prototypes.
88 */
89
90/*
91 * Static function prototypes.
92 */
93
94/*
95 * Function definition: ixNpeMhInitialize
96 */
97
98PUBLIC IX_STATUS ixNpeMhInitialize (
99    IxNpeMhNpeInterrupts npeInterrupts)
100{
101    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
102                     "ixNpeMhInitialize\n");
103
104    /* check the npeInterrupts parameter */
105    if ((npeInterrupts != IX_NPEMH_NPEINTERRUPTS_NO) &&
106        (npeInterrupts != IX_NPEMH_NPEINTERRUPTS_YES))
107    {
108        IX_NPEMH_ERROR_REPORT ("Illegal npeInterrupts parameter value\n");
109        return IX_FAIL;
110    }
111
112    /* parameters are ok ... */
113
114    /* initialize the Receive module */
115    ixNpeMhReceiveInitialize ();
116
117    /* initialize the Solicited Callback Manager module */
118    ixNpeMhSolicitedCbMgrInitialize ();
119
120    /* initialize the Unsolicited Callback Manager module */
121    ixNpeMhUnsolicitedCbMgrInitialize ();
122
123    /* initialize the Configuration module
124     *
125     * NOTE: This module was originally configured before the
126     * others, but the sequence was changed so that interrupts
127     * would only be enabled after the handler functions were
128     * set up.  The above modules need to be initialised to
129     * handle the NPE interrupts.  See SCR #2231.
130     */
131    ixNpeMhConfigInitialize (npeInterrupts);
132
133    ixNpeMhInitialized = TRUE;
134
135    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
136                     "ixNpeMhInitialize\n");
137
138    return IX_SUCCESS;
139}
140
141/*
142 * Function definition: ixNpeMhUnload
143 */
144
145PUBLIC IX_STATUS ixNpeMhUnload (void)
146{
147    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
148                     "ixNpeMhUnload\n");
149
150    if (!ixNpeMhInitialized)
151    {
152        return IX_FAIL;
153    }
154
155    /* Uninitialize the Configuration module */
156    ixNpeMhConfigUninit ();
157    /* Reset the NpeMhShow */
158    ixNpeMhShowReset (IX_NPEMH_NPEID_NPEA);
159    ixNpeMhShowReset (IX_NPEMH_NPEID_NPEB);
160#if defined(__ixp42X) || defined(__ixp46X) || defined(__ixp43X)
161    ixNpeMhShowReset (IX_NPEMH_NPEID_NPEC);
162#endif
163
164    ixNpeMhUnsolicitedCbMgrUninitialize ();
165    ixNpeMhSolicitedCbMgrUninitialize ();
166    ixNpeMhReceiveUninitialize ();
167    ixNpeMhInitialized = FALSE;
168
169    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
170                     "ixNpeMhUnload\n");
171
172    return IX_SUCCESS;
173}
174
175
176/*
177 * Function definition: ixNpeMhUnsolicitedCallbackRegister
178 */
179
180PUBLIC IX_STATUS ixNpeMhUnsolicitedCallbackRegister (
181    IxNpeMhNpeId npeId,
182    IxNpeMhMessageId messageId,
183    IxNpeMhCallback unsolicitedCallback)
184{
185    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
186                     "ixNpeMhUnsolicitedCallbackRegister\n");
187
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
195    /* check the npeId parameter */
196    if (!ixNpeMhConfigNpeIdIsValid (npeId))
197    {
198        IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
199        return IX_FAIL;
200    }
201
202    /* check the messageId parameter */
203    if ((messageId < IX_NPEMH_MIN_MESSAGE_ID)
204        || (messageId > IX_NPEMH_MAX_MESSAGE_ID))
205    {
206        IX_NPEMH_ERROR_REPORT ("Message ID is out of range\n");
207        return IX_FAIL;
208    }
209
210    /* the unsolicitedCallback parameter is allowed to be NULL */
211
212    /* parameters are ok ... */
213
214    /* get the lock to prevent other clients from entering */
215    ixNpeMhConfigLockGet (npeId);
216
217    /* save the unsolicited callback for the message ID */
218    ixNpeMhUnsolicitedCbMgrCallbackSave (
219        npeId, messageId, unsolicitedCallback);
220
221    /* release the lock to allow other clients back in */
222    ixNpeMhConfigLockRelease (npeId);
223
224    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
225                     "ixNpeMhUnsolicitedCallbackRegister\n");
226
227    return IX_SUCCESS;
228}
229
230/*
231 * Function definition: ixNpeMhUnsolicitedCallbackForRangeRegister
232 */
233
234PUBLIC IX_STATUS ixNpeMhUnsolicitedCallbackForRangeRegister (
235    IxNpeMhNpeId npeId,
236    IxNpeMhMessageId minMessageId,
237    IxNpeMhMessageId maxMessageId,
238    IxNpeMhCallback unsolicitedCallback)
239{
240    IxNpeMhMessageId messageId;
241
242    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
243                     "ixNpeMhUnsolicitedCallbackForRangeRegister\n");
244
245    /* check that we are initialized */
246    if (!ixNpeMhInitialized)
247    {
248        IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
249        return IX_FAIL;
250    }
251
252    /* check the npeId parameter */
253    if (!ixNpeMhConfigNpeIdIsValid (npeId))
254    {
255        IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
256        return IX_FAIL;
257    }
258
259    /* check the minMessageId parameter */
260    if ((minMessageId < IX_NPEMH_MIN_MESSAGE_ID)
261        || (minMessageId > IX_NPEMH_MAX_MESSAGE_ID))
262    {
263        IX_NPEMH_ERROR_REPORT ("Min message ID is out of range\n");
264        return IX_FAIL;
265    }
266
267    /* check the maxMessageId parameter */
268    if ((maxMessageId < IX_NPEMH_MIN_MESSAGE_ID)
269        || (maxMessageId > IX_NPEMH_MAX_MESSAGE_ID))
270    {
271        IX_NPEMH_ERROR_REPORT ("Max message ID is out of range\n");
272        return IX_FAIL;
273    }
274
275    /* check the semantics of the message range parameters */
276    if (minMessageId > maxMessageId)
277    {
278        IX_NPEMH_ERROR_REPORT ("Min message ID greater than max message "
279                               "ID\n");
280        return IX_FAIL;
281    }
282
283    /* the unsolicitedCallback parameter is allowed to be NULL */
284
285    /* parameters are ok ... */
286
287    /* get the lock to prevent other clients from entering */
288    ixNpeMhConfigLockGet (npeId);
289
290    /* for each message ID in the range ... */
291    for (messageId = minMessageId; messageId <= maxMessageId; messageId++)
292    {
293        /* save the unsolicited callback for the message ID */
294        ixNpeMhUnsolicitedCbMgrCallbackSave (
295            npeId, messageId, unsolicitedCallback);
296    }
297
298    /* release the lock to allow other clients back in */
299    ixNpeMhConfigLockRelease (npeId);
300
301    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
302                     "ixNpeMhUnsolicitedCallbackForRangeRegister\n");
303
304    return IX_SUCCESS;
305}
306
307/*
308 * Function definition: ixNpeMhMessageSend
309 */
310
311PUBLIC IX_STATUS ixNpeMhMessageSend (
312    IxNpeMhNpeId npeId,
313    IxNpeMhMessage message,
314    UINT32 maxSendRetries)
315{
316    IX_STATUS status = IX_SUCCESS;
317
318    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
319                     "ixNpeMhMessageSend\n");
320
321    /* check that we are initialized */
322    if (!ixNpeMhInitialized)
323    {
324        IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
325        return IX_FAIL;
326    }
327
328    /* check the npeId parameter */
329    if (!ixNpeMhConfigNpeIdIsValid (npeId))
330    {
331        IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
332        return IX_FAIL;
333    }
334
335    /* parameters are ok ... */
336
337    /* get the lock to prevent other clients from entering */
338    ixNpeMhConfigLockGet (npeId);
339
340    /* send the message */
341    status = ixNpeMhSendMessageSend (npeId, message, maxSendRetries);
342    if (status != IX_SUCCESS)
343    {
344        IX_NPEMH_ERROR_REPORT ("Failed to send message\n");
345    }
346
347    /* release the lock to allow other clients back in */
348    ixNpeMhConfigLockRelease (npeId);
349
350    IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
351                     "ixNpeMhMessageSend"
352                     " : status = %d\n", status);
353
354    return status;
355}
356
357/*
358 * Function definition: ixNpeMhMessageWithResponseSend
359 */
360
361PUBLIC IX_STATUS ixNpeMhMessageWithResponseSend (
362    IxNpeMhNpeId npeId,
363    IxNpeMhMessage message,
364    IxNpeMhMessageId solicitedMessageId,
365    IxNpeMhCallback solicitedCallback,
366    UINT32 maxSendRetries)
367{
368    IX_STATUS status = IX_SUCCESS;
369    IxNpeMhCallback unsolicitedCallback = NULL;
370
371    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
372                     "ixNpeMhMessageWithResponseSend\n");
373
374    /* check that we are initialized */
375    if (!ixNpeMhInitialized)
376    {
377        IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
378        return IX_FAIL;
379    }
380
381    /* the solicitecCallback parameter is allowed to be NULL.  this */
382    /* signifies the client is not interested in the response message */
383
384    /* check the npeId parameter */
385    if (!ixNpeMhConfigNpeIdIsValid (npeId))
386    {
387        IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
388        return IX_FAIL;
389    }
390
391    /* check the solicitedMessageId parameter */
392    if ((solicitedMessageId < IX_NPEMH_MIN_MESSAGE_ID)
393        || (solicitedMessageId > IX_NPEMH_MAX_MESSAGE_ID))
394    {
395        IX_NPEMH_ERROR_REPORT ("Solicited message ID is out of range\n");
396        return IX_FAIL;
397    }
398
399    /* check the solicitedMessageId parameter.  if an unsolicited */
400    /* callback has been registered for the specified message ID then */
401    /* report an error and return failure */
402    ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
403        npeId, solicitedMessageId, &unsolicitedCallback);
404    if (unsolicitedCallback != NULL)
405    {
406        IX_NPEMH_ERROR_REPORT ("Solicited message ID conflicts with "
407                               "unsolicited message ID\n");
408        return IX_FAIL;
409    }
410
411    /* parameters are ok ... */
412
413    /* get the lock to prevent other clients from entering */
414    ixNpeMhConfigLockGet (npeId);
415
416    /* send the message */
417    status = ixNpeMhSendMessageWithResponseSend (
418        npeId, message, solicitedMessageId, solicitedCallback,
419        maxSendRetries);
420    if (status != IX_SUCCESS)
421    {
422        IX_NPEMH_ERROR_REPORT ("Failed to send message\n");
423    }
424
425    /* release the lock to allow other clients back in */
426    ixNpeMhConfigLockRelease (npeId);
427
428    IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
429                     "ixNpeMhMessageWithResponseSend"
430                     " : status = %d\n", status);
431
432    return status;
433}
434
435/*
436 * Function definition: ixNpeMhMessagesReceive
437 */
438
439PUBLIC IX_STATUS ixNpeMhMessagesReceive (
440    IxNpeMhNpeId npeId)
441{
442    IX_STATUS status = IX_SUCCESS;
443   
444    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
445                     "ixNpeMhMessagesReceive\n");
446
447    /* check that we are initialized */
448    if (!ixNpeMhInitialized)
449    {
450        IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT,"IxNpeMh component is not initialized\n");
451        return IX_FAIL;
452    }
453
454    /* check the npeId parameter */
455    if (!ixNpeMhConfigNpeIdIsValid (npeId))
456    {
457        IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
458        return IX_FAIL;
459    }
460
461    /* parameters are ok ... */
462
463    /* get the lock to prevent other clients from entering */
464    ixNpeMhConfigLockGet (npeId);
465
466    /* receive messages from the NPE */
467    status = ixNpeMhReceiveMessagesReceive (npeId);
468   
469    if (status != IX_SUCCESS)
470    {
471        IX_NPEMH_ERROR_REPORT ("Failed to receive message\n");
472    }
473
474    /* release the lock to allow other clients back in */
475    ixNpeMhConfigLockRelease (npeId);
476
477    IX_NPEMH_TRACE1 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
478                     "ixNpeMhMessagesReceive"
479                     " : status = %d\n", status);
480
481    return status;
482}
483
484/*
485 * Function definition: ixNpeMhShow
486 */
487
488PUBLIC IX_STATUS ixNpeMhShow (
489    IxNpeMhNpeId npeId)
490{
491    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
492                     "ixNpeMhShow\n");
493
494    /* check that we are initialized */
495    if (!ixNpeMhInitialized)
496    {
497        IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
498        return IX_FAIL;
499    }
500
501    /* check the npeId parameter */
502    if (!ixNpeMhConfigNpeIdIsValid (npeId))
503    {
504        IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
505        return IX_FAIL;
506    }
507
508    /* parameters are ok ... */
509
510    /* note we don't get the lock here as printing the statistics */
511    /* to a console may take some time and we don't want to impact */
512    /* system performance.  this means that the statistics displayed */
513    /* may be in a state of flux and make not represent a consistent */
514    /* snapshot. */
515
516    /* display a header */
517    ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT,
518               "Current state of NPE ID %d:\n\n", npeId, 0, 0, 0, 0, 0);
519
520    /* show the current state of each module */
521
522    /* show the current state of the Configuration module */
523    ixNpeMhConfigShow (npeId);
524
525    /* show the current state of the Receive module */
526    ixNpeMhReceiveShow (npeId);
527
528    /* show the current state of the Send module */
529    ixNpeMhSendShow (npeId);
530
531    /* show the current state of the Solicited Callback Manager module */
532    ixNpeMhSolicitedCbMgrShow (npeId);
533
534    /* show the current state of the Unsolicited Callback Manager module */
535    ixNpeMhUnsolicitedCbMgrShow (npeId);
536
537    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
538                     "ixNpeMhShow\n");
539
540    return IX_SUCCESS;
541}
542
543/*
544 * Function definition: ixNpeMhShowReset
545 */
546
547PUBLIC IX_STATUS ixNpeMhShowReset (
548    IxNpeMhNpeId npeId)
549{
550    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
551                     "ixNpeMhShowReset\n");
552
553    /* check that we are initialized */
554    if (!ixNpeMhInitialized)
555    {
556        IX_NPEMH_ERROR_REPORT ("IxNpeMh component is not initialized\n");
557        return IX_FAIL;
558    }
559
560    /* check the npeId parameter */
561    if (!ixNpeMhConfigNpeIdIsValid (npeId))
562    {
563        IX_NPEMH_ERROR_REPORT ("NPE ID invalid\n");
564        return IX_FAIL;
565    }
566
567    /* parameters are ok ... */
568
569    /* note we don't get the lock here as resetting the statistics */
570    /* shouldn't impact system performance. */
571
572    /* reset the current state of each module */
573
574    /* reset the current state of the Configuration module */
575    ixNpeMhConfigShowReset (npeId);
576
577    /* reset the current state of the Receive module */
578    ixNpeMhReceiveShowReset (npeId);
579
580    /* reset the current state of the Send module */
581    ixNpeMhSendShowReset (npeId);
582
583    /* reset the current state of the Solicited Callback Manager module */
584    ixNpeMhSolicitedCbMgrShowReset (npeId);
585
586    /* reset the current state of the Unsolicited Callback Manager module */
587    ixNpeMhUnsolicitedCbMgrShowReset (npeId);
588
589    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
590                     "ixNpeMhShowReset\n");
591
592    return IX_SUCCESS;
593}
Note: See TracBrowser for help on using the repository browser.