2 * @file IxNpeMhReceive.c
4 * @author Intel Corporation
7 * @brief This file contains the implementation of the private API for the
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.
32 * Put the user defined include files required.
35 #include "IxNpeMhMacros_p.h"
36 #include "IxNpeMhConfig_p.h"
37 #include "IxNpeMhReceive_p.h"
38 #include "IxNpeMhSolicitedCbMgr_p.h"
39 #include "IxNpeMhUnsolicitedCbMgr_p.h"
42 * #defines and macros used in this file.
46 * Typedefs whose scope is limited to this file.
50 * @struct IxNpeMhReceiveStats
52 * @brief This structure is used to maintain statistics for the Receive
58 UINT32 isrs; /**< receive ISR invocations */
59 UINT32 receives; /**< receive messages invocations */
60 UINT32 messages; /**< messages received */
61 UINT32 solicited; /**< solicited messages received */
62 UINT32 unsolicited; /**< unsolicited messages received */
63 UINT32 callbacks; /**< callbacks invoked */
64 } IxNpeMhReceiveStats;
67 * Variable declarations global to this file only. Externs are followed by
71 PRIVATE IxNpeMhReceiveStats ixNpeMhReceiveStats[IX_NPEMH_NUM_NPES];
74 * Extern function prototypes.
78 * Static function prototypes.
81 void ixNpeMhReceiveIsr (int npeId);
84 void ixNpeMhReceiveIsr (int npeId)
88 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
89 "ixNpeMhReceiveIsr\n");
91 lockKey = ixOsalIrqLock ();
93 /* invoke the message receive routine to get messages from the NPE */
94 ixNpeMhReceiveMessagesReceive (npeId);
96 /* update statistical info */
97 ixNpeMhReceiveStats[npeId].isrs++;
99 ixOsalIrqUnlock (lockKey);
101 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
102 "ixNpeMhReceiveIsr\n");
106 * Function definition: ixNpeMhReceiveInitialize
109 void ixNpeMhReceiveInitialize (void)
111 IxNpeMhNpeId npeId = 0;
113 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
114 "ixNpeMhReceiveInitialize\n");
116 /* for each NPE ... */
117 for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
119 /* register our internal ISR for the NPE to handle "outFIFO not */
120 /* empty" interrupts */
121 ixNpeMhConfigIsrRegister (npeId, ixNpeMhReceiveIsr);
124 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
125 "ixNpeMhReceiveInitialize\n");
129 * Function definition: ixNpeMhReceiveMessagesReceive
132 IX_STATUS ixNpeMhReceiveMessagesReceive (
135 IxNpeMhMessage message = { { 0, 0 } };
136 IxNpeMhMessageId messageId = 0;
137 IxNpeMhCallback callback = NULL;
140 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
141 "ixNpeMhReceiveMessagesReceive\n");
143 /* update statistical info */
144 ixNpeMhReceiveStats[npeId].receives++;
146 /* while the NPE has messages in its outFIFO */
147 while (!ixNpeMhConfigOutFifoIsEmpty (npeId))
149 /* read a message from the NPE's outFIFO */
150 status = ixNpeMhConfigOutFifoRead (npeId, &message);
152 if (IX_SUCCESS != status)
157 /* get the ID of the message */
158 messageId = ixNpeMhConfigMessageIdGet (message);
160 IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG,
161 "Received message from NPE %d with ID 0x%02X\n",
164 /* update statistical info */
165 ixNpeMhReceiveStats[npeId].messages++;
167 /* try to find a matching unsolicited callback for this message. */
169 /* we assume the message is unsolicited. only if there is no */
170 /* unsolicited callback for this message type do we assume the */
171 /* message is solicited. it is much faster to check for an */
172 /* unsolicited callback, so doing this check first should result */
173 /* in better performance. */
175 ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
176 npeId, messageId, &callback);
178 if (callback != NULL)
180 IX_NPEMH_TRACE0 (IX_NPEMH_DEBUG,
181 "Found matching unsolicited callback\n");
183 /* update statistical info */
184 ixNpeMhReceiveStats[npeId].unsolicited++;
187 /* if no unsolicited callback was found try to find a matching */
188 /* solicited callback for this message */
189 if (callback == NULL)
191 ixNpeMhSolicitedCbMgrCallbackRetrieve (
192 npeId, messageId, &callback);
194 if (callback != NULL)
196 IX_NPEMH_TRACE0 (IX_NPEMH_DEBUG,
197 "Found matching solicited callback\n");
199 /* update statistical info */
200 ixNpeMhReceiveStats[npeId].solicited++;
204 /* if a callback (either unsolicited or solicited) was found */
205 if (callback != NULL)
207 /* invoke the callback to pass the message back to the client */
208 callback (npeId, message);
210 /* update statistical info */
211 ixNpeMhReceiveStats[npeId].callbacks++;
213 else /* no callback (neither unsolicited nor solicited) was found */
215 IX_NPEMH_TRACE2 (IX_NPEMH_WARNING,
216 "No matching callback for NPE %d"
217 " and ID 0x%02X, discarding message\n",
220 /* the message will be discarded. this is normal behaviour */
221 /* if the client passes a NULL solicited callback when */
222 /* sending a message. this indicates that the client is not */
223 /* interested in receiving the response. alternatively a */
224 /* NULL callback here may signify an unsolicited message */
225 /* with no appropriate registered callback. */
229 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
230 "ixNpeMhReceiveMessagesReceive\n");
236 * Function definition: ixNpeMhReceiveShow
239 void ixNpeMhReceiveShow (
242 /* show the ISR invocation counter */
243 IX_NPEMH_SHOW ("Receive ISR invocations",
244 ixNpeMhReceiveStats[npeId].isrs);
246 /* show the receive message invocation counter */
247 IX_NPEMH_SHOW ("Receive messages invocations",
248 ixNpeMhReceiveStats[npeId].receives);
250 /* show the message received counter */
251 IX_NPEMH_SHOW ("Messages received",
252 ixNpeMhReceiveStats[npeId].messages);
254 /* show the solicited message counter */
255 IX_NPEMH_SHOW ("Solicited messages received",
256 ixNpeMhReceiveStats[npeId].solicited);
258 /* show the unsolicited message counter */
259 IX_NPEMH_SHOW ("Unsolicited messages received",
260 ixNpeMhReceiveStats[npeId].unsolicited);
262 /* show the callback invoked counter */
263 IX_NPEMH_SHOW ("Callbacks invoked",
264 ixNpeMhReceiveStats[npeId].callbacks);
266 /* show the message discarded counter */
267 IX_NPEMH_SHOW ("Received messages discarded",
268 (ixNpeMhReceiveStats[npeId].messages -
269 ixNpeMhReceiveStats[npeId].callbacks));
273 * Function definition: ixNpeMhReceiveShowReset
276 void ixNpeMhReceiveShowReset (
279 /* reset the ISR invocation counter */
280 ixNpeMhReceiveStats[npeId].isrs = 0;
282 /* reset the receive message invocation counter */
283 ixNpeMhReceiveStats[npeId].receives = 0;
285 /* reset the message received counter */
286 ixNpeMhReceiveStats[npeId].messages = 0;
288 /* reset the solicited message counter */
289 ixNpeMhReceiveStats[npeId].solicited = 0;
291 /* reset the unsolicited message counter */
292 ixNpeMhReceiveStats[npeId].unsolicited = 0;
294 /* reset the callback invoked counter */
295 ixNpeMhReceiveStats[npeId].callbacks = 0;