xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/phl_util.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #ifndef _PHL_UTIL_H_
16 #define _PHL_UTIL_H_
17 
18 #define phlcom_to_drvpriv(_pcom) 	(_pcom->drv_priv)
19 #define phl_is_mp_mode(_phl_com)	(_phl_com->drv_mode >= RTW_DRV_MODE_MP_SMDL_START && _phl_com->drv_mode <= RTW_DRV_MODE_MP_SMDL_END)
20 
21 #ifndef is_broadcast_mac_addr
22 #define is_broadcast_mac_addr(addr) ((((addr[0]) & 0xff) == 0xff) && (((addr[1]) & 0xff) == 0xff) && \
23 	(((addr[2]) & 0xff) == 0xff) && (((addr[3]) & 0xff) == 0xff) && (((addr[4]) & 0xff) == 0xff) && \
24 					(((addr[5]) & 0xff) == 0xff))
25 #endif
26 #ifndef MIN
27 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
28 #endif
29 
30 #ifndef DIFF
31 #define DIFF(_x_, _y_) ((_x_ >= _y_) ? (_x_ - _y_) : (_y_ - _x_))
32 #endif
33 
34 #define SET_STATUS_FLAG(_status,_flags)	\
35 	((_status) |= (_flags))
36 #define TEST_STATUS_FLAG(_status,_flags)\
37 	(((_status) & (_flags))==(_flags))
38 #define CLEAR_STATUS_FLAG(_status,_flags)\
39 	((_status) &= ~(_flags))
40 
_add_bitmap_bit(u8 * bitmap,u8 * arr,u32 len)41 static inline void _add_bitmap_bit(u8 *bitmap, u8 *arr, u32 len)
42 {
43 	u32 k = 0;
44 	for(k = 0; k < (len); k++)
45 		bitmap[arr[k] / 8] |= (BIT0 << (arr[k] % 8));
46 }
47 
_clr_bitmap_bit(u8 * bitmap,u8 * arr,u32 len)48 static inline void _clr_bitmap_bit(u8 *bitmap, u8 *arr, u32 len)
49 {
50 	u32 k = 0;
51 
52 	for(k = 0; k < (len); k++)
53 		bitmap[arr[k] / 8] &= ~(BIT0 << (arr[k] % 8));
54 }
55 
56 #define _chk_bitmap_bit(_bitmap, _id) \
57 	((_bitmap)[(_id) / 8] & (BIT0 << ((_id) % 8)))
58 
59 #define _reset_bitmap(_d, _bitmap ,_len) _os_mem_set(_d, _bitmap, 0, _len)
60 
_and_bitmaps(u8 * ref_bitmap,u8 * _bitmap,u32 len)61 static inline void _and_bitmaps( u8* ref_bitmap, u8* _bitmap, u32 len)
62 {
63 	u32 k = 0;
64 
65 	for(k = 0; k < len; k++)
66 		_bitmap[k] &= ref_bitmap[k];
67 }
68 
69 
70 /*phl_queue*/
71 struct phl_queue {
72 	_os_list queue;
73 	_os_lock lock;
74 	int cnt;
75 };
_get_next(_os_list * list)76 static inline _os_list *_get_next(_os_list *list)
77 {
78 	return list->next;
79 }
80 
_get_prev(_os_list * list)81 static inline _os_list *_get_prev(_os_list *list)
82 {
83 	return list->prev;
84 }
85 
86 
_get_list_head(struct phl_queue * q)87 static inline _os_list *_get_list_head(struct phl_queue *q)
88 {
89 	return (&q->queue);
90 }
91 
92 void pq_init(void *d, struct phl_queue *q);
93 void pq_deinit(void *d, struct phl_queue *q);
94 void pq_reset(void *d, struct phl_queue *q, enum lock_type type);
95 u8 pq_push(void *d, struct phl_queue *q, _os_list *obj, u8 pos, enum lock_type type);
96 u8 pq_pop(void *d, struct phl_queue *q, _os_list **obj, u8 pos, enum lock_type type);
97 u8 pq_get_next(void *d, struct phl_queue *queue, _os_list *cur_obj,
98 	       _os_list **obj, enum lock_type type);
99 u8 pq_get_front(void *d, struct phl_queue *queue, _os_list **obj,
100 		enum lock_type type);
101 u8 pq_get_tail(void *d, struct phl_queue *q, _os_list **obj, enum lock_type type);
102 u8 pq_get_prev(void *d, struct phl_queue *queue, _os_list *cur_obj,
103 	       _os_list **obj, enum lock_type type);
104 void pq_del_node(void *d, struct phl_queue *q, _os_list *obj, enum lock_type type);
105 
106 u8 pq_search_node(void *d, struct phl_queue *q, _os_list **obj,
107 		  enum lock_type type, bool bdel, void *priv,
108 		  u8 (*search_fun)(void *d, void *obj, void *priv));
109 u8 pq_insert(void *d, struct phl_queue *q, enum lock_type type, void *priv, _os_list *input,
110 		  u8 (*pq_predicate)(void *d, void *priv,_os_list *input, _os_list *obj));
111 u32 phl_get_passing_time_us(u32 start);
112 u32 phl_get_passing_time_ms(u32 start);
113 
114 #define rtw_phl_is_ap_category(_type) (_type == PHL_RTYPE_AP ||\
115 				       _type == PHL_RTYPE_P2P_GO ||\
116 				       _type == PHL_RTYPE_VAP)
117 #define rtw_phl_is_client_category(_type) (_type == PHL_RTYPE_STATION ||\
118 					   _type == PHL_RTYPE_P2P_GC ||\
119 					   _type == PHL_RTYPE_TDLS)
120 #define rtw_phl_role_is_ap_category(_wrole) (rtw_phl_is_ap_category(_wrole->type))
121 #define rtw_phl_role_is_client_category(_wrole) (rtw_phl_is_client_category(_wrole->type))
122 #endif /*_PHL_UTIL_H_*/
123 
124