qdf_util.h 20 KB

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