source: SVN/cambria/redboot/packages/devs/eth/intel/npe/npeMh/current/src/IxNpeMhReceive.c @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 10.0 KB
Line 
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.3
13 *
14 * -- Copyright Notice --
15 *
16 * @par
17 * Copyright (c) 2001-2005, Intel Corporation.
18 * All rights reserved.
19 *
20 * @par
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 *    notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 *    notice, this list of conditions and the following disclaimer in the
28 *    documentation and/or other materials provided with the distribution.
29 * 3. Neither the name of the Intel Corporation nor the names of its contributors
30 *    may be used to endorse or promote products derived from this software
31 *    without specific prior written permission.
32 *
33 *
34 * @par
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
36 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 *
47 *
48 * @par
49 * -- End of Copyright Notice --
50*/
51
52/*
53 * Put the system defined include files required.
54 */
55
56
57/*
58 * Put the user defined include files required.
59 */
60#include "IxOsal.h"
61#include "IxNpeMhMacros_p.h"
62#include "IxNpeMhConfig_p.h"
63#include "IxNpeMhReceive_p.h"
64#include "IxNpeMhSolicitedCbMgr_p.h"
65#include "IxNpeMhUnsolicitedCbMgr_p.h"
66
67/*
68 * #defines and macros used in this file.
69 */
70
71/*
72 * Typedefs whose scope is limited to this file.
73 */
74
75/**
76 * @struct IxNpeMhReceiveStats
77 *
78 * @brief This structure is used to maintain statistics for the Receive
79 * module.
80 */
81
82typedef struct
83{
84    UINT32 isrs;        /**< receive ISR invocations */
85    UINT32 receives;    /**< receive messages invocations */
86    UINT32 messages;    /**< messages received */
87    UINT32 solicited;   /**< solicited messages received */
88    UINT32 unsolicited; /**< unsolicited messages received */
89    UINT32 callbacks;   /**< callbacks invoked */
90} IxNpeMhReceiveStats;
91
92/*
93 * Variable declarations global to this file only.  Externs are followed by
94 * static variables.
95 */
96
97PRIVATE IxNpeMhReceiveStats ixNpeMhReceiveStats[IX_NPEMH_NUM_NPES];
98
99/*
100 * Extern function prototypes.
101 */
102
103/*
104 * Static function prototypes.
105 */
106PRIVATE
107void ixNpeMhReceiveIsr (int npeId);
108
109PRIVATE
110void ixNpeMhReceiveIsr (int npeId)
111{
112    int lockKey;
113
114    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
115                     "ixNpeMhReceiveIsr\n");
116
117    lockKey = ixOsalIrqLock ();
118
119    /* invoke the message receive routine to get messages from the NPE */
120    ixNpeMhReceiveMessagesReceive (npeId);
121
122    /* update statistical info */
123    ixNpeMhReceiveStats[npeId].isrs++;
124
125    ixOsalIrqUnlock (lockKey);
126
127    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
128                     "ixNpeMhReceiveIsr\n");
129}
130
131/*
132 * Function definition: ixNpeMhReceiveInitialize
133 */
134
135void ixNpeMhReceiveInitialize (void)
136{
137    IxNpeMhNpeId npeId = 0;
138
139    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
140                     "ixNpeMhReceiveInitialize\n");
141
142    /* for each NPE ... */
143    for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
144    {
145        /* register our internal ISR for the NPE to handle "outFIFO not */
146        /* empty" interrupts */
147        ixNpeMhConfigIsrRegister (npeId, ixNpeMhReceiveIsr);
148    }
149
150    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
151                     "ixNpeMhReceiveInitialize\n");
152}
153
154/*
155 * Function definition: ixNpeMhReceiveUninitialize
156 */
157void ixNpeMhReceiveUninitialize (void)
158{
159    IxNpeMhNpeId npeId;
160
161    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
162                     "ixNpeMhReceiveUninitialize\n");
163
164    /* for each NPE ... */
165    for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
166    {
167        /* unregister and set ISR to NULL */
168        ixNpeMhConfigIsrUnregister (npeId);
169    }
170
171    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
172                     "ixNpeMhReceiveUninitialize\n");
173}
174
175/*
176 * Function definition: ixNpeMhReceiveMessagesReceive
177 */
178
179IX_STATUS ixNpeMhReceiveMessagesReceive (
180    IxNpeMhNpeId npeId)
181{
182    IxNpeMhMessage message = { { 0, 0 } };
183    IxNpeMhMessageId messageId = 0;
184    IxNpeMhCallback callback = NULL;
185    IX_STATUS status;
186
187    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
188                     "ixNpeMhReceiveMessagesReceive\n");
189
190    /* update statistical info */
191    ixNpeMhReceiveStats[npeId].receives++;
192
193    /* while the NPE has messages in its outFIFO */
194    while (!ixNpeMhConfigOutFifoIsEmpty (npeId))
195    {
196        /* read a message from the NPE's outFIFO */
197        status = ixNpeMhConfigOutFifoRead (npeId, &message);
198
199        if (IX_SUCCESS != status)
200        {
201            return status;
202        }
203       
204        /* get the ID of the message */
205        messageId = ixNpeMhConfigMessageIdGet (message);
206
207            IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG,
208                         "Received message from NPE %d with ID 0x%02X\n",
209                         npeId, messageId);
210
211        /* update statistical info */
212        ixNpeMhReceiveStats[npeId].messages++;
213
214        /* try to find a matching unsolicited callback for this message. */
215
216        /* we assume the message is unsolicited.  only if there is no */
217        /* unsolicited callback for this message type do we assume the */
218        /* message is solicited.  it is much faster to check for an */
219        /* unsolicited callback, so doing this check first should result */
220        /* in better performance. */
221
222        ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
223            npeId, messageId, &callback);
224
225        if (callback != NULL)
226        {
227            IX_NPEMH_TRACE0 (IX_NPEMH_DEBUG,
228                             "Found matching unsolicited callback\n");
229
230            /* update statistical info */
231            ixNpeMhReceiveStats[npeId].unsolicited++;
232        }
233
234        /* if no unsolicited callback was found try to find a matching */
235        /* solicited callback for this message */
236        if (callback == NULL)
237        {
238            ixNpeMhSolicitedCbMgrCallbackRetrieve (
239                npeId, messageId, &callback);
240
241            if (callback != NULL)
242            {
243                IX_NPEMH_TRACE0 (IX_NPEMH_DEBUG,
244                                 "Found matching solicited callback\n");
245
246                /* update statistical info */
247                ixNpeMhReceiveStats[npeId].solicited++;
248            }
249        }
250
251        /* if a callback (either unsolicited or solicited) was found */
252        if (callback != NULL)
253        {
254            /* invoke the callback to pass the message back to the client */
255            callback (npeId, message);
256
257            /* update statistical info */
258            ixNpeMhReceiveStats[npeId].callbacks++;
259        }
260        else /* no callback (neither unsolicited nor solicited) was found */
261        {
262            IX_NPEMH_TRACE2 (IX_NPEMH_WARNING,
263                             "No matching callback for NPE %d"
264                             " and ID 0x%02X, discarding message\n",
265                             npeId, messageId);
266
267            /* the message will be discarded.  this is normal behaviour */
268            /* if the client passes a NULL solicited callback when */
269            /* sending a message.  this indicates that the client is not */
270            /* interested in receiving the response.  alternatively a */
271            /* NULL callback here may signify an unsolicited message */
272            /* with no appropriate registered callback. */
273        }
274    }
275
276    IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
277                     "ixNpeMhReceiveMessagesReceive\n");
278   
279    return IX_SUCCESS;
280}
281
282/*
283 * Function definition: ixNpeMhReceiveShow
284 */
285
286void ixNpeMhReceiveShow (
287    IxNpeMhNpeId npeId)
288{
289    /* show the ISR invocation counter */
290    IX_NPEMH_SHOW ("Receive ISR invocations",
291                   ixNpeMhReceiveStats[npeId].isrs);
292
293    /* show the receive message invocation counter */
294    IX_NPEMH_SHOW ("Receive messages invocations",
295                   ixNpeMhReceiveStats[npeId].receives);
296
297    /* show the message received counter */
298    IX_NPEMH_SHOW ("Messages received",
299                   ixNpeMhReceiveStats[npeId].messages);
300
301    /* show the solicited message counter */
302    IX_NPEMH_SHOW ("Solicited messages received",
303                   ixNpeMhReceiveStats[npeId].solicited);
304
305    /* show the unsolicited message counter */
306    IX_NPEMH_SHOW ("Unsolicited messages received",
307                   ixNpeMhReceiveStats[npeId].unsolicited);
308
309    /* show the callback invoked counter */
310    IX_NPEMH_SHOW ("Callbacks invoked",
311                   ixNpeMhReceiveStats[npeId].callbacks);
312
313    /* show the message discarded counter */
314    IX_NPEMH_SHOW ("Received messages discarded",
315                   (ixNpeMhReceiveStats[npeId].messages -
316                    ixNpeMhReceiveStats[npeId].callbacks));
317}
318
319/*
320 * Function definition: ixNpeMhReceiveShowReset
321 */
322
323void ixNpeMhReceiveShowReset (
324    IxNpeMhNpeId npeId)
325{
326    /* reset the ISR invocation counter */
327    ixNpeMhReceiveStats[npeId].isrs = 0;
328
329    /* reset the receive message invocation counter */
330    ixNpeMhReceiveStats[npeId].receives = 0;
331
332    /* reset the message received counter */
333    ixNpeMhReceiveStats[npeId].messages = 0;
334
335    /* reset the solicited message counter */
336    ixNpeMhReceiveStats[npeId].solicited = 0;
337
338    /* reset the unsolicited message counter */
339    ixNpeMhReceiveStats[npeId].unsolicited = 0;
340
341    /* reset the callback invoked counter */
342    ixNpeMhReceiveStats[npeId].callbacks = 0;
343}
Note: See TracBrowser for help on using the repository browser.