]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/net/npe/IxNpeMhUnsolicitedCbMgr.c
doc: SPI: Add qspi test details on AM43xx
[karo-tx-uboot.git] / drivers / net / npe / IxNpeMhUnsolicitedCbMgr.c
1 /**
2  * @file IxNpeMhUnsolicitedCbMgr.c
3  *
4  * @author Intel Corporation
5  * @date 18 Jan 2002
6  *
7  * @brief This file contains the implementation of the private API for
8  * the Unsolicited Callback Manager 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.
19  * 
20  * @par
21  * SPDX-License-Identifier:     BSD-3-Clause
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
36 #include "IxNpeMhMacros_p.h"
37
38 #include "IxNpeMhUnsolicitedCbMgr_p.h"
39
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 IxNpeMhUnsolicitedCallbackTable
51  *
52  * @brief This structure is used to maintain the list of registered
53  * callbacks.  One entry exists for each message ID, and a NULL entry will
54  * signify that no callback has been registered for that ID.
55  */
56
57 typedef struct
58 {
59     /** array of entries */
60     IxNpeMhCallback entries[IX_NPEMH_MAX_MESSAGE_ID + 1];
61 } IxNpeMhUnsolicitedCallbackTable;
62
63 /**
64  * @struct IxNpeMhUnsolicitedCbMgrStats
65  *
66  * @brief This structure is used to maintain statistics for the Unsolicited
67  * Callback Manager module.
68  */
69
70 typedef struct
71 {
72     UINT32 saves;      /**< callback table saves */
73     UINT32 overwrites; /**< callback table overwrites */
74 } IxNpeMhUnsolicitedCbMgrStats;
75
76 /*
77  * Variable declarations global to this file only.  Externs are followed by
78  * static variables.
79  */
80
81 PRIVATE IxNpeMhUnsolicitedCallbackTable
82 ixNpeMhUnsolicitedCallbackTables[IX_NPEMH_NUM_NPES];
83
84 PRIVATE IxNpeMhUnsolicitedCbMgrStats
85 ixNpeMhUnsolicitedCbMgrStats[IX_NPEMH_NUM_NPES];
86
87 /*
88  * Extern function prototypes.
89  */
90
91 /*
92  * Static function prototypes.
93  */
94
95 /*
96  * Function definition: ixNpeMhUnsolicitedCbMgrInitialize
97  */
98
99 void ixNpeMhUnsolicitedCbMgrInitialize (void)
100 {
101     IxNpeMhNpeId npeId = 0;
102     IxNpeMhUnsolicitedCallbackTable *table = NULL;
103     IxNpeMhMessageId messageId = 0;
104
105     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
106                      "ixNpeMhUnsolicitedCbMgrInitialize\n");
107
108     /* for each NPE ... */
109     for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
110     {
111         /* initialise a pointer to the table for convenience */
112         table = &ixNpeMhUnsolicitedCallbackTables[npeId];
113
114         /* for each message ID ... */
115         for (messageId = IX_NPEMH_MIN_MESSAGE_ID;
116              messageId <= IX_NPEMH_MAX_MESSAGE_ID; messageId++)
117         {
118             /* initialise the callback for this message ID to NULL */
119             table->entries[messageId] = NULL;
120         }
121     }
122
123     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
124                      "ixNpeMhUnsolicitedCbMgrInitialize\n");
125 }
126
127 /*
128  * Function definition: ixNpeMhUnsolicitedCbMgrCallbackSave
129  */
130
131 void ixNpeMhUnsolicitedCbMgrCallbackSave (
132     IxNpeMhNpeId npeId,
133     IxNpeMhMessageId unsolicitedMessageId,
134     IxNpeMhCallback unsolicitedCallback)
135 {
136     IxNpeMhUnsolicitedCallbackTable *table = NULL;
137
138     /* initialise a pointer to the table for convenience */
139     table = &ixNpeMhUnsolicitedCallbackTables[npeId];
140
141     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
142                      "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
143
144     /* update statistical info */
145     ixNpeMhUnsolicitedCbMgrStats[npeId].saves++;
146
147     /* check if there is a callback already registered for this NPE and */
148     /* message ID */
149     if (table->entries[unsolicitedMessageId] != NULL)
150     {
151         /* if we are overwriting an existing callback */
152         if (unsolicitedCallback != NULL)
153         {
154             IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "Unsolicited callback "
155                              "overwriting existing callback for NPE ID %d "
156                              "message ID 0x%02X\n", npeId, unsolicitedMessageId);
157         }
158         else /* if we are clearing an existing callback */
159         {
160             IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "NULL unsolicited callback "
161                              "clearing existing callback for NPE ID %d "
162                              "message ID 0x%02X\n", npeId, unsolicitedMessageId);
163         }
164
165         /* update statistical info */
166         ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites++;
167     }
168
169     /* save the callback into the table */
170     table->entries[unsolicitedMessageId] = unsolicitedCallback;
171
172     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
173                      "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
174 }
175
176 /*
177  * Function definition: ixNpeMhUnsolicitedCbMgrCallbackRetrieve
178  */
179
180 void ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
181     IxNpeMhNpeId npeId,
182     IxNpeMhMessageId unsolicitedMessageId,
183     IxNpeMhCallback *unsolicitedCallback)
184 {
185     IxNpeMhUnsolicitedCallbackTable *table = NULL;
186
187     /* initialise a pointer to the table for convenience */
188     table = &ixNpeMhUnsolicitedCallbackTables[npeId];
189
190     /* retrieve the callback from the table */
191     *unsolicitedCallback = table->entries[unsolicitedMessageId];
192 }
193
194 /*
195  * Function definition: ixNpeMhUnsolicitedCbMgrShow
196  */
197
198 void ixNpeMhUnsolicitedCbMgrShow (
199     IxNpeMhNpeId npeId)
200 {
201     /* show the unsolicited callback table save counter */
202     IX_NPEMH_SHOW ("Unsolicited callback table saves",
203                    ixNpeMhUnsolicitedCbMgrStats[npeId].saves);
204
205     /* show the unsolicited callback table overwrite counter */
206     IX_NPEMH_SHOW ("Unsolicited callback table overwrites",
207                    ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites);
208 }
209
210 /*
211  * Function definition: ixNpeMhUnsolicitedCbMgrShowReset
212  */
213
214 void ixNpeMhUnsolicitedCbMgrShowReset (
215     IxNpeMhNpeId npeId)
216 {
217     /* reset the unsolicited callback table save counter */
218     ixNpeMhUnsolicitedCbMgrStats[npeId].saves = 0;
219
220     /* reset the unsolicited callback table overwrite counter */
221     ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites = 0;
222 }