qdf_util.h 20 KB

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