xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/phl_twt.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * Copyright(c) 2019 Realtek Corporation.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify it
6*4882a593Smuzhiyun  * under the terms of version 2 of the GNU General Public License as
7*4882a593Smuzhiyun  * published by the Free Software Foundation.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but WITHOUT
10*4882a593Smuzhiyun  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12*4882a593Smuzhiyun  * more details.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  *****************************************************************************/
15*4882a593Smuzhiyun #define _PHL_TWT_C_
16*4882a593Smuzhiyun #include "phl_headers.h"
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #ifdef CONFIG_PHL_TWT
19*4882a593Smuzhiyun #include "phl_twt.h"
_twt_transfer_config_state(enum phl_twt_action action,enum twt_config_state * state)20*4882a593Smuzhiyun void _twt_transfer_config_state(enum phl_twt_action action,
21*4882a593Smuzhiyun 				enum twt_config_state *state)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun 	if (PHL_TWT_ACTION_FREE == action)
24*4882a593Smuzhiyun 		*state = twt_config_state_free;
25*4882a593Smuzhiyun 	else if (PHL_TWT_ACTION_ALLOC == action)
26*4882a593Smuzhiyun 		*state = twt_config_state_idle;
27*4882a593Smuzhiyun 	else if (PHL_TWT_ACTION_ENABLE == action)
28*4882a593Smuzhiyun 		*state = twt_config_state_enable;
29*4882a593Smuzhiyun 	else if (PHL_TWT_ACTION_DISABLE == action)
30*4882a593Smuzhiyun 		*state = twt_config_state_idle;
31*4882a593Smuzhiyun 	else if (PHL_TWT_ACTION_UP_ERROR == action)
32*4882a593Smuzhiyun 		*state = twt_config_state_error;
33*4882a593Smuzhiyun }
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /*
36*4882a593Smuzhiyun  * Calculate map of macid
37*4882a593Smuzhiyun  * @map_offset: number of offset for wait_macid_map
38*4882a593Smuzhiyun  * @macid_map: map of macid
39*4882a593Smuzhiyun  * Ex: macid_map = 0x80(bit7), offset = 2, macid 71(7 + 2*32) wait announce
40*4882a593Smuzhiyun  */
_twt_calc_macid_map_info(u16 macid,u8 * map_offset,u32 * macid_map)41*4882a593Smuzhiyun void _twt_calc_macid_map_info(u16 macid, u8 *map_offset, u32 *macid_map)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun 	*map_offset = (u8)(macid / 32);
44*4882a593Smuzhiyun 	*macid_map = BIT(macid % 32);
45*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_calc_macid_map_info(): macid:%d, map_offset:%d, macid_map:0x%x\n",
46*4882a593Smuzhiyun 		macid, *map_offset, *macid_map);
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun 
_twt_calc_intvl(u8 exp,u16 mantissa)49*4882a593Smuzhiyun u32 _twt_calc_intvl(u8 exp, u16 mantissa)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun 	u32 intvl = 0;
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 	intvl = mantissa * (1 << exp);
54*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_calc_intvl(): exp:%u, mantissa:%u, intvl=%u\n",
55*4882a593Smuzhiyun 		exp, mantissa, intvl);
56*4882a593Smuzhiyun 	return intvl;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun 
_twt_calc_wakeup_dur(u8 dur,enum rtw_phl_wake_dur_unit dur_unit)59*4882a593Smuzhiyun u32 _twt_calc_wakeup_dur(u8 dur, enum rtw_phl_wake_dur_unit dur_unit)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun 	u32 dur_t = 0;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	if (RTW_PHL_WAKE_256US == dur_unit)
64*4882a593Smuzhiyun 		dur_t = dur * 256;
65*4882a593Smuzhiyun 	else if (RTW_PHL_WAKE_1TU == dur_unit)
66*4882a593Smuzhiyun 		dur_t = dur * 1024;
67*4882a593Smuzhiyun 	return dur_t;
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun 
_twt_fill_individual_twt_para_set(struct rtw_phl_indiv_twt_para_set * para,bool ndp_paging,u8 * buf,u8 * length)70*4882a593Smuzhiyun enum rtw_phl_status _twt_fill_individual_twt_para_set(
71*4882a593Smuzhiyun 				struct rtw_phl_indiv_twt_para_set *para,
72*4882a593Smuzhiyun 				bool ndp_paging, u8 *buf, u8 *length)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
75*4882a593Smuzhiyun 	struct rtw_phl_req_type_indiv *req_type = &para->req_type;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_fill_individual_twt_para_set(): twt_request(%d), twt_setup_cmd(%d), trigger(%d), implicit(%d), flow_type(%d), twt_flow_id(%d), twt_wake_int_exp(%d), twt_protection(%d)\n",
78*4882a593Smuzhiyun 		req_type->twt_request, req_type->twt_setup_cmd,
79*4882a593Smuzhiyun 		req_type->trigger, req_type->implicit,
80*4882a593Smuzhiyun 		req_type->flow_type, req_type->twt_flow_id,
81*4882a593Smuzhiyun 		req_type->twt_wake_int_exp, req_type->twt_protection);
82*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_fill_individual_twt_para_set(): target_wake_t_h(0x%08x), target_wake_t_l(0x%08x), nom_min_twt_wake_dur(%d), twt_wake_int_mantissa(%d), twt_channel(%d)\n",
83*4882a593Smuzhiyun 		para->target_wake_t_h, para->target_wake_t_l,
84*4882a593Smuzhiyun 		para->nom_min_twt_wake_dur, para->twt_wake_int_mantissa,
85*4882a593Smuzhiyun 		para->twt_channel);
86*4882a593Smuzhiyun 	*length = 0;
87*4882a593Smuzhiyun 	/*Request Type*/
88*4882a593Smuzhiyun 	SET_TWT_REQ_TYPE_TWT_REQUEST(buf, req_type->twt_request);
89*4882a593Smuzhiyun 	SET_TWT_REQ_TYPE_TWT_SETUP_COMMAND(buf, req_type->twt_setup_cmd);
90*4882a593Smuzhiyun 	SET_TWT_REQ_TYPE_TRIGGER(buf, req_type->trigger);
91*4882a593Smuzhiyun 	SET_TWT_REQ_TYPE_IMPLICIT(buf, req_type->implicit);
92*4882a593Smuzhiyun 	SET_TWT_REQ_TYPE_FLOW_TYPE(buf, req_type->flow_type);
93*4882a593Smuzhiyun 	SET_TWT_REQ_TYPE_TWT_FLOW_IDENTIFER(buf, req_type->twt_flow_id);
94*4882a593Smuzhiyun 	SET_TWT_REQ_TYPE_TWT_WAKE_INTERVAL_EXPONENT(buf,
95*4882a593Smuzhiyun 					req_type->twt_wake_int_exp);
96*4882a593Smuzhiyun 	SET_TWT_REQ_TYPE_TWT_PROTECTION(buf, req_type->twt_protection);
97*4882a593Smuzhiyun 	*length += REQUEST_TYPE_LENGTH;
98*4882a593Smuzhiyun 	if (RTW_PHL_TWT_GROUPING == req_type->twt_setup_cmd) {
99*4882a593Smuzhiyun 		/*TODO*/
100*4882a593Smuzhiyun 	} else {
101*4882a593Smuzhiyun 		SET_TWT_TARGET_WAKE_TIME_L(buf, para->target_wake_t_l);
102*4882a593Smuzhiyun 		SET_TWT_TARGET_WAKE_TIME_H(buf, para->target_wake_t_h);
103*4882a593Smuzhiyun 		*length += TARGET_WAKE_TIME_LENGTH;
104*4882a593Smuzhiyun 	}
105*4882a593Smuzhiyun 	SET_TWT_NOMINAL_MINIMUM_TWT_WAKE_DURATION(buf, *length,
106*4882a593Smuzhiyun 						para->nom_min_twt_wake_dur);
107*4882a593Smuzhiyun 	*length += NOMINAL_MINIMUM_TWT_WAKE_DURATION_LENGTH;
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun 	SET_TWT_TWT_WAKE_INTERVAL_MANTISSA(buf, *length,
110*4882a593Smuzhiyun 					para->twt_wake_int_mantissa);
111*4882a593Smuzhiyun 	*length += TWT_WAKE_INTERVAL_MANTISSA_LENGTH;
112*4882a593Smuzhiyun 	SET_TWT_TWT_CHANNEL(buf, *length, para->twt_channel);
113*4882a593Smuzhiyun 	*length += TWT_CHANNEL_LENGTH;
114*4882a593Smuzhiyun 	if (true == ndp_paging) {
115*4882a593Smuzhiyun 		/*TODO*/
116*4882a593Smuzhiyun 	}
117*4882a593Smuzhiyun 	pstatus = RTW_PHL_STATUS_SUCCESS;
118*4882a593Smuzhiyun 	return pstatus;
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun 
_twt_parse_individual_twt_para(u8 * twt_ele,u16 length,struct rtw_phl_twt_element * element)121*4882a593Smuzhiyun enum rtw_phl_status _twt_parse_individual_twt_para(u8 *twt_ele, u16 length,
122*4882a593Smuzhiyun 				struct rtw_phl_twt_element *element)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
125*4882a593Smuzhiyun 	struct rtw_phl_indiv_twt_para_set *para = &element->info.i_twt_para_set;
126*4882a593Smuzhiyun 	struct rtw_phl_req_type_indiv *req_type = &para->req_type;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	u8 *next_buf = twt_ele + ELEM_ID_LEN + ELEM_LEN_LEN + CONTROL_LENGTH;
129*4882a593Smuzhiyun 	req_type->twt_request = GET_TWT_REQ_TYPE_TWT_REQUEST(next_buf);
130*4882a593Smuzhiyun 	req_type->twt_setup_cmd = GET_TWT_REQ_TYPE_TWT_SETUP_COMMAND(next_buf);
131*4882a593Smuzhiyun 	req_type->trigger = GET_TWT_REQ_TYPE_TRIGGER(next_buf);
132*4882a593Smuzhiyun 	req_type->implicit = GET_TWT_REQ_TYPE_IMPLICIT(next_buf);
133*4882a593Smuzhiyun 	req_type->flow_type = GET_TWT_REQ_TYPE_FLOW_TYPE(next_buf);
134*4882a593Smuzhiyun 	req_type->twt_flow_id = GET_TWT_REQ_TYPE_TWT_FLOW_IDENTIFER(next_buf);
135*4882a593Smuzhiyun 	req_type->twt_wake_int_exp =
136*4882a593Smuzhiyun 			GET_TWT_REQ_TYPE_TWT_WAKE_INTERVAL_EXPONENT(next_buf);
137*4882a593Smuzhiyun 	req_type->twt_protection = GET_TWT_REQ_TYPE_TWT_PROTECTION(next_buf);
138*4882a593Smuzhiyun 	next_buf += REQUEST_TYPE_LENGTH;
139*4882a593Smuzhiyun 	if (RTW_PHL_TWT_GROUPING == req_type->twt_setup_cmd) {
140*4882a593Smuzhiyun 		//Todo
141*4882a593Smuzhiyun 	} else {
142*4882a593Smuzhiyun 		para->target_wake_t_l = GET_TWT_TARGET_WAKE_TIME_L(next_buf);
143*4882a593Smuzhiyun 		para->target_wake_t_h = GET_TWT_TARGET_WAKE_TIME_H(next_buf);
144*4882a593Smuzhiyun 		next_buf += TARGET_WAKE_TIME_LENGTH;
145*4882a593Smuzhiyun 	}
146*4882a593Smuzhiyun 	para->nom_min_twt_wake_dur =
147*4882a593Smuzhiyun 			GET_TWT_NOMINAL_MINIMUM_TWT_WAKE_DURATION(next_buf);
148*4882a593Smuzhiyun 	next_buf += NOMINAL_MIN_TWT_WAKE_DURATION_LENGTH;
149*4882a593Smuzhiyun 	para->twt_wake_int_mantissa =
150*4882a593Smuzhiyun 				GET_TWT_TWT_WAKE_INTERVAL_MANTISSA(next_buf);
151*4882a593Smuzhiyun 	next_buf += TWT_WAKE_INTERVAL_MANTISSA_LENGTH;
152*4882a593Smuzhiyun 	para->twt_channel = GET_TWT_TWT_CHANNEL(next_buf);
153*4882a593Smuzhiyun 	next_buf += TWT_CHANNEL_LENGTH;
154*4882a593Smuzhiyun 	if (element->twt_ctrl.ndp_paging_indic) {
155*4882a593Smuzhiyun 		/*TODO*/
156*4882a593Smuzhiyun 	}
157*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_parse_individual_twt_para(): twt_request:%d, twt_setup_cmd:%d, trigger:%d, implicit:%d, flow_type:%d, twt_flow_id:%d, twt_wake_int_exp:%d, twt_protection:%d\n",
158*4882a593Smuzhiyun 		req_type->twt_request, req_type->twt_setup_cmd,
159*4882a593Smuzhiyun 		req_type->trigger, req_type->implicit,
160*4882a593Smuzhiyun 		req_type->flow_type, req_type->twt_flow_id,
161*4882a593Smuzhiyun 		req_type->twt_wake_int_exp, req_type->twt_protection);
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_parse_individual_twt_para(): target_wake_t_h:0x%08X, target_wake_t_l:0x%08X, nom_min_twt_wake_dur:%d, twt_wake_int_mantissa:%d, twt_channel:%d\n",
164*4882a593Smuzhiyun 		para->target_wake_t_h, para->target_wake_t_l,
165*4882a593Smuzhiyun 		para->nom_min_twt_wake_dur, para->twt_wake_int_mantissa,
166*4882a593Smuzhiyun 		para->twt_channel);
167*4882a593Smuzhiyun 	pstatus = RTW_PHL_STATUS_SUCCESS;
168*4882a593Smuzhiyun 	return pstatus;
169*4882a593Smuzhiyun }
170*4882a593Smuzhiyun 
_twt_announce_info_enqueue(struct phl_info_t * phl_info,struct phl_queue * twt_annc_q,struct _twt_announce_info * twt_annc)171*4882a593Smuzhiyun enum rtw_phl_status _twt_announce_info_enqueue(struct phl_info_t *phl_info,
172*4882a593Smuzhiyun 				struct phl_queue *twt_annc_q,
173*4882a593Smuzhiyun 				struct _twt_announce_info *twt_annc)
174*4882a593Smuzhiyun {
175*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
176*4882a593Smuzhiyun 	_os_spinlockfg sp_flags;
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	if (!twt_annc)
179*4882a593Smuzhiyun 		return RTW_PHL_STATUS_FAILURE;
180*4882a593Smuzhiyun 	_os_spinlock(drv, &twt_annc_q->lock, _irq, &sp_flags);
181*4882a593Smuzhiyun 	list_add_tail(&twt_annc->list, &twt_annc_q->queue);
182*4882a593Smuzhiyun 	twt_annc_q->cnt++;
183*4882a593Smuzhiyun 	_os_spinunlock(drv, &twt_annc_q->lock, _irq, &sp_flags);
184*4882a593Smuzhiyun 	return RTW_PHL_STATUS_SUCCESS;
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun 
_twt_announce_info_dequeue(struct phl_info_t * phl_info,struct phl_queue * twt_annc_q)187*4882a593Smuzhiyun struct _twt_announce_info * _twt_announce_info_dequeue(
188*4882a593Smuzhiyun 				struct phl_info_t *phl_info,
189*4882a593Smuzhiyun 				struct phl_queue *twt_annc_q)
190*4882a593Smuzhiyun {
191*4882a593Smuzhiyun 	struct _twt_announce_info *twt_annc = NULL;
192*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
193*4882a593Smuzhiyun 	_os_spinlockfg sp_flags;
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	_os_spinlock(drv, &twt_annc_q->lock, _irq, &sp_flags);
196*4882a593Smuzhiyun 	if (list_empty(&twt_annc_q->queue)) {
197*4882a593Smuzhiyun 		twt_annc = NULL;
198*4882a593Smuzhiyun 	} else {
199*4882a593Smuzhiyun 		twt_annc = list_first_entry(&twt_annc_q->queue,
200*4882a593Smuzhiyun 					struct _twt_announce_info, list);
201*4882a593Smuzhiyun 		list_del(&twt_annc->list);
202*4882a593Smuzhiyun 		twt_annc_q->cnt--;
203*4882a593Smuzhiyun 	}
204*4882a593Smuzhiyun 	_os_spinunlock(drv, &twt_annc_q->lock, _irq, &sp_flags);
205*4882a593Smuzhiyun 	return twt_annc;
206*4882a593Smuzhiyun }
207*4882a593Smuzhiyun 
_twt_sta_announce(struct phl_info_t * phl_info,struct phl_queue * annc_queue,u16 macid)208*4882a593Smuzhiyun enum rtw_phl_status _twt_sta_announce(struct phl_info_t *phl_info,
209*4882a593Smuzhiyun 				struct phl_queue *annc_queue, u16 macid)
210*4882a593Smuzhiyun {
211*4882a593Smuzhiyun 	enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
212*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
213*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
214*4882a593Smuzhiyun 	_os_spinlockfg sp_flags;
215*4882a593Smuzhiyun 	struct _twt_announce_info *info = NULL;
216*4882a593Smuzhiyun 	_os_list *annc_list = &annc_queue->queue;
217*4882a593Smuzhiyun 	u8 offset = 0;
218*4882a593Smuzhiyun 	u32 macid_map = 0;
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun 	_twt_calc_macid_map_info(macid, &offset, &macid_map);
221*4882a593Smuzhiyun 	_os_spinlock(drv, &annc_queue->lock, _irq, &sp_flags);
222*4882a593Smuzhiyun 	phl_list_for_loop(info, struct _twt_announce_info, annc_list, list) {
223*4882a593Smuzhiyun 		if (NULL == info)
224*4882a593Smuzhiyun 			break;
225*4882a593Smuzhiyun 		if (info->map_offset != offset)
226*4882a593Smuzhiyun 			continue;
227*4882a593Smuzhiyun 		if (!(info->wait_macid_map & macid_map))
228*4882a593Smuzhiyun 			continue;
229*4882a593Smuzhiyun 		hstatus = rtw_hal_twt_sta_announce(phl_info->hal, (u8)macid);
230*4882a593Smuzhiyun 		if (RTW_HAL_STATUS_SUCCESS == hstatus) {
231*4882a593Smuzhiyun 			info->wait_macid_map &= (~macid_map);
232*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_SUCCESS;
233*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_sta_announce(): rtw_hal_twt_sta_announce success, macid:%d, map_offset:%d, wait_macid_map:0x%x\n",
234*4882a593Smuzhiyun 				macid, info->map_offset, info->wait_macid_map);
235*4882a593Smuzhiyun 		} else {
236*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "_twt_sta_announce(): rtw_hal_twt_sta_announce fail, macid:%d, map_offset:%d, wait_macid_map:0x%x\n",
237*4882a593Smuzhiyun 				macid, info->map_offset, info->wait_macid_map);
238*4882a593Smuzhiyun 		}
239*4882a593Smuzhiyun 		break;
240*4882a593Smuzhiyun 	}
241*4882a593Smuzhiyun 	_os_spinunlock(drv, &annc_queue->lock, _irq, &sp_flags);
242*4882a593Smuzhiyun 	return pstatus;
243*4882a593Smuzhiyun }
244*4882a593Smuzhiyun 
_twt_set_sta_announce_state(struct phl_info_t * phl_info,struct phl_queue * annc_q,u16 macid,enum phl_wait_annc_type type)245*4882a593Smuzhiyun enum rtw_phl_status _twt_set_sta_announce_state(struct phl_info_t *phl_info,
246*4882a593Smuzhiyun 				struct phl_queue *annc_q, u16 macid,
247*4882a593Smuzhiyun 				enum phl_wait_annc_type type)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
250*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
251*4882a593Smuzhiyun 	_os_spinlockfg sp_flags;
252*4882a593Smuzhiyun 	struct _twt_announce_info *info = NULL;
253*4882a593Smuzhiyun 	_os_list *annc_list = &annc_q->queue;
254*4882a593Smuzhiyun 	u8 offset = 0;
255*4882a593Smuzhiyun 	u32 macid_map = 0;
256*4882a593Smuzhiyun 	u8 bset = false;
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun 	_twt_calc_macid_map_info(macid, &offset, &macid_map);
259*4882a593Smuzhiyun 	_os_spinlock(drv, &annc_q->lock, _irq, &sp_flags);
260*4882a593Smuzhiyun 	phl_list_for_loop(info, struct _twt_announce_info, annc_list, list) {
261*4882a593Smuzhiyun 		if (NULL == info)
262*4882a593Smuzhiyun 			break;
263*4882a593Smuzhiyun 		if (info->map_offset != offset)
264*4882a593Smuzhiyun 			continue;
265*4882a593Smuzhiyun 		if (PHL_WAIT_ANNC_ENABLE == type) {
266*4882a593Smuzhiyun 			info->wait_macid_map |= macid_map;
267*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_set_sta_announce_state(): set macid:%d to wait annc state, map_offset:%d, wait_macid_map:0x%x\n",
268*4882a593Smuzhiyun 				macid, info->map_offset, info->wait_macid_map);
269*4882a593Smuzhiyun 		} else if (PHL_WAIT_ANNC_DISABLE == type) {
270*4882a593Smuzhiyun 			info->wait_macid_map &= (~macid_map);
271*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_set_sta_announce_state(): set macid:%d to annc state, map_offset:%d, wait_macid_map:0x%x\n",
272*4882a593Smuzhiyun 				macid, info->map_offset, info->wait_macid_map);
273*4882a593Smuzhiyun 		} else {
274*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "_twt_set_sta_announce_state(): Unknown type:%d\n",
275*4882a593Smuzhiyun 				type);
276*4882a593Smuzhiyun 			break;
277*4882a593Smuzhiyun 		}
278*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
279*4882a593Smuzhiyun 		bset = true;
280*4882a593Smuzhiyun 		break;
281*4882a593Smuzhiyun 	}
282*4882a593Smuzhiyun 	_os_spinunlock(drv, &annc_q->lock, _irq, &sp_flags);
283*4882a593Smuzhiyun 	if (true == bset)
284*4882a593Smuzhiyun 		goto exit;
285*4882a593Smuzhiyun 	if (PHL_WAIT_ANNC_ENABLE == type) {
286*4882a593Smuzhiyun 		info = _os_mem_alloc(drv, sizeof(struct _twt_announce_info));
287*4882a593Smuzhiyun 		if (NULL == info) {
288*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "_twt_sta_wait_announce(): Fail to alloc new annc info\n");
289*4882a593Smuzhiyun 		} else {
290*4882a593Smuzhiyun 			info->map_offset = offset;
291*4882a593Smuzhiyun 			info->wait_macid_map = macid_map;
292*4882a593Smuzhiyun 			_twt_announce_info_enqueue(phl_info, annc_q, info);
293*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_SUCCESS;
294*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_set_sta_announce_state(): add new Q and set macid:%d to annc state, map_offset:%d, wait_macid_map:0x%x\n",
295*4882a593Smuzhiyun 				macid, info->map_offset, info->wait_macid_map);
296*4882a593Smuzhiyun 		}
297*4882a593Smuzhiyun 	} else if (PHL_WAIT_ANNC_DISABLE == type) {
298*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "_twt_set_sta_announce_state(): macid:%d is not in wait annc state\n",
299*4882a593Smuzhiyun 				macid);
300*4882a593Smuzhiyun 	} else {
301*4882a593Smuzhiyun 		/*nothing*/
302*4882a593Smuzhiyun 	}
303*4882a593Smuzhiyun exit:
304*4882a593Smuzhiyun 	return pstatus;
305*4882a593Smuzhiyun }
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun #if 0
308*4882a593Smuzhiyun /*
309*4882a593Smuzhiyun  * Get macid of sta wait for announce form FW
310*4882a593Smuzhiyun  * @wait_case: C2HTWT_ANNOUNCE_WAIT_DISABLE_MACID = 0, C2HTWT_ANNOUNCE_WAIT_ENABLE_MACID = 1
311*4882a593Smuzhiyun  * @macid0: macid of sta
312*4882a593Smuzhiyun  * @macid1: macid of sta
313*4882a593Smuzhiyun  * @macid2: macid of sta
314*4882a593Smuzhiyun  */
315*4882a593Smuzhiyun enum rtw_phl_status _twt_handle_c2h_wait_annc(struct phl_info_t *phl_info,
316*4882a593Smuzhiyun 				u8 *content)
317*4882a593Smuzhiyun {
318*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
319*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = get_twt_info(phl_info);
320*4882a593Smuzhiyun 	struct phl_queue *annc_q = &phl_twt_info->twt_annc_queue;
321*4882a593Smuzhiyun 	u8 wait_case = 0, macid = 0;
322*4882a593Smuzhiyun 	u8 i = 0;
323*4882a593Smuzhiyun 	bool error = false;
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun 	wait_case = (*((u8*)content)) & 0xf; /*BIT0-3*/
326*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_handle_c2h_wait_annc(): content:0x%X, wait_case:%d, macid0:%d, macid1:%d, macid2:%d\n",
327*4882a593Smuzhiyun 		*content, wait_case, *((u8*)content + 1), *((u8*)content + 2),
328*4882a593Smuzhiyun 		*((u8*)content + 3));
329*4882a593Smuzhiyun 	for (i = 1; i < 4; i++) {
330*4882a593Smuzhiyun 		macid = *((u8*)content + i);
331*4882a593Smuzhiyun 		if (IGNORE_MACID == macid)
332*4882a593Smuzhiyun 			continue;
333*4882a593Smuzhiyun 		pstatus = _twt_set_sta_announce_state(phl_info, annc_q, macid,
334*4882a593Smuzhiyun 							wait_case);
335*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != pstatus) {
336*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_handle_c2h_wait_annc(): pstatus:%d, macid: %d, fail to set sta wait announce state\n",
337*4882a593Smuzhiyun 				pstatus, macid);
338*4882a593Smuzhiyun 			error = true;
339*4882a593Smuzhiyun 		}
340*4882a593Smuzhiyun 	}
341*4882a593Smuzhiyun 	if (true == error)
342*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_FAILURE;
343*4882a593Smuzhiyun 	return pstatus;
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun #endif
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun /*
348*4882a593Smuzhiyun struct rtw_twt_sta_info *
349*4882a593Smuzhiyun _twt_get_twt_sta(
350*4882a593Smuzhiyun 	struct phl_info_t *phl_info,
351*4882a593Smuzhiyun 	struct phl_queue *sta_queue,
352*4882a593Smuzhiyun 	struct rtw_phl_stainfo_t *phl_sta,
353*4882a593Smuzhiyun 	u8 id
354*4882a593Smuzhiyun )
355*4882a593Smuzhiyun {
356*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
357*4882a593Smuzhiyun 	struct rtw_twt_sta_info *twt_sta = NULL, *ret_twt_sta = NULL;
358*4882a593Smuzhiyun 	_os_list *sta_list = &sta_queue->queue;
359*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> _twt_get_twt_sta()\n");
360*4882a593Smuzhiyun 	_os_spinlock(drv, &sta_queue->lock, _bh, NULL);
361*4882a593Smuzhiyun 	phl_list_for_loop(twt_sta, struct rtw_twt_sta_info, sta_list, list) {
362*4882a593Smuzhiyun 		if (twt_sta == NULL)
363*4882a593Smuzhiyun 			break;
364*4882a593Smuzhiyun 		if (phl_sta != twt_sta->phl_sta)
365*4882a593Smuzhiyun 			continue;
366*4882a593Smuzhiyun 		if (DELETE_ALL != id && id != twt_sta->id)
367*4882a593Smuzhiyun 			continue;
368*4882a593Smuzhiyun 		ret_twt_sta = twt_sta;
369*4882a593Smuzhiyun 	}
370*4882a593Smuzhiyun 	_os_spinunlock(drv, &sta_queue->lock, _bh, NULL);
371*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== _twt_get_twt_sta()\n");
372*4882a593Smuzhiyun 	return ret_twt_sta;
373*4882a593Smuzhiyun }
374*4882a593Smuzhiyun */
375*4882a593Smuzhiyun 
_twt_fill_config_info_indiv(struct rtw_phl_twt_info * twt_info,struct rtw_phl_indiv_twt_para_set * para_set)376*4882a593Smuzhiyun void _twt_fill_config_info_indiv(struct rtw_phl_twt_info *twt_info,
377*4882a593Smuzhiyun 				struct rtw_phl_indiv_twt_para_set *para_set)
378*4882a593Smuzhiyun {
379*4882a593Smuzhiyun 	struct rtw_phl_req_type_indiv *req_type = &para_set->req_type;
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun 	twt_info->trigger = req_type->trigger;
382*4882a593Smuzhiyun 	twt_info->flow_type = req_type->flow_type;
383*4882a593Smuzhiyun 	twt_info->implicit_lastbcast = req_type->implicit;
384*4882a593Smuzhiyun 	twt_info->twt_protection = req_type->twt_protection;
385*4882a593Smuzhiyun 	twt_info->twt_wake_int_exp = req_type->twt_wake_int_exp;
386*4882a593Smuzhiyun 	twt_info->twt_wake_int_mantissa = para_set->twt_wake_int_mantissa;
387*4882a593Smuzhiyun 	twt_info->nom_min_twt_wake_dur = para_set->nom_min_twt_wake_dur;
388*4882a593Smuzhiyun 	twt_info->target_wake_time_h = para_set->target_wake_t_h;
389*4882a593Smuzhiyun 	twt_info->target_wake_time_l = para_set->target_wake_t_l;
390*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_fill_config_info_indiv(): twt_info: trigger:%d, flow_type:%d, implicit_lastbcast:%d, twt_protection:%d, twt_wake_int_exp:%d, twt_wake_int_mantissa:%d, nom_min_twt_wake_dur:%d, target_wake_time_h:0x%08X, target_wake_time_l:0x%08X\n",
391*4882a593Smuzhiyun 		twt_info->trigger, twt_info->flow_type,
392*4882a593Smuzhiyun 		twt_info->implicit_lastbcast, twt_info->twt_protection,
393*4882a593Smuzhiyun 		twt_info->twt_wake_int_exp, twt_info->twt_wake_int_mantissa,
394*4882a593Smuzhiyun 		twt_info->nom_min_twt_wake_dur, twt_info->target_wake_time_h,
395*4882a593Smuzhiyun 		twt_info->target_wake_time_l);
396*4882a593Smuzhiyun }
397*4882a593Smuzhiyun 
_twt_fill_config_info(struct rtw_phl_twt_info * twt_info,struct rtw_phl_twt_setup_info * setup_info)398*4882a593Smuzhiyun void _twt_fill_config_info(struct rtw_phl_twt_info *twt_info,
399*4882a593Smuzhiyun 				struct rtw_phl_twt_setup_info *setup_info)
400*4882a593Smuzhiyun {
401*4882a593Smuzhiyun 	struct rtw_phl_twt_element *twt_ele = &setup_info->twt_element;
402*4882a593Smuzhiyun 	struct rtw_phl_twt_control *twt_ctrl = &twt_ele->twt_ctrl;
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun 	twt_info->responder_pm_mode = twt_ctrl->responder_pm_mode;
405*4882a593Smuzhiyun 	twt_info->nego_type = twt_ctrl->nego_type;
406*4882a593Smuzhiyun 	twt_info->wake_dur_unit = twt_ctrl->wake_dur_unit;
407*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_fill_config_info(): twt_info: responder_pm_mode:%d, nego_type:%d, wake_dur_unit:%d\n",
408*4882a593Smuzhiyun 		twt_info->responder_pm_mode, twt_info->nego_type,
409*4882a593Smuzhiyun 		twt_info->wake_dur_unit);
410*4882a593Smuzhiyun 	if (RTW_PHL_INDIV_TWT == twt_info->nego_type) {
411*4882a593Smuzhiyun 		_twt_fill_config_info_indiv(twt_info,
412*4882a593Smuzhiyun 						&twt_ele->info.i_twt_para_set);
413*4882a593Smuzhiyun 	} else {
414*4882a593Smuzhiyun 		/*todo*/
415*4882a593Smuzhiyun 	}
416*4882a593Smuzhiyun }
417*4882a593Smuzhiyun 
_twt_reset_config_info(struct phl_info_t * phl,struct phl_twt_config * config)418*4882a593Smuzhiyun void _twt_reset_config_info(struct phl_info_t *phl,
419*4882a593Smuzhiyun 				struct phl_twt_config *config)
420*4882a593Smuzhiyun {
421*4882a593Smuzhiyun 	config->role = NULL;
422*4882a593Smuzhiyun 	_os_mem_set(phl_to_drvpriv(phl), &config->twt_info, 0,
423*4882a593Smuzhiyun 			sizeof(struct rtw_phl_twt_info));
424*4882a593Smuzhiyun }
425*4882a593Smuzhiyun 
_twt_compare_twt_para(struct rtw_phl_twt_info * twt_info,struct rtw_phl_twt_setup_info * twt_setup)426*4882a593Smuzhiyun u8 _twt_compare_twt_para(struct rtw_phl_twt_info *twt_info,
427*4882a593Smuzhiyun 				struct rtw_phl_twt_setup_info *twt_setup)
428*4882a593Smuzhiyun {
429*4882a593Smuzhiyun 	u8 ret = false;
430*4882a593Smuzhiyun 	u64 twt1 = 0, twt2 = 0, diff_t = 0;
431*4882a593Smuzhiyun 	u32 intvl = 0;
432*4882a593Smuzhiyun 	struct rtw_phl_twt_info cmp_info = {0};
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun 	_twt_fill_config_info(&cmp_info, twt_setup);
435*4882a593Smuzhiyun 	do {
436*4882a593Smuzhiyun 		if (cmp_info.responder_pm_mode != twt_info->responder_pm_mode)
437*4882a593Smuzhiyun 			break;
438*4882a593Smuzhiyun 		if (cmp_info.nego_type != twt_info->nego_type)
439*4882a593Smuzhiyun 			break;
440*4882a593Smuzhiyun 		if (cmp_info.trigger != twt_info->trigger)
441*4882a593Smuzhiyun 			break;
442*4882a593Smuzhiyun 		if (cmp_info.flow_type != twt_info->flow_type)
443*4882a593Smuzhiyun 			break;
444*4882a593Smuzhiyun 		if (cmp_info.implicit_lastbcast != twt_info->implicit_lastbcast)
445*4882a593Smuzhiyun 			break;
446*4882a593Smuzhiyun 		if (cmp_info.twt_protection != twt_info->twt_protection)
447*4882a593Smuzhiyun 			break;
448*4882a593Smuzhiyun 		if ((_twt_calc_wakeup_dur(cmp_info.nom_min_twt_wake_dur
449*4882a593Smuzhiyun 			, cmp_info.wake_dur_unit)) !=
450*4882a593Smuzhiyun 			(_twt_calc_wakeup_dur(twt_info->nom_min_twt_wake_dur,
451*4882a593Smuzhiyun 			twt_info->wake_dur_unit)))
452*4882a593Smuzhiyun 			break;
453*4882a593Smuzhiyun 		if ((_twt_calc_intvl(cmp_info.twt_wake_int_exp,
454*4882a593Smuzhiyun 			cmp_info.twt_wake_int_mantissa)) !=
455*4882a593Smuzhiyun 			(_twt_calc_intvl(twt_info->twt_wake_int_exp,
456*4882a593Smuzhiyun 			twt_info->twt_wake_int_mantissa)))
457*4882a593Smuzhiyun 			break;
458*4882a593Smuzhiyun 		/*compare target wake time*/
459*4882a593Smuzhiyun 		intvl = _twt_calc_intvl(twt_info->twt_wake_int_exp,
460*4882a593Smuzhiyun 					twt_info->twt_wake_int_mantissa);
461*4882a593Smuzhiyun 		twt1 = cmp_info.target_wake_time_h;
462*4882a593Smuzhiyun 		twt1 = twt1 << 32;
463*4882a593Smuzhiyun 		twt1 |= cmp_info.target_wake_time_l;
464*4882a593Smuzhiyun 		twt2 = twt_info->target_wake_time_h;
465*4882a593Smuzhiyun 		twt2 = twt2 << 32;
466*4882a593Smuzhiyun 		twt2 |= twt_info->target_wake_time_l;
467*4882a593Smuzhiyun 		if (twt1 > twt2) {
468*4882a593Smuzhiyun 			/*cmp_info target_wake_time > twt_info target_wake_time*/
469*4882a593Smuzhiyun 			diff_t = _os_minus64(twt1, twt2);
470*4882a593Smuzhiyun 		} else {
471*4882a593Smuzhiyun 			diff_t = _os_minus64(twt2, twt1);
472*4882a593Smuzhiyun 		}
473*4882a593Smuzhiyun 		if (_os_modular64(diff_t, intvl) != 0)
474*4882a593Smuzhiyun 			break;
475*4882a593Smuzhiyun 		ret = true;
476*4882a593Smuzhiyun 	} while(false);
477*4882a593Smuzhiyun 	return ret;
478*4882a593Smuzhiyun }
479*4882a593Smuzhiyun 
_twt_is_same_config(struct phl_twt_config * config,struct _twt_compare * compare_info)480*4882a593Smuzhiyun u8 _twt_is_same_config(struct phl_twt_config *config,
481*4882a593Smuzhiyun 				struct _twt_compare *compare_info)
482*4882a593Smuzhiyun {
483*4882a593Smuzhiyun 	bool found = false;
484*4882a593Smuzhiyun 
485*4882a593Smuzhiyun 	do {
486*4882a593Smuzhiyun 		if (config->role != compare_info->role)
487*4882a593Smuzhiyun 			break;
488*4882a593Smuzhiyun 		if (!(twt_config_state_idle == config->state ||
489*4882a593Smuzhiyun 			twt_config_state_enable == config->state))
490*4882a593Smuzhiyun 			break;
491*4882a593Smuzhiyun 		if (_twt_compare_twt_para(&config->twt_info,
492*4882a593Smuzhiyun 				&compare_info->twt_setup))
493*4882a593Smuzhiyun 			found = true;
494*4882a593Smuzhiyun 	} while(false);
495*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== _twt_is_same_config(): found(%d)\n",
496*4882a593Smuzhiyun 		found);
497*4882a593Smuzhiyun 	return found;
498*4882a593Smuzhiyun }
499*4882a593Smuzhiyun 
_twt_dump_twt_cfg_info(struct phl_twt_cfg_info * twt_cfg_i)500*4882a593Smuzhiyun void _twt_dump_twt_cfg_info(struct phl_twt_cfg_info *twt_cfg_i)
501*4882a593Smuzhiyun {
502*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
503*4882a593Smuzhiyun 	u8 i = 0;
504*4882a593Smuzhiyun 
505*4882a593Smuzhiyun 	config = (struct phl_twt_config *)twt_cfg_i->twt_cfg_ring;
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun 	for (i = 0; i < twt_cfg_i->twt_cfg_num; i++) {
508*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "_twt_dump_twt_cfg_info(): loop i(%d), cfg id(%d), state(%d)\n",
509*4882a593Smuzhiyun 			i, config[i].idx, config[i].state);
510*4882a593Smuzhiyun 	}
511*4882a593Smuzhiyun }
512*4882a593Smuzhiyun 
_twt_operate_twt_config(struct phl_info_t * phl_info,struct phl_twt_cfg_info * twt_cfg_i,enum phl_operate_config_type type,u8 * para,struct phl_twt_config ** ret_config)513*4882a593Smuzhiyun enum rtw_phl_status _twt_operate_twt_config(struct phl_info_t *phl_info,
514*4882a593Smuzhiyun 		struct phl_twt_cfg_info *twt_cfg_i, enum phl_operate_config_type type,
515*4882a593Smuzhiyun 		u8 *para, struct phl_twt_config **ret_config)
516*4882a593Smuzhiyun {
517*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
518*4882a593Smuzhiyun 	struct phl_twt_config *config =
519*4882a593Smuzhiyun 			(struct phl_twt_config *)twt_cfg_i->twt_cfg_ring;
520*4882a593Smuzhiyun 	u8 i = 0;
521*4882a593Smuzhiyun 
522*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "==> _twt_operate_twt_config(): type(%d)\n",
523*4882a593Smuzhiyun 		type);
524*4882a593Smuzhiyun 	if (type == PHL_GET_CONFIG_BY_ID) {
525*4882a593Smuzhiyun 		if (*para >= twt_cfg_i->twt_cfg_num) {
526*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_operate_twt_config(): get cfg by id(%d) fail, out of range(%d)\n",
527*4882a593Smuzhiyun 				*para, twt_cfg_i->twt_cfg_num);
528*4882a593Smuzhiyun 			goto exit;
529*4882a593Smuzhiyun 		}
530*4882a593Smuzhiyun 		if (twt_config_state_free == config[*para].state){
531*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_operate_twt_config(): get cfg by id(%d) fail, cfg state is in twt_config_state_free\n",
532*4882a593Smuzhiyun 				*para);
533*4882a593Smuzhiyun 			goto exit;
534*4882a593Smuzhiyun 		}
535*4882a593Smuzhiyun 		*ret_config = &config[*para];
536*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
537*4882a593Smuzhiyun 		goto exit;
538*4882a593Smuzhiyun 	} else if (type == PHL_FREE_CONFIG) {
539*4882a593Smuzhiyun 		if (*para >= twt_cfg_i->twt_cfg_num) {
540*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_operate_twt_config(): free cfg by id(%d) fail, out of range(%d)\n",
541*4882a593Smuzhiyun 				*para, twt_cfg_i->twt_cfg_num);
542*4882a593Smuzhiyun 			goto exit;
543*4882a593Smuzhiyun 		}
544*4882a593Smuzhiyun 		if (twt_config_state_free == config[*para].state){
545*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_operate_twt_config(): free cfg by id(%d) fail, cfg state is in twt_config_state_free\n",
546*4882a593Smuzhiyun 				*para);
547*4882a593Smuzhiyun 			goto exit;
548*4882a593Smuzhiyun 		}
549*4882a593Smuzhiyun 		_twt_transfer_config_state(PHL_TWT_ACTION_FREE, &config[*para].state);
550*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
551*4882a593Smuzhiyun 		goto exit;
552*4882a593Smuzhiyun 	} else if (type == PHL_GET_HEAD_CONFIG) {
553*4882a593Smuzhiyun 		*ret_config = config;
554*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
555*4882a593Smuzhiyun 		goto exit;
556*4882a593Smuzhiyun 	} else if (type == PHL_GET_NEXT_CONFIG) {
557*4882a593Smuzhiyun 		u8 next_id = 0;
558*4882a593Smuzhiyun 		if (*para >= twt_cfg_i->twt_cfg_num) {
559*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_operate_twt_config(): get cfg by id(%d) fail, out of range(%d)\n",
560*4882a593Smuzhiyun 				*para, twt_cfg_i->twt_cfg_num);
561*4882a593Smuzhiyun 			goto exit;
562*4882a593Smuzhiyun 		}
563*4882a593Smuzhiyun 		next_id = *para + 1;
564*4882a593Smuzhiyun 		if (next_id == twt_cfg_i->twt_cfg_num)
565*4882a593Smuzhiyun 			next_id = 0;
566*4882a593Smuzhiyun 		*ret_config = &config[next_id];
567*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
568*4882a593Smuzhiyun 		goto exit;
569*4882a593Smuzhiyun 	}
570*4882a593Smuzhiyun 	for (i = 0; i < twt_cfg_i->twt_cfg_num; i++) {
571*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "_twt_operate_twt_config(): loop i(%d), cfg id(%d), state(%d)\n",
572*4882a593Smuzhiyun 		i, config[i].idx, config[i].state);
573*4882a593Smuzhiyun 		if (type == PHL_GET_NEW_CONFIG) {
574*4882a593Smuzhiyun 			if (twt_config_state_free != config[i].state)
575*4882a593Smuzhiyun 				continue;
576*4882a593Smuzhiyun 			_twt_reset_config_info(phl_info, &config[i]);
577*4882a593Smuzhiyun 			_twt_transfer_config_state(PHL_TWT_ACTION_ALLOC,
578*4882a593Smuzhiyun 							&config[i].state);
579*4882a593Smuzhiyun 			config[i].twt_info.twt_id = config[i].idx;
580*4882a593Smuzhiyun 			*ret_config = &config[i];
581*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_SUCCESS;
582*4882a593Smuzhiyun 			break;
583*4882a593Smuzhiyun 		} else if (type == PHL_GET_CONFIG_BY_ROLE) {
584*4882a593Smuzhiyun 			if (twt_config_state_free == config[i].state)
585*4882a593Smuzhiyun 				continue;
586*4882a593Smuzhiyun 			if ((struct rtw_wifi_role_t *)para != config[i].role)
587*4882a593Smuzhiyun 				continue;
588*4882a593Smuzhiyun 			*ret_config = &config[i];
589*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_SUCCESS;
590*4882a593Smuzhiyun 			break;
591*4882a593Smuzhiyun 		} else if (type == PHL_GET_CONFIG_BY_PARA) {
592*4882a593Smuzhiyun 			if (twt_config_state_free == config[i].state)
593*4882a593Smuzhiyun 				continue;
594*4882a593Smuzhiyun 			if (!_twt_is_same_config(&config[i],
595*4882a593Smuzhiyun 						(struct _twt_compare *)para))
596*4882a593Smuzhiyun 				continue;
597*4882a593Smuzhiyun 			*ret_config = &config[i];
598*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_SUCCESS;
599*4882a593Smuzhiyun 			break;
600*4882a593Smuzhiyun 		}
601*4882a593Smuzhiyun 	}
602*4882a593Smuzhiyun exit:
603*4882a593Smuzhiyun 	_twt_dump_twt_cfg_info(twt_cfg_i);
604*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "<== _twt_operate_twt_config(): pstatus:%d\n",
605*4882a593Smuzhiyun 		pstatus);
606*4882a593Smuzhiyun 	return pstatus;
607*4882a593Smuzhiyun }
608*4882a593Smuzhiyun 
_twt_sta_update(void * hal,u16 macid,u8 twt_id,enum rtw_phl_twt_sta_action action)609*4882a593Smuzhiyun enum rtw_phl_status _twt_sta_update(void *hal, u16 macid, u8 twt_id,
610*4882a593Smuzhiyun 				enum rtw_phl_twt_sta_action action)
611*4882a593Smuzhiyun {
612*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
613*4882a593Smuzhiyun 	enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
614*4882a593Smuzhiyun 
615*4882a593Smuzhiyun 	hstatus = rtw_hal_twt_sta_update(hal, (u8)macid, twt_id, action);
616*4882a593Smuzhiyun 	if (hstatus != RTW_HAL_STATUS_SUCCESS) {
617*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "twt sta update fail: hstatus:%d, macid:%d, twt_id:%d, action:%d\n",
618*4882a593Smuzhiyun 			hstatus, macid, twt_id, action);
619*4882a593Smuzhiyun 	} else {
620*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "twt sta update ok: macid:%d, twt_id:%d, action:%d\n",
621*4882a593Smuzhiyun 			macid, twt_id, action);
622*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
623*4882a593Smuzhiyun 	}
624*4882a593Smuzhiyun 	return pstatus;
625*4882a593Smuzhiyun }
626*4882a593Smuzhiyun 
_twt_all_sta_update(struct phl_info_t * phl_info,u8 config_id,struct phl_queue * sta_queue,enum rtw_phl_twt_sta_action action)627*4882a593Smuzhiyun enum rtw_phl_status _twt_all_sta_update(struct phl_info_t *phl_info,
628*4882a593Smuzhiyun 				u8 config_id, struct phl_queue *sta_queue,
629*4882a593Smuzhiyun 				enum rtw_phl_twt_sta_action action)
630*4882a593Smuzhiyun {
631*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
632*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
633*4882a593Smuzhiyun 	_os_list *sta_list = &sta_queue->queue;
634*4882a593Smuzhiyun 	struct rtw_twt_sta_info *psta = NULL;
635*4882a593Smuzhiyun 
636*4882a593Smuzhiyun 	_os_spinlock(drv, &sta_queue->lock, _bh, NULL);
637*4882a593Smuzhiyun 	phl_list_for_loop(psta, struct rtw_twt_sta_info, sta_list, list) {
638*4882a593Smuzhiyun 		if (NULL == psta)
639*4882a593Smuzhiyun 			break;
640*4882a593Smuzhiyun 		pstatus = _twt_sta_update(phl_info->hal, psta->phl_sta->macid,
641*4882a593Smuzhiyun 						config_id, action);
642*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != pstatus)
643*4882a593Smuzhiyun 			break;
644*4882a593Smuzhiyun 	}
645*4882a593Smuzhiyun 	_os_spinunlock(drv, &sta_queue->lock, _bh, NULL);
646*4882a593Smuzhiyun 	return pstatus;
647*4882a593Smuzhiyun }
648*4882a593Smuzhiyun 
_twt_get_sta_info(struct phl_info_t * phl_info,struct phl_queue * sta_queue,struct rtw_phl_stainfo_t * phl_sta)649*4882a593Smuzhiyun struct rtw_twt_sta_info * _twt_get_sta_info(struct phl_info_t *phl_info,
650*4882a593Smuzhiyun 		struct phl_queue *sta_queue, struct rtw_phl_stainfo_t *phl_sta)
651*4882a593Smuzhiyun {
652*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
653*4882a593Smuzhiyun 	_os_list *sta_list = &sta_queue->queue;
654*4882a593Smuzhiyun 	struct rtw_twt_sta_info *psta = NULL, *ret_sta = NULL;
655*4882a593Smuzhiyun 
656*4882a593Smuzhiyun 	_os_spinlock(drv, &sta_queue->lock, _bh, NULL);
657*4882a593Smuzhiyun 	phl_list_for_loop(psta, struct rtw_twt_sta_info, sta_list, list) {
658*4882a593Smuzhiyun 		if (NULL == psta)
659*4882a593Smuzhiyun 			break;
660*4882a593Smuzhiyun 		if (phl_sta == psta->phl_sta) {
661*4882a593Smuzhiyun 			ret_sta = psta;
662*4882a593Smuzhiyun 			break;
663*4882a593Smuzhiyun 		}
664*4882a593Smuzhiyun 	}
665*4882a593Smuzhiyun 	_os_spinunlock(drv, &sta_queue->lock, _bh, NULL);
666*4882a593Smuzhiyun 	return ret_sta;
667*4882a593Smuzhiyun }
668*4882a593Smuzhiyun 
_twt_sta_enqueue(struct phl_info_t * phl_info,struct phl_queue * sta_q,struct rtw_twt_sta_info * psta)669*4882a593Smuzhiyun enum rtw_phl_status _twt_sta_enqueue(struct phl_info_t *phl_info,
670*4882a593Smuzhiyun 		struct phl_queue *sta_q, struct rtw_twt_sta_info *psta)
671*4882a593Smuzhiyun {
672*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
673*4882a593Smuzhiyun 
674*4882a593Smuzhiyun 	if (!psta)
675*4882a593Smuzhiyun 		return RTW_PHL_STATUS_FAILURE;
676*4882a593Smuzhiyun 	_os_spinlock(drv, &sta_q->lock, _bh, NULL);
677*4882a593Smuzhiyun 	list_add_tail(&psta->list, &sta_q->queue);
678*4882a593Smuzhiyun 	sta_q->cnt++;
679*4882a593Smuzhiyun 	_os_spinunlock(drv, &sta_q->lock, _bh, NULL);
680*4882a593Smuzhiyun 	return RTW_PHL_STATUS_SUCCESS;
681*4882a593Smuzhiyun }
682*4882a593Smuzhiyun 
_twt_sta_dequeue(struct phl_info_t * phl_info,struct phl_queue * sta_q,u16 * cnt)683*4882a593Smuzhiyun struct rtw_twt_sta_info * _twt_sta_dequeue(struct phl_info_t *phl_info,
684*4882a593Smuzhiyun 				struct phl_queue *sta_q, u16 *cnt)
685*4882a593Smuzhiyun {
686*4882a593Smuzhiyun 	struct rtw_twt_sta_info *psta = NULL;
687*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
688*4882a593Smuzhiyun 
689*4882a593Smuzhiyun 	_os_spinlock(drv, &sta_q->lock, _bh, NULL);
690*4882a593Smuzhiyun 	if (list_empty(&sta_q->queue)) {
691*4882a593Smuzhiyun 		psta = NULL;
692*4882a593Smuzhiyun 	} else {
693*4882a593Smuzhiyun 		psta = list_first_entry(&sta_q->queue,
694*4882a593Smuzhiyun 					struct rtw_twt_sta_info, list);
695*4882a593Smuzhiyun 		list_del(&psta->list);
696*4882a593Smuzhiyun 		sta_q->cnt--;
697*4882a593Smuzhiyun 		*cnt = (u16)sta_q->cnt;
698*4882a593Smuzhiyun 	}
699*4882a593Smuzhiyun 	_os_spinunlock(drv, &sta_q->lock, _bh, NULL);
700*4882a593Smuzhiyun 	return psta;
701*4882a593Smuzhiyun }
702*4882a593Smuzhiyun 
703*4882a593Smuzhiyun /*
704*4882a593Smuzhiyun  * Delete all sta entry from queue
705*4882a593Smuzhiyun  * @sta_queue: twt sta Q
706*4882a593Smuzhiyun  */
_twt_delete_all_sta(struct phl_info_t * phl_info,struct phl_queue * sta_queue)707*4882a593Smuzhiyun void _twt_delete_all_sta(struct phl_info_t *phl_info,
708*4882a593Smuzhiyun 				struct phl_queue *sta_queue)
709*4882a593Smuzhiyun {
710*4882a593Smuzhiyun 	struct rtw_twt_sta_info *twt_sta;
711*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
712*4882a593Smuzhiyun 	u16 cnt;
713*4882a593Smuzhiyun 
714*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> _twt_delete_all_sta()\n");
715*4882a593Smuzhiyun 	do {
716*4882a593Smuzhiyun 		twt_sta = _twt_sta_dequeue(phl_info, sta_queue, &cnt);
717*4882a593Smuzhiyun 		if (NULL != twt_sta)
718*4882a593Smuzhiyun 			_os_mem_free(drv, twt_sta,
719*4882a593Smuzhiyun 					sizeof(struct rtw_twt_sta_info));
720*4882a593Smuzhiyun 	} while (twt_sta != NULL);
721*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== _twt_delete_all_sta()\n");
722*4882a593Smuzhiyun }
723*4882a593Smuzhiyun 
724*4882a593Smuzhiyun /*
725*4882a593Smuzhiyun  * Delete twt sta entry by specific sta and id from queue
726*4882a593Smuzhiyun  * @sta_queue: twt sta Q
727*4882a593Smuzhiyun  * @phl_sta: specific sta
728*4882a593Smuzhiyun  * @id: specific twt folw id/broadcast twt id or delete all
729*4882a593Smuzhiyun  * @cnt: total num of sta entery in Q
730*4882a593Smuzhiyun  */
_twt_delete_sta(struct phl_info_t * phl_info,struct phl_queue * sta_q,struct rtw_phl_stainfo_t * phl_sta,u8 id,u16 * cnt)731*4882a593Smuzhiyun enum rtw_phl_status _twt_delete_sta(struct phl_info_t *phl_info,
732*4882a593Smuzhiyun 			struct phl_queue *sta_q,
733*4882a593Smuzhiyun 			struct rtw_phl_stainfo_t *phl_sta, u8 id, u16 *cnt)
734*4882a593Smuzhiyun {
735*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
736*4882a593Smuzhiyun 	struct rtw_twt_sta_info *twt_sta, *f_sta;
737*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
738*4882a593Smuzhiyun 
739*4882a593Smuzhiyun 	f_sta = _twt_sta_dequeue(phl_info, sta_q, cnt);
740*4882a593Smuzhiyun 	twt_sta = f_sta;
741*4882a593Smuzhiyun 	do {
742*4882a593Smuzhiyun 		if (twt_sta == NULL)
743*4882a593Smuzhiyun 			break;
744*4882a593Smuzhiyun 		if ((phl_sta == twt_sta->phl_sta) &&
745*4882a593Smuzhiyun 			(DELETE_ALL == id || id == twt_sta->id)) {
746*4882a593Smuzhiyun 			_os_mem_free(drv, twt_sta,
747*4882a593Smuzhiyun 					sizeof(struct rtw_twt_sta_info));
748*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_SUCCESS;
749*4882a593Smuzhiyun 			break;
750*4882a593Smuzhiyun 		}
751*4882a593Smuzhiyun 		_twt_sta_enqueue(phl_info, sta_q, twt_sta);
752*4882a593Smuzhiyun 		twt_sta = _twt_sta_dequeue(phl_info, sta_q, cnt);
753*4882a593Smuzhiyun 		if (NULL != twt_sta && twt_sta == f_sta) {
754*4882a593Smuzhiyun 			_twt_sta_enqueue(phl_info, sta_q, twt_sta);
755*4882a593Smuzhiyun 			break;
756*4882a593Smuzhiyun 		}
757*4882a593Smuzhiyun 	} while (true);
758*4882a593Smuzhiyun 	return pstatus;
759*4882a593Smuzhiyun }
760*4882a593Smuzhiyun 
761*4882a593Smuzhiyun /*
762*4882a593Smuzhiyun  * Does sta exist in twt sta entry by specific sta and id
763*4882a593Smuzhiyun  * @sta_queue: twt sta Q
764*4882a593Smuzhiyun  * @phl_sta: specific sta
765*4882a593Smuzhiyun  * @id: specific twt folw id/broadcast twt id or delete all
766*4882a593Smuzhiyun  */
_twt_sta_exist(struct phl_info_t * phl_info,struct phl_queue * sta_q,struct rtw_phl_stainfo_t * phl_sta,u8 id)767*4882a593Smuzhiyun enum rtw_phl_status _twt_sta_exist(struct phl_info_t *phl_info,
768*4882a593Smuzhiyun 			struct phl_queue *sta_q,
769*4882a593Smuzhiyun 			struct rtw_phl_stainfo_t *phl_sta, u8 id)
770*4882a593Smuzhiyun {
771*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
772*4882a593Smuzhiyun 	struct rtw_twt_sta_info *twt_sta = NULL;
773*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
774*4882a593Smuzhiyun 	_os_list *q_list = &sta_q->queue;
775*4882a593Smuzhiyun 
776*4882a593Smuzhiyun 	_os_spinlock(drv, &sta_q->lock, _bh, NULL);
777*4882a593Smuzhiyun 	phl_list_for_loop(twt_sta, struct rtw_twt_sta_info, q_list, list) {
778*4882a593Smuzhiyun 		if (NULL == twt_sta)
779*4882a593Smuzhiyun 			break;
780*4882a593Smuzhiyun 		if ((phl_sta == twt_sta->phl_sta) &&
781*4882a593Smuzhiyun 			(DELETE_ALL == id || id == twt_sta->id)) {
782*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_SUCCESS;
783*4882a593Smuzhiyun 			break;
784*4882a593Smuzhiyun 		}
785*4882a593Smuzhiyun 	}
786*4882a593Smuzhiyun 	_os_spinunlock(drv, &sta_q->lock, _bh, NULL);
787*4882a593Smuzhiyun 	return pstatus;
788*4882a593Smuzhiyun }
789*4882a593Smuzhiyun 
790*4882a593Smuzhiyun 
_twt_add_sta(struct phl_info_t * phl_info,struct rtw_phl_stainfo_t * phl_sta,struct phl_queue * sta_q,u8 id)791*4882a593Smuzhiyun enum rtw_phl_status _twt_add_sta(struct phl_info_t *phl_info,
792*4882a593Smuzhiyun 			struct rtw_phl_stainfo_t *phl_sta,
793*4882a593Smuzhiyun 			struct phl_queue *sta_q, u8 id)
794*4882a593Smuzhiyun {
795*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
796*4882a593Smuzhiyun 	struct rtw_twt_sta_info *twt_sta;
797*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
798*4882a593Smuzhiyun 
799*4882a593Smuzhiyun 	twt_sta = _os_mem_alloc(drv, sizeof(struct rtw_twt_sta_info));
800*4882a593Smuzhiyun 	if (NULL == twt_sta) {
801*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "_phl_twt_add_sta(): alloc rtw_twt_sta_info failed\n");
802*4882a593Smuzhiyun 	} else {
803*4882a593Smuzhiyun 		twt_sta->phl_sta = phl_sta;
804*4882a593Smuzhiyun 		twt_sta->id = id;
805*4882a593Smuzhiyun 		_twt_sta_enqueue(phl_info, sta_q, twt_sta);
806*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
807*4882a593Smuzhiyun 	}
808*4882a593Smuzhiyun 	return pstatus;
809*4882a593Smuzhiyun }
810*4882a593Smuzhiyun 
_twt_delete_sta_info(struct phl_info_t * phl_info,struct rtw_phl_stainfo_t * phl_sta,u8 ignore_type,enum rtw_phl_nego_type nego_type,u8 id,u8 * bitmap)811*4882a593Smuzhiyun enum rtw_phl_status _twt_delete_sta_info(struct phl_info_t *phl_info,
812*4882a593Smuzhiyun 			struct rtw_phl_stainfo_t *phl_sta,
813*4882a593Smuzhiyun 			u8 ignore_type, enum rtw_phl_nego_type nego_type,
814*4882a593Smuzhiyun 			u8 id, u8 *bitmap)
815*4882a593Smuzhiyun {
816*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
817*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = get_twt_info(phl_info);
818*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = &phl_twt_info->twt_cfg_info;
819*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL, *f_config = NULL;
820*4882a593Smuzhiyun 	enum rtw_phl_nego_type type = nego_type;
821*4882a593Smuzhiyun 	bool delete_error = false;
822*4882a593Smuzhiyun 	u16 cnt;
823*4882a593Smuzhiyun 	u8 delete_id = ignore_type ? DELETE_ALL : id;
824*4882a593Smuzhiyun 
825*4882a593Smuzhiyun 	*bitmap = 0;
826*4882a593Smuzhiyun 	if (RTW_PHL_MANAGE_BCAST_TWT == nego_type)
827*4882a593Smuzhiyun 		type = RTW_PHL_BCAST_TWT;
828*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl_info, twt_cfg_i,
829*4882a593Smuzhiyun 				PHL_GET_HEAD_CONFIG, NULL, &config)) {
830*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_delete_sta_info(): Fail to get first allocate config\n");
831*4882a593Smuzhiyun 		goto exit;
832*4882a593Smuzhiyun 	}
833*4882a593Smuzhiyun 	f_config = config;
834*4882a593Smuzhiyun 	do {
835*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "_twt_delete_sta_info(): while loop, twt_id:%d\n",
836*4882a593Smuzhiyun 			config->twt_info.twt_id);
837*4882a593Smuzhiyun 		if (twt_config_state_free == config->state)
838*4882a593Smuzhiyun 			goto next_cfg;
839*4882a593Smuzhiyun 		if (config->role != phl_sta->wrole)
840*4882a593Smuzhiyun 			goto next_cfg;
841*4882a593Smuzhiyun 		if (false == ignore_type && config->twt_info.nego_type != type)
842*4882a593Smuzhiyun 			goto next_cfg;
843*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != _twt_sta_exist(phl_info,
844*4882a593Smuzhiyun 							&config->twt_sta_queue,
845*4882a593Smuzhiyun 							phl_sta, delete_id))
846*4882a593Smuzhiyun 			goto next_cfg;
847*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != _twt_sta_update(phl_info->hal,
848*4882a593Smuzhiyun 							phl_sta->macid,
849*4882a593Smuzhiyun 							config->twt_info.twt_id,
850*4882a593Smuzhiyun 							TWT_STA_DEL_MACID)) {
851*4882a593Smuzhiyun 			delete_error = true;
852*4882a593Smuzhiyun 			goto next_cfg;
853*4882a593Smuzhiyun 		}
854*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != _twt_delete_sta(phl_info,
855*4882a593Smuzhiyun 							&config->twt_sta_queue,
856*4882a593Smuzhiyun 							phl_sta, delete_id,
857*4882a593Smuzhiyun 							&cnt)) {
858*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_delete_sta_info(): Fail to delete sta from twt_sta Q, macid(0x%x), delete_id(%d)\n",
859*4882a593Smuzhiyun 				phl_sta->macid, delete_id);
860*4882a593Smuzhiyun 			delete_error = true;
861*4882a593Smuzhiyun 			goto next_cfg;
862*4882a593Smuzhiyun 		}
863*4882a593Smuzhiyun 		if (0 == cnt)
864*4882a593Smuzhiyun 			*bitmap |= (1 << config->twt_info.twt_id);
865*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_delete_sta_info(): Delete sta success, config id = %d, twt_sta_queue cnt:%d, bitmap:0x%X\n",
866*4882a593Smuzhiyun 			config->twt_info.twt_id, cnt, *bitmap);
867*4882a593Smuzhiyun 		if (DELETE_ALL != delete_id)
868*4882a593Smuzhiyun 			break;
869*4882a593Smuzhiyun next_cfg:
870*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl_info,
871*4882a593Smuzhiyun 						twt_cfg_i, PHL_GET_NEXT_CONFIG,
872*4882a593Smuzhiyun 						(u8 *)&config->idx, &config)) {
873*4882a593Smuzhiyun 			delete_error = true;
874*4882a593Smuzhiyun 			break;
875*4882a593Smuzhiyun 		}
876*4882a593Smuzhiyun 	} while (config != f_config);
877*4882a593Smuzhiyun 	if (false == delete_error)
878*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
879*4882a593Smuzhiyun 	else
880*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_FAILURE;
881*4882a593Smuzhiyun exit:
882*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_delete_sta_info(): pstatus:%d, nego_type = %d, id:%d, bitmap:0x%x\n",
883*4882a593Smuzhiyun 		pstatus, nego_type, id, *bitmap);
884*4882a593Smuzhiyun 	return pstatus;
885*4882a593Smuzhiyun }
886*4882a593Smuzhiyun 
_twt_info_update(struct phl_info_t * phl_info,struct phl_twt_config * config,enum phl_twt_action action)887*4882a593Smuzhiyun enum rtw_phl_status _twt_info_update(struct phl_info_t *phl_info,
888*4882a593Smuzhiyun 				struct phl_twt_config *config,
889*4882a593Smuzhiyun 				enum phl_twt_action action)
890*4882a593Smuzhiyun {
891*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
892*4882a593Smuzhiyun 	enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
893*4882a593Smuzhiyun 	enum rtw_phl_twt_cfg_action config_action;
894*4882a593Smuzhiyun 
895*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> _twt_info_update()\n");
896*4882a593Smuzhiyun 	if (PHL_TWT_ACTION_ENABLE == action) {
897*4882a593Smuzhiyun 		config_action = TWT_CFG_ADD;
898*4882a593Smuzhiyun 	} else if (PHL_TWT_ACTION_DISABLE == action) {
899*4882a593Smuzhiyun 		config_action = TWT_CFG_DELETE;
900*4882a593Smuzhiyun 	} else {
901*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_info_update(): Unexpected action:%d\n",
902*4882a593Smuzhiyun 			action);
903*4882a593Smuzhiyun 		goto exit;
904*4882a593Smuzhiyun 	}
905*4882a593Smuzhiyun 	hstatus = rtw_hal_twt_info_update(phl_info, config->twt_info, config->role,
906*4882a593Smuzhiyun 						config_action);
907*4882a593Smuzhiyun 	if (hstatus == RTW_HAL_STATUS_SUCCESS) {
908*4882a593Smuzhiyun 		_twt_transfer_config_state(action, &config->state);
909*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
910*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "_twt_info_update(): update ok\n");
911*4882a593Smuzhiyun 	} else {
912*4882a593Smuzhiyun 		_twt_transfer_config_state(PHL_TWT_ACTION_UP_ERROR,
913*4882a593Smuzhiyun 								&config->state);
914*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_info_update(): update fail, hstatus:%d\n",
915*4882a593Smuzhiyun 			hstatus);
916*4882a593Smuzhiyun 	}
917*4882a593Smuzhiyun exit:
918*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<==_twt_info_update(): hstatus:%d, twt_id:%d, action:%d\n",
919*4882a593Smuzhiyun 		pstatus, config->twt_info.twt_id, action);
920*4882a593Smuzhiyun 	return pstatus;
921*4882a593Smuzhiyun }
922*4882a593Smuzhiyun 
923*4882a593Smuzhiyun /*
924*4882a593Smuzhiyun void
925*4882a593Smuzhiyun _twt_free_config(
926*4882a593Smuzhiyun 	void *phl,
927*4882a593Smuzhiyun 	struct phl_twt_config *config
928*4882a593Smuzhiyun )
929*4882a593Smuzhiyun {
930*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
931*4882a593Smuzhiyun 	_twt_info_update(phl_info->hal, config, PHL_TWT_ACTION_DISABLE);
932*4882a593Smuzhiyun 	_twt_delete_all_sta(phl_info, &config->twt_sta_queue);
933*4882a593Smuzhiyun 	_twt_reset_config_info(config);
934*4882a593Smuzhiyun 	_twt_transfer_config_state(PHL_TWT_ACTION_FREE, &config->state);
935*4882a593Smuzhiyun }
936*4882a593Smuzhiyun */
937*4882a593Smuzhiyun 
_twt_exist_same_twt_config(struct phl_info_t * phl,struct phl_twt_cfg_info * twt_cfg_i,struct rtw_wifi_role_t * role,struct rtw_phl_twt_setup_info setup_info,struct phl_twt_config ** ret_config)938*4882a593Smuzhiyun bool _twt_exist_same_twt_config(struct phl_info_t *phl,
939*4882a593Smuzhiyun 		struct phl_twt_cfg_info *twt_cfg_i, struct rtw_wifi_role_t *role,
940*4882a593Smuzhiyun 		struct rtw_phl_twt_setup_info setup_info,
941*4882a593Smuzhiyun 		struct phl_twt_config **ret_config)
942*4882a593Smuzhiyun {
943*4882a593Smuzhiyun 	bool exist = false;
944*4882a593Smuzhiyun 	struct _twt_compare compare_info = {0};
945*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
946*4882a593Smuzhiyun 
947*4882a593Smuzhiyun 	compare_info.role = role;
948*4882a593Smuzhiyun 	compare_info.twt_setup = setup_info;
949*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS == _twt_operate_twt_config(phl, twt_cfg_i,
950*4882a593Smuzhiyun 		PHL_GET_CONFIG_BY_PARA, (u8 *)&compare_info, &config)) {
951*4882a593Smuzhiyun 		*ret_config = config;
952*4882a593Smuzhiyun 		exist = true;
953*4882a593Smuzhiyun 	}
954*4882a593Smuzhiyun 	return exist;
955*4882a593Smuzhiyun }
956*4882a593Smuzhiyun 
957*4882a593Smuzhiyun /*
958*4882a593Smuzhiyun u8
959*4882a593Smuzhiyun _twt_get_new_config_entry(
960*4882a593Smuzhiyun 	struct phl_info_t *phl,
961*4882a593Smuzhiyun 	struct phl_queue *twt_queue,
962*4882a593Smuzhiyun 	struct phl_twt_config **ret_config
963*4882a593Smuzhiyun )
964*4882a593Smuzhiyun {
965*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
966*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
967*4882a593Smuzhiyun 	u8 bget = false;
968*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> _twt_get_new_config_entry()\n");
969*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS == _twt_operate_twt_config(phl, twt_queue,
970*4882a593Smuzhiyun 				PHL_GET_NEW_CONFIG, NULL, &config)) {
971*4882a593Smuzhiyun 		*ret_config = config;
972*4882a593Smuzhiyun 		bget = true;
973*4882a593Smuzhiyun 	}
974*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== _twt_get_new_config_entry(): bget:%d\n",
975*4882a593Smuzhiyun 		bget);
976*4882a593Smuzhiyun 	return bget;
977*4882a593Smuzhiyun }
978*4882a593Smuzhiyun */
979*4882a593Smuzhiyun 
_twt_new_config_is_available(struct phl_info_t * phl_i)980*4882a593Smuzhiyun bool _twt_new_config_is_available(struct phl_info_t *phl_i)
981*4882a593Smuzhiyun {
982*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = get_twt_info(phl_i);
983*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = &phl_twt_info->twt_cfg_info;
984*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
985*4882a593Smuzhiyun 	u8 available = false;
986*4882a593Smuzhiyun 
987*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS == _twt_operate_twt_config(phl_i, twt_cfg_i,
988*4882a593Smuzhiyun 				PHL_GET_NEW_CONFIG, NULL, &config)) {
989*4882a593Smuzhiyun 		_twt_operate_twt_config(phl_i, twt_cfg_i, PHL_FREE_CONFIG,
990*4882a593Smuzhiyun 					&config->twt_info.twt_id, NULL);
991*4882a593Smuzhiyun 		available = true;
992*4882a593Smuzhiyun 	}
993*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_new_config_is_available(): bavailable:%d\n", available);
994*4882a593Smuzhiyun 	return available;
995*4882a593Smuzhiyun }
996*4882a593Smuzhiyun 
997*4882a593Smuzhiyun /*
998*4882a593Smuzhiyun  * Whether the twt flow id of sta exist in any twt config entry.
999*4882a593Smuzhiyun  * @phl_sta: the specific sta
1000*4882a593Smuzhiyun  * @role: specific role for search twt config entry
1001*4882a593Smuzhiyun  * @id: twt flow id
1002*4882a593Smuzhiyun  * Note: for sta mode.
1003*4882a593Smuzhiyun */
_twt_flow_id_exist(void * phl,struct rtw_phl_stainfo_t * phl_sta,struct rtw_wifi_role_t * role,u8 id)1004*4882a593Smuzhiyun u8 _twt_flow_id_exist(void *phl, struct rtw_phl_stainfo_t *phl_sta,
1005*4882a593Smuzhiyun 				struct rtw_wifi_role_t *role, u8 id)
1006*4882a593Smuzhiyun {
1007*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1008*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = get_twt_info(phl_info);
1009*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = &phl_twt_info->twt_cfg_info;
1010*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL, *f_config = NULL;
1011*4882a593Smuzhiyun 	struct rtw_twt_sta_info *twt_sta = NULL;
1012*4882a593Smuzhiyun 	bool exist = false;
1013*4882a593Smuzhiyun 
1014*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> _twt_flow_id_exist()\n");
1015*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl, twt_cfg_i,
1016*4882a593Smuzhiyun 				PHL_GET_HEAD_CONFIG, NULL, &config)) {
1017*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_flow_id_exist(): Fail to get first allocate config\n");
1018*4882a593Smuzhiyun 		goto exit;
1019*4882a593Smuzhiyun 	}
1020*4882a593Smuzhiyun 	f_config = config;
1021*4882a593Smuzhiyun 	do {
1022*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "_twt_flow_id_exist(): while loop\n");
1023*4882a593Smuzhiyun 		if (twt_config_state_free == config->state)
1024*4882a593Smuzhiyun 			goto next_cfg;
1025*4882a593Smuzhiyun 		if (config->role != phl_sta->wrole ||
1026*4882a593Smuzhiyun 			RTW_PHL_INDIV_TWT != config->twt_info.nego_type)
1027*4882a593Smuzhiyun 			goto next_cfg;
1028*4882a593Smuzhiyun 		twt_sta = _twt_get_sta_info(phl_info, &config->twt_sta_queue,
1029*4882a593Smuzhiyun 						phl_sta);
1030*4882a593Smuzhiyun 		if (NULL != twt_sta && id == twt_sta->id) {
1031*4882a593Smuzhiyun 			exist = true;
1032*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_flow_id_exist(): exist the twt_flow_id:%d\n",
1033*4882a593Smuzhiyun 				id);
1034*4882a593Smuzhiyun 			break;
1035*4882a593Smuzhiyun 		}
1036*4882a593Smuzhiyun next_cfg:
1037*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl,
1038*4882a593Smuzhiyun 						twt_cfg_i, PHL_GET_NEXT_CONFIG,
1039*4882a593Smuzhiyun 						(u8 *)&config->idx, &config))
1040*4882a593Smuzhiyun 			break;
1041*4882a593Smuzhiyun 	} while(config != f_config);
1042*4882a593Smuzhiyun exit:
1043*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== _twt_flow_id_exist(): twt flow id:%d, bexist:%d\n",
1044*4882a593Smuzhiyun 		id, exist);
1045*4882a593Smuzhiyun 	return exist;
1046*4882a593Smuzhiyun }
1047*4882a593Smuzhiyun 
_twt_accept_bcast_by_sta(struct phl_info_t * phl,struct rtw_phl_twt_setup_info * setup_info,struct rtw_phl_stainfo_t * phl_sta,u8 * config_id)1048*4882a593Smuzhiyun enum rtw_phl_status _twt_accept_bcast_by_sta(struct phl_info_t *phl,
1049*4882a593Smuzhiyun 			struct rtw_phl_twt_setup_info *setup_info,
1050*4882a593Smuzhiyun 			struct rtw_phl_stainfo_t *phl_sta, u8 *config_id)
1051*4882a593Smuzhiyun {
1052*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1053*4882a593Smuzhiyun 
1054*4882a593Smuzhiyun 	/*TODO*/
1055*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "==> _twt_accept_bcast_by_sta(): not support, todo\n");
1056*4882a593Smuzhiyun 	pstatus = RTW_PHL_STATUS_FAILURE;
1057*4882a593Smuzhiyun 	return pstatus;
1058*4882a593Smuzhiyun }
1059*4882a593Smuzhiyun 
_twt_accept_indiv_by_sta(struct phl_info_t * phl,struct rtw_phl_twt_setup_info * setup_info,struct rtw_phl_stainfo_t * phl_sta,u8 * config_id)1060*4882a593Smuzhiyun enum rtw_phl_status _twt_accept_indiv_by_sta(struct phl_info_t *phl,
1061*4882a593Smuzhiyun 			struct rtw_phl_twt_setup_info *setup_info,
1062*4882a593Smuzhiyun 			struct rtw_phl_stainfo_t *phl_sta, u8 *config_id)
1063*4882a593Smuzhiyun {
1064*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1065*4882a593Smuzhiyun 	struct rtw_phl_twt_element *twt_ele = &setup_info->twt_element;
1066*4882a593Smuzhiyun 	struct rtw_phl_twt_control *twt_ctrl = &twt_ele->twt_ctrl;
1067*4882a593Smuzhiyun 	struct rtw_phl_indiv_twt_para_set *para = &twt_ele->info.i_twt_para_set;
1068*4882a593Smuzhiyun 	struct rtw_phl_req_type_indiv *req_type = &para->req_type;
1069*4882a593Smuzhiyun 	u8 bitmap = 0, id = 0, i = 0;
1070*4882a593Smuzhiyun 
1071*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> _twt_accept_indiv_by_sta()\n");
1072*4882a593Smuzhiyun 	if (_twt_flow_id_exist(phl, phl_sta, phl_sta->wrole,
1073*4882a593Smuzhiyun 				req_type->twt_flow_id)) {
1074*4882a593Smuzhiyun 		pstatus = _twt_delete_sta_info(phl, phl_sta, false,
1075*4882a593Smuzhiyun 						twt_ctrl->nego_type,
1076*4882a593Smuzhiyun 						req_type->twt_flow_id, &bitmap);
1077*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_accept_indiv_by_sta(): twt flow id(%d) exist, first, delete twt sta, pstatus:%d, bitmap:0x%x\n",
1078*4882a593Smuzhiyun 			req_type->twt_flow_id, pstatus, bitmap);
1079*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS == pstatus && bitmap != 0) {
1080*4882a593Smuzhiyun 			id = 0;
1081*4882a593Smuzhiyun 			do {
1082*4882a593Smuzhiyun 				i = ((bitmap >> id) & BIT0);
1083*4882a593Smuzhiyun 				if (i != 0) {
1084*4882a593Smuzhiyun 					bitmap &= ~(BIT(id));
1085*4882a593Smuzhiyun 					break;
1086*4882a593Smuzhiyun 				}
1087*4882a593Smuzhiyun 				id++;
1088*4882a593Smuzhiyun 			} while (true);
1089*4882a593Smuzhiyun 			pstatus = rtw_phl_twt_free_twt_config(phl, id);
1090*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_accept_indiv_by_sta():sta Q is empty in twt config entry(%d), we free it, pstatus:%d \n",
1091*4882a593Smuzhiyun 				id, pstatus);
1092*4882a593Smuzhiyun 			if (bitmap !=0) {
1093*4882a593Smuzhiyun 				PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "_twt_accept_indiv_by_sta():  TWT config entry bitmap(0x%x) != 0, some twt config entry not free. please check code\n",
1094*4882a593Smuzhiyun 						bitmap);
1095*4882a593Smuzhiyun 			}
1096*4882a593Smuzhiyun 		}
1097*4882a593Smuzhiyun 	}
1098*4882a593Smuzhiyun 	pstatus = rtw_phl_twt_alloc_twt_config(phl, phl_sta->wrole, *setup_info,
1099*4882a593Smuzhiyun 						true, &id);
1100*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS == pstatus) {
1101*4882a593Smuzhiyun 		pstatus = rtw_phl_twt_add_sta_info(phl, phl_sta, id,
1102*4882a593Smuzhiyun 							req_type->twt_flow_id);
1103*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1104*4882a593Smuzhiyun 			rtw_phl_twt_free_twt_config(phl, id);
1105*4882a593Smuzhiyun 		} else {
1106*4882a593Smuzhiyun 			*config_id = id;
1107*4882a593Smuzhiyun 		}
1108*4882a593Smuzhiyun 	}
1109*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "_twt_accept_indiv_by_sta(): pstatus:%d, config_id:%d\n",
1110*4882a593Smuzhiyun 		pstatus, *config_id);
1111*4882a593Smuzhiyun 	return pstatus;
1112*4882a593Smuzhiyun }
1113*4882a593Smuzhiyun 
1114*4882a593Smuzhiyun /*
1115*4882a593Smuzhiyun  * Initialize twt
1116*4882a593Smuzhiyun  */
phl_twt_init(void * phl)1117*4882a593Smuzhiyun enum rtw_phl_status phl_twt_init(void *phl)
1118*4882a593Smuzhiyun {
1119*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1120*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1121*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
1122*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_i = NULL;
1123*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1124*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
1125*4882a593Smuzhiyun 	u16 len = 0;
1126*4882a593Smuzhiyun 	u8 i = 0;
1127*4882a593Smuzhiyun 
1128*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> phl_twt_init()\n");
1129*4882a593Smuzhiyun 	if (NULL == phl_info->phl_twt_info) {
1130*4882a593Smuzhiyun 		phl_info->phl_twt_info = _os_mem_alloc(drv,
1131*4882a593Smuzhiyun 					sizeof(struct phl_twt_info));
1132*4882a593Smuzhiyun 		if (NULL == phl_info->phl_twt_info) {
1133*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "phl_twt_init(): Failed to allocate phl_twt_info\n");
1134*4882a593Smuzhiyun 			goto exit;
1135*4882a593Smuzhiyun 		}
1136*4882a593Smuzhiyun 		_os_mem_set(phl_to_drvpriv(phl_info), phl_info->phl_twt_info,
1137*4882a593Smuzhiyun 				0, sizeof(struct phl_twt_info));
1138*4882a593Smuzhiyun 	} else {
1139*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "phl_twt_init(): Duplicate init1, please check code\n");
1140*4882a593Smuzhiyun 	}
1141*4882a593Smuzhiyun 	phl_twt_i = get_twt_info(phl_info);
1142*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_i->twt_cfg_info;
1143*4882a593Smuzhiyun 	if (NULL == twt_cfg_i->twt_cfg_ring) {
1144*4882a593Smuzhiyun 		twt_cfg_i->twt_cfg_num = MAX_NUM_HW_TWT_CONFIG;
1145*4882a593Smuzhiyun 		len = sizeof(struct phl_twt_config) * twt_cfg_i->twt_cfg_num;
1146*4882a593Smuzhiyun 		twt_cfg_i->twt_cfg_ring = _os_mem_alloc(drv, len);
1147*4882a593Smuzhiyun 		if (NULL == twt_cfg_i->twt_cfg_ring) {
1148*4882a593Smuzhiyun 			twt_cfg_i->twt_cfg_num = 0;
1149*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "phl_twt_init(): Failed to allocate twt_cfg_ring\n");
1150*4882a593Smuzhiyun 			goto exit;
1151*4882a593Smuzhiyun 		}
1152*4882a593Smuzhiyun 		config = (struct phl_twt_config *)twt_cfg_i->twt_cfg_ring;
1153*4882a593Smuzhiyun 		for (i = 0; i < twt_cfg_i->twt_cfg_num; i++) {
1154*4882a593Smuzhiyun 			_os_mem_set(phl_to_drvpriv(phl_info), config, 0,
1155*4882a593Smuzhiyun 					sizeof(struct phl_twt_config));
1156*4882a593Smuzhiyun 			config->idx = i;
1157*4882a593Smuzhiyun 			pq_init(drv, &config->twt_sta_queue);
1158*4882a593Smuzhiyun 			config++;
1159*4882a593Smuzhiyun 		}
1160*4882a593Smuzhiyun 	} else {
1161*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "phl_twt_init(): Duplicate init2, please check code\n");
1162*4882a593Smuzhiyun 	}
1163*4882a593Smuzhiyun 	/* init for twt_annc_queue */
1164*4882a593Smuzhiyun 	pq_init(drv, &phl_twt_i->twt_annc_queue);
1165*4882a593Smuzhiyun 	pstatus = RTW_PHL_STATUS_SUCCESS;
1166*4882a593Smuzhiyun exit:
1167*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "<== phl_twt_init(): pstatus:%d\n",
1168*4882a593Smuzhiyun 		pstatus);
1169*4882a593Smuzhiyun 	return pstatus;
1170*4882a593Smuzhiyun }
1171*4882a593Smuzhiyun 
1172*4882a593Smuzhiyun /*
1173*4882a593Smuzhiyun  * Deinitialize twt
1174*4882a593Smuzhiyun  */
phl_twt_deinit(void * phl)1175*4882a593Smuzhiyun void phl_twt_deinit(void *phl)
1176*4882a593Smuzhiyun {
1177*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1178*4882a593Smuzhiyun 	void *drv = phl_to_drvpriv(phl_info);
1179*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_i = get_twt_info(phl_info);
1180*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
1181*4882a593Smuzhiyun 	struct _twt_announce_info *annc_info = NULL;
1182*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1183*4882a593Smuzhiyun 	u8 i = 0;
1184*4882a593Smuzhiyun 	u16 len = 0;
1185*4882a593Smuzhiyun 
1186*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> phl_twt_deinit()\n");
1187*4882a593Smuzhiyun 	if (NULL == phl_twt_i)
1188*4882a593Smuzhiyun 		goto exit;
1189*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_i->twt_cfg_info;
1190*4882a593Smuzhiyun 	if (NULL == twt_cfg_i->twt_cfg_ring)
1191*4882a593Smuzhiyun 		goto free_twt_info;
1192*4882a593Smuzhiyun 	config = (struct phl_twt_config *)(twt_cfg_i->twt_cfg_ring);
1193*4882a593Smuzhiyun 	for (i = 0; i < twt_cfg_i->twt_cfg_num; i++) {
1194*4882a593Smuzhiyun 		if (config->twt_sta_queue.cnt > 0) {
1195*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "rtw_phl_twt_deinit(): config_id: %d, twt_sta_queue.cnt(%d) >0, force delete all\n",
1196*4882a593Smuzhiyun 				config->idx ,config->twt_sta_queue.cnt);
1197*4882a593Smuzhiyun 			_twt_delete_all_sta(phl_info, &config->twt_sta_queue);
1198*4882a593Smuzhiyun 		}
1199*4882a593Smuzhiyun 		pq_deinit(drv, &config->twt_sta_queue);
1200*4882a593Smuzhiyun 		config++;
1201*4882a593Smuzhiyun 	}
1202*4882a593Smuzhiyun 	len = sizeof(struct phl_twt_config) * twt_cfg_i->twt_cfg_num;
1203*4882a593Smuzhiyun 	_os_mem_free(drv, twt_cfg_i->twt_cfg_ring, len);
1204*4882a593Smuzhiyun 	do {
1205*4882a593Smuzhiyun 		annc_info = _twt_announce_info_dequeue(phl_info,
1206*4882a593Smuzhiyun 						&phl_twt_i->twt_annc_queue);
1207*4882a593Smuzhiyun 		if (NULL == annc_info)
1208*4882a593Smuzhiyun 			break;
1209*4882a593Smuzhiyun 		_os_mem_free(drv, annc_info, sizeof(struct _twt_announce_info));
1210*4882a593Smuzhiyun 	} while(true);
1211*4882a593Smuzhiyun 	pq_deinit(drv, &phl_twt_i->twt_annc_queue);
1212*4882a593Smuzhiyun free_twt_info:
1213*4882a593Smuzhiyun 	_os_mem_free(drv, phl_info->phl_twt_info, sizeof(struct phl_twt_info));
1214*4882a593Smuzhiyun exit:
1215*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_deinit()\n");
1216*4882a593Smuzhiyun }
1217*4882a593Smuzhiyun 
1218*4882a593Smuzhiyun /*
1219*4882a593Smuzhiyun  * Allocate new twt config
1220*4882a593Smuzhiyun  * @role: the user of twt config
1221*4882a593Smuzhiyun  * @setup_info: twt setup info
1222*4882a593Smuzhiyun  * @benable: whether to enable the twt config to fw,
1223*4882a593Smuzhiyun  * if benable is equal to false, only allocate twt config entry
1224*4882a593Smuzhiyun  * @id: Output the id of twt confi entry
1225*4882a593Smuzhiyun  */
rtw_phl_twt_alloc_twt_config(void * phl,struct rtw_wifi_role_t * role,struct rtw_phl_twt_setup_info setup_info,u8 benable,u8 * id)1226*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_alloc_twt_config(void *phl,
1227*4882a593Smuzhiyun 				struct rtw_wifi_role_t *role,
1228*4882a593Smuzhiyun 				struct rtw_phl_twt_setup_info setup_info,
1229*4882a593Smuzhiyun 				u8 benable, u8 *id)
1230*4882a593Smuzhiyun {
1231*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1232*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1233*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
1234*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1235*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
1236*4882a593Smuzhiyun 	bool alloc = false;
1237*4882a593Smuzhiyun 
1238*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_alloc_twt_config()\n");
1239*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1240*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_alloc_twt_config(): twt_sup == false\n");
1241*4882a593Smuzhiyun 		return pstatus;
1242*4882a593Smuzhiyun 	}
1243*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1244*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_alloc_twt_config(): twt_init == false\n");
1245*4882a593Smuzhiyun 		return pstatus;
1246*4882a593Smuzhiyun 	}
1247*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
1248*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_info->twt_cfg_info;
1249*4882a593Smuzhiyun /*	if (true == _twt_exist_same_twt_config(phl_info, twt_cfg_i, role,
1250*4882a593Smuzhiyun 						setup_info, &config)) {
1251*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "[TWT]alloc from existing config, id = %d\n",
1252*4882a593Smuzhiyun 			config->twt_info.twt_id);
1253*4882a593Smuzhiyun 		alloc = true;
1254*4882a593Smuzhiyun 	} else */{
1255*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS == _twt_operate_twt_config(phl_info,
1256*4882a593Smuzhiyun 				twt_cfg_i, PHL_GET_NEW_CONFIG, NULL, &config)) {
1257*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "[TWT]alloc from new config, id = %d\n",
1258*4882a593Smuzhiyun 				config->twt_info.twt_id);
1259*4882a593Smuzhiyun 			alloc = true;
1260*4882a593Smuzhiyun 		} else {
1261*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "[TWT]fail to alloc new config\n");
1262*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_RESOURCE;
1263*4882a593Smuzhiyun 		}
1264*4882a593Smuzhiyun 	}
1265*4882a593Smuzhiyun 	if (true == alloc) {
1266*4882a593Smuzhiyun 		*id = config->twt_info.twt_id;
1267*4882a593Smuzhiyun 		config->role = role;
1268*4882a593Smuzhiyun 		_twt_fill_config_info(&config->twt_info, &setup_info);
1269*4882a593Smuzhiyun 		if (benable) {
1270*4882a593Smuzhiyun 			pstatus = _twt_info_update(phl_info->hal, config,
1271*4882a593Smuzhiyun 							PHL_TWT_ACTION_ENABLE);
1272*4882a593Smuzhiyun 			if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1273*4882a593Smuzhiyun 				/*todo*/
1274*4882a593Smuzhiyun 			}
1275*4882a593Smuzhiyun 		} else {
1276*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_SUCCESS;
1277*4882a593Smuzhiyun 		}
1278*4882a593Smuzhiyun 	}
1279*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_alloc_twt_config(): pstatus:%d\n",
1280*4882a593Smuzhiyun 		pstatus);
1281*4882a593Smuzhiyun 	return pstatus;
1282*4882a593Smuzhiyun }
1283*4882a593Smuzhiyun 
1284*4882a593Smuzhiyun /*
1285*4882a593Smuzhiyun  * Free twt config entry by specific config ID
1286*4882a593Smuzhiyun  * @id: id of twt config entry
1287*4882a593Smuzhiyun  */
rtw_phl_twt_free_twt_config(void * phl,u8 id)1288*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_free_twt_config(void *phl, u8 id)
1289*4882a593Smuzhiyun {
1290*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1291*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1292*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
1293*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1294*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
1295*4882a593Smuzhiyun 
1296*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_free_twt_config()\n");
1297*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1298*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_free_twt_config(): twt_sup == false\n");
1299*4882a593Smuzhiyun 		return pstatus;
1300*4882a593Smuzhiyun 	}
1301*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1302*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_free_twt_config(): twt_init == false\n");
1303*4882a593Smuzhiyun 		return pstatus;
1304*4882a593Smuzhiyun 	}
1305*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
1306*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_info->twt_cfg_info;
1307*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS == _twt_operate_twt_config(phl, twt_cfg_i,
1308*4882a593Smuzhiyun 							PHL_GET_CONFIG_BY_ID,
1309*4882a593Smuzhiyun 							&id, &config)) {
1310*4882a593Smuzhiyun 		_twt_info_update(phl_info->hal, config, PHL_TWT_ACTION_DISABLE);
1311*4882a593Smuzhiyun 		_twt_delete_all_sta(phl_info, &config->twt_sta_queue);
1312*4882a593Smuzhiyun 		_twt_operate_twt_config(phl, twt_cfg_i, PHL_FREE_CONFIG, &id,
1313*4882a593Smuzhiyun 									NULL);
1314*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "[TWT]Free twt config success, id = %d\n",
1315*4882a593Smuzhiyun 			id);
1316*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
1317*4882a593Smuzhiyun 	}
1318*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_free_twt_config(): pstatus:%d\n",
1319*4882a593Smuzhiyun 		pstatus);
1320*4882a593Smuzhiyun 	return pstatus;
1321*4882a593Smuzhiyun }
1322*4882a593Smuzhiyun 
1323*4882a593Smuzhiyun /*
1324*4882a593Smuzhiyun  * Enable twt config by specific config id
1325*4882a593Smuzhiyun  * @id: id of twt confi entry
1326*4882a593Smuzhiyun  */
rtw_phl_twt_enable_twt_config(void * phl,u8 id)1327*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_enable_twt_config(void *phl, u8 id)
1328*4882a593Smuzhiyun {
1329*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1330*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1331*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
1332*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1333*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
1334*4882a593Smuzhiyun 
1335*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_enable_twt_config()\n");
1336*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1337*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_enable_twt_config(): twt_sup == false\n");
1338*4882a593Smuzhiyun 		return pstatus;
1339*4882a593Smuzhiyun 	}
1340*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1341*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_enable_twt_config(): twt_init == false\n");
1342*4882a593Smuzhiyun 		return pstatus;
1343*4882a593Smuzhiyun 	}
1344*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
1345*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_info->twt_cfg_info;
1346*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS == _twt_operate_twt_config(phl, twt_cfg_i,
1347*4882a593Smuzhiyun 					PHL_GET_CONFIG_BY_ID, &id, &config)) {
1348*4882a593Smuzhiyun 		pstatus = _twt_info_update(phl_info->hal, config,
1349*4882a593Smuzhiyun 							PHL_TWT_ACTION_ENABLE);
1350*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS == pstatus) {
1351*4882a593Smuzhiyun 			_twt_all_sta_update(phl_info, id, &config->twt_sta_queue,
1352*4882a593Smuzhiyun 						TWT_STA_ADD_MACID);
1353*4882a593Smuzhiyun 		}
1354*4882a593Smuzhiyun 	}
1355*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_enable_twt_config(): pstatus:%d, id = %d\n",
1356*4882a593Smuzhiyun 		pstatus, id);
1357*4882a593Smuzhiyun 	return pstatus;
1358*4882a593Smuzhiyun }
1359*4882a593Smuzhiyun 
1360*4882a593Smuzhiyun /*
1361*4882a593Smuzhiyun  * Free all twt config by specific role
1362*4882a593Smuzhiyun  * @role: specific role for search twt config entry
1363*4882a593Smuzhiyun  */
rtw_phl_twt_free_all_twt_by_role(void * phl,struct rtw_wifi_role_t * role)1364*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_free_all_twt_by_role(void *phl,
1365*4882a593Smuzhiyun 				struct rtw_wifi_role_t *role)
1366*4882a593Smuzhiyun {
1367*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1368*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1369*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
1370*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1371*4882a593Smuzhiyun 	struct phl_twt_config *config;
1372*4882a593Smuzhiyun 	u8 id;
1373*4882a593Smuzhiyun 	bool free = false;
1374*4882a593Smuzhiyun 
1375*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_free_all_twt_by_role()\n");
1376*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1377*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_free_all_twt_by_role(): twt_sup == false\n");
1378*4882a593Smuzhiyun 		return pstatus;
1379*4882a593Smuzhiyun 	}
1380*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1381*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_free_all_twt_by_role(): twt_init == false\n");
1382*4882a593Smuzhiyun 		return pstatus;
1383*4882a593Smuzhiyun 	}
1384*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
1385*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_info->twt_cfg_info;
1386*4882a593Smuzhiyun 	do {
1387*4882a593Smuzhiyun 		pstatus = _twt_operate_twt_config(phl, twt_cfg_i,
1388*4882a593Smuzhiyun 				PHL_GET_CONFIG_BY_ROLE, (u8 *)role, &config);
1389*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != pstatus)
1390*4882a593Smuzhiyun 			break;
1391*4882a593Smuzhiyun 		id = config->twt_info.twt_id;
1392*4882a593Smuzhiyun 		_twt_info_update(phl_info->hal, config, PHL_TWT_ACTION_DISABLE);
1393*4882a593Smuzhiyun 		_twt_delete_all_sta(phl_info, &config->twt_sta_queue);
1394*4882a593Smuzhiyun 		_twt_operate_twt_config(phl, twt_cfg_i, PHL_FREE_CONFIG, &id,
1395*4882a593Smuzhiyun 									NULL);
1396*4882a593Smuzhiyun 		free = true;
1397*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "Free twt config success, id = %d\n",
1398*4882a593Smuzhiyun 			id);
1399*4882a593Smuzhiyun 	} while(true);
1400*4882a593Smuzhiyun 	if (true == free)
1401*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
1402*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_free_all_twt_by_role(): pstatus:%d\n",
1403*4882a593Smuzhiyun 		pstatus);
1404*4882a593Smuzhiyun 	return pstatus;
1405*4882a593Smuzhiyun }
1406*4882a593Smuzhiyun 
1407*4882a593Smuzhiyun /*
1408*4882a593Smuzhiyun  * Pause all twt config by specific role
1409*4882a593Smuzhiyun  * @role: specific role for search twt config entry
1410*4882a593Smuzhiyun  */
rtw_phl_twt_disable_all_twt_by_role(void * phl,struct rtw_wifi_role_t * role)1411*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_disable_all_twt_by_role(void *phl,
1412*4882a593Smuzhiyun 				struct rtw_wifi_role_t *role)
1413*4882a593Smuzhiyun {
1414*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1415*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1416*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
1417*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1418*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL, *f_config = NULL;
1419*4882a593Smuzhiyun 
1420*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_disable_all_twt_by_role()\n");
1421*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1422*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_disable_all_twt_by_role(): twt_sup == false\n");
1423*4882a593Smuzhiyun 		goto exit;
1424*4882a593Smuzhiyun 	}
1425*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1426*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_disable_all_twt_by_role(): twt_init == false\n");
1427*4882a593Smuzhiyun 		goto exit;
1428*4882a593Smuzhiyun 	}
1429*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
1430*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_info->twt_cfg_info;
1431*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl, twt_cfg_i,
1432*4882a593Smuzhiyun 				PHL_GET_HEAD_CONFIG, NULL, &config)) {
1433*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_disable_all_twt_by_role(): Fail to get first allocate config\n");
1434*4882a593Smuzhiyun 		goto exit;
1435*4882a593Smuzhiyun 	}
1436*4882a593Smuzhiyun 	f_config = config;
1437*4882a593Smuzhiyun 	do {
1438*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "rtw_phl_twt_disable_all_twt_by_role(): while loop, twt_id:%d\n",
1439*4882a593Smuzhiyun 			config->twt_info.twt_id);
1440*4882a593Smuzhiyun 		if (twt_config_state_free == config->state)
1441*4882a593Smuzhiyun 			goto next_cfg;
1442*4882a593Smuzhiyun 		if (config->role == role)
1443*4882a593Smuzhiyun 			_twt_info_update(phl_info->hal, config,
1444*4882a593Smuzhiyun 					PHL_TWT_ACTION_DISABLE);
1445*4882a593Smuzhiyun next_cfg:
1446*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl,
1447*4882a593Smuzhiyun 						twt_cfg_i, PHL_GET_NEXT_CONFIG,
1448*4882a593Smuzhiyun 						(u8 *)&config->idx, &config))
1449*4882a593Smuzhiyun 			goto exit;
1450*4882a593Smuzhiyun 	} while(config != f_config);
1451*4882a593Smuzhiyun 	pstatus = RTW_PHL_STATUS_SUCCESS;
1452*4882a593Smuzhiyun exit:
1453*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_disable_all_twt_by_role(): pstatus:%d\n",
1454*4882a593Smuzhiyun 		pstatus);
1455*4882a593Smuzhiyun 	return pstatus;
1456*4882a593Smuzhiyun }
1457*4882a593Smuzhiyun 
1458*4882a593Smuzhiyun /*
1459*4882a593Smuzhiyun  * Enable all twt config by specific role
1460*4882a593Smuzhiyun  * @role: specific role for search twt config entry
1461*4882a593Smuzhiyun  */
rtw_phl_twt_enable_all_twt_by_role(void * phl,struct rtw_wifi_role_t * role)1462*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_enable_all_twt_by_role(void *phl,
1463*4882a593Smuzhiyun 				struct rtw_wifi_role_t *role)
1464*4882a593Smuzhiyun {
1465*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1466*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1467*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
1468*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1469*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL, *f_config = NULL;
1470*4882a593Smuzhiyun 	bool error = false;
1471*4882a593Smuzhiyun 
1472*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_enable_all_twt_by_role()\n");
1473*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1474*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_enable_all_twt_by_role(): twt_sup == false\n");
1475*4882a593Smuzhiyun 		goto exit;
1476*4882a593Smuzhiyun 	}
1477*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1478*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_enable_all_twt_by_role(): twt_init == false\n");
1479*4882a593Smuzhiyun 		goto exit;
1480*4882a593Smuzhiyun 	}
1481*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
1482*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_info->twt_cfg_info;
1483*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl, twt_cfg_i,
1484*4882a593Smuzhiyun 				PHL_GET_HEAD_CONFIG, NULL, &config)) {
1485*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_enable_all_twt_by_role(): Fail to get first allocate config\n");
1486*4882a593Smuzhiyun 		goto exit;
1487*4882a593Smuzhiyun 	}
1488*4882a593Smuzhiyun 	f_config = config;
1489*4882a593Smuzhiyun 	do {
1490*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "rtw_phl_twt_enable_all_twt_by_role(): while loop, twt_id:%d\n",
1491*4882a593Smuzhiyun 			config->twt_info.twt_id);
1492*4882a593Smuzhiyun 		if (twt_config_state_free == config->state)
1493*4882a593Smuzhiyun 			goto next_cfg;
1494*4882a593Smuzhiyun 		if (config->role != role)
1495*4882a593Smuzhiyun 			goto next_cfg;
1496*4882a593Smuzhiyun 		pstatus = _twt_info_update(phl_info->hal, config,
1497*4882a593Smuzhiyun 						PHL_TWT_ACTION_ENABLE);
1498*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS == pstatus) {
1499*4882a593Smuzhiyun 			pstatus = _twt_all_sta_update(phl_info,
1500*4882a593Smuzhiyun 							config->twt_info.twt_id,
1501*4882a593Smuzhiyun 							&config->twt_sta_queue,
1502*4882a593Smuzhiyun 							TWT_STA_ADD_MACID);
1503*4882a593Smuzhiyun 			if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1504*4882a593Smuzhiyun 				error = true;
1505*4882a593Smuzhiyun 				PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "rtw_phl_twt_enable_all_twt_by_role(): Fail to update all twt sta, twt_id:%d\n",
1506*4882a593Smuzhiyun 						config->twt_info.twt_id);
1507*4882a593Smuzhiyun 			}
1508*4882a593Smuzhiyun 		} else {
1509*4882a593Smuzhiyun 			error = true;
1510*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "rtw_phl_twt_enable_all_twt_by_role(): Fail to enable twt config, twt_id:%d\n",
1511*4882a593Smuzhiyun 				config->twt_info.twt_id);
1512*4882a593Smuzhiyun 		}
1513*4882a593Smuzhiyun next_cfg:
1514*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl,
1515*4882a593Smuzhiyun 						twt_cfg_i, PHL_GET_NEXT_CONFIG,
1516*4882a593Smuzhiyun 						(u8 *)&config->idx, &config)) {
1517*4882a593Smuzhiyun 			error = true;
1518*4882a593Smuzhiyun 			break;
1519*4882a593Smuzhiyun 		}
1520*4882a593Smuzhiyun 	} while(config != f_config);
1521*4882a593Smuzhiyun 	if (true == error)
1522*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_FAILURE;
1523*4882a593Smuzhiyun exit:
1524*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_enable_all_twt_by_role(): pstatus:%d\n",
1525*4882a593Smuzhiyun 		pstatus);
1526*4882a593Smuzhiyun 	return pstatus;
1527*4882a593Smuzhiyun }
1528*4882a593Smuzhiyun 
1529*4882a593Smuzhiyun /*
1530*4882a593Smuzhiyun  *  Add twt sta to specifi twt conig entry
1531*4882a593Smuzhiyun  * @phl_sta: sta entry that you wnat to add in specifi twt conig entry
1532*4882a593Smuzhiyun  * @config_id: id of target twt config entry
1533*4882a593Smuzhiyun  * @id: twt flow id/ broadcast twt id
1534*4882a593Smuzhiyun  */
rtw_phl_twt_add_sta_info(void * phl,struct rtw_phl_stainfo_t * phl_sta,u8 config_id,u8 id)1535*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_add_sta_info(void *phl,
1536*4882a593Smuzhiyun 			struct rtw_phl_stainfo_t *phl_sta, u8 config_id, u8 id)
1537*4882a593Smuzhiyun {
1538*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1539*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1540*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
1541*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1542*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
1543*4882a593Smuzhiyun 	struct phl_queue *sta_q = NULL;
1544*4882a593Smuzhiyun 	u16 cnt = 0;
1545*4882a593Smuzhiyun 
1546*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_add_sta_info()\n");
1547*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1548*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_add_sta_info(): twt_sup == false\n");
1549*4882a593Smuzhiyun 		goto fail;
1550*4882a593Smuzhiyun 	}
1551*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1552*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_add_sta_info(): twt_init == false\n");
1553*4882a593Smuzhiyun 		goto fail;
1554*4882a593Smuzhiyun 	}
1555*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
1556*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_info->twt_cfg_info;
1557*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl, twt_cfg_i,
1558*4882a593Smuzhiyun 							PHL_GET_CONFIG_BY_ID,
1559*4882a593Smuzhiyun 							&config_id, &config)) {
1560*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "Fail to get TWT config by id(%d)\n",
1561*4882a593Smuzhiyun 			config_id);
1562*4882a593Smuzhiyun 		goto fail;
1563*4882a593Smuzhiyun 	}
1564*4882a593Smuzhiyun 	sta_q = &config->twt_sta_queue;
1565*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS != _twt_add_sta(phl, phl_sta, sta_q, id)) {
1566*4882a593Smuzhiyun 		goto fail;
1567*4882a593Smuzhiyun 	}
1568*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS != _twt_sta_update(phl_info->hal,
1569*4882a593Smuzhiyun 				phl_sta->macid, config_id, TWT_STA_ADD_MACID)) {
1570*4882a593Smuzhiyun 		_twt_delete_sta(phl, sta_q, phl_sta, id, &cnt);
1571*4882a593Smuzhiyun 		goto fail;
1572*4882a593Smuzhiyun 	}
1573*4882a593Smuzhiyun 	pstatus = RTW_PHL_STATUS_SUCCESS;
1574*4882a593Smuzhiyun fail:
1575*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_add_sta_info(): pstatus:%d\n",
1576*4882a593Smuzhiyun 		pstatus);
1577*4882a593Smuzhiyun 	return pstatus;
1578*4882a593Smuzhiyun }
1579*4882a593Smuzhiyun 
1580*4882a593Smuzhiyun /*
1581*4882a593Smuzhiyun  *  Remove all twt sta from twt config entry by specific sta entry
1582*4882a593Smuzhiyun  * @phl_sta: sta entry that you wnat to remove
1583*4882a593Smuzhiyun  * @bitmap: Output the bitmap. Indicate the statue that twt sta don't exist in the twt config entry that twt sta removed from it.
1584*4882a593Smuzhiyun  * ex: Bitmap=10: We remove the twt sta from id 1, id 3 and other id of twt config entry,
1585*4882a593Smuzhiyun  * but after remove, there are no twt sta existing in the twt config entry of id 1 and id 3.
1586*4882a593Smuzhiyun  * ex: Bitmap=0: We remove the twt sta, after remove, there are at least one twt sta existing in the twt config entry that twt sta removed from it.
1587*4882a593Smuzhiyun  */
rtw_phl_twt_delete_all_sta_info(void * phl,struct rtw_phl_stainfo_t * phl_sta,u8 * bitmap)1588*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_delete_all_sta_info(void *phl,
1589*4882a593Smuzhiyun 				struct rtw_phl_stainfo_t *phl_sta, u8 *bitmap)
1590*4882a593Smuzhiyun {
1591*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1592*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1593*4882a593Smuzhiyun 
1594*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_delete_all_sta_info()\n");
1595*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1596*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_delete_all_sta_info(): twt_sup == false\n");
1597*4882a593Smuzhiyun 		return pstatus;
1598*4882a593Smuzhiyun 	}
1599*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1600*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_delete_all_sta_info(): twt_init == false\n");
1601*4882a593Smuzhiyun 		return pstatus;
1602*4882a593Smuzhiyun 	}
1603*4882a593Smuzhiyun 	pstatus = _twt_delete_sta_info(phl, phl_sta, true, 0, 0, bitmap);
1604*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_delete_all_sta_info(): pstatus:%d, bitmap:0x%x\n",
1605*4882a593Smuzhiyun 		pstatus, *bitmap);
1606*4882a593Smuzhiyun 	return pstatus;
1607*4882a593Smuzhiyun }
1608*4882a593Smuzhiyun 
1609*4882a593Smuzhiyun /*
1610*4882a593Smuzhiyun  * Remove twt sta when tx/rx twt teardown frame
1611*4882a593Smuzhiyun  * @phl_sta: sta entry that you wnat to remove
1612*4882a593Smuzhiyun  * @twt_flow: twt flow field info
1613*4882a593Smuzhiyun  * @bitmap: Output the bitmap. Indicate the statue that twt sta don't exist in the twt config entry that twt sta removed from it.
1614*4882a593Smuzhiyun  * ex: Bitmap=10: We remove the twt sta from id 1, id 3 and other id of twt config entry,
1615*4882a593Smuzhiyun  * but after remove, there are no twt sta existing in the twt config entry of id 1 and id 3.
1616*4882a593Smuzhiyun  * ex: Bitmap=0: We remove the twt sta, after remove, there are at least one twt sta existing in the twt config entry that twt sta removed from it.
1617*4882a593Smuzhiyun  */
rtw_phl_twt_teardown_sta(void * phl,struct rtw_phl_stainfo_t * phl_sta,struct rtw_phl_twt_flow_field * twt_flow,u8 * bitmap)1618*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_teardown_sta(void *phl,
1619*4882a593Smuzhiyun 			struct rtw_phl_stainfo_t *phl_sta,
1620*4882a593Smuzhiyun 			struct rtw_phl_twt_flow_field *twt_flow, u8 *bitmap)
1621*4882a593Smuzhiyun {
1622*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1623*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1624*4882a593Smuzhiyun 	u8 id = 0;
1625*4882a593Smuzhiyun 
1626*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_teardown_sta()\n");
1627*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1628*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_teardown_sta(): twt_sup == false\n");
1629*4882a593Smuzhiyun 		return pstatus;
1630*4882a593Smuzhiyun 	}
1631*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1632*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_teardown_sta(): twt_init == false\n");
1633*4882a593Smuzhiyun 		return pstatus;
1634*4882a593Smuzhiyun 	}
1635*4882a593Smuzhiyun 	if (RTW_PHL_INDIV_TWT == twt_flow->nego_type ||
1636*4882a593Smuzhiyun 		RTW_PHL_WAKE_TBTT_INR == twt_flow->nego_type) {
1637*4882a593Smuzhiyun 		if (twt_flow->info.twt_flow01.teardown_all)
1638*4882a593Smuzhiyun 			id = DELETE_ALL;
1639*4882a593Smuzhiyun 		else
1640*4882a593Smuzhiyun 			id = twt_flow->info.twt_flow01.twt_flow_id;
1641*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
1642*4882a593Smuzhiyun 	} else if (RTW_PHL_BCAST_TWT == twt_flow->nego_type ) {
1643*4882a593Smuzhiyun 		/*Todo*/
1644*4882a593Smuzhiyun 	} else if (RTW_PHL_MANAGE_BCAST_TWT == twt_flow->nego_type) {
1645*4882a593Smuzhiyun 		if (twt_flow->info.twt_flow3.teardown_all)
1646*4882a593Smuzhiyun 			id = DELETE_ALL;
1647*4882a593Smuzhiyun 		else
1648*4882a593Smuzhiyun 			id = twt_flow->info.twt_flow3.bcast_twt_id;
1649*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
1650*4882a593Smuzhiyun 	} else {
1651*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "rtw_phl_twt_teardown_sta(): Unknown nego_type:%d\n",
1652*4882a593Smuzhiyun 			twt_flow->nego_type);
1653*4882a593Smuzhiyun 	}
1654*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS == pstatus) {
1655*4882a593Smuzhiyun 		pstatus = _twt_delete_sta_info(phl, phl_sta, false,
1656*4882a593Smuzhiyun 					twt_flow->nego_type, id, bitmap);
1657*4882a593Smuzhiyun 	}
1658*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_teardown_sta(): pstatus:%d, twt_flow->nego_type:%d, id:%d, bitmap:0x%x\n",
1659*4882a593Smuzhiyun 		pstatus, twt_flow->nego_type, id, *bitmap);
1660*4882a593Smuzhiyun 	return pstatus;
1661*4882a593Smuzhiyun }
1662*4882a593Smuzhiyun 
1663*4882a593Smuzhiyun /*
1664*4882a593Smuzhiyun  * Assign new flow id for twt setup of sta.
1665*4882a593Smuzhiyun  * @phl_sta: the specific sta
1666*4882a593Smuzhiyun  * @role: specific role for search twt config entry
1667*4882a593Smuzhiyun  * @id: Output: twt flow id
1668*4882a593Smuzhiyun  * Note: for sta mode.
1669*4882a593Smuzhiyun  */
rtw_phl_twt_get_new_flow_id(void * phl,struct rtw_phl_stainfo_t * phl_sta,u8 * id)1670*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_get_new_flow_id(void *phl,
1671*4882a593Smuzhiyun 				struct rtw_phl_stainfo_t *phl_sta, u8 *id)
1672*4882a593Smuzhiyun {
1673*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_RESOURCE;
1674*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1675*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
1676*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1677*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL, *f_config = NULL;
1678*4882a593Smuzhiyun 	struct rtw_twt_sta_info *twt_sta = NULL;
1679*4882a593Smuzhiyun 	u8 use_map = 0, unuse_map = 0;
1680*4882a593Smuzhiyun 	u8 i = 0;
1681*4882a593Smuzhiyun 
1682*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_get_new_flow_id()\n");
1683*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1684*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_get_new_flow_id(): twt_sup == false\n");
1685*4882a593Smuzhiyun 		goto exit;
1686*4882a593Smuzhiyun 	}
1687*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1688*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_get_new_flow_id(): twt_init == false\n");
1689*4882a593Smuzhiyun 		goto exit;
1690*4882a593Smuzhiyun 	}
1691*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
1692*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_info->twt_cfg_info;
1693*4882a593Smuzhiyun 	if (false == _twt_new_config_is_available(phl_info))
1694*4882a593Smuzhiyun 		goto exit;
1695*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl, twt_cfg_i,
1696*4882a593Smuzhiyun 				PHL_GET_HEAD_CONFIG, NULL, &config)) {
1697*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_get_new_flow_id(): Fail to get first allocate config\n");
1698*4882a593Smuzhiyun 		goto exit;
1699*4882a593Smuzhiyun 	}
1700*4882a593Smuzhiyun 	f_config = config;
1701*4882a593Smuzhiyun 	do {
1702*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "rtw_phl_twt_get_new_flow_id(): while loop\n");
1703*4882a593Smuzhiyun 		if (twt_config_state_free == config->state)
1704*4882a593Smuzhiyun 			goto next_cfg;
1705*4882a593Smuzhiyun 		if (config->role != phl_sta->wrole ||
1706*4882a593Smuzhiyun 			RTW_PHL_INDIV_TWT != config->twt_info.nego_type)
1707*4882a593Smuzhiyun 			goto next_cfg;
1708*4882a593Smuzhiyun 		twt_sta = _twt_get_sta_info(phl_info, &config->twt_sta_queue,
1709*4882a593Smuzhiyun 						phl_sta);
1710*4882a593Smuzhiyun 		if (NULL != twt_sta) {
1711*4882a593Smuzhiyun 			use_map |= (1 << twt_sta->id);
1712*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "rtw_phl_twt_get_new_flow_id(): config_ID:%d, get match sta, twt_sta->id:%d\n",
1713*4882a593Smuzhiyun 				config->twt_info.twt_id, twt_sta->id);
1714*4882a593Smuzhiyun 		}
1715*4882a593Smuzhiyun next_cfg:
1716*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != _twt_operate_twt_config(phl,
1717*4882a593Smuzhiyun 						twt_cfg_i, PHL_GET_NEXT_CONFIG,
1718*4882a593Smuzhiyun 						(u8 *)&config->idx, &config))
1719*4882a593Smuzhiyun 			goto exit;
1720*4882a593Smuzhiyun 	} while(config != f_config);
1721*4882a593Smuzhiyun 	unuse_map = (~use_map) & 0xFF;
1722*4882a593Smuzhiyun 	i = 0;
1723*4882a593Smuzhiyun 	while ((unuse_map >> i) > 0) {
1724*4882a593Smuzhiyun 		if ((unuse_map >> i) & BIT0) {
1725*4882a593Smuzhiyun 			*id = i;
1726*4882a593Smuzhiyun 			pstatus = RTW_PHL_STATUS_SUCCESS;
1727*4882a593Smuzhiyun 			break;
1728*4882a593Smuzhiyun 		}
1729*4882a593Smuzhiyun 		i++;
1730*4882a593Smuzhiyun 	}
1731*4882a593Smuzhiyun exit:
1732*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_get_new_flow_id(): pstatus:%d, use_map:%d, unuse_map:%d, new_flow_id:%d\n",
1733*4882a593Smuzhiyun 		pstatus, use_map, unuse_map, *id);
1734*4882a593Smuzhiyun 	return pstatus;
1735*4882a593Smuzhiyun }
1736*4882a593Smuzhiyun 
1737*4882a593Smuzhiyun /*
1738*4882a593Smuzhiyun  * get target wake time
1739*4882a593Smuzhiyun  * @port: port num of role
1740*4882a593Smuzhiyun  * @id: reference id of twt configuration
1741*4882a593Smuzhiyun  * @offset: unit: ms. An amount of time that you will start TWT from now
1742*4882a593Smuzhiyun  * @tsf_h: return high 4-byte value of target wake time
1743*4882a593Smuzhiyun  * @tsf_l: return low 4-byte value of target wake time
1744*4882a593Smuzhiyun  */
rtw_phl_twt_get_target_wake_time(void * phl,u8 port,u8 id,u16 offset,u32 * tsf_h,u32 * tsf_l)1745*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_get_target_wake_time(void *phl,
1746*4882a593Smuzhiyun 			u8 port, u8 id, u16 offset, u32 *tsf_h, u32 *tsf_l)
1747*4882a593Smuzhiyun {
1748*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1749*4882a593Smuzhiyun 	enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
1750*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
1751*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
1752*4882a593Smuzhiyun 	struct phl_twt_cfg_info *twt_cfg_i = NULL;
1753*4882a593Smuzhiyun 	struct phl_twt_config *config = NULL;
1754*4882a593Smuzhiyun 	u32 c_tsf_l = 0, c_tsf_h = 0, intvl = 0;
1755*4882a593Smuzhiyun 	u64 cur_tsf = 0, tgt_tsf = 0, ref_tsf = 0, dif_tsf = 0;
1756*4882a593Smuzhiyun 
1757*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_get_target_wake_time()\n");
1758*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
1759*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_get_target_wake_time(): twt_sup == false\n");
1760*4882a593Smuzhiyun 		goto exit;
1761*4882a593Smuzhiyun 	}
1762*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
1763*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_get_target_wake_time(): twt_init == false\n");
1764*4882a593Smuzhiyun 		goto exit;
1765*4882a593Smuzhiyun 	}
1766*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
1767*4882a593Smuzhiyun 	twt_cfg_i = &phl_twt_info->twt_cfg_info;
1768*4882a593Smuzhiyun 	hstatus = rtw_hal_get_tsf(phl_info->hal, port, &c_tsf_h, &c_tsf_l);
1769*4882a593Smuzhiyun 	if (RTW_HAL_STATUS_FAILURE == hstatus) {
1770*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "rtw_phl_twt_get_target_wake_time(): Fail to get tsf, hstatus:%d, port:%d\n",
1771*4882a593Smuzhiyun 		hstatus, port);
1772*4882a593Smuzhiyun 		goto exit;
1773*4882a593Smuzhiyun 	}
1774*4882a593Smuzhiyun 	cur_tsf = c_tsf_h;
1775*4882a593Smuzhiyun 	cur_tsf = cur_tsf << 32;
1776*4882a593Smuzhiyun 	cur_tsf |= c_tsf_l;
1777*4882a593Smuzhiyun 	if (IGNORE_CFG_ID == id) {
1778*4882a593Smuzhiyun 		tgt_tsf = _os_add64(cur_tsf, offset * 1000);
1779*4882a593Smuzhiyun 	} else {
1780*4882a593Smuzhiyun 		pstatus = _twt_operate_twt_config(phl, twt_cfg_i,
1781*4882a593Smuzhiyun 					PHL_GET_CONFIG_BY_ID, &id, &config);
1782*4882a593Smuzhiyun 		if (RTW_PHL_STATUS_SUCCESS != pstatus) {
1783*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "rtw_phl_twt_get_target_wake_time(): Fail to get twt entry by id, pstatus:%d, id:%d\n",
1784*4882a593Smuzhiyun 				pstatus, id);
1785*4882a593Smuzhiyun 			goto exit;
1786*4882a593Smuzhiyun 		}
1787*4882a593Smuzhiyun 		ref_tsf = config->twt_info.target_wake_time_h;
1788*4882a593Smuzhiyun 		ref_tsf = ref_tsf << 32;
1789*4882a593Smuzhiyun 		ref_tsf |= config->twt_info.target_wake_time_l;
1790*4882a593Smuzhiyun 		intvl = _twt_calc_intvl(config->twt_info.twt_wake_int_exp,
1791*4882a593Smuzhiyun 					config->twt_info.twt_wake_int_mantissa);
1792*4882a593Smuzhiyun 		tgt_tsf = _os_add64(cur_tsf, offset * 1000);
1793*4882a593Smuzhiyun 		dif_tsf = _os_minus64(tgt_tsf, ref_tsf);
1794*4882a593Smuzhiyun 		tgt_tsf = _os_minus64(tgt_tsf, _os_modular64(dif_tsf, intvl));
1795*4882a593Smuzhiyun 		tgt_tsf = _os_add64(tgt_tsf, intvl);
1796*4882a593Smuzhiyun 	}
1797*4882a593Smuzhiyun 	*tsf_h = (u32)(tgt_tsf >> 32);
1798*4882a593Smuzhiyun 	*tsf_l = (u32)(tgt_tsf);
1799*4882a593Smuzhiyun 	pstatus = RTW_PHL_STATUS_SUCCESS;
1800*4882a593Smuzhiyun exit:
1801*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_get_target_wake_time(): pstatus(%d), port:%d, twt_id:%d, offset:0x%08x, tsf_h: 0x%08X, tsf_l: 0x%08X\n",
1802*4882a593Smuzhiyun 		pstatus, port, id, offset, *tsf_h, *tsf_l);
1803*4882a593Smuzhiyun 	return pstatus;
1804*4882a593Smuzhiyun }
1805*4882a593Smuzhiyun 
1806*4882a593Smuzhiyun /*
1807*4882a593Smuzhiyun  * Fill twt element
1808*4882a593Smuzhiyun  * @twt_ele: twt element info
1809*4882a593Smuzhiyun  * @buf: fill memory
1810*4882a593Smuzhiyun  * @len: the length of twt element
1811*4882a593Smuzhiyun  */
rtw_phl_twt_fill_twt_element(struct rtw_phl_twt_element * twt_ele,u8 * buf,u8 * len)1812*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_fill_twt_element(
1813*4882a593Smuzhiyun 			struct rtw_phl_twt_element *twt_ele, u8 *buf, u8 *len)
1814*4882a593Smuzhiyun {
1815*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1816*4882a593Smuzhiyun 	u8 twt_para_length = 0;
1817*4882a593Smuzhiyun 	struct rtw_phl_twt_control *twt_ctrl = NULL;
1818*4882a593Smuzhiyun 
1819*4882a593Smuzhiyun 	if (twt_ele == NULL || buf == NULL || len == NULL) {
1820*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_fill_twt_element(): twt_ele or buf or len = NULL\n");
1821*4882a593Smuzhiyun 		return pstatus;
1822*4882a593Smuzhiyun 	}
1823*4882a593Smuzhiyun 	twt_ctrl = &twt_ele->twt_ctrl;
1824*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_fill_twt_element(): twt_ctrl: ndp_paging_indic(%d), responder_pm_mode(%d), nego_type(%d), twt_info_frame_disable(%d), wake_dur_unit(%d)\n",
1825*4882a593Smuzhiyun 		twt_ctrl->ndp_paging_indic, twt_ctrl->responder_pm_mode,
1826*4882a593Smuzhiyun 		twt_ctrl->nego_type, twt_ctrl->twt_info_frame_disable,
1827*4882a593Smuzhiyun 		twt_ctrl->wake_dur_unit);
1828*4882a593Smuzhiyun 	*len = 0;
1829*4882a593Smuzhiyun /*Control filed*/
1830*4882a593Smuzhiyun 	SET_TWT_CONTROL_NDP_PAGING_INDICATOR(buf, twt_ctrl->ndp_paging_indic);
1831*4882a593Smuzhiyun 	SET_TWT_CONTROL_RESPONDER_PM_MODE(buf, twt_ctrl->responder_pm_mode);
1832*4882a593Smuzhiyun 	SET_TWT_CONTROL_NEGOTIATION_TYPE(buf, twt_ctrl->nego_type);
1833*4882a593Smuzhiyun 	SET_TWT_CONTROL_TWT_INFORMATION_FRAME_DISABLE(buf,
1834*4882a593Smuzhiyun 					twt_ctrl->twt_info_frame_disable);
1835*4882a593Smuzhiyun 	SET_TWT_CONTROL_WAKE_DURATION_UNIT(buf, twt_ctrl->wake_dur_unit);
1836*4882a593Smuzhiyun 	*len += CONTROL_LENGTH;
1837*4882a593Smuzhiyun /*TWT Parameter Information*/
1838*4882a593Smuzhiyun 	if (RTW_PHL_INDIV_TWT == twt_ctrl->nego_type) {
1839*4882a593Smuzhiyun 		pstatus = _twt_fill_individual_twt_para_set(
1840*4882a593Smuzhiyun 					&twt_ele->info.i_twt_para_set,
1841*4882a593Smuzhiyun 					twt_ctrl->ndp_paging_indic,
1842*4882a593Smuzhiyun 					buf + *len, &twt_para_length);
1843*4882a593Smuzhiyun 		*len += twt_para_length;
1844*4882a593Smuzhiyun 	} else {
1845*4882a593Smuzhiyun 		/*todo*/
1846*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_fill_twt_element(): not support, todo, twt_ctrl->nego_type(%d)\n",
1847*4882a593Smuzhiyun 			twt_ctrl->nego_type);
1848*4882a593Smuzhiyun 	}
1849*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_fill_twt_element()\n");
1850*4882a593Smuzhiyun 	return pstatus;
1851*4882a593Smuzhiyun }
1852*4882a593Smuzhiyun 
1853*4882a593Smuzhiyun /*
1854*4882a593Smuzhiyun  * Fill twt flow field of TWT teardown frame
1855*4882a593Smuzhiyun  * @twt_flow: twt flow field info
1856*4882a593Smuzhiyun  * @buf: fill memory
1857*4882a593Smuzhiyun  * @length: the length of twt flow field
1858*4882a593Smuzhiyun  */
rtw_phl_twt_fill_flow_field(struct rtw_phl_twt_flow_field * twt_flow,u8 * buf,u16 * length)1859*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_fill_flow_field(
1860*4882a593Smuzhiyun 		struct rtw_phl_twt_flow_field *twt_flow, u8 *buf, u16 *length)
1861*4882a593Smuzhiyun {
1862*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1863*4882a593Smuzhiyun 
1864*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_fill_flow_field()\n");
1865*4882a593Smuzhiyun 	if (twt_flow == NULL || buf == NULL || length == NULL) {
1866*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_fill_flow_field(): twt_flow or buf or length = NULL\n");
1867*4882a593Smuzhiyun 		return pstatus;
1868*4882a593Smuzhiyun 	}
1869*4882a593Smuzhiyun 	*length = 0;
1870*4882a593Smuzhiyun 	if (RTW_PHL_INDIV_TWT == twt_flow->nego_type ||
1871*4882a593Smuzhiyun 		RTW_PHL_WAKE_TBTT_INR == twt_flow->nego_type) {
1872*4882a593Smuzhiyun 		struct rtw_phl_twt_flow_type01 *flow_info =
1873*4882a593Smuzhiyun 						&twt_flow->info.twt_flow01;
1874*4882a593Smuzhiyun 		SET_TWT_FLOW_ID(buf, flow_info->twt_flow_id);
1875*4882a593Smuzhiyun 		SET_NEGOTIATION_TYPE(buf, twt_flow->nego_type);
1876*4882a593Smuzhiyun 		SET_TEARDOWN_ALL_TWT(buf, flow_info->teardown_all);
1877*4882a593Smuzhiyun 		*length = TWT_FLOW_FIELD_LENGTH;
1878*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
1879*4882a593Smuzhiyun 	} else if (RTW_PHL_BCAST_TWT  == twt_flow->nego_type) {
1880*4882a593Smuzhiyun 		SET_NEGOTIATION_TYPE(buf, twt_flow->nego_type);
1881*4882a593Smuzhiyun 		*length = TWT_FLOW_FIELD_LENGTH;
1882*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
1883*4882a593Smuzhiyun 	} else if (RTW_PHL_MANAGE_BCAST_TWT == twt_flow->nego_type) {
1884*4882a593Smuzhiyun 		struct rtw_phl_twt_flow_type3 *flow_info =
1885*4882a593Smuzhiyun 						&twt_flow->info.twt_flow3;
1886*4882a593Smuzhiyun 		SET_BROADCAST_TWT_ID(buf, flow_info->bcast_twt_id);
1887*4882a593Smuzhiyun 		SET_NEGOTIATION_TYPE(buf, twt_flow->nego_type);
1888*4882a593Smuzhiyun 		SET_TEARDOWN_ALL_TWT(buf, flow_info->teardown_all);
1889*4882a593Smuzhiyun 		*length = TWT_FLOW_FIELD_LENGTH;
1890*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
1891*4882a593Smuzhiyun 	} else {
1892*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_fill_flow_field(): Unknown type(%d)\n",
1893*4882a593Smuzhiyun 			twt_flow->nego_type);
1894*4882a593Smuzhiyun 	}
1895*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_fill_flow_field()\n");
1896*4882a593Smuzhiyun 	return pstatus;
1897*4882a593Smuzhiyun }
1898*4882a593Smuzhiyun 
1899*4882a593Smuzhiyun /*
1900*4882a593Smuzhiyun  * Parse twt element from pkt
1901*4882a593Smuzhiyun  * @twt_ele: the address of twt elemant
1902*4882a593Smuzhiyun  * @length: length of pkt
1903*4882a593Smuzhiyun  * @twt_element: Parse info
1904*4882a593Smuzhiyun  */
rtw_phl_twt_parse_element(u8 * twt_ele,u16 length,struct rtw_phl_twt_element * twt_element)1905*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_parse_element(u8 *twt_ele, u16 length,
1906*4882a593Smuzhiyun 				struct rtw_phl_twt_element *twt_element)
1907*4882a593Smuzhiyun {
1908*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1909*4882a593Smuzhiyun 	struct rtw_phl_twt_control *twt_ctrl = NULL;
1910*4882a593Smuzhiyun 	u8 ele_len = 0, ele_id = 0;
1911*4882a593Smuzhiyun 	u8 *next_buf = twt_ele;
1912*4882a593Smuzhiyun 
1913*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_parse_element()\n");
1914*4882a593Smuzhiyun 	if (twt_ele == NULL || twt_element == NULL) {
1915*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_parse_element(): twt_ele or twt_element = NULL\n");
1916*4882a593Smuzhiyun 		return pstatus;
1917*4882a593Smuzhiyun 	}
1918*4882a593Smuzhiyun 	twt_ctrl = &twt_element->twt_ctrl;
1919*4882a593Smuzhiyun 	if (length < (MIN_TWT_ELE_LEN + ELEM_ID_LEN + ELEM_LEN_LEN)) {
1920*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "rtw_phl_twt_parse_element(): error buffer length(%d) < %d\n",
1921*4882a593Smuzhiyun 			length, (MIN_TWT_ELE_LEN + ELEM_ID_LEN + ELEM_LEN_LEN));
1922*4882a593Smuzhiyun 		goto exit;
1923*4882a593Smuzhiyun 	}
1924*4882a593Smuzhiyun 	ele_id = GET_ELE_ID(next_buf);
1925*4882a593Smuzhiyun 	next_buf += ELEM_ID_LEN;
1926*4882a593Smuzhiyun 	ele_len = GET_ELE_LEN(next_buf);
1927*4882a593Smuzhiyun 	next_buf += ELEM_LEN_LEN;
1928*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "rtw_phl_twt_parse_element(): ele_id:%d, ele_len:%d, length:%d\n",
1929*4882a593Smuzhiyun 		ele_id, ele_len, length);
1930*4882a593Smuzhiyun 	if (ele_len < MIN_TWT_ELE_LEN) {
1931*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_WARNING_, "rtw_phl_twt_parse_element(): error ele length(%d) < %d\n",
1932*4882a593Smuzhiyun 			ele_len, MIN_TWT_ELE_LEN);
1933*4882a593Smuzhiyun 		goto exit;
1934*4882a593Smuzhiyun 	}
1935*4882a593Smuzhiyun 	twt_ctrl->ndp_paging_indic =
1936*4882a593Smuzhiyun 				GET_TWT_CONTROL_NDP_PAGING_INDICATOR(next_buf);
1937*4882a593Smuzhiyun 	twt_ctrl->responder_pm_mode =
1938*4882a593Smuzhiyun 				GET_TWT_CONTROL_RESPONDER_PM_MODE(next_buf);
1939*4882a593Smuzhiyun 	twt_ctrl->nego_type = GET_TWT_CONTROL_NEGOTIATION_TYPE(next_buf);
1940*4882a593Smuzhiyun 	twt_ctrl->twt_info_frame_disable =
1941*4882a593Smuzhiyun 			GET_TWT_CONTROL_TWT_INFORMATION_FRAME_DISABLE(next_buf);
1942*4882a593Smuzhiyun 	twt_ctrl->wake_dur_unit = GET_TWT_CONTROL_WAKE_DURATION_UNIT(next_buf);
1943*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "rtw_phl_twt_parse_element(): twt_ctrl: ndp_paging_indic(%d), responder_pm_mode(%d), nego_type(%d), twt_info_frame_disable(%d), wake_dur_unit(%d)\n",
1944*4882a593Smuzhiyun 		twt_ctrl->ndp_paging_indic, twt_ctrl->responder_pm_mode,
1945*4882a593Smuzhiyun 		twt_ctrl->nego_type, twt_ctrl->twt_info_frame_disable,
1946*4882a593Smuzhiyun 		twt_ctrl->wake_dur_unit);
1947*4882a593Smuzhiyun 	if (RTW_PHL_INDIV_TWT == twt_ctrl->nego_type) {
1948*4882a593Smuzhiyun 		pstatus = _twt_parse_individual_twt_para(twt_ele, length,
1949*4882a593Smuzhiyun 							twt_element);
1950*4882a593Smuzhiyun 	} else {
1951*4882a593Smuzhiyun 		/*todo*/
1952*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_parse_element(): not support, todo, twt_ctrl->nego_type(%d)\n",
1953*4882a593Smuzhiyun 			twt_ctrl->nego_type);
1954*4882a593Smuzhiyun 	}
1955*4882a593Smuzhiyun exit:
1956*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_parse_element(): pstatus(%d)\n",
1957*4882a593Smuzhiyun 		pstatus);
1958*4882a593Smuzhiyun 	return pstatus;
1959*4882a593Smuzhiyun }
1960*4882a593Smuzhiyun 
1961*4882a593Smuzhiyun /*
1962*4882a593Smuzhiyun  * Parse twt setup info from pkt
1963*4882a593Smuzhiyun  * @pkt: the address of Category of twt setup info frame
1964*4882a593Smuzhiyun  * @length: length of pkt
1965*4882a593Smuzhiyun  * @twt_setup_info: Parse info
1966*4882a593Smuzhiyun  */
rtw_phl_twt_parse_setup_info(u8 * pkt,u16 length,struct rtw_phl_twt_setup_info * setup_info)1967*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_parse_setup_info(u8 *pkt, u16 length,
1968*4882a593Smuzhiyun 				struct rtw_phl_twt_setup_info *setup_info)
1969*4882a593Smuzhiyun {
1970*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1971*4882a593Smuzhiyun 	u8 *twt_ele = NULL;
1972*4882a593Smuzhiyun 	u16 ele_length = length - TOKEN_OFFSET- TOKEN_LENGTH;
1973*4882a593Smuzhiyun 
1974*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_parse_setup_info()\n");
1975*4882a593Smuzhiyun 	if (pkt == NULL || setup_info == NULL) {
1976*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_parse_setup_info(): pkt or setup_info = NULL\n");
1977*4882a593Smuzhiyun 		return pstatus;
1978*4882a593Smuzhiyun 	}
1979*4882a593Smuzhiyun 	twt_ele = pkt + TOKEN_OFFSET + TOKEN_LENGTH;
1980*4882a593Smuzhiyun 	setup_info->dialog_token = GET_DIALOG_TOKEN(pkt + TOKEN_OFFSET);
1981*4882a593Smuzhiyun 	pstatus = rtw_phl_twt_parse_element(twt_ele, ele_length,
1982*4882a593Smuzhiyun 						&setup_info->twt_element);
1983*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_parse_setup_info(): pstatus(%d)\n",
1984*4882a593Smuzhiyun 		pstatus);
1985*4882a593Smuzhiyun 	return pstatus;
1986*4882a593Smuzhiyun }
1987*4882a593Smuzhiyun 
1988*4882a593Smuzhiyun /*
1989*4882a593Smuzhiyun  * Parse twt twt flow field from twt teardown frame
1990*4882a593Smuzhiyun  * @pkt: the address of twt flow field
1991*4882a593Smuzhiyun  * @length: length of pkt
1992*4882a593Smuzhiyun  * @twt_flow_info: Parse info
1993*4882a593Smuzhiyun  */
rtw_phl_twt_parse_flow_field(u8 * pkt,u16 length,struct rtw_phl_twt_flow_field * twt_flow)1994*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_parse_flow_field(u8 *pkt, u16 length,
1995*4882a593Smuzhiyun 				struct rtw_phl_twt_flow_field *twt_flow)
1996*4882a593Smuzhiyun {
1997*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
1998*4882a593Smuzhiyun 
1999*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_parse_flow_field()\n");
2000*4882a593Smuzhiyun 	if (pkt == NULL || twt_flow == NULL) {
2001*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_parse_flow_field(): pkt or twt_flow = NULL\n");
2002*4882a593Smuzhiyun 		return pstatus;
2003*4882a593Smuzhiyun 	}
2004*4882a593Smuzhiyun 	twt_flow->nego_type = GET_NEGOTIATION_TYPE(pkt);
2005*4882a593Smuzhiyun 	if (RTW_PHL_INDIV_TWT == twt_flow->nego_type ||
2006*4882a593Smuzhiyun 		RTW_PHL_WAKE_TBTT_INR == twt_flow->nego_type) {
2007*4882a593Smuzhiyun 		struct rtw_phl_twt_flow_type01 *flow_info =
2008*4882a593Smuzhiyun 						&twt_flow->info.twt_flow01;
2009*4882a593Smuzhiyun 		flow_info->twt_flow_id = GET_TWT_FLOW_ID(pkt);
2010*4882a593Smuzhiyun 		flow_info->teardown_all = GET_TEARDOWN_ALL_TWT(pkt);
2011*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "rtw_phl_twt_parse_flow_field(): nego_type:%d, twt_flow_id:%d, teardown_all:%d\n",
2012*4882a593Smuzhiyun 			twt_flow->nego_type, flow_info->twt_flow_id,
2013*4882a593Smuzhiyun 			flow_info->teardown_all);
2014*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
2015*4882a593Smuzhiyun 	} else if (RTW_PHL_BCAST_TWT == twt_flow->nego_type) {
2016*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_parse_flow_field(): not support, todo, twt_flow->nego_type(%d)\n",
2017*4882a593Smuzhiyun 			twt_flow->nego_type);
2018*4882a593Smuzhiyun 	} else if (RTW_PHL_MANAGE_BCAST_TWT == twt_flow->nego_type) {
2019*4882a593Smuzhiyun 		struct rtw_phl_twt_flow_type3 *flow_info =
2020*4882a593Smuzhiyun 						&twt_flow->info.twt_flow3;
2021*4882a593Smuzhiyun 		flow_info->bcast_twt_id = GET_BROADCAST_TWT_ID(pkt);
2022*4882a593Smuzhiyun 		flow_info->teardown_all = GET_TEARDOWN_ALL_TWT(pkt);
2023*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "rtw_phl_twt_parse_flow_field(): nego_type:%d, bcast_twt_id:%d, teardown_all:%d\n",
2024*4882a593Smuzhiyun 			twt_flow->nego_type, flow_info->bcast_twt_id,
2025*4882a593Smuzhiyun 			flow_info->teardown_all);
2026*4882a593Smuzhiyun 		pstatus = RTW_PHL_STATUS_SUCCESS;
2027*4882a593Smuzhiyun 	} else {
2028*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_parse_flow_field(): Unknown type, twt_flow->nego_type(%d)\n",
2029*4882a593Smuzhiyun 			twt_flow->nego_type);
2030*4882a593Smuzhiyun 	}
2031*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_parse_flow_field(): pstatus(%d)\n",
2032*4882a593Smuzhiyun 		pstatus);
2033*4882a593Smuzhiyun 	return pstatus;
2034*4882a593Smuzhiyun }
2035*4882a593Smuzhiyun 
2036*4882a593Smuzhiyun /*
2037*4882a593Smuzhiyun  * Tell fw which macid is announced in awake state
2038*4882a593Smuzhiyun  * @macid: macid of sta that is in awake state
2039*4882a593Smuzhiyun  */
rtw_phl_twt_sta_announce_to_fw(void * phl,u16 macid)2040*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_sta_announce_to_fw(void *phl,
2041*4882a593Smuzhiyun 				u16 macid)
2042*4882a593Smuzhiyun {
2043*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
2044*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2045*4882a593Smuzhiyun 	struct phl_twt_info *phl_twt_info = NULL;
2046*4882a593Smuzhiyun 	struct phl_queue *annc_q = NULL;
2047*4882a593Smuzhiyun 
2048*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_sta_announce_to_fw()\n");
2049*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
2050*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_sta_announce_to_fw(): twt_sup == false\n");
2051*4882a593Smuzhiyun 		return pstatus;
2052*4882a593Smuzhiyun 	}
2053*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
2054*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_sta_announce_to_fw(): twt_init == false\n");
2055*4882a593Smuzhiyun 		return pstatus;
2056*4882a593Smuzhiyun 	}
2057*4882a593Smuzhiyun 	phl_twt_info = get_twt_info(phl_info);
2058*4882a593Smuzhiyun 	annc_q = &phl_twt_info->twt_annc_queue;
2059*4882a593Smuzhiyun 	pstatus = _twt_sta_announce(phl_info, annc_q, macid);
2060*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_sta_announce_to_fw(): pstatus:%d, macid: %d\n",
2061*4882a593Smuzhiyun 		pstatus, macid);
2062*4882a593Smuzhiyun 	return pstatus;
2063*4882a593Smuzhiyun }
2064*4882a593Smuzhiyun 
2065*4882a593Smuzhiyun #if 0
2066*4882a593Smuzhiyun /*
2067*4882a593Smuzhiyun  * Handle twt c2h
2068*4882a593Smuzhiyun  * @c: c2h content
2069*4882a593Smuzhiyun  */
2070*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_handle_c2h(void *phl_com, void *c)
2071*4882a593Smuzhiyun {
2072*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
2073*4882a593Smuzhiyun 	struct rtw_phl_com_t *phl_com_info= (struct rtw_phl_com_t *)phl_com;
2074*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t*)phl_com_info->phl_priv;
2075*4882a593Smuzhiyun 	struct rtw_c2h_info *c2h = (struct rtw_c2h_info *)c;
2076*4882a593Smuzhiyun 
2077*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
2078*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_handle_c2h(): twt_sup == false\n");
2079*4882a593Smuzhiyun 		return pstatus;
2080*4882a593Smuzhiyun 	}
2081*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
2082*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_handle_c2h(): twt_init == false\n");
2083*4882a593Smuzhiyun 		return pstatus;
2084*4882a593Smuzhiyun 	}
2085*4882a593Smuzhiyun 	if (C2H_FUN_WAIT_ANNC == c2h->c2h_func) {
2086*4882a593Smuzhiyun 		pstatus = _twt_handle_c2h_wait_annc(phl_info, c2h->content);
2087*4882a593Smuzhiyun 	}
2088*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "rtw_phl_twt_handle_c2h(): pstatus:%d cat:%d, class:%d, func:%d, len:%d, content:0x%x\n",
2089*4882a593Smuzhiyun 		pstatus, c2h->c2h_cat, c2h->c2h_class, c2h->c2h_func,
2090*4882a593Smuzhiyun 		c2h->content_len, *(c2h->content));
2091*4882a593Smuzhiyun 	return pstatus;
2092*4882a593Smuzhiyun }
2093*4882a593Smuzhiyun #endif
2094*4882a593Smuzhiyun 
2095*4882a593Smuzhiyun /*
2096*4882a593Smuzhiyun  * Handle sta to config twt when sta accept the twt agreement
2097*4882a593Smuzhiyun  * @phl_sta: sta entry that you wnat to config twt
2098*4882a593Smuzhiyun  * @setup_info: twt setup info
2099*4882a593Smuzhiyun  * @id: Output the id of twt confi entry
2100*4882a593Smuzhiyun  * Note: for sta mode
2101*4882a593Smuzhiyun  */
rtw_phl_twt_accept_for_sta_mode(void * phl,struct rtw_phl_stainfo_t * phl_sta,struct rtw_phl_twt_setup_info * setup_info,u8 * id)2102*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_accept_for_sta_mode(void *phl,
2103*4882a593Smuzhiyun 			struct rtw_phl_stainfo_t *phl_sta,
2104*4882a593Smuzhiyun 			struct rtw_phl_twt_setup_info *setup_info, u8 *id)
2105*4882a593Smuzhiyun {
2106*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
2107*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2108*4882a593Smuzhiyun 	struct rtw_phl_twt_element *element = &setup_info->twt_element;
2109*4882a593Smuzhiyun 	struct rtw_phl_twt_control *twt_ctrl =&element->twt_ctrl;
2110*4882a593Smuzhiyun 
2111*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_accept_for_sta_mode()\n");
2112*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
2113*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_accept_for_sta_mode(): twt_sup == false\n");
2114*4882a593Smuzhiyun 		return pstatus;
2115*4882a593Smuzhiyun 	}
2116*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
2117*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_accept_for_sta_mode(): twt_init == false\n");
2118*4882a593Smuzhiyun 		return pstatus;
2119*4882a593Smuzhiyun 	}
2120*4882a593Smuzhiyun 	if (RTW_PHL_INDIV_TWT == twt_ctrl->nego_type) {
2121*4882a593Smuzhiyun 		pstatus = _twt_accept_indiv_by_sta(phl_info, setup_info, phl_sta, id);
2122*4882a593Smuzhiyun 	} else {
2123*4882a593Smuzhiyun 		pstatus = _twt_accept_bcast_by_sta(phl_info, setup_info, phl_sta, id);
2124*4882a593Smuzhiyun 	}
2125*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_accept_for_sta_mode(): pstatus:%d, config_id:%d\n",
2126*4882a593Smuzhiyun 		pstatus, *id);
2127*4882a593Smuzhiyun 	return pstatus;
2128*4882a593Smuzhiyun }
2129*4882a593Smuzhiyun 
2130*4882a593Smuzhiyun /*
2131*4882a593Smuzhiyun  * Handle sta to disable twt when sta tx/rx twt teardown frame
2132*4882a593Smuzhiyun  * @phl_sta: sta entry that you wnat to config twt
2133*4882a593Smuzhiyun  * @twt_flow: twt flow field info
2134*4882a593Smuzhiyun  * Note: for sta mode.
2135*4882a593Smuzhiyun  */
rtw_phl_twt_teardown_for_sta_mode(void * phl,struct rtw_phl_stainfo_t * phl_sta,struct rtw_phl_twt_flow_field * twt_flow)2136*4882a593Smuzhiyun enum rtw_phl_status rtw_phl_twt_teardown_for_sta_mode(void *phl,
2137*4882a593Smuzhiyun 				struct rtw_phl_stainfo_t *phl_sta,
2138*4882a593Smuzhiyun 				struct rtw_phl_twt_flow_field *twt_flow)
2139*4882a593Smuzhiyun {
2140*4882a593Smuzhiyun 	enum rtw_phl_status pstatus = RTW_PHL_STATUS_FAILURE;
2141*4882a593Smuzhiyun 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
2142*4882a593Smuzhiyun 	u8 bitmap =0; /*bitmap of empty config of twt*/
2143*4882a593Smuzhiyun 	u8 i = 0;
2144*4882a593Smuzhiyun 
2145*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "==> rtw_phl_twt_teardown_for_sta_mode()\n");
2146*4882a593Smuzhiyun 	if (false == twt_sup(phl_info)) {
2147*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_teardown_for_sta_mode(): twt_sup == false\n");
2148*4882a593Smuzhiyun 		goto exit;
2149*4882a593Smuzhiyun 	}
2150*4882a593Smuzhiyun 	if (false == twt_init(phl_info)) {
2151*4882a593Smuzhiyun 		PHL_TRACE(COMP_PHL_TWT, _PHL_ERR_, "rtw_phl_twt_teardown_for_sta_mode(): twt_init == false\n");
2152*4882a593Smuzhiyun 		goto exit;
2153*4882a593Smuzhiyun 	}
2154*4882a593Smuzhiyun 	pstatus = rtw_phl_twt_teardown_sta(phl, phl_sta, twt_flow, &bitmap);
2155*4882a593Smuzhiyun 	if (RTW_PHL_STATUS_SUCCESS != pstatus)
2156*4882a593Smuzhiyun 		goto exit;
2157*4882a593Smuzhiyun 	if (bitmap == 0)
2158*4882a593Smuzhiyun 		goto exit;
2159*4882a593Smuzhiyun 	i = 0;
2160*4882a593Smuzhiyun 	do {
2161*4882a593Smuzhiyun 		if (((bitmap >> i) & BIT0)) {
2162*4882a593Smuzhiyun 			pstatus = rtw_phl_twt_free_twt_config(phl, i);
2163*4882a593Smuzhiyun 			PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "rtw_phl_twt_teardown_for_sta_mode():sta Q is empty in twt config entry(%d), we free it, pstatus:%d \n",
2164*4882a593Smuzhiyun 				i, pstatus);
2165*4882a593Smuzhiyun 		}
2166*4882a593Smuzhiyun 		i++;
2167*4882a593Smuzhiyun 	} while ((bitmap >> i) != 0);
2168*4882a593Smuzhiyun exit:
2169*4882a593Smuzhiyun 	PHL_TRACE(COMP_PHL_TWT, _PHL_INFO_, "<== rtw_phl_twt_teardown_for_sta_mode(): pstatus(%d)\n",
2170*4882a593Smuzhiyun 		pstatus);
2171*4882a593Smuzhiyun 	return pstatus;
2172*4882a593Smuzhiyun }
2173*4882a593Smuzhiyun #endif /* CONFIG_PHL_TWT */
2174