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