qdf_util.h 18 KB

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