2 * @file IxNpeMhUnsolicitedCbMgr.c
4 * @author Intel Corporation
7 * @brief This file contains the implementation of the private API for
8 * the Unsolicited Callback Manager module.
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.
56 * Put the user defined include files required.
60 #include "IxNpeMhMacros_p.h"
62 #include "IxNpeMhUnsolicitedCbMgr_p.h"
66 * #defines and macros used in this file.
70 * Typedefs whose scope is limited to this file.
74 * @struct IxNpeMhUnsolicitedCallbackTable
76 * @brief This structure is used to maintain the list of registered
77 * callbacks. One entry exists for each message ID, and a NULL entry will
78 * signify that no callback has been registered for that ID.
83 /** array of entries */
84 IxNpeMhCallback entries[IX_NPEMH_MAX_MESSAGE_ID + 1];
85 } IxNpeMhUnsolicitedCallbackTable;
88 * @struct IxNpeMhUnsolicitedCbMgrStats
90 * @brief This structure is used to maintain statistics for the Unsolicited
91 * Callback Manager module.
96 UINT32 saves; /**< callback table saves */
97 UINT32 overwrites; /**< callback table overwrites */
98 } IxNpeMhUnsolicitedCbMgrStats;
101 * Variable declarations global to this file only. Externs are followed by
105 PRIVATE IxNpeMhUnsolicitedCallbackTable
106 ixNpeMhUnsolicitedCallbackTables[IX_NPEMH_NUM_NPES];
108 PRIVATE IxNpeMhUnsolicitedCbMgrStats
109 ixNpeMhUnsolicitedCbMgrStats[IX_NPEMH_NUM_NPES];
112 * Extern function prototypes.
116 * Static function prototypes.
120 * Function definition: ixNpeMhUnsolicitedCbMgrInitialize
123 void ixNpeMhUnsolicitedCbMgrInitialize (void)
125 IxNpeMhNpeId npeId = 0;
126 IxNpeMhUnsolicitedCallbackTable *table = NULL;
127 IxNpeMhMessageId messageId = 0;
129 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
130 "ixNpeMhUnsolicitedCbMgrInitialize\n");
132 /* for each NPE ... */
133 for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
135 /* initialise a pointer to the table for convenience */
136 table = &ixNpeMhUnsolicitedCallbackTables[npeId];
138 /* for each message ID ... */
139 for (messageId = IX_NPEMH_MIN_MESSAGE_ID;
140 messageId <= IX_NPEMH_MAX_MESSAGE_ID; messageId++)
142 /* initialise the callback for this message ID to NULL */
143 table->entries[messageId] = NULL;
147 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
148 "ixNpeMhUnsolicitedCbMgrInitialize\n");
152 * Function definition: ixNpeMhUnsolicitedCbMgrCallbackSave
155 void ixNpeMhUnsolicitedCbMgrCallbackSave (
157 IxNpeMhMessageId unsolicitedMessageId,
158 IxNpeMhCallback unsolicitedCallback)
160 IxNpeMhUnsolicitedCallbackTable *table = NULL;
162 /* initialise a pointer to the table for convenience */
163 table = &ixNpeMhUnsolicitedCallbackTables[npeId];
165 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
166 "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
168 /* update statistical info */
169 ixNpeMhUnsolicitedCbMgrStats[npeId].saves++;
171 /* check if there is a callback already registered for this NPE and */
173 if (table->entries[unsolicitedMessageId] != NULL)
175 /* if we are overwriting an existing callback */
176 if (unsolicitedCallback != NULL)
178 IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "Unsolicited callback "
179 "overwriting existing callback for NPE ID %d "
180 "message ID 0x%02X\n", npeId, unsolicitedMessageId);
182 else /* if we are clearing an existing callback */
184 IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "NULL unsolicited callback "
185 "clearing existing callback for NPE ID %d "
186 "message ID 0x%02X\n", npeId, unsolicitedMessageId);
189 /* update statistical info */
190 ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites++;
193 /* save the callback into the table */
194 table->entries[unsolicitedMessageId] = unsolicitedCallback;
196 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
197 "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
201 * Function definition: ixNpeMhUnsolicitedCbMgrCallbackRetrieve
204 void ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
206 IxNpeMhMessageId unsolicitedMessageId,
207 IxNpeMhCallback *unsolicitedCallback)
209 IxNpeMhUnsolicitedCallbackTable *table = NULL;
211 /* initialise a pointer to the table for convenience */
212 table = &ixNpeMhUnsolicitedCallbackTables[npeId];
214 /* retrieve the callback from the table */
215 *unsolicitedCallback = table->entries[unsolicitedMessageId];
219 * Function definition: ixNpeMhUnsolicitedCbMgrShow
222 void ixNpeMhUnsolicitedCbMgrShow (
225 /* show the unsolicited callback table save counter */
226 IX_NPEMH_SHOW ("Unsolicited callback table saves",
227 ixNpeMhUnsolicitedCbMgrStats[npeId].saves);
229 /* show the unsolicited callback table overwrite counter */
230 IX_NPEMH_SHOW ("Unsolicited callback table overwrites",
231 ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites);
235 * Function definition: ixNpeMhUnsolicitedCbMgrShowReset
238 void ixNpeMhUnsolicitedCbMgrShowReset (
241 /* reset the unsolicited callback table save counter */
242 ixNpeMhUnsolicitedCbMgrStats[npeId].saves = 0;
244 /* reset the unsolicited callback table overwrite counter */
245 ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites = 0;