1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2025 Intel Corporation */ 3 /** 4 ***************************************************************************** 5 * @file lac_common.h Common macros 6 * 7 * @defgroup Lac Look Aside Crypto LLD Doc 8 * 9 *****************************************************************************/ 10 11 /** 12 ***************************************************************************** 13 * @defgroup LacCommon LAC Common 14 * Common code for Lac which includes init/shutdown, memory, logging and 15 * hooks. 16 * 17 * @ingroup Lac 18 * 19 *****************************************************************************/ 20 21 /***************************************************************************/ 22 23 #ifndef LAC_COMMON_H 24 #define LAC_COMMON_H 25 26 /* 27 ****************************************************************************** 28 * Include public/global header files 29 ****************************************************************************** 30 */ 31 32 #include "cpa.h" 33 #include "qat_utils.h" 34 #include "cpa_cy_common.h" 35 #include "icp_adf_init.h" 36 37 #define LAC_ARCH_UINT uintptr_t 38 #define LAC_ARCH_INT intptr_t 39 40 /* 41 ***************************************************************************** 42 * Max range values for some primitive param checking 43 ***************************************************************************** 44 */ 45 46 /**< Maximum number of instances */ 47 #define SAL_MAX_NUM_INSTANCES_PER_DEV 512 48 49 #define SAL_DEFAULT_RING_SIZE 256 50 /**< Default ring size */ 51 52 #define SAL_64_CONCURR_REQUESTS 64 53 #define SAL_128_CONCURR_REQUESTS 128 54 #define SAL_256_CONCURR_REQUESTS 256 55 #define SAL_512_CONCURR_REQUESTS 512 56 #define SAL_1024_CONCURR_REQUESTS 1024 57 #define SAL_2048_CONCURR_REQUESTS 2048 58 #define SAL_4096_CONCURR_REQUESTS 4096 59 #define SAL_MAX_CONCURR_REQUESTS 65536 60 /**< Valid options for the num of concurrent requests per ring pair read 61 from the config file. These values are used to size the rings */ 62 63 #define SAL_BATCH_SUBMIT_FREE_SPACE 2 64 /**< For data plane batch submissions ADF leaves 2 spaces free on the ring */ 65 66 /* 67 ****************************************************************************** 68 * Some common settings for QA API queries 69 ****************************************************************************** 70 */ 71 72 #define SAL_INFO2_VENDOR_NAME "Intel(R)" 73 /**< @ingroup LacCommon 74 * Name of vendor of this driver */ 75 #define SAL_INFO2_PART_NAME "%s with Intel(R) QuickAssist Technology" 76 /**< @ingroup LacCommon 77 */ 78 79 /* 80 ******************************************************************************** 81 * User process name defines and functions 82 ******************************************************************************** 83 */ 84 85 #define LAC_USER_PROCESS_NAME_MAX_LEN 32 86 /**< @ingroup LacCommon 87 * Max length of user process name */ 88 89 #define LAC_KERNEL_PROCESS_NAME "KERNEL_QAT" 90 /**< @ingroup LacCommon 91 * Default name for kernel process */ 92 93 /* 94 ******************************************************************************** 95 * response mode indicator from Config file 96 ******************************************************************************** 97 */ 98 99 #define SAL_RESP_POLL_CFG_FILE 1 100 #define SAL_RESP_EPOLL_CFG_FILE 2 101 102 /* 103 * @ingroup LacCommon 104 * @description 105 * This function sets the process name 106 * 107 * @context 108 * This functions is called from module_init or from user space process 109 * initialization function 110 * 111 * @assumptions 112 * None 113 * @sideEffects 114 * None 115 * @reentrant 116 * No 117 * @threadSafe 118 * No 119 * 120 * param[in] processName Process name to be set 121 */ 122 CpaStatus icpSetProcessName(const char *processName); 123 124 /* 125 * @ingroup LacCommon 126 * @description 127 * This function gets the process name 128 * 129 * @context 130 * This functions is called from LAC context 131 * 132 * @assumptions 133 * None 134 * @sideEffects 135 * None 136 * @reentrant 137 * Yes 138 * @threadSafe 139 * Yes 140 * 141 */ 142 char *icpGetProcessName(void); 143 144 /* Sections of the config file */ 145 #define LAC_CFG_SECTION_GENERAL "GENERAL" 146 #define LAC_CFG_SECTION_INTERNAL "INTERNAL" 147 148 /* 149 ******************************************************************************** 150 * Debug Macros and settings 151 ******************************************************************************** 152 */ 153 154 #define SEPARATOR "+--------------------------------------------------+\n" 155 /**< @ingroup LacCommon 156 * separator used for printing stats to standard output*/ 157 158 #define BORDER "|" 159 /**< @ingroup LacCommon 160 * separator used for printing stats to standard output*/ 161 162 /** 163 ***************************************************************************** 164 * @ingroup LacCommon 165 * Component state 166 * 167 * @description 168 * This enum is used to indicate the state that the component is in. Its 169 * purpose is to prevent components from being initialised or shutdown 170 * incorrectly. 171 * 172 *****************************************************************************/ 173 typedef enum { 174 LAC_COMP_SHUT_DOWN = 0, 175 /**< Component in the Shut Down state */ 176 LAC_COMP_SHUTTING_DOWN, 177 /**< Component in the Process of Shutting down */ 178 LAC_COMP_INITIALISING, 179 /**< Component in the Process of being initialised */ 180 LAC_COMP_INITIALISED, 181 /**< Component in the initialised state */ 182 } lac_comp_state_t; 183 184 /** 185 ******************************************************************************* 186 * @ingroup LacCommon 187 * This macro checks if a parameter is NULL 188 * 189 * @param[in] param Parameter 190 * 191 * @return CPA_STATUS_INVALID_PARAM Parameter is NULL 192 * @return void Parameter is not NULL 193 ******************************************************************************/ 194 #define LAC_CHECK_NULL_PARAM(param) \ 195 do { \ 196 if (NULL == (param)) { \ 197 return CPA_STATUS_INVALID_PARAM; \ 198 } \ 199 } while (0) 200 201 /** 202 ******************************************************************************* 203 * @ingroup LacCommon 204 * This macro checks if a parameter is within a specified range 205 * 206 * @param[in] param Parameter 207 * @param[in] min Parameter must be greater than OR equal to 208 *min 209 * @param[in] max Parameter must be less than max 210 * 211 * @return CPA_STATUS_INVALID_PARAM Parameter is outside range 212 * @return void Parameter is within range 213 ******************************************************************************/ 214 #define LAC_CHECK_PARAM_RANGE(param, min, max) \ 215 do { \ 216 if (((param) < (min)) || ((param) >= (max))) { \ 217 return CPA_STATUS_INVALID_PARAM; \ 218 } \ 219 } while (0) 220 221 /** 222 ******************************************************************************* 223 * @ingroup LacCommon 224 * This checks if a param is 8 byte aligned. 225 * 226 ******************************************************************************/ 227 #define LAC_CHECK_8_BYTE_ALIGNMENT(param) \ 228 do { \ 229 if ((Cpa64U)param % 8 != 0) { \ 230 return CPA_STATUS_INVALID_PARAM; \ 231 } \ 232 } while (0) 233 234 /** 235 ******************************************************************************* 236 * @ingroup LacCommon 237 * This checks if a param is 64 byte aligned. 238 * 239 ******************************************************************************/ 240 #define LAC_CHECK_64_BYTE_ALIGNMENT(param) \ 241 do { \ 242 if ((LAC_ARCH_UINT)param % 64 != 0) { \ 243 return CPA_STATUS_INVALID_PARAM; \ 244 } \ 245 } while (0) 246 247 /** 248 ******************************************************************************* 249 * @ingroup LacCommon 250 * This macro returns the size of the buffer list structure given the 251 * number of elements in the buffer list - note: only the sizeof the 252 * buffer list structure is returned. 253 * 254 * @param[in] numBuffers The number of flatbuffers in a buffer list 255 * 256 * @return size of the buffer list structure 257 ******************************************************************************/ 258 #define LAC_BUFFER_LIST_SIZE_GET(numBuffers) \ 259 (sizeof(CpaBufferList) + (numBuffers * sizeof(CpaFlatBuffer))) 260 261 /** 262 ******************************************************************************* 263 * @ingroup LacCommon 264 * This macro checks that a flatbuffer is valid i.e. that it is not 265 * null and the data it points to is not null 266 * 267 * @param[in] pFlatBuffer Pointer to flatbuffer 268 * 269 * @return CPA_STATUS_INVALID_PARAM Invalid flatbuffer pointer 270 * @return void flatbuffer is ok 271 ******************************************************************************/ 272 #define LAC_CHECK_FLAT_BUFFER(pFlatBuffer) \ 273 do { \ 274 LAC_CHECK_NULL_PARAM((pFlatBuffer)); \ 275 LAC_CHECK_NULL_PARAM((pFlatBuffer)->pData); \ 276 } while (0) 277 278 /** 279 ******************************************************************************* 280 * @ingroup LacCommon 281 * This macro verifies that the status is ok i.e. equal to CPA_STATUS_SUCCESS 282 * 283 * @param[in] status status we are checking 284 * 285 * @return void status is ok (CPA_STATUS_SUCCESS) 286 * @return status The value in the status parameter is an error one 287 * 288 ******************************************************************************/ 289 #define LAC_CHECK_STATUS(status) \ 290 do { \ 291 if (CPA_STATUS_SUCCESS != (status)) { \ 292 return status; \ 293 } \ 294 } while (0) 295 296 /** 297 ******************************************************************************* 298 * @ingroup LacCommon 299 * This macro verifies that the Instance Handle is valid. 300 * 301 * @param[in] instanceHandle Instance Handle 302 * 303 * @return CPA_STATUS_INVALID_PARAM Parameter is NULL 304 * @return void Parameter is not NULL 305 * 306 ******************************************************************************/ 307 #define LAC_CHECK_INSTANCE_HANDLE(instanceHandle) \ 308 do { \ 309 if (NULL == (instanceHandle)) { \ 310 return CPA_STATUS_INVALID_PARAM; \ 311 } \ 312 } while (0) 313 314 /** 315 ******************************************************************************* 316 * @ingroup LacCommon 317 * This macro copies a string from one location to another 318 * 319 * @param[out] pDestinationBuffer Pointer to destination buffer 320 * @param[in] pSource Pointer to source buffer 321 * 322 ******************************************************************************/ 323 #define LAC_COPY_STRING(pDestinationBuffer, pSource) \ 324 do { \ 325 memcpy(pDestinationBuffer, pSource, (sizeof(pSource) - 1)); \ 326 pDestinationBuffer[(sizeof(pSource) - 1)] = '\0'; \ 327 } while (0) 328 329 /** 330 ******************************************************************************* 331 * @ingroup LacCommon 332 * This macro fills a memory zone with ZEROES 333 * 334 * @param[in] pBuffer Pointer to buffer 335 * @param[in] count Buffer length 336 * 337 * @return void 338 * 339 ******************************************************************************/ 340 #define LAC_OS_BZERO(pBuffer, count) memset(pBuffer, 0, count); 341 342 /** 343 ******************************************************************************* 344 * @ingroup LacCommon 345 * This macro calculates the position of the given member in a struct 346 * Only for use on a struct where all members are of equal size to map 347 * the struct member position to an array index 348 * 349 * @param[in] structType the struct 350 * @param[in] member the member of the given struct 351 * 352 ******************************************************************************/ 353 #define LAC_IDX_OF(structType, member) \ 354 (offsetof(structType, member) / sizeof(((structType *)0)->member)) 355 356 /* 357 ******************************************************************************** 358 * Alignment, Bid define and Bit Operation Macros 359 ******************************************************************************** 360 */ 361 362 #define LAC_BIT31_SET 0x80000000 /**< bit 31 == 1 */ 363 #define LAC_BIT7_SET 0x80 /**< bit 7 == 1 */ 364 #define LAC_BIT6_SET 0x40 /**< bit 6 == 1 */ 365 #define LAC_BIT5_SET 0x20 /**< bit 5 == 1 */ 366 #define LAC_BIT4_SET 0x10 /**< bit 4 == 1 */ 367 #define LAC_BIT3_SET 0x08 /**< bit 3 == 1 */ 368 #define LAC_BIT2_SET 0x04 /**< bit 2 == 1 */ 369 #define LAC_BIT1_SET 0x02 /**< bit 1 == 1 */ 370 #define LAC_BIT0_SET 0x01 /**< bit 0 == 1 */ 371 372 #define LAC_NUM_BITS_IN_BYTE (8) 373 /**< @ingroup LacCommon 374 * Number of bits in a byte */ 375 376 #define LAC_LONG_WORD_IN_BYTES (4) 377 /**< @ingroup LacCommon 378 * Number of bytes in an IA word */ 379 380 #define LAC_QUAD_WORD_IN_BYTES (8) 381 /**< @ingroup LacCommon 382 * Number of bytes in a QUAD word */ 383 384 #define LAC_QAT_MAX_MSG_SZ_LW (32) 385 /**< @ingroup LacCommon 386 * Maximum size in Long Words for a QAT message */ 387 388 /** 389 ***************************************************************************** 390 * @ingroup LacCommon 391 * Alignment shift requirements of a buffer. 392 * 393 * @description 394 * This enum is used to indicate the alignment shift of a buffer. 395 * All alignments are to power of 2 396 * 397 *****************************************************************************/ 398 typedef enum lac_aligment_shift_s { 399 LAC_NO_ALIGNMENT_SHIFT = 0, 400 /**< No alignment shift (to a power of 2)*/ 401 LAC_8BYTE_ALIGNMENT_SHIFT = 3, 402 /**< 8 byte alignment shift (to a power of 2)*/ 403 LAC_16BYTE_ALIGNMENT_SHIFT = 4, 404 /**< 16 byte alignment shift (to a power of 2)*/ 405 LAC_64BYTE_ALIGNMENT_SHIFT = 6, 406 /**< 64 byte alignment shift (to a power of 2)*/ 407 LAC_4KBYTE_ALIGNMENT_SHIFT = 12, 408 /**< 4k byte alignment shift (to a power of 2)*/ 409 } lac_aligment_shift_t; 410 411 /** 412 ***************************************************************************** 413 * @ingroup LacCommon 414 * Alignment of a buffer. 415 * 416 * @description 417 * This enum is used to indicate the alignment requirements of a buffer. 418 * 419 *****************************************************************************/ 420 typedef enum lac_aligment_s { 421 LAC_NO_ALIGNMENT = 0, 422 /**< No alignment */ 423 LAC_1BYTE_ALIGNMENT = 1, 424 /**< 1 byte alignment */ 425 LAC_8BYTE_ALIGNMENT = 8, 426 /**< 8 byte alignment*/ 427 LAC_64BYTE_ALIGNMENT = 64, 428 /**< 64 byte alignment*/ 429 LAC_4KBYTE_ALIGNMENT = 4096, 430 /**< 4k byte alignment */ 431 } lac_aligment_t; 432 433 /** 434 ***************************************************************************** 435 * @ingroup LacCommon 436 * Size of a buffer. 437 * 438 * @description 439 * This enum is used to indicate the required size. 440 * The buffer must be a multiple of the required size. 441 * 442 *****************************************************************************/ 443 typedef enum lac_expected_size_s { 444 LAC_NO_LENGTH_REQUIREMENTS = 0, 445 /**< No requirement for size */ 446 LAC_4KBYTE_MULTIPLE_REQUIRED = 4096, 447 /**< 4k multiple requirement for size */ 448 } lac_expected_size_t; 449 450 #define LAC_OPTIMAL_ALIGNMENT_SHIFT LAC_64BYTE_ALIGNMENT_SHIFT 451 /**< @ingroup LacCommon 452 * optimal alignment to a power of 2 */ 453 454 #define LAC_SHIFT_8 (1 << LAC_8BYTE_ALIGNMENT_SHIFT) 455 /**< shift by 8 bits */ 456 #define LAC_SHIFT_24 \ 457 ((1 << LAC_8BYTE_ALIGNMENT_SHIFT) + (1 << LAC_16BYTE_ALIGNMENT_SHIFT)) 458 /**< shift by 24 bits */ 459 460 #define LAC_MAX_16_BIT_VALUE ((1 << 16) - 1) 461 /**< @ingroup LacCommon 462 * maximum value a 16 bit type can hold */ 463 464 /** 465 ******************************************************************************* 466 * @ingroup LacCommon 467 * This macro can be used to avoid an unused variable warning from the 468 * compiler 469 * 470 * @param[in] variable unused variable 471 * 472 ******************************************************************************/ 473 #define LAC_UNUSED_VARIABLE(x) (void)(x) 474 475 /** 476 ******************************************************************************* 477 * @ingroup LacCommon 478 * This macro checks if an address is aligned to the specified power of 2 479 * Returns 0 if alignment is ok, or non-zero otherwise 480 * 481 * @param[in] address the address we are checking 482 * 483 * @param[in] alignment the byte alignment to check (specified as power of 2) 484 * 485 ******************************************************************************/ 486 #define LAC_ADDRESS_ALIGNED(address, alignment) \ 487 (!((LAC_ARCH_UINT)(address) & ((1 << (alignment)) - 1))) 488 489 /** 490 ******************************************************************************* 491 * @ingroup LacCommon 492 * This macro rounds up a number to a be a multiple of the alignment when 493 * the alignment is a power of 2. 494 * 495 * @param[in] num Number 496 * @param[in] align Alignment (must be a power of 2) 497 * 498 ******************************************************************************/ 499 #define LAC_ALIGN_POW2_ROUNDUP(num, align) (((num) + (align)-1) & ~((align)-1)) 500 501 /** 502 ******************************************************************************* 503 * @ingroup LacCommon 504 * This macro generates a bit mask to select a particular bit 505 * 506 * @param[in] bitPos Bit position to select 507 * 508 ******************************************************************************/ 509 #define LAC_BIT(bitPos) (0x1 << (bitPos)) 510 511 /** 512 ******************************************************************************* 513 * @ingroup LacCommon 514 * This macro converts a size in bits to the equivalent size in bytes, 515 * using a bit shift to divide by 8 516 * 517 * @param[in] x size in bits 518 * 519 ******************************************************************************/ 520 #define LAC_BITS_TO_BYTES(x) ((x) >> 3) 521 522 /** 523 ******************************************************************************* 524 * @ingroup LacCommon 525 * This macro converts a size in bytes to the equivalent size in bits, 526 * using a bit shift to multiply by 8 527 * 528 * @param[in] x size in bytes 529 * 530 ******************************************************************************/ 531 #define LAC_BYTES_TO_BITS(x) ((x) << 3) 532 533 /** 534 ******************************************************************************* 535 * @ingroup LacCommon 536 * This macro converts a size in bytes to the equivalent size in longwords, 537 * using a bit shift to divide by 4 538 * 539 * @param[in] x size in bytes 540 * 541 ******************************************************************************/ 542 #define LAC_BYTES_TO_LONGWORDS(x) ((x) >> 2) 543 544 /** 545 ******************************************************************************* 546 * @ingroup LacCommon 547 * This macro converts a size in longwords to the equivalent size in bytes, 548 * using a bit shift to multiply by 4 549 * 550 * @param[in] x size in long words 551 * 552 ******************************************************************************/ 553 #define LAC_LONGWORDS_TO_BYTES(x) ((x) << 2) 554 555 /** 556 ******************************************************************************* 557 * @ingroup LacCommon 558 * This macro converts a size in bytes to the equivalent size in quadwords, 559 * using a bit shift to divide by 8 560 * 561 * @param[in] x size in bytes 562 * 563 ******************************************************************************/ 564 #define LAC_BYTES_TO_QUADWORDS(x) (((x) >> 3) + (((x) % 8) ? 1 : 0)) 565 566 /** 567 ******************************************************************************* 568 * @ingroup LacCommon 569 * This macro converts a size in quadwords to the equivalent size in bytes, 570 * using a bit shift to multiply by 8 571 * 572 * @param[in] x size in quad words 573 * 574 ******************************************************************************/ 575 #define LAC_QUADWORDS_TO_BYTES(x) ((x) << 3) 576 577 /******************************************************************************/ 578 579 /* 580 ******************************************************************************* 581 * Mutex Macros 582 ******************************************************************************* 583 */ 584 585 /** 586 ******************************************************************************* 587 * @ingroup LacCommon 588 * This macro tries to acquire a mutex and returns the status 589 * 590 * @param[in] pLock Pointer to Lock 591 * @param[in] timeout Timeout 592 * 593 * @retval CPA_STATUS_SUCCESS Function executed successfully. 594 * @retval CPA_STATUS_RESOURCE Error with Mutex 595 ******************************************************************************/ 596 #define LAC_LOCK_MUTEX(pLock, timeout) \ 597 ((CPA_STATUS_SUCCESS != qatUtilsMutexLock((pLock), (timeout))) ? \ 598 CPA_STATUS_RESOURCE : \ 599 CPA_STATUS_SUCCESS) 600 601 /** 602 ******************************************************************************* 603 * @ingroup LacCommon 604 * This macro unlocks a mutex and returns the status 605 * 606 * @param[in] pLock Pointer to Lock 607 * 608 * @retval CPA_STATUS_SUCCESS Function executed successfully. 609 * @retval CPA_STATUS_RESOURCE Error with Mutex 610 ******************************************************************************/ 611 #define LAC_UNLOCK_MUTEX(pLock) \ 612 ((CPA_STATUS_SUCCESS != qatUtilsMutexUnlock((pLock))) ? \ 613 CPA_STATUS_RESOURCE : \ 614 CPA_STATUS_SUCCESS) 615 616 /** 617 ******************************************************************************* 618 * @ingroup LacCommon 619 * This macro initialises a mutex and returns the status 620 * 621 * @param[in] pLock Pointer to Lock 622 * 623 * @retval CPA_STATUS_SUCCESS Function executed successfully. 624 * @retval CPA_STATUS_RESOURCE Error with Mutex 625 ******************************************************************************/ 626 #define LAC_INIT_MUTEX(pLock) \ 627 ((CPA_STATUS_SUCCESS != qatUtilsMutexInit((pLock))) ? \ 628 CPA_STATUS_RESOURCE : \ 629 CPA_STATUS_SUCCESS) 630 631 /** 632 ******************************************************************************* 633 * @ingroup LacCommon 634 * This macro destroys a mutex and returns the status 635 * 636 * @param[in] pLock Pointer to Lock 637 * 638 * @retval CPA_STATUS_SUCCESS Function executed successfully. 639 * @retval CPA_STATUS_RESOURCE Error with Mutex 640 ******************************************************************************/ 641 #define LAC_DESTROY_MUTEX(pLock) \ 642 ((CPA_STATUS_SUCCESS != qatUtilsMutexDestroy((pLock))) ? \ 643 CPA_STATUS_RESOURCE : \ 644 CPA_STATUS_SUCCESS) 645 646 /** 647 ******************************************************************************* 648 * @ingroup LacCommon 649 * This macro calls a trylock on a mutex 650 * 651 * @param[in] pLock Pointer to Lock 652 * 653 * @retval CPA_STATUS_SUCCESS Function executed successfully. 654 * @retval CPA_STATUS_RESOURCE Error with Mutex 655 ******************************************************************************/ 656 #define LAC_TRYLOCK_MUTEX(pLock) \ 657 ((CPA_STATUS_SUCCESS != \ 658 qatUtilsMutexTryLock((pLock), QAT_UTILS_WAIT_NONE)) ? \ 659 CPA_STATUS_RESOURCE : \ 660 CPA_STATUS_SUCCESS) 661 662 /* 663 ******************************************************************************* 664 * Semaphore Macros 665 ******************************************************************************* 666 */ 667 668 /** 669 ******************************************************************************* 670 * @ingroup LacCommon 671 * This macro waits on a semaphore and returns the status 672 * 673 * @param[in] sid The semaphore 674 * @param[in] timeout Timeout 675 * 676 * @retval CPA_STATUS_SUCCESS Function executed successfully. 677 * @retval CPA_STATUS_RESOURCE Error with semaphore 678 ******************************************************************************/ 679 #define LAC_WAIT_SEMAPHORE(sid, timeout) \ 680 ((CPA_STATUS_SUCCESS != qatUtilsSemaphoreWait(&sid, (timeout))) ? \ 681 CPA_STATUS_RESOURCE : \ 682 CPA_STATUS_SUCCESS) 683 684 /** 685 ******************************************************************************* 686 * @ingroup LacCommon 687 * This macro checks a semaphore and returns the status 688 * 689 * @param[in] sid The semaphore 690 * 691 * @retval CPA_STATUS_SUCCESS Function executed successfully. 692 * @retval CPA_STATUS_RESOURCE Error with semaphore 693 ******************************************************************************/ 694 #define LAC_CHECK_SEMAPHORE(sid) \ 695 ((CPA_STATUS_SUCCESS != qatUtilsSemaphoreTryWait(&sid)) ? \ 696 CPA_STATUS_RETRY : \ 697 CPA_STATUS_SUCCESS) 698 699 /** 700 ******************************************************************************* 701 * @ingroup LacCommon 702 * This macro post a semaphore and returns the status 703 * 704 * @param[in] sid The semaphore 705 * 706 * @retval CPA_STATUS_SUCCESS Function executed successfully. 707 * @retval CPA_STATUS_RESOURCE Error with semaphore 708 ******************************************************************************/ 709 #define LAC_POST_SEMAPHORE(sid) \ 710 ((CPA_STATUS_SUCCESS != qatUtilsSemaphorePost(&sid)) ? \ 711 CPA_STATUS_RESOURCE : \ 712 CPA_STATUS_SUCCESS) 713 /** 714 ******************************************************************************* 715 * @ingroup LacCommon 716 * This macro initialises a semaphore and returns the status 717 * 718 * @param[in] sid The semaphore 719 * @param[in] semValue Initial semaphore value 720 * 721 * @retval CPA_STATUS_SUCCESS Function executed successfully. 722 * @retval CPA_STATUS_RESOURCE Error with semaphore 723 ******************************************************************************/ 724 #define LAC_INIT_SEMAPHORE(sid, semValue) \ 725 ((CPA_STATUS_SUCCESS != qatUtilsSemaphoreInit(&sid, semValue)) ? \ 726 CPA_STATUS_RESOURCE : \ 727 CPA_STATUS_SUCCESS) 728 729 /** 730 ******************************************************************************* 731 * @ingroup LacCommon 732 * This macro destroys a semaphore and returns the status 733 * 734 * @param[in] sid The semaphore 735 * 736 * @retval CPA_STATUS_SUCCESS Function executed successfully. 737 * @retval CPA_STATUS_RESOURCE Error with semaphore 738 ******************************************************************************/ 739 #define LAC_DESTROY_SEMAPHORE(sid) \ 740 ((CPA_STATUS_SUCCESS != qatUtilsSemaphoreDestroy(&sid)) ? \ 741 CPA_STATUS_RESOURCE : \ 742 CPA_STATUS_SUCCESS) 743 744 /* 745 ******************************************************************************* 746 * Spinlock Macros 747 ******************************************************************************* 748 */ 749 typedef struct mtx *lac_lock_t; 750 #define LAC_SPINLOCK_INIT(lock) \ 751 ((CPA_STATUS_SUCCESS != qatUtilsLockInit(lock)) ? \ 752 CPA_STATUS_RESOURCE : \ 753 CPA_STATUS_SUCCESS) 754 #define LAC_SPINLOCK(lock) \ 755 ({ \ 756 (void)qatUtilsLock(lock); \ 757 }) 758 #define LAC_SPINUNLOCK(lock) \ 759 ({ \ 760 (void)qatUtilsUnlock(lock); \ 761 }) 762 #define LAC_SPINLOCK_DESTROY(lock) \ 763 ({ \ 764 (void)qatUtilsLockDestroy(lock); \ 765 }) 766 767 #define LAC_CONST_PTR_CAST(castee) ((void *)(LAC_ARCH_UINT)(castee)) 768 #define LAC_CONST_VOLATILE_PTR_CAST(castee) ((void *)(LAC_ARCH_UINT)(castee)) 769 770 /* Type of ring */ 771 #define SAL_RING_TYPE_NONE 0 772 #define SAL_RING_TYPE_A_SYM_HI 1 773 #define SAL_RING_TYPE_A_SYM_LO 2 774 #define SAL_RING_TYPE_A_ASYM 3 775 #define SAL_RING_TYPE_B_SYM_HI 4 776 #define SAL_RING_TYPE_B_SYM_LO 5 777 #define SAL_RING_TYPE_B_ASYM 6 778 #define SAL_RING_TYPE_DC 7 779 #define SAL_RING_TYPE_ADMIN 8 780 #define SAL_RING_TYPE_TRNG 9 781 782 /* Maps Ring Service to generic service type */ 783 static inline icp_adf_ringInfoService_t 784 lac_getRingType(int type) 785 { 786 switch (type) { 787 case SAL_RING_TYPE_NONE: 788 return ICP_ADF_RING_SERVICE_0; 789 case SAL_RING_TYPE_A_SYM_HI: 790 return ICP_ADF_RING_SERVICE_1; 791 case SAL_RING_TYPE_A_SYM_LO: 792 return ICP_ADF_RING_SERVICE_2; 793 case SAL_RING_TYPE_A_ASYM: 794 return ICP_ADF_RING_SERVICE_3; 795 case SAL_RING_TYPE_B_SYM_HI: 796 return ICP_ADF_RING_SERVICE_4; 797 case SAL_RING_TYPE_B_SYM_LO: 798 return ICP_ADF_RING_SERVICE_5; 799 case SAL_RING_TYPE_B_ASYM: 800 return ICP_ADF_RING_SERVICE_6; 801 case SAL_RING_TYPE_DC: 802 return ICP_ADF_RING_SERVICE_7; 803 case SAL_RING_TYPE_ADMIN: 804 return ICP_ADF_RING_SERVICE_8; 805 case SAL_RING_TYPE_TRNG: 806 return ICP_ADF_RING_SERVICE_9; 807 default: 808 return ICP_ADF_RING_SERVICE_0; 809 } 810 return ICP_ADF_RING_SERVICE_0; 811 } 812 813 /* Maps generic service type to Ring Service type */ 814 static inline int 815 lac_getServiceType(icp_adf_ringInfoService_t type) 816 { 817 switch (type) { 818 case ICP_ADF_RING_SERVICE_0: 819 return SAL_RING_TYPE_NONE; 820 case ICP_ADF_RING_SERVICE_1: 821 return SAL_RING_TYPE_A_SYM_HI; 822 case ICP_ADF_RING_SERVICE_2: 823 return SAL_RING_TYPE_A_SYM_LO; 824 case ICP_ADF_RING_SERVICE_3: 825 return SAL_RING_TYPE_A_ASYM; 826 case ICP_ADF_RING_SERVICE_4: 827 return SAL_RING_TYPE_B_SYM_HI; 828 case ICP_ADF_RING_SERVICE_5: 829 return SAL_RING_TYPE_B_SYM_LO; 830 case ICP_ADF_RING_SERVICE_6: 831 return SAL_RING_TYPE_B_ASYM; 832 case ICP_ADF_RING_SERVICE_7: 833 return SAL_RING_TYPE_DC; 834 case ICP_ADF_RING_SERVICE_8: 835 return SAL_RING_TYPE_ADMIN; 836 default: 837 return SAL_RING_TYPE_NONE; 838 } 839 return SAL_RING_TYPE_NONE; 840 } 841 842 #endif /* LAC_COMMON_H */ 843