2 * @file IxNpeMhSolicitedCbMgr.c
4 * @author Intel Corporation
7 * @brief This file contains the implementation of the private API for the
8 * Solicited Callback Manager module.
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 --
25 #ifndef IXNPEMHCONFIG_P_H
26 # define IXNPEMHSOLICITEDCBMGR_C
28 # error "Error, IxNpeMhConfig_p.h should not be included before this definition."
32 * Put the system defined include files required.
37 * Put the user defined include files required.
42 #include "IxNpeMhMacros_p.h"
43 #include "IxNpeMhSolicitedCbMgr_p.h"
44 #include "IxNpeMhConfig_p.h"
46 * #defines and macros used in this file.
50 * Typedefs whose scope is limited to this file.
54 * @struct IxNpeMhSolicitedCallbackListEntry
56 * @brief This structure is used to store the information associated with
57 * an entry in the callback list. This consists of the ID of the send
58 * message (which indicates the ID of the corresponding response message)
59 * and the callback function pointer itself.
63 typedef struct IxNpeMhSolicitedCallbackListEntry
66 IxNpeMhMessageId messageId;
68 /** callback function pointer */
69 IxNpeMhCallback callback;
71 /** pointer to next entry in the list */
72 struct IxNpeMhSolicitedCallbackListEntry *next;
73 } IxNpeMhSolicitedCallbackListEntry;
76 * @struct IxNpeMhSolicitedCallbackList
78 * @brief This structure is used to maintain the list of response
79 * callbacks. The number of entries in this list will be variable, and
80 * they will be stored in a linked list fashion for ease of addition and
81 * removal. The entries themselves are statically allocated, and are
82 * organised into a "free" list and a "callback" list. Adding an entry
83 * means taking an entry from the "free" list and adding it to the
84 * "callback" list. Removing an entry means removing it from the
85 * "callback" list and returning it to the "free" list.
90 /** pointer to the head of the free list */
91 IxNpeMhSolicitedCallbackListEntry *freeHead;
93 /** pointer to the head of the callback list */
94 IxNpeMhSolicitedCallbackListEntry *callbackHead;
96 /** pointer to the tail of the callback list */
97 IxNpeMhSolicitedCallbackListEntry *callbackTail;
99 /** array of entries - the first entry is used as a dummy entry to */
100 /* avoid the scenario of having an empty list, hence '+ 1' */
101 IxNpeMhSolicitedCallbackListEntry entries[IX_NPEMH_MAX_CALLBACKS + 1];
102 } IxNpeMhSolicitedCallbackList;
105 * @struct IxNpeMhSolicitedCbMgrStats
107 * @brief This structure is used to maintain statistics for the Solicited
108 * Callback Manager module.
113 UINT32 saves; /**< callback list saves */
114 UINT32 retrieves; /**< callback list retrieves */
115 } IxNpeMhSolicitedCbMgrStats;
118 * Variable declarations global to this file only. Externs are followed by
122 PRIVATE IxNpeMhSolicitedCallbackList
123 ixNpeMhSolicitedCbMgrCallbackLists[IX_NPEMH_NUM_NPES];
125 PRIVATE IxNpeMhSolicitedCbMgrStats
126 ixNpeMhSolicitedCbMgrStats[IX_NPEMH_NUM_NPES];
129 * Extern function prototypes.
133 * Static function prototypes.
137 * Function definition: ixNpeMhSolicitedCbMgrInitialize
140 void ixNpeMhSolicitedCbMgrInitialize (void)
144 IxNpeMhSolicitedCallbackList *list = NULL;
146 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
147 "ixNpeMhSolicitedCbMgrInitialize\n");
149 /* for each NPE ... */
150 for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
152 /* initialise a pointer to the list for convenience */
153 list = &ixNpeMhSolicitedCbMgrCallbackLists[npeId];
155 /* for each entry in the list, after the dummy entry ... */
156 for (localIndex = 1; localIndex <= IX_NPEMH_MAX_CALLBACKS; localIndex++)
158 /* initialise the entry */
159 list->entries[localIndex].messageId = 0x00;
160 list->entries[localIndex].callback = NULL;
162 /* if this entry is before the last entry */
163 if (localIndex < IX_NPEMH_MAX_CALLBACKS)
165 /* chain this entry to the following entry */
166 list->entries[localIndex].next = &(list->entries[localIndex + 1]);
168 else /* this entry is the last entry */
170 /* the last entry isn't chained to anything */
171 list->entries[localIndex].next = NULL;
175 /* set the free list pointer to point to the first real entry */
176 /* (all real entries begin chained together on the free list) */
177 list->freeHead = &(list->entries[1]);
179 /* set the callback list pointers to point to the dummy entry */
180 /* (the callback list is initially empty) */
181 list->callbackHead = &(list->entries[0]);
182 list->callbackTail = &(list->entries[0]);
185 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
186 "ixNpeMhSolicitedCbMgrInitialize\n");
190 * Function definition: ixNpeMhSolicitedCbMgrCallbackSave
193 IX_STATUS ixNpeMhSolicitedCbMgrCallbackSave (
195 IxNpeMhMessageId solicitedMessageId,
196 IxNpeMhCallback solicitedCallback)
198 IxNpeMhSolicitedCallbackList *list = NULL;
199 IxNpeMhSolicitedCallbackListEntry *callbackEntry = NULL;
201 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
202 "ixNpeMhSolicitedCbMgrCallbackSave\n");
204 /* initialise a pointer to the list for convenience */
205 list = &ixNpeMhSolicitedCbMgrCallbackLists[npeId];
207 /* check to see if there are any entries in the free list */
208 if (list->freeHead == NULL)
210 IX_NPEMH_ERROR_REPORT ("Solicited callback list is full\n");
214 /* there is an entry in the free list we can use */
216 /* update statistical info */
217 ixNpeMhSolicitedCbMgrStats[npeId].saves++;
219 /* remove a callback entry from the start of the free list */
220 callbackEntry = list->freeHead;
221 list->freeHead = callbackEntry->next;
223 /* fill in the callback entry with the new data */
224 callbackEntry->messageId = solicitedMessageId;
225 callbackEntry->callback = solicitedCallback;
227 /* the new callback entry will be added to the tail of the callback */
228 /* list, so it isn't chained to anything */
229 callbackEntry->next = NULL;
231 /* chain new callback entry to the last entry of the callback list */
232 list->callbackTail->next = callbackEntry;
233 list->callbackTail = callbackEntry;
235 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
236 "ixNpeMhSolicitedCbMgrCallbackSave\n");
242 * Function definition: ixNpeMhSolicitedCbMgrCallbackRetrieve
245 void ixNpeMhSolicitedCbMgrCallbackRetrieve (
247 IxNpeMhMessageId solicitedMessageId,
248 IxNpeMhCallback *solicitedCallback)
250 IxNpeMhSolicitedCallbackList *list = NULL;
251 IxNpeMhSolicitedCallbackListEntry *callbackEntry = NULL;
252 IxNpeMhSolicitedCallbackListEntry *previousEntry = NULL;
254 /* initialise a pointer to the list for convenience */
255 list = &ixNpeMhSolicitedCbMgrCallbackLists[npeId];
257 /* initialise the callback entry to the first entry of the callback */
258 /* list - we must skip over the dummy entry, which is the previous */
259 callbackEntry = list->callbackHead->next;
260 previousEntry = list->callbackHead;
262 /* traverse the callback list looking for an entry with a matching */
263 /* message ID. note we also save the previous entry's pointer to */
264 /* allow us to unchain the matching entry from the callback list */
265 while ((callbackEntry != NULL) &&
266 (callbackEntry->messageId != solicitedMessageId))
268 previousEntry = callbackEntry;
269 callbackEntry = callbackEntry->next;
272 /* if we didn't find a matching callback entry */
273 if (callbackEntry == NULL)
275 /* return a NULL callback in the outgoing parameter */
276 *solicitedCallback = NULL;
278 else /* we found a matching callback entry */
280 /* update statistical info */
281 ixNpeMhSolicitedCbMgrStats[npeId].retrieves++;
283 /* return the callback in the outgoing parameter */
284 *solicitedCallback = callbackEntry->callback;
286 /* unchain callback entry by chaining previous entry to next */
287 previousEntry->next = callbackEntry->next;
289 /* if the callback entry is at the tail of the list */
290 if (list->callbackTail == callbackEntry)
292 /* update the tail of the callback list */
293 list->callbackTail = previousEntry;
296 /* re-initialise the callback entry */
297 callbackEntry->messageId = 0x00;
298 callbackEntry->callback = NULL;
300 /* add the callback entry to the start of the free list */
301 callbackEntry->next = list->freeHead;
302 list->freeHead = callbackEntry;
307 * Function definition: ixNpeMhSolicitedCbMgrShow
310 void ixNpeMhSolicitedCbMgrShow (
313 /* show the solicited callback list save counter */
314 IX_NPEMH_SHOW ("Solicited callback list saves",
315 ixNpeMhSolicitedCbMgrStats[npeId].saves);
317 /* show the solicited callback list retrieve counter */
318 IX_NPEMH_SHOW ("Solicited callback list retrieves",
319 ixNpeMhSolicitedCbMgrStats[npeId].retrieves);
323 * Function definition: ixNpeMhSolicitedCbMgrShowReset
326 void ixNpeMhSolicitedCbMgrShowReset (
329 /* reset the solicited callback list save counter */
330 ixNpeMhSolicitedCbMgrStats[npeId].saves = 0;
332 /* reset the solicited callback list retrieve counter */
333 ixNpeMhSolicitedCbMgrStats[npeId].retrieves = 0;