qdf_util.h 23 KB

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