1 /* 2 * Copyright (c) 2014-2019 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 #define qdf_ewma_rx_rssi __qdf_ewma_rx_rssi 126 127 #define qdf_ewma_rx_rssi_init(rx_rssi) \ 128 __qdf_ewma_rx_rssi_init(rx_rssi) 129 130 #define qdf_ewma_rx_rssi_add(rx_rssi, value) \ 131 __qdf_ewma_rx_rssi_add(rx_rssi, value) 132 133 #define qdf_ewma_rx_rssi_read(rx_rssi) \ 134 __qdf_ewma_rx_rssi_read(rx_rssi) 135 /** 136 * qdf_set_bit() - set bit in address 137 * @nr: bit number to be set 138 * @addr: address buffer pointer 139 * 140 * Return: none 141 */ 142 #define qdf_set_bit(nr, addr) __qdf_set_bit(nr, addr) 143 144 /** 145 * qdf_clear_bit() - clear bit in address 146 * @nr: bit number to be clear 147 * @addr: address buffer pointer 148 * 149 * Return: none 150 */ 151 #define qdf_clear_bit(nr, addr) __qdf_clear_bit(nr, addr) 152 153 /** 154 * qdf_test_bit() - test bit position in address 155 * @nr: bit number to be tested 156 * @addr: address buffer pointer 157 * 158 * Return: none 159 */ 160 #define qdf_test_bit(nr, addr) __qdf_test_bit(nr, addr) 161 162 /** 163 * qdf_test_and_clear_bit() - test and clear bit position in address 164 * @nr: bit number to be tested 165 * @addr: address buffer pointer 166 * 167 * Return: none 168 */ 169 #define qdf_test_and_clear_bit(nr, addr) __qdf_test_and_clear_bit(nr, addr) 170 171 /** 172 * qdf_find_first_bit() - find first bit position in address 173 * @addr: address buffer pointer 174 * @nbits: number of bits 175 * 176 * Return: position first set bit in addr 177 */ 178 #define qdf_find_first_bit(addr, nbits) __qdf_find_first_bit(addr, nbits) 179 180 #define qdf_wait_queue_interruptible(wait_queue, condition) \ 181 __qdf_wait_queue_interruptible(wait_queue, condition) 182 183 /** 184 * qdf_wait_queue_timeout() - wait for specified time on given condition 185 * @wait_queue: wait queue to wait on 186 * @condition: condition to wait on 187 * @timeout: timeout value in jiffies 188 * 189 * Return: 0 if condition becomes false after timeout 190 * 1 or remaining jiffies, if condition becomes true during timeout 191 */ 192 #define qdf_wait_queue_timeout(wait_queue, condition, timeout) \ 193 __qdf_wait_queue_timeout(wait_queue, \ 194 condition, timeout) 195 196 197 #define qdf_init_waitqueue_head(_q) __qdf_init_waitqueue_head(_q) 198 199 #define qdf_wake_up_interruptible(_q) __qdf_wake_up_interruptible(_q) 200 201 /** 202 * qdf_wake_up() - wakes up sleeping waitqueue 203 * @wait_queue: wait queue, which needs wake up 204 * 205 * Return: none 206 */ 207 #define qdf_wake_up(_q) __qdf_wake_up(_q) 208 209 #define qdf_wake_up_completion(_q) __qdf_wake_up_completion(_q) 210 211 /** 212 * qdf_container_of - cast a member of a structure out to the containing 213 * structure 214 * @ptr: the pointer to the member. 215 * @type: the type of the container struct this is embedded in. 216 * @member: the name of the member within the struct. 217 */ 218 #define qdf_container_of(ptr, type, member) \ 219 __qdf_container_of(ptr, type, member) 220 221 /** 222 * qdf_is_pwr2 - test input value is power of 2 integer 223 * @value: input integer 224 */ 225 #define QDF_IS_PWR2(value) (((value) ^ ((value)-1)) == ((value) << 1) - 1) 226 227 /** 228 * qdf_roundup() - roundup the input value 229 * @x: value to roundup 230 * @y: input value rounded to multiple of this 231 * 232 * Return: rounded value 233 */ 234 #define qdf_roundup(x, y) __qdf_roundup(x, y) 235 236 /** 237 * qdf_is_macaddr_equal() - compare two QDF MacAddress 238 * @mac_addr1: Pointer to one qdf MacAddress to compare 239 * @mac_addr2: Pointer to the other qdf MacAddress to compare 240 * 241 * This function returns a bool that tells if a two QDF MacAddress' 242 * are equivalent. 243 * 244 * Return: true if the MacAddress's are equal 245 * not true if the MacAddress's are not equal 246 */ 247 static inline bool qdf_is_macaddr_equal(struct qdf_mac_addr *mac_addr1, 248 struct qdf_mac_addr *mac_addr2) 249 { 250 return __qdf_is_macaddr_equal(mac_addr1, mac_addr2); 251 } 252 253 254 /** 255 * qdf_is_macaddr_zero() - check for a MacAddress of all zeros. 256 * @mac_addr: pointer to the struct qdf_mac_addr to check. 257 * 258 * This function returns a bool that tells if a MacAddress is made up of 259 * all zeros. 260 * 261 * Return: true if the MacAddress is all Zeros 262 * false if the MacAddress is not all Zeros. 263 */ 264 static inline bool qdf_is_macaddr_zero(struct qdf_mac_addr *mac_addr) 265 { 266 struct qdf_mac_addr zero_mac_addr = QDF_MAC_ADDR_ZERO_INIT; 267 268 return qdf_is_macaddr_equal(mac_addr, &zero_mac_addr); 269 } 270 271 /** 272 * qdf_zero_macaddr() - zero out a MacAddress 273 * @mac_addr: pointer to the struct qdf_mac_addr to zero. 274 * 275 * This function zeros out a QDF MacAddress type. 276 * 277 * Return: none 278 */ 279 static inline void qdf_zero_macaddr(struct qdf_mac_addr *mac_addr) 280 { 281 __qdf_zero_macaddr(mac_addr); 282 } 283 284 285 /** 286 * qdf_is_macaddr_group() - check for a MacAddress is a 'group' address 287 * @mac_addr1: pointer to the qdf MacAddress to check 288 * 289 * This function returns a bool that tells if a the input QDF MacAddress 290 * is a "group" address. Group addresses have the 'group address bit' turned 291 * on in the MacAddress. Group addresses are made up of Broadcast and 292 * Multicast addresses. 293 * 294 * Return: true if the input MacAddress is a Group address 295 * false if the input MacAddress is not a Group address 296 */ 297 static inline bool qdf_is_macaddr_group(struct qdf_mac_addr *mac_addr) 298 { 299 return mac_addr->bytes[0] & 0x01; 300 } 301 302 303 /** 304 * qdf_is_macaddr_broadcast() - check for a MacAddress is a broadcast address 305 * @mac_addr: Pointer to the qdf MacAddress to check 306 * 307 * This function returns a bool that tells if a the input QDF MacAddress 308 * is a "broadcast" address. 309 * 310 * Return: true if the input MacAddress is a broadcast address 311 * flase if the input MacAddress is not a broadcast address 312 */ 313 static inline bool qdf_is_macaddr_broadcast(struct qdf_mac_addr *mac_addr) 314 { 315 struct qdf_mac_addr broadcast_mac_addr = QDF_MAC_ADDR_BCAST_INIT; 316 return qdf_is_macaddr_equal(mac_addr, &broadcast_mac_addr); 317 } 318 319 /** 320 * qdf_copy_macaddr() - copy a QDF MacAddress 321 * @dst_addr: pointer to the qdf MacAddress to copy TO (the destination) 322 * @src_addr: pointer to the qdf MacAddress to copy FROM (the source) 323 * 324 * This function copies a QDF MacAddress into another QDF MacAddress. 325 * 326 * Return: none 327 */ 328 static inline void qdf_copy_macaddr(struct qdf_mac_addr *dst_addr, 329 struct qdf_mac_addr *src_addr) 330 { 331 *dst_addr = *src_addr; 332 } 333 334 /** 335 * qdf_set_macaddr_broadcast() - set a QDF MacAddress to the 'broadcast' 336 * @mac_addr: pointer to the qdf MacAddress to set to broadcast 337 * 338 * This function sets a QDF MacAddress to the 'broadcast' MacAddress. Broadcast 339 * MacAddress contains all 0xFF bytes. 340 * 341 * Return: none 342 */ 343 static inline void qdf_set_macaddr_broadcast(struct qdf_mac_addr *mac_addr) 344 { 345 __qdf_set_macaddr_broadcast(mac_addr); 346 } 347 348 /** 349 * qdf_set_u16() - Assign 16-bit unsigned value to a byte array base on CPU's 350 * endianness. 351 * @ptr: Starting address of a byte array 352 * @value: The value to assign to the byte array 353 * 354 * Caller must validate the byte array has enough space to hold the vlaue 355 * 356 * Return: The address to the byte after the assignment. This may or may not 357 * be valid. Caller to verify. 358 */ 359 static inline uint8_t *qdf_set_u16(uint8_t *ptr, uint16_t value) 360 { 361 #if defined(ANI_BIG_BYTE_ENDIAN) 362 *(ptr) = (uint8_t) (value >> 8); 363 *(ptr + 1) = (uint8_t) (value); 364 #else 365 *(ptr + 1) = (uint8_t) (value >> 8); 366 *(ptr) = (uint8_t) (value); 367 #endif 368 return ptr + 2; 369 } 370 371 /** 372 * qdf_get_u16() - Retrieve a 16-bit unsigned value from a byte array base on 373 * CPU's endianness. 374 * @ptr: Starting address of a byte array 375 * @value: Pointer to a caller allocated buffer for 16 bit value. Value is to 376 * assign to this location. 377 * 378 * Caller must validate the byte array has enough space to hold the vlaue 379 * 380 * Return: The address to the byte after the assignment. This may or may not 381 * be valid. Caller to verify. 382 */ 383 static inline uint8_t *qdf_get_u16(uint8_t *ptr, uint16_t *value) 384 { 385 #if defined(ANI_BIG_BYTE_ENDIAN) 386 *value = (((uint16_t) (*ptr << 8)) | ((uint16_t) (*(ptr + 1)))); 387 #else 388 *value = (((uint16_t) (*(ptr + 1) << 8)) | ((uint16_t) (*ptr))); 389 #endif 390 return ptr + 2; 391 } 392 393 /** 394 * qdf_get_u32() - retrieve a 32-bit unsigned value from a byte array base on 395 * CPU's endianness. 396 * @ptr: Starting address of a byte array 397 * @value: Pointer to a caller allocated buffer for 32 bit value. Value is to 398 * assign to this location. 399 * 400 * Caller must validate the byte array has enough space to hold the vlaue 401 * 402 * Return: The address to the byte after the assignment. This may or may not 403 * be valid. Caller to verify. 404 */ 405 static inline uint8_t *qdf_get_u32(uint8_t *ptr, uint32_t *value) 406 { 407 #if defined(ANI_BIG_BYTE_ENDIAN) 408 *value = ((uint32_t) (*(ptr) << 24) | 409 (uint32_t) (*(ptr + 1) << 16) | 410 (uint32_t) (*(ptr + 2) << 8) | (uint32_t) (*(ptr + 3))); 411 #else 412 *value = ((uint32_t) (*(ptr + 3) << 24) | 413 (uint32_t) (*(ptr + 2) << 16) | 414 (uint32_t) (*(ptr + 1) << 8) | (uint32_t) (*(ptr))); 415 #endif 416 return ptr + 4; 417 } 418 419 /** 420 * qdf_ntohs - Convert a 16-bit value from network byte order to host byte order 421 */ 422 #define qdf_ntohs(x) __qdf_ntohs(x) 423 424 /** 425 * qdf_ntohl - Convert a 32-bit value from network byte order to host byte order 426 */ 427 #define qdf_ntohl(x) __qdf_ntohl(x) 428 429 /** 430 * qdf_htons - Convert a 16-bit value from host byte order to network byte order 431 */ 432 #define qdf_htons(x) __qdf_htons(x) 433 434 /** 435 * qdf_htonl - Convert a 32-bit value from host byte order to network byte order 436 */ 437 #define qdf_htonl(x) __qdf_htonl(x) 438 439 /** 440 * qdf_cpu_to_le16 - Convert a 16-bit value from CPU byte order to 441 * little-endian byte order 442 * 443 * @x: value to be converted 444 */ 445 #define qdf_cpu_to_le16(x) __qdf_cpu_to_le16(x) 446 447 /** 448 * qdf_cpu_to_le32 - Convert a 32-bit value from CPU byte order to 449 * little-endian byte order 450 * 451 * @x: value to be converted 452 */ 453 #define qdf_cpu_to_le32(x) __qdf_cpu_to_le32(x) 454 455 /** 456 * qdf_cpu_to_le64 - Convert a 64-bit value from CPU byte order to 457 * little-endian byte order 458 * 459 * @x: value to be converted 460 */ 461 #define qdf_cpu_to_le64(x) __qdf_cpu_to_le64(x) 462 463 /** 464 * qdf_le16_to_cpu - Convert a 16-bit value from little-endian byte order 465 * to CPU byte order 466 * 467 * @x: value to be converted 468 */ 469 #define qdf_le16_to_cpu(x) __qdf_le16_to_cpu(x) 470 471 /** 472 * qdf_le32_to_cpu - Convert a 32-bit value from little-endian byte 473 * order to CPU byte order 474 * 475 * @x: value to be converted 476 */ 477 #define qdf_le32_to_cpu(x) __qdf_le32_to_cpu(x) 478 479 /** 480 * qdf_le64_to_cpu - Convert a 64-bit value from little-endian byte 481 * order to CPU byte order 482 * 483 * @x: value to be converted 484 */ 485 #define qdf_le64_to_cpu(x) __qdf_le64_to_cpu(x) 486 487 /** 488 * qdf_cpu_to_be16 - Convert a 16-bit value from CPU byte order to 489 * big-endian byte order 490 * 491 * @x: value to be converted 492 */ 493 #define qdf_cpu_to_be16(x) __qdf_cpu_to_be16(x) 494 495 /** 496 * qdf_cpu_to_be32 - Convert a 32-bit value from CPU byte order to 497 * big-endian byte order 498 * 499 * @x: value to be converted 500 */ 501 #define qdf_cpu_to_be32(x) __qdf_cpu_to_be32(x) 502 503 /** 504 * qdf_cpu_to_be64 - Convert a 64-bit value from CPU byte order to 505 * big-endian byte order 506 * 507 * @x: value to be converted 508 */ 509 #define qdf_cpu_to_be64(x) __qdf_cpu_to_be64(x) 510 511 512 /** 513 * qdf_be16_to_cpu - Convert a 16-bit value from big-endian byte order 514 * to CPU byte order 515 * 516 * @x: value to be converted 517 */ 518 #define qdf_be16_to_cpu(x) __qdf_be16_to_cpu(x) 519 520 /** 521 * qdf_be32_to_cpu - Convert a 32-bit value from big-endian byte order 522 * to CPU byte order 523 * 524 * @x: value to be converted 525 */ 526 #define qdf_be32_to_cpu(x) __qdf_be32_to_cpu(x) 527 528 /** 529 * qdf_be64_to_cpu - Convert a 64-bit value from big-endian byte order 530 * to CPU byte order 531 * 532 * @x: value to be converted 533 */ 534 #define qdf_be64_to_cpu(x) __qdf_be64_to_cpu(x) 535 536 /** 537 * qdf_function - replace with the name of the current function 538 */ 539 #define qdf_function __qdf_function 540 541 /** 542 * qdf_min - minimum of two numbers 543 */ 544 #define qdf_min(a, b) __qdf_min(a, b) 545 546 /** 547 * qdf_ffz() - find first (least significant) zero bit 548 * @mask: the bitmask to check 549 * 550 * Return: The zero-based index of the first zero bit, or -1 if none are found 551 */ 552 #define qdf_ffz(mask) __qdf_ffz(mask) 553 554 /** 555 * qdf_get_pwr2() - get next power of 2 integer from input value 556 * @value: input value to find next power of 2 integer 557 * 558 * Get next power of 2 integer from input value 559 * 560 * Return: Power of 2 integer 561 */ 562 static inline int qdf_get_pwr2(int value) 563 { 564 int log2; 565 566 if (QDF_IS_PWR2(value)) 567 return value; 568 569 log2 = 0; 570 while (value) { 571 value >>= 1; 572 log2++; 573 } 574 return 1 << log2; 575 } 576 577 static inline 578 int qdf_get_cpu(void) 579 { 580 return __qdf_get_cpu(); 581 } 582 583 /** 584 * qdf_get_hweight8() - count num of 1's in bitmap 585 * @value: input bitmap 586 * 587 * Count num of 1's set in the bitmap 588 * 589 * Return: num of 1's 590 */ 591 static inline 592 unsigned int qdf_get_hweight8(unsigned int w) 593 { 594 unsigned int res = w - ((w >> 1) & 0x55); 595 res = (res & 0x33) + ((res >> 2) & 0x33); 596 return (res + (res >> 4)) & 0x0F; 597 } 598 599 /** 600 * qdf_device_init_wakeup() - allow a device to wake up the aps system 601 * @qdf_dev: the qdf device context 602 * @enable: enable/disable the device as a wakup source 603 * 604 * Return: 0 or errno 605 */ 606 static inline int qdf_device_init_wakeup(qdf_device_t qdf_dev, bool enable) 607 { 608 return __qdf_device_init_wakeup(qdf_dev, enable); 609 } 610 611 static inline 612 uint64_t qdf_get_totalramsize(void) 613 { 614 return __qdf_get_totalramsize(); 615 } 616 617 /** 618 * qdf_get_lower_32_bits() - get lower 32 bits from an address. 619 * @addr: address 620 * 621 * This api returns the lower 32 bits of an address. 622 * 623 * Return: lower 32 bits. 624 */ 625 static inline 626 uint32_t qdf_get_lower_32_bits(qdf_dma_addr_t addr) 627 { 628 return __qdf_get_lower_32_bits(addr); 629 } 630 631 /** 632 * qdf_get_upper_32_bits() - get upper 32 bits from an address. 633 * @addr: address 634 * 635 * This api returns the upper 32 bits of an address. 636 * 637 * Return: upper 32 bits. 638 */ 639 static inline 640 uint32_t qdf_get_upper_32_bits(qdf_dma_addr_t addr) 641 { 642 return __qdf_get_upper_32_bits(addr); 643 } 644 645 /** 646 * qdf_rounddown_pow_of_two() - Round down to nearest power of two 647 * @n: number to be tested 648 * 649 * Test if the input number is power of two, and return the nearest power of two 650 * 651 * Return: number rounded down to the nearest power of two 652 */ 653 static inline 654 unsigned long qdf_rounddown_pow_of_two(unsigned long n) 655 { 656 return __qdf_rounddown_pow_of_two(n); 657 } 658 659 /** 660 * qdf_set_dma_coherent_mask() - set max number of bits allowed in dma addr 661 * @dev: device pointer 662 * @addr_bits: max number of bits allowed in dma address 663 * 664 * This API sets the maximum allowed number of bits in the dma address. 665 * 666 * Return: 0 - success, non zero - failure 667 */ 668 static inline 669 int qdf_set_dma_coherent_mask(struct device *dev, uint8_t addr_bits) 670 { 671 return __qdf_set_dma_coherent_mask(dev, addr_bits); 672 } 673 674 /** 675 * qdf_do_div() - wrapper function for kernel macro(do_div). 676 * @dividend: Dividend value 677 * @divisor : Divisor value 678 * 679 * Return: Quotient 680 */ 681 static inline 682 uint64_t qdf_do_div(uint64_t dividend, uint32_t divisor) 683 { 684 return __qdf_do_div(dividend, divisor); 685 } 686 687 /** 688 * qdf_do_div_rem() - wrapper function for kernel macro(do_div) 689 * to get remainder. 690 * @dividend: Dividend value 691 * @divisor : Divisor value 692 * 693 * Return: remainder 694 */ 695 static inline 696 uint64_t qdf_do_div_rem(uint64_t dividend, uint32_t divisor) 697 { 698 return __qdf_do_div_rem(dividend, divisor); 699 } 700 701 /** 702 * qdf_get_random_bytes() - returns nbytes bytes of random 703 * data 704 * 705 * Return: random bytes of data 706 */ 707 static inline 708 void qdf_get_random_bytes(void *buf, int nbytes) 709 { 710 return __qdf_get_random_bytes(buf, nbytes); 711 } 712 713 /** 714 * qdf_hex_to_bin() - QDF API to Convert hexa decimal ASCII character to 715 * unsigned integer value. 716 * @ch: hexa decimal ASCII character 717 * 718 * Return: For hexa decimal ASCII char return actual decimal value 719 * else -1 for bad input. 720 */ 721 static inline 722 int qdf_hex_to_bin(char ch) 723 { 724 return __qdf_hex_to_bin(ch); 725 } 726 727 /** 728 * qdf_hex_str_to_binary() - QDF API to Convert string of hexa decimal 729 * ASCII characters to array of unsigned integers. 730 * @dst: output array to hold converted values 731 * @src: input string of hexa decimal ASCII characters 732 * @count: size of dst string 733 * 734 * This function is used to convert string of hexa decimal characters to 735 * array of unsigned integers and caller should ensure: 736 * a) @dst, @src are not NULL, 737 * b) size of @dst should be (size of src / 2) 738 * 739 * Example 1: 740 * src = 11aa, means, src[0] = '1', src[1] = '2', src[2] = 'a', src[3] = 'a' 741 * count = (size of src / 2) = 2 742 * after conversion, dst[0] = 0x11, dst[1] = oxAA and return (0). 743 * 744 * Example 2: 745 * src = 11az, means, src[0] = '1', src[1] = '2', src[2] = 'a', src[3] = 'z' 746 * src[3] is not ASCII hexa decimal character, return negative value (-1). 747 * 748 * Return: For a string of hexa decimal ASCII characters return 0 749 * else -1 for bad input. 750 */ 751 static inline 752 int qdf_hex_str_to_binary(u8 *dst, const char *src, size_t count) 753 { 754 return __qdf_hex_str_to_binary(dst, src, count); 755 } 756 757 #endif /*_QDF_UTIL_H*/ 758