1 /* 2 * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /** 20 * DOC: qdf_util.h 21 * This file defines utility functions. 22 */ 23 24 #ifndef _QDF_UTIL_H 25 #define _QDF_UTIL_H 26 27 #include <i_qdf_util.h> 28 29 #ifdef QCA_CONFIG_SMP 30 #define QDF_MAX_AVAILABLE_CPU 8 31 #else 32 #define QDF_MAX_AVAILABLE_CPU 1 33 #endif 34 35 typedef __qdf_wait_queue_head_t qdf_wait_queue_head_t; 36 37 /** 38 * qdf_unlikely - Compiler-dependent macro denoting code likely to execute 39 * @_expr: expression to be checked 40 */ 41 #define qdf_unlikely(_expr) __qdf_unlikely(_expr) 42 43 /** 44 * qdf_likely - Compiler-dependent macro denoting code unlikely to execute 45 * @_expr: expression to be checked 46 */ 47 #define qdf_likely(_expr) __qdf_likely(_expr) 48 49 /** 50 * qdf_mb - read + write memory barrier. 51 */ 52 #define qdf_mb() __qdf_mb() 53 54 /** 55 * qdf_ioread32 - read a register 56 * @offset: register address 57 */ 58 #define qdf_ioread32(offset) __qdf_ioread32(offset) 59 /** 60 * qdf_iowrite32 - write a register 61 * @offset: register address 62 * @value: value to write (32bit value) 63 */ 64 #define qdf_iowrite32(offset, value) __qdf_iowrite32(offset, value) 65 66 /** 67 * qdf_assert - assert "expr" evaluates to false. 68 */ 69 #ifdef QDF_DEBUG 70 #define qdf_assert(expr) __qdf_assert(expr) 71 #else 72 #define qdf_assert(expr) 73 #endif /* QDF_DEBUG */ 74 75 /** 76 * qdf_assert_always - alway assert "expr" evaluates to false. 77 */ 78 #define qdf_assert_always(expr) __qdf_assert(expr) 79 80 /** 81 * qdf_target_assert_always - alway target assert "expr" evaluates to false. 82 */ 83 #define qdf_target_assert_always(expr) __qdf_target_assert(expr) 84 85 /** 86 * QDF_MAX - get maximum of two values 87 * @_x: 1st argument 88 * @_y: 2nd argument 89 */ 90 #define QDF_MAX(_x, _y) (((_x) > (_y)) ? (_x) : (_y)) 91 92 /** 93 * QDF_MIN - get minimum of two values 94 * @_x: 1st argument 95 * @_y: 2nd argument 96 */ 97 #define QDF_MIN(_x, _y) (((_x) < (_y)) ? (_x) : (_y)) 98 99 /** 100 * QDF_IS_ADDR_BROADCAST - is mac address broadcast mac address 101 * @_a: pointer to mac address 102 */ 103 #define QDF_IS_ADDR_BROADCAST(_a) \ 104 ((_a)[0] == 0xff && \ 105 (_a)[1] == 0xff && \ 106 (_a)[2] == 0xff && \ 107 (_a)[3] == 0xff && \ 108 (_a)[4] == 0xff && \ 109 (_a)[5] == 0xff) 110 111 #define QDF_DECLARE_EWMA(name, factor, weight) \ 112 __QDF_DECLARE_EWMA(name, factor, weight) 113 114 #define qdf_ewma_tx_lag __qdf_ewma_tx_lag 115 116 #define qdf_ewma_tx_lag_init(tx_lag) \ 117 __qdf_ewma_tx_lag_init(tx_lag) 118 119 #define qdf_ewma_tx_lag_add(tx_lag, value) \ 120 __qdf_ewma_tx_lag_add(tx_lag, value) 121 122 #define qdf_ewma_tx_lag_read(tx_lag) \ 123 __qdf_ewma_tx_lag_read(tx_lag) 124 125 /** 126 * qdf_status_to_os_return - returns the status to OS. 127 * @status: enum QDF_STATUS 128 * 129 * returns: int status success/failure 130 */ 131 static inline int qdf_status_to_os_return(QDF_STATUS status) 132 { 133 return __qdf_status_to_os_return(status); 134 } 135 136 /** 137 * qdf_status_from_os_return() - map OS specific return code to a QDF_STATUS 138 * @rc: the input return code to map 139 * 140 * Return: QDF_STATUS 141 */ 142 static inline QDF_STATUS qdf_status_from_os_return(int rc) 143 { 144 return __qdf_status_from_os_return(rc); 145 } 146 147 /** 148 * qdf_set_bit() - set bit in address 149 * @nr: bit number to be set 150 * @addr: address buffer pointer 151 * 152 * Return: none 153 */ 154 #define qdf_set_bit(nr, addr) __qdf_set_bit(nr, addr) 155 156 /** 157 * qdf_clear_bit() - clear bit in address 158 * @nr: bit number to be clear 159 * @addr: address buffer pointer 160 * 161 * Return: none 162 */ 163 #define qdf_clear_bit(nr, addr) __qdf_clear_bit(nr, addr) 164 165 /** 166 * qdf_test_bit() - test bit position in address 167 * @nr: bit number to be tested 168 * @addr: address buffer pointer 169 * 170 * Return: none 171 */ 172 #define qdf_test_bit(nr, addr) __qdf_test_bit(nr, addr) 173 174 /** 175 * qdf_test_and_clear_bit() - test and clear bit position in address 176 * @nr: bit number to be tested 177 * @addr: address buffer pointer 178 * 179 * Return: none 180 */ 181 #define qdf_test_and_clear_bit(nr, addr) __qdf_test_and_clear_bit(nr, addr) 182 183 /** 184 * qdf_find_first_bit() - find first bit position in address 185 * @addr: address buffer pointer 186 * @nbits: number of bits 187 * 188 * Return: position first set bit in addr 189 */ 190 #define qdf_find_first_bit(addr, nbits) __qdf_find_first_bit(addr, nbits) 191 192 #define qdf_wait_queue_interruptible(wait_queue, condition) \ 193 __qdf_wait_queue_interruptible(wait_queue, condition) 194 195 /** 196 * qdf_wait_queue_timeout() - wait for specified time on given condition 197 * @wait_queue: wait queue to wait on 198 * @condition: condition to wait on 199 * @timeout: timeout value in jiffies 200 * 201 * Return: 0 if condition becomes false after timeout 202 * 1 or remaining jiffies, if condition becomes true during timeout 203 */ 204 #define qdf_wait_queue_timeout(wait_queue, condition, timeout) \ 205 __qdf_wait_queue_timeout(wait_queue, \ 206 condition, timeout) 207 208 209 #define qdf_init_waitqueue_head(_q) __qdf_init_waitqueue_head(_q) 210 211 #define qdf_wake_up_interruptible(_q) __qdf_wake_up_interruptible(_q) 212 213 /** 214 * qdf_wake_up() - wakes up sleeping waitqueue 215 * @wait_queue: wait queue, which needs wake up 216 * 217 * Return: none 218 */ 219 #define qdf_wake_up(_q) __qdf_wake_up(_q) 220 221 #define qdf_wake_up_completion(_q) __qdf_wake_up_completion(_q) 222 223 /** 224 * qdf_container_of - cast a member of a structure out to the containing 225 * structure 226 * @ptr: the pointer to the member. 227 * @type: the type of the container struct this is embedded in. 228 * @member: the name of the member within the struct. 229 */ 230 #define qdf_container_of(ptr, type, member) \ 231 __qdf_container_of(ptr, type, member) 232 233 /** 234 * qdf_is_pwr2 - test input value is power of 2 integer 235 * @value: input integer 236 */ 237 #define QDF_IS_PWR2(value) (((value) ^ ((value)-1)) == ((value) << 1) - 1) 238 239 /** 240 * qdf_roundup() - roundup the input value 241 * @x: value to roundup 242 * @y: input value rounded to multiple of this 243 * 244 * Return: rounded value 245 */ 246 #define qdf_roundup(x, y) __qdf_roundup(x, y) 247 248 /** 249 * qdf_is_macaddr_equal() - compare two QDF MacAddress 250 * @mac_addr1: Pointer to one qdf MacAddress to compare 251 * @mac_addr2: Pointer to the other qdf MacAddress to compare 252 * 253 * This function returns a bool that tells if a two QDF MacAddress' 254 * are equivalent. 255 * 256 * Return: true if the MacAddress's are equal 257 * not true if the MacAddress's are not equal 258 */ 259 static inline bool qdf_is_macaddr_equal(struct qdf_mac_addr *mac_addr1, 260 struct qdf_mac_addr *mac_addr2) 261 { 262 return __qdf_is_macaddr_equal(mac_addr1, mac_addr2); 263 } 264 265 266 /** 267 * qdf_is_macaddr_zero() - check for a MacAddress of all zeros. 268 * @mac_addr: pointer to the struct qdf_mac_addr to check. 269 * 270 * This function returns a bool that tells if a MacAddress is made up of 271 * all zeros. 272 * 273 * Return: true if the MacAddress is all Zeros 274 * false if the MacAddress is not all Zeros. 275 */ 276 static inline bool qdf_is_macaddr_zero(struct qdf_mac_addr *mac_addr) 277 { 278 struct qdf_mac_addr zero_mac_addr = QDF_MAC_ADDR_ZERO_INIT; 279 280 return qdf_is_macaddr_equal(mac_addr, &zero_mac_addr); 281 } 282 283 /** 284 * qdf_zero_macaddr() - zero out a MacAddress 285 * @mac_addr: pointer to the struct qdf_mac_addr to zero. 286 * 287 * This function zeros out a QDF MacAddress type. 288 * 289 * Return: none 290 */ 291 static inline void qdf_zero_macaddr(struct qdf_mac_addr *mac_addr) 292 { 293 __qdf_zero_macaddr(mac_addr); 294 } 295 296 297 /** 298 * qdf_is_macaddr_group() - check for a MacAddress is a 'group' address 299 * @mac_addr1: pointer to the qdf MacAddress to check 300 * 301 * This function returns a bool that tells if a the input QDF MacAddress 302 * is a "group" address. Group addresses have the 'group address bit' turned 303 * on in the MacAddress. Group addresses are made up of Broadcast and 304 * Multicast addresses. 305 * 306 * Return: true if the input MacAddress is a Group address 307 * false if the input MacAddress is not a Group address 308 */ 309 static inline bool qdf_is_macaddr_group(struct qdf_mac_addr *mac_addr) 310 { 311 return mac_addr->bytes[0] & 0x01; 312 } 313 314 315 /** 316 * qdf_is_macaddr_broadcast() - check for a MacAddress is a broadcast address 317 * @mac_addr: Pointer to the qdf MacAddress to check 318 * 319 * This function returns a bool that tells if a the input QDF MacAddress 320 * is a "broadcast" address. 321 * 322 * Return: true if the input MacAddress is a broadcast address 323 * flase if the input MacAddress is not a broadcast address 324 */ 325 static inline bool qdf_is_macaddr_broadcast(struct qdf_mac_addr *mac_addr) 326 { 327 struct qdf_mac_addr broadcast_mac_addr = QDF_MAC_ADDR_BCAST_INIT; 328 return qdf_is_macaddr_equal(mac_addr, &broadcast_mac_addr); 329 } 330 331 /** 332 * qdf_copy_macaddr() - copy a QDF MacAddress 333 * @dst_addr: pointer to the qdf MacAddress to copy TO (the destination) 334 * @src_addr: pointer to the qdf MacAddress to copy FROM (the source) 335 * 336 * This function copies a QDF MacAddress into another QDF MacAddress. 337 * 338 * Return: none 339 */ 340 static inline void qdf_copy_macaddr(struct qdf_mac_addr *dst_addr, 341 struct qdf_mac_addr *src_addr) 342 { 343 *dst_addr = *src_addr; 344 } 345 346 /** 347 * qdf_set_macaddr_broadcast() - set a QDF MacAddress to the 'broadcast' 348 * @mac_addr: pointer to the qdf MacAddress to set to broadcast 349 * 350 * This function sets a QDF MacAddress to the 'broadcast' MacAddress. Broadcast 351 * MacAddress contains all 0xFF bytes. 352 * 353 * Return: none 354 */ 355 static inline void qdf_set_macaddr_broadcast(struct qdf_mac_addr *mac_addr) 356 { 357 __qdf_set_macaddr_broadcast(mac_addr); 358 } 359 360 /** 361 * qdf_set_u16() - Assign 16-bit unsigned value to a byte array base on CPU's 362 * endianness. 363 * @ptr: Starting address of a byte array 364 * @value: The value to assign to the byte array 365 * 366 * Caller must validate the byte array has enough space to hold the vlaue 367 * 368 * Return: The address to the byte after the assignment. This may or may not 369 * be valid. Caller to verify. 370 */ 371 static inline uint8_t *qdf_set_u16(uint8_t *ptr, uint16_t value) 372 { 373 #if defined(ANI_BIG_BYTE_ENDIAN) 374 *(ptr) = (uint8_t) (value >> 8); 375 *(ptr + 1) = (uint8_t) (value); 376 #else 377 *(ptr + 1) = (uint8_t) (value >> 8); 378 *(ptr) = (uint8_t) (value); 379 #endif 380 return ptr + 2; 381 } 382 383 /** 384 * qdf_get_u16() - Retrieve a 16-bit unsigned value from a byte array base on 385 * CPU's endianness. 386 * @ptr: Starting address of a byte array 387 * @value: Pointer to a caller allocated buffer for 16 bit value. Value is to 388 * assign to this location. 389 * 390 * Caller must validate the byte array has enough space to hold the vlaue 391 * 392 * Return: The address to the byte after the assignment. This may or may not 393 * be valid. Caller to verify. 394 */ 395 static inline uint8_t *qdf_get_u16(uint8_t *ptr, uint16_t *value) 396 { 397 #if defined(ANI_BIG_BYTE_ENDIAN) 398 *value = (((uint16_t) (*ptr << 8)) | ((uint16_t) (*(ptr + 1)))); 399 #else 400 *value = (((uint16_t) (*(ptr + 1) << 8)) | ((uint16_t) (*ptr))); 401 #endif 402 return ptr + 2; 403 } 404 405 /** 406 * qdf_get_u32() - retrieve a 32-bit unsigned value from a byte array base on 407 * CPU's endianness. 408 * @ptr: Starting address of a byte array 409 * @value: Pointer to a caller allocated buffer for 32 bit value. Value is to 410 * assign to this location. 411 * 412 * Caller must validate the byte array has enough space to hold the vlaue 413 * 414 * Return: The address to the byte after the assignment. This may or may not 415 * be valid. Caller to verify. 416 */ 417 static inline uint8_t *qdf_get_u32(uint8_t *ptr, uint32_t *value) 418 { 419 #if defined(ANI_BIG_BYTE_ENDIAN) 420 *value = ((uint32_t) (*(ptr) << 24) | 421 (uint32_t) (*(ptr + 1) << 16) | 422 (uint32_t) (*(ptr + 2) << 8) | (uint32_t) (*(ptr + 3))); 423 #else 424 *value = ((uint32_t) (*(ptr + 3) << 24) | 425 (uint32_t) (*(ptr + 2) << 16) | 426 (uint32_t) (*(ptr + 1) << 8) | (uint32_t) (*(ptr))); 427 #endif 428 return ptr + 4; 429 } 430 431 /** 432 * qdf_ntohs - Convert a 16-bit value from network byte order to host byte order 433 */ 434 #define qdf_ntohs(x) __qdf_ntohs(x) 435 436 /** 437 * qdf_ntohl - Convert a 32-bit value from network byte order to host byte order 438 */ 439 #define qdf_ntohl(x) __qdf_ntohl(x) 440 441 /** 442 * qdf_htons - Convert a 16-bit value from host byte order to network byte order 443 */ 444 #define qdf_htons(x) __qdf_htons(x) 445 446 /** 447 * qdf_htonl - Convert a 32-bit value from host byte order to network byte order 448 */ 449 #define qdf_htonl(x) __qdf_htonl(x) 450 451 /** 452 * qdf_cpu_to_le16 - Convert a 16-bit value from CPU byte order to 453 * little-endian byte order 454 * 455 * @x: value to be converted 456 */ 457 #define qdf_cpu_to_le16(x) __qdf_cpu_to_le16(x) 458 459 /** 460 * qdf_cpu_to_le32 - Convert a 32-bit value from CPU byte order to 461 * little-endian byte order 462 * 463 * @x: value to be converted 464 */ 465 #define qdf_cpu_to_le32(x) __qdf_cpu_to_le32(x) 466 467 /** 468 * qdf_cpu_to_le64 - Convert a 64-bit value from CPU byte order to 469 * little-endian byte order 470 * 471 * @x: value to be converted 472 */ 473 #define qdf_cpu_to_le64(x) __qdf_cpu_to_le64(x) 474 475 /** 476 * qdf_le16_to_cpu - Convert a 16-bit value from little-endian byte order 477 * to CPU byte order 478 * 479 * @x: value to be converted 480 */ 481 #define qdf_le16_to_cpu(x) __qdf_le16_to_cpu(x) 482 483 /** 484 * qdf_le32_to_cpu - Convert a 32-bit value from little-endian byte 485 * order to CPU byte order 486 * 487 * @x: value to be converted 488 */ 489 #define qdf_le32_to_cpu(x) __qdf_le32_to_cpu(x) 490 491 /** 492 * qdf_le64_to_cpu - Convert a 64-bit value from little-endian byte 493 * order to CPU byte order 494 * 495 * @x: value to be converted 496 */ 497 #define qdf_le64_to_cpu(x) __qdf_le64_to_cpu(x) 498 499 /** 500 * qdf_cpu_to_be16 - Convert a 16-bit value from CPU byte order to 501 * big-endian byte order 502 * 503 * @x: value to be converted 504 */ 505 #define qdf_cpu_to_be16(x) __qdf_cpu_to_be16(x) 506 507 /** 508 * qdf_cpu_to_be32 - Convert a 32-bit value from CPU byte order to 509 * big-endian byte order 510 * 511 * @x: value to be converted 512 */ 513 #define qdf_cpu_to_be32(x) __qdf_cpu_to_be32(x) 514 515 /** 516 * qdf_cpu_to_be64 - Convert a 64-bit value from CPU byte order to 517 * big-endian byte order 518 * 519 * @x: value to be converted 520 */ 521 #define qdf_cpu_to_be64(x) __qdf_cpu_to_be64(x) 522 523 524 /** 525 * qdf_be16_to_cpu - Convert a 16-bit value from big-endian byte order 526 * to CPU byte order 527 * 528 * @x: value to be converted 529 */ 530 #define qdf_be16_to_cpu(x) __qdf_be16_to_cpu(x) 531 532 /** 533 * qdf_be32_to_cpu - Convert a 32-bit value from big-endian byte order 534 * to CPU byte order 535 * 536 * @x: value to be converted 537 */ 538 #define qdf_be32_to_cpu(x) __qdf_be32_to_cpu(x) 539 540 /** 541 * qdf_be64_to_cpu - Convert a 64-bit value from big-endian byte order 542 * to CPU byte order 543 * 544 * @x: value to be converted 545 */ 546 #define qdf_be64_to_cpu(x) __qdf_be64_to_cpu(x) 547 548 /** 549 * qdf_function - replace with the name of the current function 550 */ 551 #define qdf_function __qdf_function 552 553 /** 554 * qdf_min - minimum of two numbers 555 */ 556 #define qdf_min(a, b) __qdf_min(a, b) 557 558 /** 559 * qdf_ffz() - find first (least significant) zero bit 560 * @mask: the bitmask to check 561 * 562 * Return: The zero-based index of the first zero bit, or -1 if none are found 563 */ 564 #define qdf_ffz(mask) __qdf_ffz(mask) 565 566 /** 567 * qdf_get_pwr2() - get next power of 2 integer from input value 568 * @value: input value to find next power of 2 integer 569 * 570 * Get next power of 2 integer from input value 571 * 572 * Return: Power of 2 integer 573 */ 574 static inline int qdf_get_pwr2(int value) 575 { 576 int log2; 577 578 if (QDF_IS_PWR2(value)) 579 return value; 580 581 log2 = 0; 582 while (value) { 583 value >>= 1; 584 log2++; 585 } 586 return 1 << log2; 587 } 588 589 static inline 590 int qdf_get_cpu(void) 591 { 592 return __qdf_get_cpu(); 593 } 594 595 /** 596 * qdf_get_hweight8() - count num of 1's in bitmap 597 * @value: input bitmap 598 * 599 * Count num of 1's set in the bitmap 600 * 601 * Return: num of 1's 602 */ 603 static inline 604 unsigned int qdf_get_hweight8(unsigned int w) 605 { 606 unsigned int res = w - ((w >> 1) & 0x55); 607 res = (res & 0x33) + ((res >> 2) & 0x33); 608 return (res + (res >> 4)) & 0x0F; 609 } 610 611 /** 612 * qdf_device_init_wakeup() - allow a device to wake up the aps system 613 * @qdf_dev: the qdf device context 614 * @enable: enable/disable the device as a wakup source 615 * 616 * Return: 0 or errno 617 */ 618 static inline int qdf_device_init_wakeup(qdf_device_t qdf_dev, bool enable) 619 { 620 return __qdf_device_init_wakeup(qdf_dev, enable); 621 } 622 623 static inline 624 uint64_t qdf_get_totalramsize(void) 625 { 626 return __qdf_get_totalramsize(); 627 } 628 629 /** 630 * qdf_get_lower_32_bits() - get lower 32 bits from an address. 631 * @addr: address 632 * 633 * This api returns the lower 32 bits of an address. 634 * 635 * Return: lower 32 bits. 636 */ 637 static inline 638 uint32_t qdf_get_lower_32_bits(qdf_dma_addr_t addr) 639 { 640 return __qdf_get_lower_32_bits(addr); 641 } 642 643 /** 644 * qdf_get_upper_32_bits() - get upper 32 bits from an address. 645 * @addr: address 646 * 647 * This api returns the upper 32 bits of an address. 648 * 649 * Return: upper 32 bits. 650 */ 651 static inline 652 uint32_t qdf_get_upper_32_bits(qdf_dma_addr_t addr) 653 { 654 return __qdf_get_upper_32_bits(addr); 655 } 656 657 /** 658 * qdf_rounddown_pow_of_two() - Round down to nearest power of two 659 * @n: number to be tested 660 * 661 * Test if the input number is power of two, and return the nearest power of two 662 * 663 * Return: number rounded down to the nearest power of two 664 */ 665 static inline 666 unsigned long qdf_rounddown_pow_of_two(unsigned long n) 667 { 668 return __qdf_rounddown_pow_of_two(n); 669 } 670 671 /** 672 * qdf_set_dma_coherent_mask() - set max number of bits allowed in dma addr 673 * @dev: device pointer 674 * @addr_bits: max number of bits allowed in dma address 675 * 676 * This API sets the maximum allowed number of bits in the dma address. 677 * 678 * Return: 0 - success, non zero - failure 679 */ 680 static inline 681 int qdf_set_dma_coherent_mask(struct device *dev, uint8_t addr_bits) 682 { 683 return __qdf_set_dma_coherent_mask(dev, addr_bits); 684 } 685 686 /** 687 * qdf_do_div() - wrapper function for kernel macro(do_div). 688 * @dividend: Dividend value 689 * @divisor : Divisor value 690 * 691 * Return: Quotient 692 */ 693 static inline 694 uint64_t qdf_do_div(uint64_t dividend, uint32_t divisor) 695 { 696 return __qdf_do_div(dividend, divisor); 697 } 698 699 /** 700 * qdf_do_div_rem() - wrapper function for kernel macro(do_div) 701 * to get remainder. 702 * @dividend: Dividend value 703 * @divisor : Divisor value 704 * 705 * Return: remainder 706 */ 707 static inline 708 uint64_t qdf_do_div_rem(uint64_t dividend, uint32_t divisor) 709 { 710 return __qdf_do_div_rem(dividend, divisor); 711 } 712 713 /** 714 * qdf_get_random_bytes() - returns nbytes bytes of random 715 * data 716 * 717 * Return: random bytes of data 718 */ 719 static inline 720 void qdf_get_random_bytes(void *buf, int nbytes) 721 { 722 return __qdf_get_random_bytes(buf, nbytes); 723 } 724 725 /** 726 * qdf_hex_to_bin() - QDF API to Convert hexa decimal ASCII character to 727 * unsigned integer value. 728 * @ch: hexa decimal ASCII character 729 * 730 * Return: For hexa decimal ASCII char return actual decimal value 731 * else -1 for bad input. 732 */ 733 static inline 734 int qdf_hex_to_bin(char ch) 735 { 736 return __qdf_hex_to_bin(ch); 737 } 738 739 /** 740 * qdf_hex_str_to_binary() - QDF API to Convert string of hexa decimal 741 * ASCII characters to array of unsigned integers. 742 * @dst: output array to hold converted values 743 * @src: input string of hexa decimal ASCII characters 744 * @count: size of dst string 745 * 746 * This function is used to convert string of hexa decimal characters to 747 * array of unsigned integers and caller should ensure: 748 * a) @dst, @src are not NULL, 749 * b) size of @dst should be (size of src / 2) 750 * 751 * Example 1: 752 * src = 11aa, means, src[0] = '1', src[1] = '2', src[2] = 'a', src[3] = 'a' 753 * count = (size of src / 2) = 2 754 * after conversion, dst[0] = 0x11, dst[1] = oxAA and return (0). 755 * 756 * Example 2: 757 * src = 11az, means, src[0] = '1', src[1] = '2', src[2] = 'a', src[3] = 'z' 758 * src[3] is not ASCII hexa decimal character, return negative value (-1). 759 * 760 * Return: For a string of hexa decimal ASCII characters return 0 761 * else -1 for bad input. 762 */ 763 static inline 764 int qdf_hex_str_to_binary(u8 *dst, const char *src, size_t count) 765 { 766 return __qdf_hex_str_to_binary(dst, src, count); 767 } 768 769 #endif /*_QDF_UTIL_H*/ 770