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