]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/net/npe/IxNpeMhReceive.c
SPDX-License-Identifier: convert BSD-3-Clause files
[thirdparty/u-boot.git] / drivers / net / npe / IxNpeMhReceive.c
CommitLineData
ba94a1bb
WD
1/**
2 * @file IxNpeMhReceive.c
3 *
4 * @author Intel Corporation
5 * @date 18 Jan 2002
6 *
7 * @brief This file contains the implementation of the private API for the
8 * Receive module.
9 *
10 *
11 * @par
12 * IXP400 SW Release version 2.0
13 *
14 * -- Copyright Notice --
15 *
16 * @par
17 * Copyright 2001-2005, Intel Corporation.
18 * All rights reserved.
cb3761ea 19 *
ba94a1bb 20 * @par
cb3761ea 21 * SPDX-License-Identifier: BSD-3-Clause
ba94a1bb
WD
22 * @par
23 * -- End of Copyright Notice --
24*/
25
26/*
27 * Put the system defined include files required.
28 */
29
30
31/*
32 * Put the user defined include files required.
33 */
34#include "IxOsal.h"
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"
40
41/*
42 * #defines and macros used in this file.
43 */
44
45/*
46 * Typedefs whose scope is limited to this file.
47 */
48
49/**
50 * @struct IxNpeMhReceiveStats
51 *
52 * @brief This structure is used to maintain statistics for the Receive
53 * module.
54 */
55
56typedef struct
57{
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;
65
66/*
67 * Variable declarations global to this file only. Externs are followed by
68 * static variables.
69 */
70
71PRIVATE IxNpeMhReceiveStats ixNpeMhReceiveStats[IX_NPEMH_NUM_NPES];
72
73/*
74 * Extern function prototypes.
75 */
76
77/*
78 * Static function prototypes.
79 */
80PRIVATE
81void ixNpeMhReceiveIsr (int npeId);
82
83PRIVATE
84void ixNpeMhReceiveIsr (int npeId)
85{
86 int lockKey;
87
88 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
89 "ixNpeMhReceiveIsr\n");
90
91 lockKey = ixOsalIrqLock ();
92
93 /* invoke the message receive routine to get messages from the NPE */
94 ixNpeMhReceiveMessagesReceive (npeId);
95
96 /* update statistical info */
97 ixNpeMhReceiveStats[npeId].isrs++;
98
99 ixOsalIrqUnlock (lockKey);
100
101 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
102 "ixNpeMhReceiveIsr\n");
103}
104
105/*
106 * Function definition: ixNpeMhReceiveInitialize
107 */
108
109void ixNpeMhReceiveInitialize (void)
110{
111 IxNpeMhNpeId npeId = 0;
112
113 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
114 "ixNpeMhReceiveInitialize\n");
115
116 /* for each NPE ... */
117 for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
118 {
119 /* register our internal ISR for the NPE to handle "outFIFO not */
120 /* empty" interrupts */
121 ixNpeMhConfigIsrRegister (npeId, ixNpeMhReceiveIsr);
122 }
123
124 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
125 "ixNpeMhReceiveInitialize\n");
126}
127
128/*
129 * Function definition: ixNpeMhReceiveMessagesReceive
130 */
131
132IX_STATUS ixNpeMhReceiveMessagesReceive (
133 IxNpeMhNpeId npeId)
134{
135 IxNpeMhMessage message = { { 0, 0 } };
136 IxNpeMhMessageId messageId = 0;
137 IxNpeMhCallback callback = NULL;
138 IX_STATUS status;
139
140 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
141 "ixNpeMhReceiveMessagesReceive\n");
142
143 /* update statistical info */
144 ixNpeMhReceiveStats[npeId].receives++;
145
146 /* while the NPE has messages in its outFIFO */
147 while (!ixNpeMhConfigOutFifoIsEmpty (npeId))
148 {
149 /* read a message from the NPE's outFIFO */
150 status = ixNpeMhConfigOutFifoRead (npeId, &message);
151
152 if (IX_SUCCESS != status)
153 {
154 return status;
155 }
156
157 /* get the ID of the message */
158 messageId = ixNpeMhConfigMessageIdGet (message);
159
160 IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG,
161 "Received message from NPE %d with ID 0x%02X\n",
162 npeId, messageId);
163
164 /* update statistical info */
165 ixNpeMhReceiveStats[npeId].messages++;
166
167 /* try to find a matching unsolicited callback for this message. */
168
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. */
174
175 ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
176 npeId, messageId, &callback);
177
178 if (callback != NULL)
179 {
180 IX_NPEMH_TRACE0 (IX_NPEMH_DEBUG,
181 "Found matching unsolicited callback\n");
182
183 /* update statistical info */
184 ixNpeMhReceiveStats[npeId].unsolicited++;
185 }
186
187 /* if no unsolicited callback was found try to find a matching */
188 /* solicited callback for this message */
189 if (callback == NULL)
190 {
191 ixNpeMhSolicitedCbMgrCallbackRetrieve (
192 npeId, messageId, &callback);
193
194 if (callback != NULL)
195 {
196 IX_NPEMH_TRACE0 (IX_NPEMH_DEBUG,
197 "Found matching solicited callback\n");
198
199 /* update statistical info */
200 ixNpeMhReceiveStats[npeId].solicited++;
201 }
202 }
203
204 /* if a callback (either unsolicited or solicited) was found */
205 if (callback != NULL)
206 {
207 /* invoke the callback to pass the message back to the client */
208 callback (npeId, message);
209
210 /* update statistical info */
211 ixNpeMhReceiveStats[npeId].callbacks++;
212 }
213 else /* no callback (neither unsolicited nor solicited) was found */
214 {
215 IX_NPEMH_TRACE2 (IX_NPEMH_WARNING,
216 "No matching callback for NPE %d"
217 " and ID 0x%02X, discarding message\n",
218 npeId, messageId);
219
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. */
226 }
227 }
228
229 IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
230 "ixNpeMhReceiveMessagesReceive\n");
231
232 return IX_SUCCESS;
233}
234
235/*
236 * Function definition: ixNpeMhReceiveShow
237 */
238
239void ixNpeMhReceiveShow (
240 IxNpeMhNpeId npeId)
241{
242 /* show the ISR invocation counter */
243 IX_NPEMH_SHOW ("Receive ISR invocations",
244 ixNpeMhReceiveStats[npeId].isrs);
245
246 /* show the receive message invocation counter */
247 IX_NPEMH_SHOW ("Receive messages invocations",
248 ixNpeMhReceiveStats[npeId].receives);
249
250 /* show the message received counter */
251 IX_NPEMH_SHOW ("Messages received",
252 ixNpeMhReceiveStats[npeId].messages);
253
254 /* show the solicited message counter */
255 IX_NPEMH_SHOW ("Solicited messages received",
256 ixNpeMhReceiveStats[npeId].solicited);
257
258 /* show the unsolicited message counter */
259 IX_NPEMH_SHOW ("Unsolicited messages received",
260 ixNpeMhReceiveStats[npeId].unsolicited);
261
262 /* show the callback invoked counter */
263 IX_NPEMH_SHOW ("Callbacks invoked",
264 ixNpeMhReceiveStats[npeId].callbacks);
265
266 /* show the message discarded counter */
267 IX_NPEMH_SHOW ("Received messages discarded",
268 (ixNpeMhReceiveStats[npeId].messages -
269 ixNpeMhReceiveStats[npeId].callbacks));
270}
271
272/*
273 * Function definition: ixNpeMhReceiveShowReset
274 */
275
276void ixNpeMhReceiveShowReset (
277 IxNpeMhNpeId npeId)
278{
279 /* reset the ISR invocation counter */
280 ixNpeMhReceiveStats[npeId].isrs = 0;
281
282 /* reset the receive message invocation counter */
283 ixNpeMhReceiveStats[npeId].receives = 0;
284
285 /* reset the message received counter */
286 ixNpeMhReceiveStats[npeId].messages = 0;
287
288 /* reset the solicited message counter */
289 ixNpeMhReceiveStats[npeId].solicited = 0;
290
291 /* reset the unsolicited message counter */
292 ixNpeMhReceiveStats[npeId].unsolicited = 0;
293
294 /* reset the callback invoked counter */
295 ixNpeMhReceiveStats[npeId].callbacks = 0;
296}