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