]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/net/npe/IxNpeMhSend.c
doc: SPI: Add qspi test details on AM43xx
[karo-tx-uboot.git] / drivers / net / npe / IxNpeMhSend.c
1 /**
2  * @file IxNpeMhSend.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  * Send 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
35 #include "IxNpeMhMacros_p.h"
36
37 #include "IxNpeMhConfig_p.h"
38 #include "IxNpeMhSend_p.h"
39 #include "IxNpeMhSolicitedCbMgr_p.h"
40
41 /*
42  * #defines and macros used in this file.
43  */
44
45 /**
46  * @def IX_NPEMH_INFIFO_RETRY_DELAY_US
47  *
48  * @brief Amount of time (uSecs) to delay between retries
49  * while inFIFO is Full when attempting to send a message
50  */
51 #define IX_NPEMH_INFIFO_RETRY_DELAY_US (1)
52
53
54 /*
55  * Typedefs whose scope is limited to this file.
56  */
57
58 /**
59  * @struct IxNpeMhSendStats
60  *
61  * @brief This structure is used to maintain statistics for the Send
62  * module.
63  */
64
65 typedef struct
66 {
67     UINT32 sends;             /**< send invocations */
68     UINT32 sendWithResponses; /**< send with response invocations */
69     UINT32 queueFulls;        /**< fifo queue full occurrences */
70     UINT32 queueFullRetries;  /**< fifo queue full retry occurrences */
71     UINT32 maxQueueFullRetries; /**< max fifo queue full retries */
72     UINT32 callbackFulls;     /**< callback list full occurrences */
73 } IxNpeMhSendStats;
74
75 /*
76  * Variable declarations global to this file only.  Externs are followed by
77  * static variables.
78  */
79
80 PRIVATE IxNpeMhSendStats ixNpeMhSendStats[IX_NPEMH_NUM_NPES];
81
82 /*
83  * Extern function prototypes.
84  */
85
86 /*
87  * Static function prototypes.
88  */
89 PRIVATE
90 BOOL ixNpeMhSendInFifoIsFull(
91     IxNpeMhNpeId npeId,
92     UINT32 maxSendRetries);
93
94 /*
95  * Function definition: ixNpeMhSendInFifoIsFull
96  */
97
98 PRIVATE
99 BOOL ixNpeMhSendInFifoIsFull(
100     IxNpeMhNpeId npeId,
101     UINT32 maxSendRetries)
102 {
103     BOOL isFull = false;
104     UINT32 numRetries = 0;
105
106     /* check the NPE's inFIFO */
107     isFull = ixNpeMhConfigInFifoIsFull (npeId);
108
109     /* we retry a few times, just to give the NPE a chance to read from */
110     /* the FIFO if the FIFO is currently full */
111     while (isFull && (numRetries++ < maxSendRetries))
112     {
113         if (numRetries >= IX_NPEMH_SEND_RETRIES_DEFAULT)
114         {
115             /* Delay here for as short a time as possible (1 us). */
116             /* Adding a delay here should ensure we are not hogging */
117             /* the AHB bus while we are retrying                    */
118             ixOsalBusySleep (IX_NPEMH_INFIFO_RETRY_DELAY_US);
119         }
120
121         /* re-check the NPE's inFIFO */
122         isFull = ixNpeMhConfigInFifoIsFull (npeId);
123
124         /* update statistical info */
125         ixNpeMhSendStats[npeId].queueFullRetries++;
126     }
127
128     /* record the highest number of retries that occurred */
129     if (ixNpeMhSendStats[npeId].maxQueueFullRetries < numRetries)
130     {
131         ixNpeMhSendStats[npeId].maxQueueFullRetries = numRetries;
132     }
133
134     if (isFull)
135     {
136         /* update statistical info */
137         ixNpeMhSendStats[npeId].queueFulls++;
138     }
139
140     return isFull;
141 }
142
143 /*
144  * Function definition: ixNpeMhSendMessageSend
145  */
146
147 IX_STATUS ixNpeMhSendMessageSend (
148     IxNpeMhNpeId npeId,
149     IxNpeMhMessage message,
150     UINT32 maxSendRetries)
151 {
152     IX_STATUS status;
153
154     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
155                      "ixNpeMhSendMessageSend\n");
156
157     /* update statistical info */
158     ixNpeMhSendStats[npeId].sends++;
159
160     /* check if the NPE's inFIFO is full - if so return an error */
161     if (ixNpeMhSendInFifoIsFull (npeId, maxSendRetries))
162     {
163         IX_NPEMH_TRACE0 (IX_NPEMH_WARNING, "NPE's inFIFO is full\n");
164         return IX_FAIL;
165     }
166
167     /* write the message to the NPE's inFIFO */
168     status = ixNpeMhConfigInFifoWrite (npeId, message);
169
170     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
171                      "ixNpeMhSendMessageSend\n");
172
173     return status;
174 }
175
176 /*
177  * Function definition: ixNpeMhSendMessageWithResponseSend
178  */
179
180 IX_STATUS ixNpeMhSendMessageWithResponseSend (
181     IxNpeMhNpeId npeId,
182     IxNpeMhMessage message,
183     IxNpeMhMessageId solicitedMessageId,
184     IxNpeMhCallback solicitedCallback,
185     UINT32 maxSendRetries)
186 {
187     IX_STATUS status = IX_SUCCESS;
188
189     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
190                      "ixNpeMhSendMessageWithResponseSend\n");
191
192     /* update statistical info */
193     ixNpeMhSendStats[npeId].sendWithResponses++;
194
195     /* sr: this sleep will call the receive routine (no interrupts used!!!) */
196     ixOsalSleep (IX_NPEMH_INFIFO_RETRY_DELAY_US);
197
198     /* check if the NPE's inFIFO is full - if so return an error */
199     if (ixNpeMhSendInFifoIsFull (npeId, maxSendRetries))
200     {
201         IX_NPEMH_TRACE0 (IX_NPEMH_WARNING, "NPE's inFIFO is full\n");
202         return IX_FAIL;
203     }
204
205     /* save the solicited callback */
206     status = ixNpeMhSolicitedCbMgrCallbackSave (
207         npeId, solicitedMessageId, solicitedCallback);
208     if (status != IX_SUCCESS)
209     {
210         IX_NPEMH_ERROR_REPORT ("Failed to save solicited callback\n");
211
212         /* update statistical info */
213         ixNpeMhSendStats[npeId].callbackFulls++;
214
215         return status;
216     }
217
218     /* write the message to the NPE's inFIFO */
219     status = ixNpeMhConfigInFifoWrite (npeId, message);
220
221     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
222                      "ixNpeMhSendMessageWithResponseSend\n");
223
224     return status;
225 }
226
227 /*
228  * Function definition: ixNpeMhSendShow
229  */
230
231 void ixNpeMhSendShow (
232     IxNpeMhNpeId npeId)
233 {
234     /* show the message send invocation counter */
235     IX_NPEMH_SHOW ("Send invocations",
236                    ixNpeMhSendStats[npeId].sends);
237
238     /* show the message send with response invocation counter */
239     IX_NPEMH_SHOW ("Send with response invocations",
240                    ixNpeMhSendStats[npeId].sendWithResponses);
241
242     /* show the fifo queue full occurrence counter */
243     IX_NPEMH_SHOW ("Fifo queue full occurrences",
244                    ixNpeMhSendStats[npeId].queueFulls);
245
246     /* show the fifo queue full retry occurrence counter */
247     IX_NPEMH_SHOW ("Fifo queue full retry occurrences",
248                    ixNpeMhSendStats[npeId].queueFullRetries);
249
250     /* show the fifo queue full maximum retries counter */
251     IX_NPEMH_SHOW ("Maximum fifo queue full retries",
252                    ixNpeMhSendStats[npeId].maxQueueFullRetries);
253
254     /* show the callback list full occurrence counter */
255     IX_NPEMH_SHOW ("Solicited callback list full occurrences",
256                    ixNpeMhSendStats[npeId].callbackFulls);
257 }
258
259 /*
260  * Function definition: ixNpeMhSendShowReset
261  */
262
263 void ixNpeMhSendShowReset (
264     IxNpeMhNpeId npeId)
265 {
266     /* reset the message send invocation counter */
267     ixNpeMhSendStats[npeId].sends = 0;
268
269     /* reset the message send with response invocation counter */
270     ixNpeMhSendStats[npeId].sendWithResponses = 0;
271
272     /* reset the fifo queue full occurrence counter */
273     ixNpeMhSendStats[npeId].queueFulls = 0;
274
275     /* reset the fifo queue full retry occurrence counter */
276     ixNpeMhSendStats[npeId].queueFullRetries = 0;
277
278     /* reset the max fifo queue full retries counter */
279     ixNpeMhSendStats[npeId].maxQueueFullRetries = 0;
280
281     /* reset the callback list full occurrence counter */
282     ixNpeMhSendStats[npeId].callbackFulls = 0;
283 }