developer | 02e6591 | 2023-08-17 16:33:10 +0800 | [diff] [blame^] | 1 | /* adapter_global_eip97.c |
| 2 | * |
| 3 | * Security-IP-97 Global Control Adapter |
| 4 | */ |
| 5 | |
| 6 | /***************************************************************************** |
| 7 | * Copyright (c) 2011-2021 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 "api_global_eip97.h" |
| 27 | #include "adapter_global_internal.h" |
| 28 | |
| 29 | /*---------------------------------------------------------------------------- |
| 30 | * This module uses (requires) the following interface(s): |
| 31 | */ |
| 32 | |
| 33 | // Default Adapter configuration |
| 34 | #include "c_adapter_global.h" |
| 35 | |
| 36 | #ifndef GLOBALCONTROL_BUILD |
| 37 | #include "adapter_ring_eip202.h" // Ring EIP-202 interface to pass |
| 38 | // config params from Global Control |
| 39 | #endif |
| 40 | |
| 41 | // Driver Framework Basic Definitions API |
| 42 | #include "basic_defs.h" // uint8_t, uint32_t, bool, IDENTIFIER_NOT_USED |
| 43 | |
| 44 | // Driver Framework C Library API |
| 45 | #include "clib.h" // memcpy, ZEROINIT |
| 46 | |
| 47 | // EIP-97 Driver Library Global Control API |
| 48 | #include "eip97_global_event.h" // Event Management |
| 49 | #include "eip97_global_init.h" // Init/Uninit |
| 50 | #include "eip97_global_prng.h" // PRNG Control |
| 51 | |
| 52 | #include "device_types.h" // Device_Handle_t |
| 53 | #include "device_mgmt.h" // Device_find |
| 54 | |
| 55 | // Logging API |
| 56 | #include "log.h" // Log_*, LOG_* |
| 57 | |
| 58 | #ifdef GLOBALCONTROL_BUILD |
| 59 | #include "shdevxs_init.h" // SHDevXS_Global_init() |
| 60 | #endif |
| 61 | |
| 62 | // Runtime Power Management Device Macros API |
| 63 | #include "rpm_device_macros.h" // RPM_* |
| 64 | |
| 65 | |
| 66 | /*---------------------------------------------------------------------------- |
| 67 | * Definitions and macros |
| 68 | */ |
| 69 | |
| 70 | typedef struct |
| 71 | { |
| 72 | bool fCached; |
| 73 | |
| 74 | GlobalControl97_Ring_PE_Map_t RingPEMap; |
| 75 | |
| 76 | } GlobalControl97_Ring_PE_Map_Cache_t; |
| 77 | |
| 78 | typedef struct |
| 79 | { |
| 80 | bool fCached; |
| 81 | |
| 82 | GlobalControl97_PRNG_Reseed_t ReseedData; |
| 83 | |
| 84 | } GlobalControl97_PRNG_Cache_t; |
| 85 | |
| 86 | |
| 87 | /*---------------------------------------------------------------------------- |
| 88 | * Local variables |
| 89 | */ |
| 90 | static EIP97_Global_IOArea_t Global_IOArea; |
| 91 | static bool Global_IsInitialized; |
| 92 | static bool Global_PRNG_Present; |
| 93 | |
| 94 | static const GlobalControl97_Capabilities_t Global_CapabilitiesString = |
| 95 | { |
| 96 | "EIP-97 v_._p_ with EIP-202 v_._p_ and EIP-96 v_._p_, " |
| 97 | "#PE=__ #rings=__ central-prng=_"// szTextDescription |
| 98 | }; |
| 99 | |
| 100 | static unsigned int GlobalControl97_NofPEs; |
| 101 | static unsigned int GlobalControl97_NofRings; |
| 102 | static unsigned int GlobalControl97_NofLAInterfaces; |
| 103 | static unsigned int GlobalControl97_NofInlineInterfaces; |
| 104 | |
| 105 | // Cached values for RPM resume callback |
| 106 | static GlobalControl97_Ring_PE_Map_Cache_t GlobalControl97_RingPEMap [ADAPTER_GLOBAL_EIP97_NOF_PES]; |
| 107 | static GlobalControl97_PRNG_Cache_t GlobalControl97_Prng [ADAPTER_GLOBAL_EIP97_NOF_PES]; |
| 108 | |
| 109 | |
| 110 | /*---------------------------------------------------------------------------- |
| 111 | * YesNo |
| 112 | */ |
| 113 | static const char * |
| 114 | YesNo( |
| 115 | const bool b) |
| 116 | { |
| 117 | if (b) |
| 118 | return "Yes"; |
| 119 | else |
| 120 | return "No"; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | /*---------------------------------------------------------------------------- |
| 125 | * GlobalControl97Lib_Resume |
| 126 | * |
| 127 | */ |
| 128 | static int |
| 129 | GlobalControl97Lib_Resume(void * p) |
| 130 | { |
| 131 | unsigned int i; |
| 132 | EIP97_Global_Error_t rc; |
| 133 | EIP97_Global_Capabilities_t Capabilities; |
| 134 | |
| 135 | IDENTIFIER_NOT_USED(p); |
| 136 | |
| 137 | LOG_INFO("\n\t\t\t\t EIP97_Global_Init \n"); |
| 138 | |
| 139 | rc = EIP97_Global_Init(&Global_IOArea, |
| 140 | Device_Find(ADAPTER_GLOBAL_DEVICE_NAME)); |
| 141 | if (rc != EIP97_GLOBAL_NO_ERROR) |
| 142 | { |
| 143 | LOG_CRIT("%s: EIP97_Global_Init() returned error %d\n", __func__, rc); |
| 144 | return -1; // error |
| 145 | } |
| 146 | |
| 147 | rc = EIP97_Global_HWRevision_Get(&Global_IOArea, &Capabilities); |
| 148 | if (rc != EIP97_GLOBAL_NO_ERROR) |
| 149 | { |
| 150 | LOG_CRIT("%s: EIP97_Global_HWRevision_Get() returned error %d\n", __func__, rc); |
| 151 | return -1; // error |
| 152 | } |
| 153 | GlobalControl97_NofPEs = MIN(Capabilities.EIP202_Options.NofPes, ADAPTER_GLOBAL_EIP97_NOF_PES); |
| 154 | for (i = 0; i < GlobalControl97_NofPEs; i++) |
| 155 | { |
| 156 | if (GlobalControl97_RingPEMap[i].fCached) |
| 157 | { |
| 158 | LOG_INFO("\n\t\t\t\t EIP97_Global_Configure \n"); |
| 159 | |
| 160 | rc = EIP97_Global_Configure(&Global_IOArea, |
| 161 | i, |
| 162 | &GlobalControl97_RingPEMap[i].RingPEMap); |
| 163 | if (rc != EIP97_GLOBAL_NO_ERROR) |
| 164 | { |
| 165 | LOG_CRIT("%s: EIP97_Global_Configure() error %d for PE %d\n", |
| 166 | __func__, |
| 167 | rc, |
| 168 | i); |
| 169 | return -2; // error |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if (GlobalControl97_Prng[i].fCached && Global_PRNG_Present) |
| 174 | { |
| 175 | LOG_INFO("\n\t\t\t\t EIP97_Global_PRNG_Reseed \n"); |
| 176 | |
| 177 | rc = EIP97_Global_PRNG_Reseed(&Global_IOArea, |
| 178 | i, |
| 179 | &GlobalControl97_Prng[i].ReseedData); |
| 180 | if (rc != EIP97_GLOBAL_NO_ERROR) |
| 181 | { |
| 182 | LOG_CRIT("%s: EIP97_Global_PRNG_Reseed() error %d for PE %d\n", |
| 183 | __func__, |
| 184 | rc, |
| 185 | i); |
| 186 | return -3; // error |
| 187 | } |
| 188 | } |
| 189 | } // for |
| 190 | |
| 191 | return 0; // success |
| 192 | } |
| 193 | |
| 194 | |
| 195 | /*---------------------------------------------------------------------------- |
| 196 | * GlobalControl97_Capabilities_Get |
| 197 | */ |
| 198 | GlobalControl97_Error_t |
| 199 | GlobalControl97_Capabilities_Get( |
| 200 | GlobalControl97_Capabilities_t * const Capabilities_p) |
| 201 | { |
| 202 | uint8_t Versions[14]; |
| 203 | |
| 204 | LOG_INFO("\n\t\t\t GlobalControl97_Capabilities_Get \n"); |
| 205 | |
| 206 | memcpy(Capabilities_p, &Global_CapabilitiesString, |
| 207 | sizeof(Global_CapabilitiesString)); |
| 208 | |
| 209 | { |
| 210 | EIP97_Global_Error_t rc; |
| 211 | EIP97_Global_Capabilities_t Capabilities; |
| 212 | |
| 213 | ZEROINIT(Capabilities); |
| 214 | |
| 215 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 216 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 217 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 218 | |
| 219 | LOG_INFO("\n\t\t\t\t EIP97_Global_HWRevision_Get \n"); |
| 220 | |
| 221 | rc = EIP97_Global_HWRevision_Get(&Global_IOArea, &Capabilities); |
| 222 | |
| 223 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 224 | RPM_FLAG_ASYNC); |
| 225 | |
| 226 | if (rc != EIP97_GLOBAL_NO_ERROR) |
| 227 | { |
| 228 | LOG_CRIT("GlobalControl97_Capabilities_Get: returned error"); |
| 229 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 230 | } |
| 231 | |
| 232 | // Show those capabilities not propagated to higher layer. |
| 233 | LOG_CRIT("GlobalControl97_Capabilities_Get\n"); |
| 234 | LOG_CRIT("EIP202: PEs=%d rings=%d 64-bit=%s, fill level extension=%s\n" |
| 235 | "CF size=%d RF size=%d DMA len = %d " |
| 236 | "Align=%d HDW=%d HostIfc=%d\n", |
| 237 | Capabilities.EIP202_Options.NofPes, |
| 238 | Capabilities.EIP202_Options.NofRings, |
| 239 | YesNo(Capabilities.EIP202_Options.fAddr64), |
| 240 | YesNo(Capabilities.EIP202_Options.fExpPlf), |
| 241 | Capabilities.EIP202_Options.CF_Size, |
| 242 | Capabilities.EIP202_Options.RF_Size, |
| 243 | Capabilities.EIP202_Options.DMA_Len, |
| 244 | Capabilities.EIP202_Options.TgtAlign, |
| 245 | Capabilities.EIP202_Options.HDW, |
| 246 | Capabilities.EIP202_Options.HostIfc); |
| 247 | LOG_CRIT("EIP96 options:\n" |
| 248 | "AES: %s with CFB/OFB: %s Fast: %s\n" |
| 249 | "DES: %s with CFB/OFB: %s Fast: %s\n" |
| 250 | "ARCFOUR level: %d\n" |
| 251 | "AES-XTS: %s Wireless crypto: %s\n" |
| 252 | "MD5: %s SHA1: %s Fast: %s SHA256: %s SHA512: %s\n" |
| 253 | "(X)CBC-MAC: %s Fast: %s All key sizes: %s GHASH %s\n", |
| 254 | YesNo(Capabilities.EIP96_Options.fAES), |
| 255 | YesNo(Capabilities.EIP96_Options.fAESfb), |
| 256 | YesNo(Capabilities.EIP96_Options.fAESspeed), |
| 257 | YesNo(Capabilities.EIP96_Options.fDES), |
| 258 | YesNo(Capabilities.EIP96_Options.fDESfb), |
| 259 | YesNo(Capabilities.EIP96_Options.fDESspeed), |
| 260 | Capabilities.EIP96_Options.ARC4, |
| 261 | YesNo(Capabilities.EIP96_Options.fAES_XTS), |
| 262 | YesNo(Capabilities.EIP96_Options.fWireless), |
| 263 | YesNo(Capabilities.EIP96_Options.fMD5), |
| 264 | YesNo(Capabilities.EIP96_Options.fSHA1), |
| 265 | YesNo(Capabilities.EIP96_Options.fSHA1speed), |
| 266 | YesNo(Capabilities.EIP96_Options.fSHA224_256), |
| 267 | YesNo(Capabilities.EIP96_Options.fSHA384_512), |
| 268 | YesNo(Capabilities.EIP96_Options.fXCBC_MAC), |
| 269 | YesNo(Capabilities.EIP96_Options.fCBC_MACspeed), |
| 270 | YesNo(Capabilities.EIP96_Options.fCBC_MACkeylens), |
| 271 | YesNo(Capabilities.EIP96_Options.fGHASH)); |
| 272 | LOG_CRIT("EIP97 options: PEs=%d, In Dbuf size=%d In Tbuf size=%d," |
| 273 | " Out Dbuf size=%d, Out Tbuf size=%d, Central PRNG: %s\n" |
| 274 | "Token Generator: %s, Transform Record Cache: %s\n", |
| 275 | Capabilities.EIP97_Options.NofPes, |
| 276 | Capabilities.EIP97_Options.in_dbuf_size, |
| 277 | Capabilities.EIP97_Options.in_tbuf_size, |
| 278 | Capabilities.EIP97_Options.out_dbuf_size, |
| 279 | Capabilities.EIP97_Options.out_tbuf_size, |
| 280 | YesNo(Capabilities.EIP97_Options.central_prng), |
| 281 | YesNo(Capabilities.EIP97_Options.tg), |
| 282 | YesNo(Capabilities.EIP97_Options.trc)); |
| 283 | LOG_CRIT("EIP206 options: PE type=%d InClassifier=%d OutClassifier=%d " |
| 284 | "MAC chans=%d \n" |
| 285 | "InDBuf=%dkB InTBuf=%dkB OutDBuf=%dkB OutTBuf=%dkB\n", |
| 286 | Capabilities.EIP206_Options.PE_Type, |
| 287 | Capabilities.EIP206_Options.InClassifier, |
| 288 | Capabilities.EIP206_Options.OutClassifier, |
| 289 | Capabilities.EIP206_Options.NofMAC_Channels, |
| 290 | Capabilities.EIP206_Options.InDbufSizeKB, |
| 291 | Capabilities.EIP206_Options.InTbufSizeKB, |
| 292 | Capabilities.EIP206_Options.OutDbufSizeKB, |
| 293 | Capabilities.EIP206_Options.OutTbufSizeKB); |
| 294 | |
| 295 | Versions[0] = Capabilities.EIP97_Version.MajHWRevision; |
| 296 | Versions[1] = Capabilities.EIP97_Version.MinHWRevision; |
| 297 | Versions[2] = Capabilities.EIP97_Version.HWPatchLevel; |
| 298 | |
| 299 | Versions[3] = Capabilities.EIP202_Version.MajHWRevision; |
| 300 | Versions[4] = Capabilities.EIP202_Version.MinHWRevision; |
| 301 | Versions[5] = Capabilities.EIP202_Version.HWPatchLevel; |
| 302 | |
| 303 | Versions[6] = Capabilities.EIP96_Version.MajHWRevision; |
| 304 | Versions[7] = Capabilities.EIP96_Version.MinHWRevision; |
| 305 | Versions[8] = Capabilities.EIP96_Version.HWPatchLevel; |
| 306 | |
| 307 | Versions[9] = Capabilities.EIP202_Options.NofPes / 10; |
| 308 | Versions[10] = Capabilities.EIP202_Options.NofPes % 10; |
| 309 | Versions[11] = Capabilities.EIP202_Options.NofRings / 10; |
| 310 | Versions[12] = Capabilities.EIP202_Options.NofRings % 10; |
| 311 | Versions[13] = (uint8_t)Capabilities.EIP97_Options.central_prng; |
| 312 | } |
| 313 | |
| 314 | { |
| 315 | char * p = Capabilities_p->szTextDescription; |
| 316 | int VerIndex = 0; |
| 317 | int i = 0; |
| 318 | |
| 319 | while(p[i]) |
| 320 | { |
| 321 | if (p[i] == '_') |
| 322 | { |
| 323 | if (Versions[VerIndex] > 9) |
| 324 | p[i] = '?'; |
| 325 | else |
| 326 | p[i] = '0' + Versions[VerIndex]; |
| 327 | |
| 328 | VerIndex++; |
| 329 | } |
| 330 | |
| 331 | i++; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | return GLOBAL_CONTROL_NO_ERROR; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | /*---------------------------------------------------------------------------- |
| 340 | * GlobalControl97_Init |
| 341 | */ |
| 342 | GlobalControl97_Error_t |
| 343 | GlobalControl97_Init( |
| 344 | const bool fHWResetDone) |
| 345 | { |
| 346 | EIP97_Global_Error_t rc; |
| 347 | GlobalControl97_Error_t GC97_Rc = GLOBAL_CONTROL_ERROR_INTERNAL; |
| 348 | Device_Handle_t dev; |
| 349 | EIP97_Global_Capabilities_t Capabilities; |
| 350 | |
| 351 | LOG_INFO("\n\t\t\t GlobalControl97_Init \n"); |
| 352 | |
| 353 | if (Global_IsInitialized) |
| 354 | { |
| 355 | LOG_CRIT("GlobalControl97_Init: called while already initialized\n"); |
| 356 | return GLOBAL_CONTROL_ERROR_BAD_USE_ORDER; |
| 357 | } |
| 358 | |
| 359 | dev = Device_Find(ADAPTER_GLOBAL_DEVICE_NAME); |
| 360 | if (dev == NULL) |
| 361 | { |
| 362 | LOG_CRIT("GlobalControl97_Init: Could not find device\n"); |
| 363 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 364 | } |
| 365 | |
| 366 | ZEROINIT(GlobalControl97_RingPEMap); |
| 367 | ZEROINIT(GlobalControl97_Prng); |
| 368 | |
| 369 | if (RPM_DEVICE_INIT_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 370 | NULL, // Suspend callback not used |
| 371 | GlobalControl97Lib_Resume) != RPM_SUCCESS) |
| 372 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 373 | |
| 374 | if (!fHWResetDone) |
| 375 | { |
| 376 | LOG_INFO("\n\t\t\t\t EIP97_Global_Reset \n"); |
| 377 | |
| 378 | // Need to do a software reset first. |
| 379 | rc = EIP97_Global_Reset(&Global_IOArea, dev); |
| 380 | if (rc == EIP97_GLOBAL_BUSY_RETRY_LATER) |
| 381 | { |
| 382 | unsigned int tries = 0; |
| 383 | do { |
| 384 | LOG_INFO("\n\t\t\t\t EIP97_Global_Reset_IsDone \n"); |
| 385 | |
| 386 | rc = EIP97_Global_Reset_IsDone(&Global_IOArea); |
| 387 | if (rc != EIP97_GLOBAL_NO_ERROR && |
| 388 | rc != EIP97_GLOBAL_BUSY_RETRY_LATER) |
| 389 | { |
| 390 | LOG_CRIT("GlobalControl97_Init:" |
| 391 | " Error from EIP97_Global_Reset_IsDone\n"); |
| 392 | goto exit; // error |
| 393 | } |
| 394 | tries ++; |
| 395 | if (tries > ADAPTER_GLOBAL_RESET_MAX_RETRIES) |
| 396 | { |
| 397 | LOG_CRIT("GlobalControl97_Init: Reset timeout\n"); |
| 398 | goto exit; // error |
| 399 | } |
| 400 | } while (rc == EIP97_GLOBAL_BUSY_RETRY_LATER); |
| 401 | } |
| 402 | else if (rc != EIP97_GLOBAL_NO_ERROR) |
| 403 | { |
| 404 | LOG_CRIT("GlobalControl97_Init: Error from EIP97_Global_Reset\n"); |
| 405 | goto exit; // error |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | ZEROINIT(Capabilities); |
| 410 | |
| 411 | rc = EIP97_Global_HWRevision_Get(&Global_IOArea, &Capabilities); |
| 412 | if (rc != EIP97_GLOBAL_NO_ERROR) |
| 413 | { |
| 414 | LOG_CRIT("GlobalControl97_Init: returned error"); |
| 415 | goto exit; // error |
| 416 | } |
| 417 | Global_PRNG_Present = !Capabilities.EIP97_Options.central_prng; |
| 418 | |
| 419 | if (GlobalControl97Lib_Resume(NULL) != 0) |
| 420 | goto exit; // error |
| 421 | else |
| 422 | { |
| 423 | Global_IsInitialized = true; |
| 424 | |
| 425 | GlobalControl97_NofRings = Capabilities.EIP202_Options.NofRings; |
| 426 | GlobalControl97_NofLAInterfaces = Capabilities.EIP202_Options2.NofLA_Ifs; |
| 427 | GlobalControl97_NofInlineInterfaces = Capabilities.EIP202_Options2.NofIN_Ifs; |
| 428 | |
| 429 | #ifdef GLOBALCONTROL_BUILD |
| 430 | if (SHDevXS_Global_Init() != 0) |
| 431 | { |
| 432 | LOG_CRIT( |
| 433 | "GlobalControl97_Init: SHDevXS_Global_Init() returned error"); |
| 434 | goto exit; // error |
| 435 | } |
| 436 | #else |
| 437 | // Pass HW default configuration parameters obtained via |
| 438 | // the Global Control interface to the Ring Control |
| 439 | // for its automatic configuration |
| 440 | Adapter_Ring_EIP202_Configure(Capabilities.EIP202_Options.HDW, |
| 441 | Capabilities.EIP202_Options.CF_Size, |
| 442 | Capabilities.EIP202_Options.RF_Size); |
| 443 | #endif |
| 444 | |
| 445 | GC97_Rc = GLOBAL_CONTROL_NO_ERROR; // success |
| 446 | } |
| 447 | |
| 448 | exit: |
| 449 | (void)RPM_DEVICE_INIT_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID); |
| 450 | |
| 451 | return GC97_Rc; |
| 452 | } |
| 453 | |
| 454 | |
| 455 | /*---------------------------------------------------------------------------- |
| 456 | * GlobalControl97_UnInit |
| 457 | */ |
| 458 | GlobalControl97_Error_t |
| 459 | GlobalControl97_UnInit(void) |
| 460 | { |
| 461 | EIP97_Global_Error_t rc; |
| 462 | GlobalControl97_Error_t GC97_Rc = GLOBAL_CONTROL_ERROR_INTERNAL; |
| 463 | Device_Handle_t dev; |
| 464 | |
| 465 | LOG_INFO("\n\t\t\t GlobalControl97_UnInit \n"); |
| 466 | |
| 467 | if (!Global_IsInitialized) |
| 468 | { |
| 469 | LOG_CRIT("GlobalControl97_UnInit: called while not initialized\n"); |
| 470 | return GLOBAL_CONTROL_ERROR_BAD_USE_ORDER; |
| 471 | } |
| 472 | |
| 473 | dev = Device_Find(ADAPTER_GLOBAL_DEVICE_NAME); |
| 474 | if (dev == NULL) |
| 475 | { |
| 476 | LOG_CRIT("GlobalControl97_UnInit: Could not find device\n"); |
| 477 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 478 | } |
| 479 | |
| 480 | if (RPM_DEVICE_UNINIT_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 481 | true) != RPM_SUCCESS) |
| 482 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 483 | |
| 484 | LOG_INFO("\n\t\t\t\t EIP97_Global_Reset \n"); |
| 485 | |
| 486 | rc = EIP97_Global_Reset(&Global_IOArea, dev); |
| 487 | if (rc == EIP97_GLOBAL_BUSY_RETRY_LATER) |
| 488 | { |
| 489 | unsigned int tries = 0; |
| 490 | do { |
| 491 | LOG_INFO("\n\t\t\t\t EIP97_Global_Reset_IsDone \n"); |
| 492 | |
| 493 | rc = EIP97_Global_Reset_IsDone(&Global_IOArea); |
| 494 | if (rc != EIP97_GLOBAL_NO_ERROR && |
| 495 | rc != EIP97_GLOBAL_BUSY_RETRY_LATER) |
| 496 | { |
| 497 | LOG_CRIT("GlobalControl97_UnInit:" |
| 498 | " Error from EIP97_Global_Reset_IsDone\n"); |
| 499 | goto exit; // error |
| 500 | } |
| 501 | tries ++; |
| 502 | if (tries > ADAPTER_GLOBAL_RESET_MAX_RETRIES) |
| 503 | { |
| 504 | LOG_CRIT("GlobalControl97_UnInit: Reset timeout\n"); |
| 505 | goto exit; // error |
| 506 | } |
| 507 | } while (rc == EIP97_GLOBAL_BUSY_RETRY_LATER); |
| 508 | } |
| 509 | else if (rc != EIP97_GLOBAL_NO_ERROR) |
| 510 | { |
| 511 | LOG_CRIT("GlobalControl97_Init: Error from EIP97_Global_Reset\n"); |
| 512 | goto exit; // error |
| 513 | } |
| 514 | |
| 515 | #ifdef GLOBALCONTROL_BUILD |
| 516 | SHDevXS_Global_UnInit(); |
| 517 | #endif |
| 518 | |
| 519 | Global_IsInitialized = false; |
| 520 | |
| 521 | GC97_Rc = GLOBAL_CONTROL_NO_ERROR; // success |
| 522 | |
| 523 | exit: |
| 524 | (void)RPM_DEVICE_UNINIT_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID); |
| 525 | |
| 526 | return GC97_Rc; |
| 527 | } |
| 528 | |
| 529 | |
| 530 | /*---------------------------------------------------------------------------- |
| 531 | * GlobalControl97_Configure |
| 532 | */ |
| 533 | GlobalControl97_Error_t |
| 534 | GlobalControl97_Configure( |
| 535 | const unsigned int PE_Number, |
| 536 | const GlobalControl97_Ring_PE_Map_t * const RingPEMap_p) |
| 537 | { |
| 538 | EIP97_Global_Error_t rc; |
| 539 | |
| 540 | LOG_INFO("\n\t\t\t GlobalControl97_Configure \n"); |
| 541 | |
| 542 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 543 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 544 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 545 | |
| 546 | LOG_INFO("\n\t\t\t\t EIP97_Global_Configure \n"); |
| 547 | |
| 548 | rc = EIP97_Global_Configure(&Global_IOArea, PE_Number, RingPEMap_p); |
| 549 | |
| 550 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 551 | RPM_FLAG_ASYNC); |
| 552 | |
| 553 | if (rc == EIP97_GLOBAL_NO_ERROR) |
| 554 | { |
| 555 | // Fall back on EIP97_Global_Configure() for PE_Number bounds check |
| 556 | GlobalControl97_RingPEMap[PE_Number].fCached = true; |
| 557 | GlobalControl97_RingPEMap[PE_Number].RingPEMap = *RingPEMap_p; |
| 558 | return GLOBAL_CONTROL_NO_ERROR; |
| 559 | } |
| 560 | else if (rc == EIP97_GLOBAL_ARGUMENT_ERROR) |
| 561 | return GLOBAL_CONTROL_ERROR_BAD_PARAMETER; |
| 562 | else |
| 563 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 564 | } |
| 565 | |
| 566 | |
| 567 | /*---------------------------------------------------------------------------- |
| 568 | * GlobalControl97_PRNG_Reseed |
| 569 | */ |
| 570 | GlobalControl97_Error_t |
| 571 | GlobalControl97_PRNG_Reseed( |
| 572 | const unsigned int PE_Number, |
| 573 | const GlobalControl97_PRNG_Reseed_t * const ReseedData_p) |
| 574 | { |
| 575 | EIP97_Global_Error_t rc; |
| 576 | |
| 577 | LOG_INFO("\n\t\t\t GlobalControl97_PRNG_Reseed \n"); |
| 578 | |
| 579 | if (!Global_PRNG_Present) |
| 580 | { |
| 581 | LOG_CRIT("%s: PRNG device not present\n",__func__); |
| 582 | return GLOBAL_CONTROL_ERROR_NOT_IMPLEMENTED; |
| 583 | } |
| 584 | |
| 585 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 586 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 587 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 588 | |
| 589 | LOG_INFO("\n\t\t\t\t EIP97_Global_PRNG_Reseed \n"); |
| 590 | |
| 591 | rc = EIP97_Global_PRNG_Reseed(&Global_IOArea, PE_Number, ReseedData_p); |
| 592 | |
| 593 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 594 | RPM_FLAG_ASYNC); |
| 595 | |
| 596 | if (rc == EIP97_GLOBAL_NO_ERROR) |
| 597 | { |
| 598 | GlobalControl97_Prng[PE_Number].fCached = true; |
| 599 | GlobalControl97_Prng[PE_Number].ReseedData = *ReseedData_p; |
| 600 | return GLOBAL_CONTROL_NO_ERROR; |
| 601 | } |
| 602 | else if (rc == EIP97_GLOBAL_ARGUMENT_ERROR) |
| 603 | return GLOBAL_CONTROL_ERROR_BAD_PARAMETER; |
| 604 | else |
| 605 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 606 | |
| 607 | } |
| 608 | |
| 609 | |
| 610 | /*---------------------------------------------------------------------------- |
| 611 | * GlobalControl97_DFE_Status_Get |
| 612 | */ |
| 613 | GlobalControl97_Error_t |
| 614 | GlobalControl97_DFE_Status_Get( |
| 615 | const unsigned int PE_Number, |
| 616 | GlobalControl97_DFE_Status_t * const DFE_Status_p) |
| 617 | { |
| 618 | EIP97_Global_Error_t rc; |
| 619 | |
| 620 | LOG_INFO("\n\t\t\t GlobalControl97_DFE_Status_Get \n"); |
| 621 | |
| 622 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 623 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 624 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 625 | |
| 626 | LOG_INFO("\n\t\t\t\t EIP97_Global_DFE_Status_Get \n"); |
| 627 | |
| 628 | rc = EIP97_Global_DFE_Status_Get(&Global_IOArea, PE_Number, DFE_Status_p); |
| 629 | |
| 630 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 631 | RPM_FLAG_ASYNC); |
| 632 | |
| 633 | if (rc == EIP97_GLOBAL_NO_ERROR) |
| 634 | return GLOBAL_CONTROL_NO_ERROR; |
| 635 | else if (rc == EIP97_GLOBAL_ARGUMENT_ERROR) |
| 636 | return GLOBAL_CONTROL_ERROR_BAD_PARAMETER; |
| 637 | else |
| 638 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 639 | } |
| 640 | |
| 641 | |
| 642 | /*---------------------------------------------------------------------------- |
| 643 | * GlobalControl97_DSE_Status_Get |
| 644 | */ |
| 645 | GlobalControl97_Error_t |
| 646 | GlobalControl97_DSE_Status_Get( |
| 647 | const unsigned int PE_Number, |
| 648 | GlobalControl97_DSE_Status_t * const DSE_Status_p) |
| 649 | { |
| 650 | EIP97_Global_Error_t rc; |
| 651 | |
| 652 | LOG_INFO("\n\t\t\t GlobalControl97_DSE_Status_Get \n"); |
| 653 | |
| 654 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 655 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 656 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 657 | |
| 658 | LOG_INFO("\n\t\t\t\t EIP97_Global_DSE_Status_Get \n"); |
| 659 | |
| 660 | rc = EIP97_Global_DSE_Status_Get(&Global_IOArea, PE_Number, DSE_Status_p); |
| 661 | |
| 662 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, RPM_FLAG_ASYNC); |
| 663 | |
| 664 | if (rc == EIP97_GLOBAL_NO_ERROR) |
| 665 | return GLOBAL_CONTROL_NO_ERROR; |
| 666 | else if (rc == EIP97_GLOBAL_ARGUMENT_ERROR) |
| 667 | return GLOBAL_CONTROL_ERROR_BAD_PARAMETER; |
| 668 | else |
| 669 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 670 | } |
| 671 | |
| 672 | |
| 673 | /*---------------------------------------------------------------------------- |
| 674 | * GlobalControl97_Token_Status_Get |
| 675 | */ |
| 676 | GlobalControl97_Error_t |
| 677 | GlobalControl97_Token_Status_Get( |
| 678 | const unsigned int PE_Number, |
| 679 | GlobalControl97_Token_Status_t * const Token_Status_p) |
| 680 | { |
| 681 | EIP97_Global_Error_t rc; |
| 682 | |
| 683 | LOG_INFO("\n\t\t\t GlobalControl97_Token_Status_Get \n"); |
| 684 | |
| 685 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 686 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 687 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 688 | |
| 689 | LOG_INFO("\n\t\t\t\t EIP97_Global_EIP96_Token_Status_Get \n"); |
| 690 | |
| 691 | rc = EIP97_Global_EIP96_Token_Status_Get(&Global_IOArea, |
| 692 | PE_Number, |
| 693 | Token_Status_p); |
| 694 | |
| 695 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 696 | RPM_FLAG_ASYNC); |
| 697 | |
| 698 | if (rc == EIP97_GLOBAL_NO_ERROR) |
| 699 | return GLOBAL_CONTROL_NO_ERROR; |
| 700 | else if (rc == EIP97_GLOBAL_ARGUMENT_ERROR) |
| 701 | return GLOBAL_CONTROL_ERROR_BAD_PARAMETER; |
| 702 | else |
| 703 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 704 | } |
| 705 | |
| 706 | |
| 707 | /*---------------------------------------------------------------------------- |
| 708 | * GlobalControl97_Context_Status_Get |
| 709 | */ |
| 710 | GlobalControl97_Error_t |
| 711 | GlobalControl97_Context_Status_Get( |
| 712 | const unsigned int PE_Number, |
| 713 | GlobalControl97_Context_Status_t * const Context_Status_p) |
| 714 | { |
| 715 | EIP97_Global_Error_t rc; |
| 716 | |
| 717 | LOG_INFO("\n\t\t\t GlobalControl97_Context_Status_Get \n"); |
| 718 | |
| 719 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 720 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 721 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 722 | |
| 723 | LOG_INFO("\n\t\t\t\t EIP97_Global_EIP96_Context_Status_Get \n"); |
| 724 | |
| 725 | rc = EIP97_Global_EIP96_Context_Status_Get(&Global_IOArea, |
| 726 | PE_Number, |
| 727 | Context_Status_p); |
| 728 | |
| 729 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 730 | RPM_FLAG_ASYNC); |
| 731 | |
| 732 | if (rc == EIP97_GLOBAL_NO_ERROR) |
| 733 | return GLOBAL_CONTROL_NO_ERROR; |
| 734 | else if (rc == EIP97_GLOBAL_ARGUMENT_ERROR) |
| 735 | return GLOBAL_CONTROL_ERROR_BAD_PARAMETER; |
| 736 | else |
| 737 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 738 | } |
| 739 | |
| 740 | |
| 741 | /*---------------------------------------------------------------------------- |
| 742 | * GlobalControl97_Interrupt_Status_Get |
| 743 | */ |
| 744 | GlobalControl97_Error_t |
| 745 | GlobalControl97_Interrupt_Status_Get( |
| 746 | const unsigned int PE_Number, |
| 747 | GlobalControl97_Interrupt_Status_t * const Interrupt_Status_p) |
| 748 | { |
| 749 | IDENTIFIER_NOT_USED(PE_Number); |
| 750 | |
| 751 | LOG_INFO("\n\t\t\t GlobalControl97_Interrupt_Status_Get \n"); |
| 752 | |
| 753 | // Not implemented yet, must use EIP-96 AIC |
| 754 | ZEROINIT(*Interrupt_Status_p); |
| 755 | |
| 756 | return GLOBAL_CONTROL_NO_ERROR; |
| 757 | } |
| 758 | |
| 759 | |
| 760 | /*---------------------------------------------------------------------------- |
| 761 | * GlobalControl97_OutXfer_Status_Get |
| 762 | */ |
| 763 | GlobalControl97_Error_t |
| 764 | GlobalControl97_OutXfer_Status_Get( |
| 765 | const unsigned int PE_Number, |
| 766 | GlobalControl97_Output_Transfer_Status_t * const OutXfer_Status_p) |
| 767 | { |
| 768 | EIP97_Global_Error_t rc; |
| 769 | |
| 770 | LOG_INFO("\n\t\t\t GlobalControl97_OutXfer_Status_Get \n"); |
| 771 | |
| 772 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 773 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 774 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 775 | |
| 776 | LOG_INFO("\n\t\t\t\t EIP97_Global_EIP96_OutXfer_Status_Get \n"); |
| 777 | |
| 778 | rc = EIP97_Global_EIP96_OutXfer_Status_Get(&Global_IOArea, |
| 779 | PE_Number, |
| 780 | OutXfer_Status_p); |
| 781 | |
| 782 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 783 | RPM_FLAG_ASYNC); |
| 784 | |
| 785 | if (rc == EIP97_GLOBAL_NO_ERROR) |
| 786 | return GLOBAL_CONTROL_NO_ERROR; |
| 787 | else if (rc == EIP97_GLOBAL_ARGUMENT_ERROR) |
| 788 | return GLOBAL_CONTROL_ERROR_BAD_PARAMETER; |
| 789 | else |
| 790 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 791 | } |
| 792 | |
| 793 | |
| 794 | /*---------------------------------------------------------------------------- |
| 795 | * GlobalControl97_PRNG_Status_Get |
| 796 | */ |
| 797 | GlobalControl97_Error_t |
| 798 | GlobalControl97_PRNG_Status_Get( |
| 799 | const unsigned int PE_Number, |
| 800 | GlobalControl97_PRNG_Status_t * const PRNG_Status_p) |
| 801 | { |
| 802 | EIP97_Global_Error_t rc; |
| 803 | |
| 804 | LOG_INFO("\n\t\t\t GlobalControl97_PRNG_Status_Get \n"); |
| 805 | |
| 806 | if (!Global_PRNG_Present) |
| 807 | { |
| 808 | return GLOBAL_CONTROL_ERROR_NOT_IMPLEMENTED; |
| 809 | } |
| 810 | |
| 811 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 812 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 813 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 814 | |
| 815 | LOG_INFO("\n\t\t\t\t EIP97_Global_EIP96_PRNG_Status_Get \n"); |
| 816 | |
| 817 | rc = EIP97_Global_EIP96_PRNG_Status_Get(&Global_IOArea, |
| 818 | PE_Number, |
| 819 | PRNG_Status_p); |
| 820 | |
| 821 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 822 | RPM_FLAG_ASYNC); |
| 823 | |
| 824 | if (rc == EIP97_GLOBAL_NO_ERROR) |
| 825 | return GLOBAL_CONTROL_NO_ERROR; |
| 826 | else if (rc == EIP97_GLOBAL_ARGUMENT_ERROR) |
| 827 | return GLOBAL_CONTROL_ERROR_BAD_PARAMETER; |
| 828 | else |
| 829 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 830 | } |
| 831 | |
| 832 | #ifdef ADAPTER_GLOBAL_DBG_STATISTICS |
| 833 | /*---------------------------------------------------------------------------- |
| 834 | * GlobalControl97_Debug_Statistics_Get |
| 835 | */ |
| 836 | GlobalControl97_Error_t |
| 837 | GlobalControl97_Debug_Statistics_Get( |
| 838 | GlobalControl97_Debug_Statistics_t * const Debug_Statistics_p) |
| 839 | { |
| 840 | EIP97_Global_Error_t rc; |
| 841 | |
| 842 | LOG_INFO("\n\t\t\t GlobalControl97_DSE_Debug_Statistics_Get \n"); |
| 843 | |
| 844 | if (RPM_DEVICE_IO_START_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, |
| 845 | RPM_FLAG_SYNC) != RPM_SUCCESS) |
| 846 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 847 | |
| 848 | LOG_INFO("\n\t\t\t\t EIP97_Global_Deubg_Statistics_Get \n"); |
| 849 | |
| 850 | rc = EIP97_Global_Debug_Statistics_Get(&Global_IOArea, Debug_Statistics_p); |
| 851 | |
| 852 | (void)RPM_DEVICE_IO_STOP_MACRO(ADAPTER_GLOBAL_RPM_EIP97_DEVICE_ID, RPM_FLAG_ASYNC); |
| 853 | |
| 854 | if (rc == EIP97_GLOBAL_NO_ERROR) |
| 855 | return GLOBAL_CONTROL_NO_ERROR; |
| 856 | else if (rc == EIP97_GLOBAL_ARGUMENT_ERROR) |
| 857 | return GLOBAL_CONTROL_ERROR_BAD_PARAMETER; |
| 858 | else |
| 859 | return GLOBAL_CONTROL_ERROR_INTERNAL; |
| 860 | } |
| 861 | #endif |
| 862 | |
| 863 | /*---------------------------------------------------------------------------- |
| 864 | * GlobalControl97_Interfaces_Get |
| 865 | */ |
| 866 | void |
| 867 | GlobalControl97_Interfaces_Get( |
| 868 | unsigned int * const NofPEs_p, |
| 869 | unsigned int * const NofRings_p, |
| 870 | unsigned int * const NofLAInterfaces_p, |
| 871 | unsigned int * const NofInlineInterfaces_p) |
| 872 | { |
| 873 | if (NofPEs_p) |
| 874 | *NofPEs_p = GlobalControl97_NofPEs; |
| 875 | if (NofRings_p) |
| 876 | *NofRings_p = GlobalControl97_NofRings; |
| 877 | if (NofLAInterfaces_p) |
| 878 | *NofLAInterfaces_p = GlobalControl97_NofLAInterfaces; |
| 879 | if (NofInlineInterfaces_p) |
| 880 | *NofInlineInterfaces_p = GlobalControl97_NofInlineInterfaces; |
| 881 | } |
| 882 | |
| 883 | |
| 884 | /* end of file adapter_global_eip97.c */ |