developer | 02e6591 | 2023-08-17 16:33:10 +0800 | [diff] [blame] | 1 | /* adapter_global_init.c |
| 2 | * |
| 3 | * Global Control initialization module. |
| 4 | */ |
| 5 | |
| 6 | /***************************************************************************** |
| 7 | * Copyright (c) 2011-2022 by Rambus, Inc. and/or its subsidiaries. |
| 8 | * |
| 9 | * This program is free software: you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation, either version 2 of the License, or |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | *****************************************************************************/ |
| 22 | |
| 23 | /*---------------------------------------------------------------------------- |
| 24 | * This module implements (provides) the following interface(s): |
| 25 | */ |
| 26 | #include "adapter_global_init.h" |
| 27 | |
| 28 | |
| 29 | /*---------------------------------------------------------------------------- |
| 30 | * This module uses (requires) the following interface(s): |
| 31 | */ |
| 32 | |
| 33 | // Default Adapter configuration |
| 34 | #include "c_adapter_global.h" // ADAPTER_GLOBAL_PRNG_SEED |
| 35 | |
| 36 | // Global Control API: Packet I/O |
| 37 | #include "api_global_eip97.h" |
| 38 | |
| 39 | // Driver Framework Basic Definitions API |
| 40 | #include "basic_defs.h" // uint8_t, uint32_t, bool |
| 41 | |
| 42 | // Driver Framework C Library API |
| 43 | #include "clib.h" // memcpy |
| 44 | |
| 45 | // EIP-97 Driver Library Global Control API |
| 46 | #include "eip97_global_event.h" // Event Management |
| 47 | #include "eip97_global_init.h" // Init/Uninit |
| 48 | #include "eip97_global_prng.h" // PRNG Control |
| 49 | |
| 50 | #include "device_types.h" // Device_Handle_t |
| 51 | #include "device_mgmt.h" // Device_find |
| 52 | #include "log.h" // Log API |
| 53 | |
| 54 | #include "adapter_global_internal.h" |
| 55 | |
| 56 | /*---------------------------------------------------------------------------- |
| 57 | * Definitions and macros |
| 58 | */ |
| 59 | |
| 60 | |
| 61 | /*---------------------------------------------------------------------------- |
| 62 | * Local variables |
| 63 | */ |
| 64 | static const uint32_t Global_PRNG_Key[8] = ADAPTER_GLOBAL_PRNG_SEED; |
| 65 | |
| 66 | /*---------------------------------------------------------------------------- |
| 67 | * BoolToString() |
| 68 | * |
| 69 | * Convert boolean value to string. |
| 70 | */ |
| 71 | static const char * |
| 72 | BoolToString( |
| 73 | const bool b) |
| 74 | { |
| 75 | if (b) |
| 76 | return "true"; |
| 77 | else |
| 78 | return "false"; |
| 79 | } |
| 80 | |
| 81 | /*---------------------------------------------------------------------------- |
| 82 | * Adapter_Global_StatusReport() |
| 83 | * |
| 84 | * Obtain all available global status information from the EIP-97 driver |
| 85 | * and report it. |
| 86 | */ |
| 87 | static void |
| 88 | Adapter_Global_StatusReport(void) |
| 89 | { |
| 90 | GlobalControl97_Error_t rc; |
| 91 | unsigned int i; |
| 92 | unsigned int NofPEs; |
| 93 | GlobalControl97_Interfaces_Get(&NofPEs,NULL,NULL,NULL); |
| 94 | |
| 95 | LOG_INFO("\n\t\t Adapter_Global_StatusReport \n"); |
| 96 | |
| 97 | LOG_CRIT("Global Status of the EIP-97\n"); |
| 98 | |
| 99 | for (i=0; i < NofPEs; i++) |
| 100 | { |
| 101 | LOG_CRIT("Packet Engine %d Status\n", i); |
| 102 | { |
| 103 | GlobalControl97_DFE_Status_t DFE_Status; |
| 104 | |
| 105 | rc = GlobalControl97_DFE_Status_Get(i, &DFE_Status); |
| 106 | |
| 107 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 108 | { |
| 109 | continue; |
| 110 | } |
| 111 | |
| 112 | LOG_CRIT("DFE Status: CD FIFO Words: %d, CDR ID: %d, DMA size: %d\n" |
| 113 | "AtDMA busy: %s, DataDMA busy: %s, DMA err: %s\n", |
| 114 | DFE_Status.CDFifoWord32Count, |
| 115 | DFE_Status.CDR_ID, |
| 116 | DFE_Status.DMASize, |
| 117 | BoolToString(DFE_Status.fAtDMABusy), |
| 118 | BoolToString(DFE_Status.fDataDMABusy), |
| 119 | BoolToString(DFE_Status.fDMAError)); |
| 120 | } |
| 121 | |
| 122 | { |
| 123 | GlobalControl97_DSE_Status_t DSE_Status; |
| 124 | |
| 125 | rc = GlobalControl97_DSE_Status_Get(i, &DSE_Status); |
| 126 | |
| 127 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 128 | { |
| 129 | continue; |
| 130 | } |
| 131 | |
| 132 | LOG_CRIT("DSE Status: RD FIFO Words: %d, RDR ID: %d, DMA size: %d\n" |
| 133 | "Data flush busy: %s, DataDMA busy: %s, DMA err: %s\n", |
| 134 | DSE_Status.RDFifoWord32Count, |
| 135 | DSE_Status.RDR_ID, |
| 136 | DSE_Status.DMASize, |
| 137 | BoolToString(DSE_Status.fDataFlushBusy), |
| 138 | BoolToString(DSE_Status.fDataDMABusy), |
| 139 | BoolToString(DSE_Status.fDMAError)); |
| 140 | } |
| 141 | |
| 142 | { |
| 143 | GlobalControl97_Token_Status_t Token_Status; |
| 144 | rc = GlobalControl97_Token_Status_Get(i, &Token_Status); |
| 145 | |
| 146 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 147 | { |
| 148 | continue; |
| 149 | } |
| 150 | |
| 151 | LOG_CRIT("Token Status: Active: %d, loc available: %s\n" |
| 152 | "res available: %s, read active: %s, ccache active: %s\n" |
| 153 | "cntx fetch: %s, res cntx: %s\n" |
| 154 | "processing held: %s, busy: %s\n", |
| 155 | Token_Status.ActiveTokenCount, |
| 156 | BoolToString(Token_Status.fTokenLocationAvailable), |
| 157 | BoolToString(Token_Status.fResultTokenAvailable), |
| 158 | BoolToString(Token_Status.fTokenReadActive), |
| 159 | BoolToString(Token_Status.fContextCacheActive), |
| 160 | BoolToString(Token_Status.fContextFetch), |
| 161 | BoolToString(Token_Status.fResultContext), |
| 162 | BoolToString(Token_Status.fProcessingHeld), |
| 163 | BoolToString(Token_Status.fBusy)); |
| 164 | } |
| 165 | |
| 166 | { |
| 167 | GlobalControl97_Context_Status_t Context_Status; |
| 168 | |
| 169 | rc = GlobalControl97_Context_Status_Get(i, &Context_Status); |
| 170 | |
| 171 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 172 | { |
| 173 | continue; |
| 174 | } |
| 175 | |
| 176 | LOG_CRIT("Context Status: Err mask: %04x, Available: %d\n" |
| 177 | "Active cntx: %s, next cntx: %s, result cntx: %s" |
| 178 | " Err recov: %s\n", |
| 179 | Context_Status.Error, |
| 180 | Context_Status.AvailableTokenCount, |
| 181 | BoolToString(Context_Status.fActiveContext), |
| 182 | BoolToString(Context_Status.fNextContext), |
| 183 | BoolToString(Context_Status.fResultContext), |
| 184 | BoolToString(Context_Status.fErrorRecovery)); |
| 185 | } |
| 186 | |
| 187 | { |
| 188 | GlobalControl97_Interrupt_Status_t Interrupt_Status; |
| 189 | |
| 190 | rc = GlobalControl97_Interrupt_Status_Get(i, &Interrupt_Status); |
| 191 | |
| 192 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 193 | { |
| 194 | continue; |
| 195 | } |
| 196 | |
| 197 | LOG_CRIT("Interrupt Status: input DMA err: %s, output DMA err %s \n" |
| 198 | "pkt proc err: %s, pkt timeout: %s, f a t a l err: %s, " |
| 199 | "PE int out: %s\n" |
| 200 | "inp DMA enable: %s, outp DMA enable %s, " |
| 201 | "pkt proc enable: %s\n" |
| 202 | "pkt timeout enable: %s, f a t a l enable: %s," |
| 203 | "PE int out enable: %s\n", |
| 204 | BoolToString(Interrupt_Status.fInputDMAError), |
| 205 | BoolToString(Interrupt_Status.fOutputDMAError), |
| 206 | BoolToString(Interrupt_Status.fPacketProcessingError), |
| 207 | BoolToString(Interrupt_Status.fPacketTimeout), |
| 208 | BoolToString(Interrupt_Status.fFatalError), |
| 209 | BoolToString(Interrupt_Status.fPeInterruptOut), |
| 210 | BoolToString(Interrupt_Status.fInputDMAErrorEnabled), |
| 211 | BoolToString(Interrupt_Status.fOutputDMAErrorEnabled), |
| 212 | BoolToString(Interrupt_Status.fPacketProcessingEnabled), |
| 213 | BoolToString(Interrupt_Status.fPacketTimeoutEnabled), |
| 214 | BoolToString(Interrupt_Status.fFatalErrorEnabled), |
| 215 | BoolToString(Interrupt_Status.fPeInterruptOutEnabled)); |
| 216 | } |
| 217 | { |
| 218 | GlobalControl97_Output_Transfer_Status_t OutXfer_Status; |
| 219 | |
| 220 | rc = GlobalControl97_OutXfer_Status_Get(i, &OutXfer_Status); |
| 221 | |
| 222 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 223 | { |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | LOG_CRIT("Output Transfer Status: availabe: %d, " |
| 228 | "min: %d, max: %d, size mask: %d\n", |
| 229 | OutXfer_Status.AvailableWord32Count, |
| 230 | OutXfer_Status.MinTransferWordCount, |
| 231 | OutXfer_Status.MaxTransferWordCount, |
| 232 | OutXfer_Status.TransferSizeMask); |
| 233 | } |
| 234 | { |
| 235 | GlobalControl97_PRNG_Status_t PRNG_Status; |
| 236 | |
| 237 | rc = GlobalControl97_PRNG_Status_Get(i, &PRNG_Status); |
| 238 | |
| 239 | if (rc == GLOBAL_CONTROL_ERROR_NOT_IMPLEMENTED) |
| 240 | { |
| 241 | LOG_CRIT("No PRNG present in EIP-96\n"); |
| 242 | } |
| 243 | else if (rc == GLOBAL_CONTROL_NO_ERROR) |
| 244 | { |
| 245 | LOG_CRIT("PRNG Status: busy: %s, res ready: %s\n", |
| 246 | BoolToString(PRNG_Status.fBusy), |
| 247 | BoolToString(PRNG_Status.fResultReady)); |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | #ifdef ADAPTER_GLOBAL_DBG_STATISTICS |
| 252 | { |
| 253 | GlobalControl97_Debug_Statistics_t Debug_Statistics; |
| 254 | |
| 255 | rc = GlobalControl97_Debug_Statistics_Get(&Debug_Statistics); |
| 256 | |
| 257 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 258 | { |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | LOG_CRIT("\nInterface DBG Statistics:\n"); |
| 263 | for (i=0; i<16; i++) |
| 264 | { |
| 265 | if(Debug_Statistics.Ifc_Packets_In[i] != 0 || |
| 266 | Debug_Statistics.Ifc_Packets_Out[i] != 0) |
| 267 | { |
| 268 | LOG_CRIT("\t\tInterface #%2u Input pkts=%10u Output pkts=%10u\n", |
| 269 | i, |
| 270 | (unsigned int)Debug_Statistics.Ifc_Packets_In[i], |
| 271 | (unsigned int)Debug_Statistics.Ifc_Packets_Out[i]); |
| 272 | } |
| 273 | } |
| 274 | LOG_CRIT("\nPipe DBG Statistics:\n"); |
| 275 | for (i=0; i <NofPEs; i++) |
| 276 | { |
| 277 | LOG_CRIT("\t\tPipe #%2u Total=%10u Data=%10u Cur=%3u Max=%3u\n", |
| 278 | i, |
| 279 | (unsigned int)Debug_Statistics.Pipe_Total_Packets[i], |
| 280 | (unsigned int)Debug_Statistics.Pipe_Data_Count[i], |
| 281 | (unsigned int)Debug_Statistics.Pipe_Current_Packets[i], |
| 282 | (unsigned int)Debug_Statistics.Pipe_Max_Packets[i]); |
| 283 | } |
| 284 | } |
| 285 | #endif |
| 286 | } |
| 287 | |
| 288 | |
| 289 | /*---------------------------------------------------------------------------- |
| 290 | * Adapter_Global_Init() |
| 291 | * |
| 292 | */ |
| 293 | bool |
| 294 | Adapter_Global_Init(void) |
| 295 | { |
| 296 | unsigned int NofPEs, NofRings, NofLAInterfaces, NofInlineInterfaces; |
| 297 | GlobalControl97_Error_t rc; |
| 298 | unsigned int i; |
| 299 | |
| 300 | LOG_INFO("\n\t\t Adapter_Global_Init \n"); |
| 301 | |
| 302 | // Initialize the device |
| 303 | rc = GlobalControl97_Init(false); |
| 304 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 305 | { |
| 306 | LOG_CRIT("Adaptar_Global_Init: EIP97 initialization failed\n"); |
| 307 | return false; // error |
| 308 | } |
| 309 | |
| 310 | GlobalControl97_Interfaces_Get(&NofPEs, |
| 311 | &NofRings, |
| 312 | &NofLAInterfaces, |
| 313 | &NofInlineInterfaces); |
| 314 | |
| 315 | // First read the device capabilities |
| 316 | { |
| 317 | GlobalControl97_Capabilities_t Capabilities; |
| 318 | |
| 319 | rc = GlobalControl97_Capabilities_Get(&Capabilities); |
| 320 | if ( rc != GLOBAL_CONTROL_NO_ERROR) |
| 321 | { |
| 322 | LOG_CRIT("GlobalControl97_Capabilities_Get returned error\n"); |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | LOG_CRIT("Global EIP-97 capabilities: %s\n", |
| 327 | Capabilities.szTextDescription); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | // Enable the rings for the packet engines |
| 332 | { |
| 333 | GlobalControl97_Ring_PE_Map_t RingPEMap; |
| 334 | |
| 335 | ZEROINIT(RingPEMap); |
| 336 | |
| 337 | // Enable rings |
| 338 | RingPEMap.RingPE_Mask = (1 << (NofRings + NofLAInterfaces + NofInlineInterfaces)) - 1; |
| 339 | |
| 340 | // Set rings priority |
| 341 | RingPEMap.RingPrio_Mask = ADAPTER_GLOBAL_EIP97_PRIOMASK; |
| 342 | |
| 343 | for (i=0; i < NofPEs; i++) |
| 344 | { |
| 345 | rc = GlobalControl97_Configure(i, &RingPEMap); |
| 346 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 347 | { |
| 348 | LOG_CRIT("Ring configuration failed for PE %d\n", i); |
| 349 | GlobalControl97_UnInit(); |
| 350 | return false; // error |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | { |
| 356 | GlobalControl97_PRNG_Status_t PRNG_Status; |
| 357 | // Check whether we have a PRNG. |
| 358 | rc = GlobalControl97_PRNG_Status_Get(0, &PRNG_Status); |
| 359 | |
| 360 | if (rc != GLOBAL_CONTROL_NO_ERROR && rc != GLOBAL_CONTROL_ERROR_NOT_IMPLEMENTED) |
| 361 | { |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | if (rc != GLOBAL_CONTROL_ERROR_NOT_IMPLEMENTED) |
| 366 | { |
| 367 | for (i=0; i < NofPEs; i++) |
| 368 | { |
| 369 | GlobalControl97_PRNG_Reseed_t PRNG_Reseed; |
| 370 | |
| 371 | PRNG_Reseed.SeedLo = Global_PRNG_Key[0]; |
| 372 | PRNG_Reseed.SeedHi = Global_PRNG_Key[1]; |
| 373 | PRNG_Reseed.Key0Lo = Global_PRNG_Key[2]; |
| 374 | PRNG_Reseed.Key0Hi = Global_PRNG_Key[3]; |
| 375 | PRNG_Reseed.Key1Lo = Global_PRNG_Key[4]; |
| 376 | PRNG_Reseed.Key1Hi = Global_PRNG_Key[5]; |
| 377 | PRNG_Reseed.LFSRLo = Global_PRNG_Key[6]; |
| 378 | PRNG_Reseed.LFSRHi = Global_PRNG_Key[7]; |
| 379 | |
| 380 | rc = GlobalControl97_PRNG_Reseed(i, &PRNG_Reseed); |
| 381 | |
| 382 | if (rc != GLOBAL_CONTROL_NO_ERROR) |
| 383 | { |
| 384 | LOG_CRIT("Could not reseed PRNG of PE#%d\n",i); |
| 385 | GlobalControl97_UnInit(); |
| 386 | return false; // error |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | else |
| 391 | { |
| 392 | LOG_CRIT("No PRNG in PEs, skip initialization\n"); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | Adapter_Global_StatusReport(); |
| 397 | |
| 398 | return true; // success |
| 399 | } |
| 400 | |
| 401 | |
| 402 | /*---------------------------------------------------------------------------- |
| 403 | * Adapter_Global_UnInit() |
| 404 | * |
| 405 | */ |
| 406 | void |
| 407 | Adapter_Global_UnInit(void) |
| 408 | { |
| 409 | LOG_INFO("\n\t\t Adapter_Global_UnInit \n"); |
| 410 | |
| 411 | Adapter_Global_StatusReport(); |
| 412 | |
| 413 | GlobalControl97_UnInit(); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | /* end of file adapter_global_eip97.c */ |