blob: 4bcb88e0ef78a00533ed65821f991686455ef474 [file] [log] [blame]
developer02e65912023-08-17 16:33:10 +08001/* adapter_init_pec.c
2 *
3 * Adapter module responsible for Adapter PEC initialization tasks.
4 *
5 */
6
7/*****************************************************************************
8* Copyright (c) 2012-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// Logging API
44#include "log.h" // LOG_*
45
46// Driver Framework Device API
47#include "device_mgmt.h" // Device_Initialize, Device_UnInitialize
48#include "device_rw.h" // Device_Read32, Device_Write32
49
50// Driver Framework DMAResource API
51#include "dmares_mgmt.h" // DMAResource_Init, DMAResource_UnInit
52
53// Driver Framework C Library API
54#include "clib.h" // memcpy, ZEROINIT
55
56// Driver Framework Basic Definitions API
57#include "basic_defs.h" // bool, true, false
58
59
60/*----------------------------------------------------------------------------
61 * Local variables
62 */
63
64static bool Adapter_IsInitialized = false;
65static int Device_IRQ;
66
67
68/*----------------------------------------------------------------------------
69 * Forward declarations
70 */
71
72
73/*----------------------------------------------------------------------------
74 * Adapter_Init
75 *
76 * Return Value
77 * true Success
78 * false Failure (fatal!)
79 */
80bool
81Adapter_Init(void)
82{
83 Device_IRQ = -1;
84
85 if (Adapter_IsInitialized != false)
86 {
87 LOG_WARN("Adapter_Init: Already initialized\n");
88 return true;
89 }
90
91 // trigger first-time initialization of the adapter
92 if (Device_Initialize(&Device_IRQ) < 0)
93 return false;
94
95 if (!DMAResource_Init())
96 {
97 Device_UnInitialize();
98 return false;
99 }
100
101#ifdef ADAPTER_PEC_INTERRUPTS_ENABLE
102 if (Adapter_Interrupts_Init(Device_IRQ) < 0)
103 {
104 LOG_CRIT("Adapter_Init: Adapter_Interrupts_Init failed\n");
105 DMAResource_UnInit();
106 Device_UnInitialize();
107 return false;
108 }
109#endif
110
111 Adapter_IsInitialized = true;
112
113 return true; // success
114}
115
116
117/*----------------------------------------------------------------------------
118 * Adapter_UnInit
119 */
120void
121Adapter_UnInit(void)
122{
123 if (!Adapter_IsInitialized)
124 {
125 LOG_WARN("Adapter_UnInit: Adapter is not initialized\n");
126 return;
127 }
128
129 Adapter_IsInitialized = false;
130
131 DMAResource_UnInit();
132
133#ifdef ADAPTER_PEC_INTERRUPTS_ENABLE
134 Adapter_Interrupts_UnInit(Device_IRQ);
135#endif
136
137 Device_UnInitialize();
138}
139
140
141/*----------------------------------------------------------------------------
142 * Adapter_Report_Build_Params
143 */
144void
145Adapter_Report_Build_Params(void)
146{
147 // This function is dependent on config file cs_adapter.h.
148 // Please update this when Config file for Adapter is changed.
149 Log_FormattedMessage("Adapter build configuration of %s:\n",
150 ADAPTER_VERSION_STRING);
151
152#define REPORT_SET(_X) \
153 Log_FormattedMessage("\t" #_X "\n")
154
155#define REPORT_STR(_X) \
156 Log_FormattedMessage("\t" #_X ": %s\n", _X)
157
158#define REPORT_INT(_X) \
159 Log_FormattedMessage("\t" #_X ": %d\n", _X)
160
161#define REPORT_HEX32(_X) \
162 Log_FormattedMessage("\t" #_X ": 0x%08X\n", _X)
163
164#define REPORT_EQ(_X, _Y) \
165 Log_FormattedMessage("\t" #_X " == " #_Y "\n")
166
167#define REPORT_EXPL(_X, _Y) \
168 Log_FormattedMessage("\t" #_X _Y "\n")
169
170 // Adapter PEC
171#ifdef ADAPTER_PEC_DBG
172 REPORT_SET(ADAPTER_PEC_DBG);
173#endif
174
175#ifdef ADAPTER_PEC_STRICT_ARGS
176 REPORT_SET(ADAPTER_PEC_STRICT_ARGS);
177#endif
178
179#ifdef ADAPTER_PEC_ENABLE_SCATTERGATHER
180 REPORT_SET(ADAPTER_PEC_ENABLE_SCATTERGATHER);
181#endif
182
183#ifdef ADAPTER_PEC_SEPARATE_RINGS
184 REPORT_SET(ADAPTER_PEC_SEPARATE_RINGS);
185#else
186 REPORT_EXPL(ADAPTER_PEC_SEPARATE_RINGS, " is NOT set => Overlapping");
187#endif
188
189#ifdef ADAPTER_PEC_ARMRING_ENABLE_SWAP
190 REPORT_SET(ADAPTER_PEC_ARMRING_ENABLE_SWAP);
191#endif
192
193 REPORT_INT(ADAPTER_PEC_DEVICE_COUNT);
194 REPORT_INT(ADAPTER_PEC_MAX_PACKETS);
195 REPORT_INT(ADAPTER_MAX_PECLOGICDESCR);
196 REPORT_INT(ADAPTER_PEC_MAX_SAS);
197 REPORT_INT(ADAPTER_DESCRIPTORDONETIMEOUT);
198 REPORT_INT(ADAPTER_DESCRIPTORDONECOUNT);
199
200#ifdef ADAPTER_REMOVE_BOUNCEBUFFERS
201 REPORT_EXPL(ADAPTER_REMOVE_BOUNCEBUFFERS, " is SET => Bounce DISABLED");
202#else
203 REPORT_EXPL(ADAPTER_REMOVE_BOUNCEBUFFERS, " is NOT set => Bounce ENABLED");
204#endif
205
206#ifdef ADAPTER_EIP202_INTERRUPTS_ENABLE
207 REPORT_EXPL(ADAPTER_EIP202_INTERRUPTS_ENABLE,
208 " is SET => Interrupts ENABLED");
209#else
210 REPORT_EXPL(ADAPTER_EIP202_INTERRUPTS_ENABLE,
211 " is NOT set => Interrupts DISABLED");
212#endif
213
214#ifdef ADAPTER_PCL_ENABLE
215 REPORT_SET(ADAPTER_PCL_ENABLE);
216 REPORT_INT(ADAPTER_PCL_FLOW_HASH_ENTRIES_COUNT);
217#endif
218
219#ifdef ADAPTER_64BIT_HOST
220 REPORT_EXPL(ADAPTER_64BIT_HOST,
221 " is SET => addresses are 64-bit");
222#else
223 REPORT_EXPL(ADAPTER_64BIT_HOST,
224 " is NOT set => addresses are 32-bit");
225#endif
226
227#ifdef ADAPTER_64BIT_DEVICE
228 REPORT_EXPL(ADAPTER_64BIT_DEVICE,
229 " is SET => full 64-bit DMA addresses usable");
230#else
231 REPORT_EXPL(ADAPTER_64BIT_DEVICE,
232 " is NOT set => DMA addresses must be below 4GB");
233#endif
234
235#ifdef ADAPTER_DMARESOURCE_BANKS_ENABLE
236 REPORT_SET(ADAPTER_DMARESOURCE_BANKS_ENABLE);
237#endif
238
239 // Adapter Global Classification Control
240#ifdef ADAPTER_CS_TIMER_PRESCALER
241 REPORT_INT(ADAPTER_CS_TIMER_PRESCALER);
242#endif
243
244 // Log
245 Log_FormattedMessage("Logging:\n");
246
247#if (LOG_SEVERITY_MAX == LOG_SEVERITY_INFO)
248 REPORT_EQ(LOG_SEVERITY_MAX, LOG_SEVERITY_INFO);
249#elif (LOG_SEVERITY_MAX == LOG_SEVERITY_WARNING)
250 REPORT_EQ(LOG_SEVERITY_MAX, LOG_SEVERITY_W_A_R_N_I_N_G);
251#elif (LOG_SEVERITY_MAX == LOG_SEVERITY_CRITICAL)
252 REPORT_EQ(LOG_SEVERITY_MAX, LOG_SEVERITY_CRITICAL);
253#else
254 REPORT_EXPL(LOG_SEVERITY_MAX, " - Unknown (not info/warn/crit)");
255#endif
256
257 // Adapter other
258 Log_FormattedMessage("Other:\n");
259 REPORT_STR(ADAPTER_DRIVER_NAME);
260 REPORT_STR(ADAPTER_LICENSE);
261 REPORT_HEX32(ADAPTER_INTERRUPTS_TRACEFILTER);
262}
263
264
265/* end of file adapter_init_pec.c */