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