qdf_util.h 24 KB

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