blob: ef08853e4a908eac79ad9eabdd1ba76d258c2314 [file] [log] [blame]
developer02e65912023-08-17 16:33:10 +08001/* adapter_init.c
2 *
3 * Adapter module responsible for adapter initialization tasks.
4 *
5 */
6
7/*****************************************************************************
8* Copyright (c) 2011-2022 by Rambus, Inc. and/or its subsidiaries.
9*
10* This program is free software: you can redistribute it and/or modify
11* it under the terms of the GNU General Public License as published by
12* the Free Software Foundation, either version 2 of the License, or
13* any later version.
14*
15* This program is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more details.
19*
20* You should have received a copy of the GNU General Public License
21* along with this program. If not, see <http://www.gnu.org/licenses/>.
22*****************************************************************************/
23
24/*----------------------------------------------------------------------------
25 * This module implements (provides) the following interface(s):
26 */
27
28#include "adapter_init.h"
29
30
31/*----------------------------------------------------------------------------
32 * This module uses (requires) the following interface(s):
33 */
34
35// Top-level Adapter configuration
36#include "cs_adapter.h"
37
38#ifdef ADAPTER_PEC_INTERRUPTS_ENABLE
39#include "adapter_interrupts.h" // Adapter_Interrupts_Init,
40 // Adapter_Interrupts_UnInit
41#endif
42
43// Runtime Power Management Device Macros API
44#include "rpm_device_macros.h" // RPM_*
45
46// Logging API
47#include "log.h" // LOG_*
48
49// Driver Framework Device API
50#include "device_mgmt.h" // Device_Initialize, Device_UnInitialize
51#include "device_rw.h" // Device_Read32, Device_Write32
52
53// Driver Framework DMAResource API
54#include "dmares_mgmt.h" // DMAResource_Init, DMAResource_UnInit
55
56// Driver Framework C Library API
57#include "clib.h" // memcpy, ZEROINIT
58
59// Driver Framework Basic Definitions API
60#include "basic_defs.h" // bool, true, false
61
62
63/*----------------------------------------------------------------------------
64 * Local variables
65 */
66
67static bool Adapter_IsInitialized = false;
68
69#ifdef ADAPTER_GLOBAL_BOARDCTRL_SUPPORT_ENABLE
70static Device_Handle_t Adapter_Device_BOARDCTRL;
71#endif
72
73static int Device_IRQ;
74
75/*----------------------------------------------------------------------------
76 * Forward declarations
77 */
78
79static int
80AdapterLib_EIP197_Resume(void * p);
81
82#ifdef ADAPTER_GLOBAL_RPM_EIP197_DEVICE_ID
83static int
84AdapterLib_EIP197_Suspend(void * p);
85#endif // ADAPTER_GLOBAL_RPM_EIP197_DEVICE_ID
86
87#ifdef ADAPTER_PEC_INTERRUPTS_ENABLE
88#ifdef ADAPTER_GLOBAL_RPM_EIP201_DEVICE_ID
89static int
90AdapterLib_EIP201_Resume(void * p);
91#endif
92#endif
93
94
95/*----------------------------------------------------------------------------
96 * AdapterLib_EIP197_Resume
97 *
98 */
99static int
100AdapterLib_EIP197_Resume(void * p)
101{
102 IDENTIFIER_NOT_USED(p);
103
104 // FPGA board specific functionality
105#ifdef ADAPTER_GLOBAL_BOARDCTRL_SUPPORT_ENABLE
106 {
107#ifdef ADAPTER_GLOBAL_FPGA_HW_RESET_ENABLE
108 LOG_INFO("%s: reset FPGA\n", __func__);
109 // Perform HW Reset for the EIP-197 FPGA board
110 Device_Write32(Adapter_Device_BOARDCTRL, 0x2000, 0);
111 Device_Write32(Adapter_Device_BOARDCTRL, 0x2000, 0xFFFFFFFF);
112 Device_Write32(Adapter_Device_BOARDCTRL, 0x2000, 0);
113#endif // ADAPTER_GLOBAL_FPGA_HW_RESET_ENABLE
114 }
115#endif // ADAPTER_GLOBAL_BOARDCTRL_SUPPORT_ENABLE
116
117 return 0; // success
118}
119
120
121#ifdef ADAPTER_GLOBAL_RPM_EIP197_DEVICE_ID
122/*----------------------------------------------------------------------------
123 * AdapterLib_EIP197_Suspend
124 *
125 */
126static int
127AdapterLib_EIP197_Suspend(void * p)
128{
129 IDENTIFIER_NOT_USED(p);
130
131 // FPGA board specific functionality
132#ifdef ADAPTER_GLOBAL_BOARDCTRL_SUPPORT_ENABLE
133 {
134#ifdef ADAPTER_GLOBAL_FPGA_HW_RESET_ENABLE
135 LOG_INFO("%s: reset FPGA\n", __func__);
136 // Perform HW Reset for the EIP-197 FPGA board
137 Device_Write32(Adapter_Device_BOARDCTRL, 0x2000, 0);
138 Device_Write32(Adapter_Device_BOARDCTRL, 0x2000, 0xFFFFFFFF);
139 Device_Write32(Adapter_Device_BOARDCTRL, 0x2000, 0);
140#endif // ADAPTER_GLOBAL_FPGA_HW_RESET_ENABLE
141 }
142#endif // ADAPTER_GLOBAL_BOARDCTRL_SUPPORT_ENABLE
143
144 return 0; // success
145}
146#endif // ADAPTER_GLOBAL_RPM_EIP197_DEVICE_ID
147
148
149#ifdef ADAPTER_PEC_INTERRUPTS_ENABLE
150#ifdef ADAPTER_GLOBAL_RPM_EIP201_DEVICE_ID
151/*----------------------------------------------------------------------------
152 * AdapterLib_EIP201_Resume
153 *
154 */
155static int
156AdapterLib_EIP201_Resume(void * p)
157{
158 IDENTIFIER_NOT_USED(p);
159
160 return Adapter_Interrupts_Resume();
161}
162#endif
163#endif
164
165
166/*----------------------------------------------------------------------------
167 * Adapter_Init
168 *
169 * Return Value
170 * true Success
171 * false Failure (fatal!)
172 */
173bool
174Adapter_Init(void)
175{
176 Device_IRQ = -1;
177
178 if (Adapter_IsInitialized != false)
179 {
180 LOG_WARN("Adapter_Init: Already initialized\n");
181 return true;
182 }
183
184 // trigger first-time initialization of the adapter
185 if (Device_Initialize(&Device_IRQ) < 0)
186 return false;
187
188#ifdef ADAPTER_GLOBAL_BOARDCTRL_SUPPORT_ENABLE
189 Adapter_Device_BOARDCTRL = Device_Find("BOARD_CTRL");
190 if (Adapter_Device_BOARDCTRL == NULL)
191 {
192 LOG_CRIT("Adapter_Init: Failed to locate BOARD_CTRL\n");
193 Device_UnInitialize();
194 return false;
195 }
196#endif // ADAPTER_GLOBAL_BOARDCTRL_SUPPORT_ENABLE
197
198 if (!DMAResource_Init())
199 {
200 Device_UnInitialize();
201 return false;
202 }
203
204 if (RPM_DEVICE_INIT_START_MACRO(ADAPTER_GLOBAL_RPM_EIP197_DEVICE_ID,
205 AdapterLib_EIP197_Suspend,
206 AdapterLib_EIP197_Resume)
207 != RPM_SUCCESS)
208 {
209 DMAResource_UnInit();
210 Device_UnInitialize();
211 return false;
212 }
213
214 AdapterLib_EIP197_Resume(NULL);
215
216 (void)RPM_DEVICE_INIT_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP197_DEVICE_ID);
217
218#ifdef ADAPTER_PEC_INTERRUPTS_ENABLE
219 {
220 int res;
221
222 if (RPM_DEVICE_INIT_START_MACRO(ADAPTER_GLOBAL_RPM_EIP201_DEVICE_ID,
223 NULL, // Suspend callback not used
224 AdapterLib_EIP201_Resume)
225 != RPM_SUCCESS)
226 {
227 DMAResource_UnInit();
228 Device_UnInitialize();
229 return false;
230 }
231
232 res = Adapter_Interrupts_Init(Device_IRQ);
233
234 (void)RPM_DEVICE_INIT_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP201_DEVICE_ID);
235
236 if (res < 0)
237 {
238 LOG_CRIT("Adapter_Init: Adapter_Interrupts_Init failed\n");
239 DMAResource_UnInit();
240 Device_UnInitialize();
241 return false;
242 }
243 }
244#endif
245
246 Adapter_IsInitialized = true;
247
248 return true; // success
249}
250
251
252/*----------------------------------------------------------------------------
253 * Adapter_UnInit
254 */
255void
256Adapter_UnInit(void)
257{
258 if (!Adapter_IsInitialized)
259 {
260 LOG_WARN("Adapter_UnInit: Adapter is not initialized\n");
261 return;
262 }
263
264 Adapter_IsInitialized = false;
265
266 DMAResource_UnInit();
267
268#ifdef ADAPTER_PEC_INTERRUPTS_ENABLE
269 if (RPM_DEVICE_UNINIT_START_MACRO(ADAPTER_GLOBAL_RPM_EIP201_DEVICE_ID,
270 true) == RPM_SUCCESS)
271 {
272 Adapter_Interrupts_UnInit(Device_IRQ);
273 (void)RPM_DEVICE_UNINIT_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP201_DEVICE_ID);
274 }
275#endif
276
277 (void)RPM_DEVICE_UNINIT_START_MACRO(ADAPTER_GLOBAL_RPM_EIP197_DEVICE_ID, false);
278 (void)RPM_DEVICE_UNINIT_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP197_DEVICE_ID);
279
280 Device_UnInitialize();
281}
282
283
284/*----------------------------------------------------------------------------
285 * Adapter_Report_Build_Params
286 */
287void
288Adapter_Report_Build_Params(void)
289{
290 // This function is dependent on config file cs_adapter.h.
291 // Please update this when Config file for Adapter is changed.
292 Log_FormattedMessage("Adapter build configuration of %s:\n",
293 ADAPTER_VERSION_STRING);
294
295#define REPORT_SET(_X) \
296 Log_FormattedMessage("\t" #_X "\n")
297
298#define REPORT_STR(_X) \
299 Log_FormattedMessage("\t" #_X ": %s\n", _X)
300
301#define REPORT_INT(_X) \
302 Log_FormattedMessage("\t" #_X ": %d\n", _X)
303
304#define REPORT_HEX32(_X) \
305 Log_FormattedMessage("\t" #_X ": 0x%08X\n", _X)
306
307#define REPORT_EQ(_X, _Y) \
308 Log_FormattedMessage("\t" #_X " == " #_Y "\n")
309
310#define REPORT_EXPL(_X, _Y) \
311 Log_FormattedMessage("\t" #_X _Y "\n")
312
313 // Adapter PEC
314#ifdef ADAPTER_PEC_DBG
315 REPORT_SET(ADAPTER_PEC_DBG);
316#endif
317
318#ifdef ADAPTER_PEC_STRICT_ARGS
319 REPORT_SET(ADAPTER_PEC_STRICT_ARGS);
320#endif
321
322#ifdef ADAPTER_PEC_ENABLE_SCATTERGATHER
323 REPORT_SET(ADAPTER_PEC_ENABLE_SCATTERGATHER);
324#endif
325
326#ifdef ADAPTER_PEC_SEPARATE_RINGS
327 REPORT_SET(ADAPTER_PEC_SEPARATE_RINGS);
328#else
329 REPORT_EXPL(ADAPTER_PEC_SEPARATE_RINGS, " is NOT set => Overlapping");
330#endif
331
332#ifdef ADAPTER_PEC_ARMRING_ENABLE_SWAP
333 REPORT_SET(ADAPTER_PEC_ARMRING_ENABLE_SWAP);
334#endif
335
336 REPORT_INT(ADAPTER_PEC_DEVICE_COUNT);
337 REPORT_INT(ADAPTER_PEC_MAX_PACKETS);
338 REPORT_INT(ADAPTER_MAX_PECLOGICDESCR);
339 REPORT_INT(ADAPTER_PEC_MAX_SAS);
340 REPORT_INT(ADAPTER_DESCRIPTORDONETIMEOUT);
341 REPORT_INT(ADAPTER_DESCRIPTORDONECOUNT);
342
343#ifdef ADAPTER_REMOVE_BOUNCEBUFFERS
344 REPORT_EXPL(ADAPTER_REMOVE_BOUNCEBUFFERS, " is SET => Bounce DISABLED");
345#else
346 REPORT_EXPL(ADAPTER_REMOVE_BOUNCEBUFFERS, " is NOT set => Bounce ENABLED");
347#endif
348
349#ifdef ADAPTER_EIP202_INTERRUPTS_ENABLE
350 REPORT_EXPL(ADAPTER_EIP202_INTERRUPTS_ENABLE,
351 " is SET => Interrupts ENABLED");
352#else
353 REPORT_EXPL(ADAPTER_EIP202_INTERRUPTS_ENABLE,
354 " is NOT set => Interrupts DISABLED");
355#endif
356
357#ifdef ADAPTER_PCL_ENABLE
358 REPORT_SET(ADAPTER_PCL_ENABLE);
359 REPORT_INT(ADAPTER_PCL_FLOW_HASH_ENTRIES_COUNT);
360#endif
361
362#ifdef ADAPTER_64BIT_HOST
363 REPORT_EXPL(ADAPTER_64BIT_HOST,
364 " is SET => addresses are 64-bit");
365#else
366 REPORT_EXPL(ADAPTER_64BIT_HOST,
367 " is NOT set => addresses are 32-bit");
368#endif
369
370#ifdef ADAPTER_64BIT_DEVICE
371 REPORT_EXPL(ADAPTER_64BIT_DEVICE,
372 " is SET => full 64-bit DMA addresses usable");
373#else
374 REPORT_EXPL(ADAPTER_64BIT_DEVICE,
375 " is NOT set => DMA addresses must be below 4GB");
376#endif
377
378#ifdef ADAPTER_DMARESOURCE_BANKS_ENABLE
379 REPORT_SET(ADAPTER_DMARESOURCE_BANKS_ENABLE);
380#endif
381
382 // Adapter Global Classification Control
383#ifdef ADAPTER_CS_TIMER_PRESCALER
384 REPORT_INT(ADAPTER_CS_TIMER_PRESCALER);
385#endif
386
387#ifdef ADAPTER_GLOBAL_BOARDCTRL_SUPPORT_ENABLE
388 REPORT_SET(ADAPTER_GLOBAL_BOARDCTRL_SUPPORT_ENABLE);
389#endif
390
391 // Log
392 Log_FormattedMessage("Logging:\n");
393
394#if (LOG_SEVERITY_MAX == LOG_SEVERITY_INFO)
395 REPORT_EQ(LOG_SEVERITY_MAX, LOG_SEVERITY_INFO);
396#elif (LOG_SEVERITY_MAX == LOG_SEVERITY_WARNING)
397 REPORT_EQ(LOG_SEVERITY_MAX, LOG_SEVERITY_W_A_R_N_I_N_G);
398#elif (LOG_SEVERITY_MAX == LOG_SEVERITY_CRITICAL)
399 REPORT_EQ(LOG_SEVERITY_MAX, LOG_SEVERITY_CRITICAL);
400#else
401 REPORT_EXPL(LOG_SEVERITY_MAX, " - Unknown (not info/warn/crit)");
402#endif
403
404 // Adapter other
405 Log_FormattedMessage("Other:\n");
406 REPORT_STR(ADAPTER_DRIVER_NAME);
407 REPORT_STR(ADAPTER_LICENSE);
408 REPORT_HEX32(ADAPTER_INTERRUPTS_TRACEFILTER);
409 REPORT_STR(RPM_DEVICE_CAPABILITIES_STR_MACRO);
410}
411
412
413/* end of file adapter_init.c */