xref: /wlan-driver/qca-wifi-host-cmn/wmi/src/wmi_unified_11be_tlv.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2021, The Linux Foundation. All rights reserved.
3*5113495bSYour Name  * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name  *
5*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for any
6*5113495bSYour Name  * purpose with or without fee is hereby granted, provided that the above
7*5113495bSYour Name  * copyright notice and this permission notice appear in all copies.
8*5113495bSYour Name  *
9*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*5113495bSYour Name  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*5113495bSYour Name  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*5113495bSYour Name  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*5113495bSYour Name  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*5113495bSYour Name  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*5113495bSYour Name  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*5113495bSYour Name  */
17*5113495bSYour Name 
18*5113495bSYour Name #include <osdep.h>
19*5113495bSYour Name #include "wmi.h"
20*5113495bSYour Name #include "wmi_unified_priv.h"
21*5113495bSYour Name #include "wmi_unified_api.h"
22*5113495bSYour Name #ifdef WLAN_MLO_MULTI_CHIP
23*5113495bSYour Name #include "wmi_unified_11be_setup_api.h"
24*5113495bSYour Name #endif
25*5113495bSYour Name #include "wmi_unified_11be_tlv.h"
26*5113495bSYour Name 
vdev_create_mlo_params_size(struct vdev_create_params * param)27*5113495bSYour Name size_t vdev_create_mlo_params_size(struct vdev_create_params *param)
28*5113495bSYour Name {
29*5113495bSYour Name 	if (qdf_is_macaddr_zero((struct qdf_mac_addr *)param->mlo_mac))
30*5113495bSYour Name 		return WMI_TLV_HDR_SIZE;
31*5113495bSYour Name 
32*5113495bSYour Name 	return sizeof(wmi_vdev_create_mlo_params) + WMI_TLV_HDR_SIZE;
33*5113495bSYour Name }
34*5113495bSYour Name 
vdev_create_add_mlo_params(uint8_t * buf_ptr,struct vdev_create_params * param)35*5113495bSYour Name uint8_t *vdev_create_add_mlo_params(uint8_t *buf_ptr,
36*5113495bSYour Name 				    struct vdev_create_params *param)
37*5113495bSYour Name {
38*5113495bSYour Name 	wmi_vdev_create_mlo_params *mlo_params;
39*5113495bSYour Name 
40*5113495bSYour Name 	if (qdf_is_macaddr_zero((struct qdf_mac_addr *)param->mlo_mac)) {
41*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, 0);
42*5113495bSYour Name 		return buf_ptr + WMI_TLV_HDR_SIZE;
43*5113495bSYour Name 	}
44*5113495bSYour Name 
45*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
46*5113495bSYour Name 		       sizeof(wmi_vdev_create_mlo_params));
47*5113495bSYour Name 	buf_ptr += sizeof(uint32_t);
48*5113495bSYour Name 
49*5113495bSYour Name 	mlo_params = (wmi_vdev_create_mlo_params *)buf_ptr;
50*5113495bSYour Name 	WMITLV_SET_HDR(&mlo_params->tlv_header,
51*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_vdev_create_mlo_params,
52*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_vdev_create_mlo_params));
53*5113495bSYour Name 
54*5113495bSYour Name 	WMI_CHAR_ARRAY_TO_MAC_ADDR(param->mlo_mac, &mlo_params->mld_macaddr);
55*5113495bSYour Name 
56*5113495bSYour Name 	wmi_debug("MLD Addr = "QDF_MAC_ADDR_FMT,
57*5113495bSYour Name 		  QDF_MAC_ADDR_REF(param->mlo_mac));
58*5113495bSYour Name 	return buf_ptr + sizeof(wmi_vdev_create_mlo_params);
59*5113495bSYour Name }
60*5113495bSYour Name 
vdev_start_mlo_params_size(struct vdev_start_params * req)61*5113495bSYour Name size_t vdev_start_mlo_params_size(struct vdev_start_params *req)
62*5113495bSYour Name {
63*5113495bSYour Name 	size_t vdev_start_mlo_size;
64*5113495bSYour Name 
65*5113495bSYour Name 	vdev_start_mlo_size = sizeof(wmi_vdev_start_mlo_params) +
66*5113495bSYour Name 			      WMI_TLV_HDR_SIZE +
67*5113495bSYour Name 			      (req->mlo_partner.num_links *
68*5113495bSYour Name 			      sizeof(wmi_partner_link_params)) +
69*5113495bSYour Name 			      WMI_TLV_HDR_SIZE;
70*5113495bSYour Name 
71*5113495bSYour Name 	return vdev_start_mlo_size;
72*5113495bSYour Name }
73*5113495bSYour Name 
74*5113495bSYour Name #ifdef WLAN_MCAST_MLO
vdev_start_add_mlo_mcast_params(uint32_t * mlo_flags,struct vdev_start_params * req)75*5113495bSYour Name static void vdev_start_add_mlo_mcast_params(uint32_t *mlo_flags,
76*5113495bSYour Name 					    struct vdev_start_params *req)
77*5113495bSYour Name {
78*5113495bSYour Name 	WMI_MLO_FLAGS_SET_MCAST_VDEV(*mlo_flags,
79*5113495bSYour Name 				     req->mlo_flags.mlo_mcast_vdev);
80*5113495bSYour Name }
81*5113495bSYour Name #else
82*5113495bSYour Name #define vdev_start_add_mlo_mcast_params(mlo_flags, req)
83*5113495bSYour Name #endif
84*5113495bSYour Name 
vdev_start_add_mlo_params(uint8_t * buf_ptr,struct vdev_start_params * req)85*5113495bSYour Name uint8_t *vdev_start_add_mlo_params(uint8_t *buf_ptr,
86*5113495bSYour Name 				   struct vdev_start_params *req)
87*5113495bSYour Name {
88*5113495bSYour Name 	wmi_vdev_start_mlo_params *mlo_params;
89*5113495bSYour Name 
90*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
91*5113495bSYour Name 		       sizeof(wmi_vdev_start_mlo_params));
92*5113495bSYour Name 	buf_ptr += sizeof(uint32_t);
93*5113495bSYour Name 
94*5113495bSYour Name 	mlo_params = (wmi_vdev_start_mlo_params *)buf_ptr;
95*5113495bSYour Name 	WMITLV_SET_HDR(&mlo_params->tlv_header,
96*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_vdev_start_mlo_params,
97*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_vdev_start_mlo_params));
98*5113495bSYour Name 
99*5113495bSYour Name 	mlo_params->mlo_flags.mlo_flags = 0;
100*5113495bSYour Name 	WMI_MLO_FLAGS_SET_ENABLED(mlo_params->mlo_flags.mlo_flags,
101*5113495bSYour Name 				  req->mlo_flags.mlo_enabled);
102*5113495bSYour Name 	WMI_MLO_FLAGS_SET_ASSOC_LINK(mlo_params->mlo_flags.mlo_flags,
103*5113495bSYour Name 				     req->mlo_flags.mlo_assoc_link);
104*5113495bSYour Name 	WMI_MLO_FLAGS_SET_LINK_ADD(mlo_params->mlo_flags.mlo_flags,
105*5113495bSYour Name 				   req->mlo_flags.mlo_link_add);
106*5113495bSYour Name 	mlo_params->mlo_flags.emlsr_support = req->mlo_flags.emlsr_support;
107*5113495bSYour Name 
108*5113495bSYour Name 	vdev_start_add_mlo_mcast_params(&mlo_params->mlo_flags.mlo_flags,
109*5113495bSYour Name 					req);
110*5113495bSYour Name 
111*5113495bSYour Name 	wmi_info("mlo_flags 0x%x emlsr_support %d ",
112*5113495bSYour Name 		 mlo_params->mlo_flags.mlo_flags,
113*5113495bSYour Name 		 mlo_params->mlo_flags.emlsr_support);
114*5113495bSYour Name 
115*5113495bSYour Name 	return buf_ptr + sizeof(wmi_vdev_start_mlo_params);
116*5113495bSYour Name }
117*5113495bSYour Name 
vdev_start_add_ml_partner_links(uint8_t * buf_ptr,struct vdev_start_params * req)118*5113495bSYour Name uint8_t *vdev_start_add_ml_partner_links(uint8_t *buf_ptr,
119*5113495bSYour Name 					 struct vdev_start_params *req)
120*5113495bSYour Name {
121*5113495bSYour Name 	wmi_partner_link_params *ml_partner_link;
122*5113495bSYour Name 	struct mlo_vdev_start_partner_links *req_partner;
123*5113495bSYour Name 	uint8_t i;
124*5113495bSYour Name 
125*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
126*5113495bSYour Name 		      (req->mlo_partner.num_links *
127*5113495bSYour Name 		      sizeof(wmi_partner_link_params)));
128*5113495bSYour Name 	buf_ptr += sizeof(uint32_t);
129*5113495bSYour Name 
130*5113495bSYour Name 	req_partner = &req->mlo_partner;
131*5113495bSYour Name 	ml_partner_link = (wmi_partner_link_params *)buf_ptr;
132*5113495bSYour Name 	for (i = 0; i < req->mlo_partner.num_links; i++) {
133*5113495bSYour Name 		WMITLV_SET_HDR(&ml_partner_link->tlv_header,
134*5113495bSYour Name 			       WMITLV_TAG_STRUC_wmi_partner_link_params,
135*5113495bSYour Name 			       WMITLV_GET_STRUCT_TLVLEN(wmi_partner_link_params));
136*5113495bSYour Name 		ml_partner_link->vdev_id = req_partner->partner_info[i].vdev_id;
137*5113495bSYour Name 		ml_partner_link->hw_link_id =
138*5113495bSYour Name 				req_partner->partner_info[i].hw_mld_link_id;
139*5113495bSYour Name 		WMI_CHAR_ARRAY_TO_MAC_ADDR(req_partner->partner_info[i].mac_addr,
140*5113495bSYour Name 					   &ml_partner_link->vdev_macaddr);
141*5113495bSYour Name 		wmi_info("vdev_id %d hw_link_id %d MAC addr " QDF_MAC_ADDR_FMT,
142*5113495bSYour Name 			 ml_partner_link->vdev_id,
143*5113495bSYour Name 			 ml_partner_link->hw_link_id,
144*5113495bSYour Name 			 QDF_MAC_ADDR_REF(req_partner->partner_info[i].mac_addr));
145*5113495bSYour Name 		ml_partner_link++;
146*5113495bSYour Name 	}
147*5113495bSYour Name 
148*5113495bSYour Name 	return buf_ptr +
149*5113495bSYour Name 		(req->mlo_partner.num_links *
150*5113495bSYour Name 		 sizeof(wmi_partner_link_params));
151*5113495bSYour Name }
152*5113495bSYour Name 
bcn_tmpl_mlo_param_size(struct beacon_tmpl_params * param)153*5113495bSYour Name size_t bcn_tmpl_mlo_param_size(struct beacon_tmpl_params *param)
154*5113495bSYour Name {
155*5113495bSYour Name 	return WMI_TLV_HDR_SIZE;
156*5113495bSYour Name }
157*5113495bSYour Name 
bcn_tmpl_add_ml_partner_links(uint8_t * buf_ptr,struct beacon_tmpl_params * param)158*5113495bSYour Name uint8_t *bcn_tmpl_add_ml_partner_links(uint8_t *buf_ptr,
159*5113495bSYour Name 				       struct beacon_tmpl_params *param)
160*5113495bSYour Name {
161*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, 0);
162*5113495bSYour Name 	return buf_ptr + WMI_TLV_HDR_SIZE;
163*5113495bSYour Name }
164*5113495bSYour Name 
bcn_tmpl_ml_info_size(struct beacon_tmpl_params * param)165*5113495bSYour Name size_t bcn_tmpl_ml_info_size(struct beacon_tmpl_params *param)
166*5113495bSYour Name {
167*5113495bSYour Name 	return (WMI_TLV_HDR_SIZE + sizeof(wmi_bcn_tmpl_ml_info));
168*5113495bSYour Name }
169*5113495bSYour Name 
bcn_tmpl_add_ml_info(uint8_t * buf_ptr,struct beacon_tmpl_params * param)170*5113495bSYour Name uint8_t *bcn_tmpl_add_ml_info(uint8_t *buf_ptr,
171*5113495bSYour Name 			      struct beacon_tmpl_params *param)
172*5113495bSYour Name {
173*5113495bSYour Name 	wmi_bcn_tmpl_ml_info *ml_info;
174*5113495bSYour Name 
175*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
176*5113495bSYour Name 		       sizeof(wmi_bcn_tmpl_ml_info));
177*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
178*5113495bSYour Name 
179*5113495bSYour Name 	ml_info = (wmi_bcn_tmpl_ml_info *)buf_ptr;
180*5113495bSYour Name 
181*5113495bSYour Name 	WMITLV_SET_HDR(&ml_info->tlv_header,
182*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_bcn_tmpl_ml_info,
183*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_bcn_tmpl_ml_info));
184*5113495bSYour Name 
185*5113495bSYour Name 	ml_info->hw_link_id = param->cu_ml_info.hw_link_id;
186*5113495bSYour Name 	ml_info->cu_vdev_map_cat1_lo = param->cu_ml_info.cu_vdev_map_cat1_lo;
187*5113495bSYour Name 	ml_info->cu_vdev_map_cat1_hi = param->cu_ml_info.cu_vdev_map_cat1_hi;
188*5113495bSYour Name 	ml_info->cu_vdev_map_cat2_lo = param->cu_ml_info.cu_vdev_map_cat2_lo;
189*5113495bSYour Name 	ml_info->cu_vdev_map_cat2_hi = param->cu_ml_info.cu_vdev_map_cat2_hi;
190*5113495bSYour Name 
191*5113495bSYour Name 	return buf_ptr + sizeof(wmi_bcn_tmpl_ml_info);
192*5113495bSYour Name }
193*5113495bSYour Name 
prb_resp_tmpl_ml_info_size(struct wmi_probe_resp_params * param)194*5113495bSYour Name size_t prb_resp_tmpl_ml_info_size(struct wmi_probe_resp_params *param)
195*5113495bSYour Name {
196*5113495bSYour Name 	return (WMI_TLV_HDR_SIZE + sizeof(wmi_prb_resp_tmpl_ml_info));
197*5113495bSYour Name }
198*5113495bSYour Name 
prb_resp_tmpl_add_ml_info(uint8_t * buf_ptr,struct wmi_probe_resp_params * param)199*5113495bSYour Name uint8_t *prb_resp_tmpl_add_ml_info(uint8_t *buf_ptr,
200*5113495bSYour Name 				   struct wmi_probe_resp_params *param)
201*5113495bSYour Name {
202*5113495bSYour Name 	wmi_prb_resp_tmpl_ml_info *ml_info;
203*5113495bSYour Name 
204*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
205*5113495bSYour Name 		       sizeof(wmi_prb_resp_tmpl_ml_info));
206*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
207*5113495bSYour Name 
208*5113495bSYour Name 	ml_info = (wmi_prb_resp_tmpl_ml_info *)buf_ptr;
209*5113495bSYour Name 
210*5113495bSYour Name 	WMITLV_SET_HDR(&ml_info->tlv_header,
211*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_prb_resp_tmpl_ml_info,
212*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_prb_resp_tmpl_ml_info));
213*5113495bSYour Name 
214*5113495bSYour Name 	ml_info->hw_link_id = param->cu_ml_info.hw_link_id;
215*5113495bSYour Name 	ml_info->cu_vdev_map_cat1_lo = param->cu_ml_info.cu_vdev_map_cat1_lo;
216*5113495bSYour Name 	ml_info->cu_vdev_map_cat1_hi = param->cu_ml_info.cu_vdev_map_cat1_hi;
217*5113495bSYour Name 	ml_info->cu_vdev_map_cat2_lo = param->cu_ml_info.cu_vdev_map_cat2_lo;
218*5113495bSYour Name 	ml_info->cu_vdev_map_cat2_hi = param->cu_ml_info.cu_vdev_map_cat2_hi;
219*5113495bSYour Name 
220*5113495bSYour Name 	return buf_ptr + sizeof(wmi_prb_resp_tmpl_ml_info);
221*5113495bSYour Name }
222*5113495bSYour Name 
peer_create_mlo_params_size(struct peer_create_params * req)223*5113495bSYour Name size_t peer_create_mlo_params_size(struct peer_create_params *req)
224*5113495bSYour Name {
225*5113495bSYour Name 	return sizeof(wmi_peer_create_mlo_params) + WMI_TLV_HDR_SIZE;
226*5113495bSYour Name }
227*5113495bSYour Name 
peer_create_add_mlo_params(uint8_t * buf_ptr,struct peer_create_params * req)228*5113495bSYour Name uint8_t *peer_create_add_mlo_params(uint8_t *buf_ptr,
229*5113495bSYour Name 				    struct peer_create_params *req)
230*5113495bSYour Name {
231*5113495bSYour Name 	wmi_peer_create_mlo_params *mlo_params;
232*5113495bSYour Name 
233*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
234*5113495bSYour Name 		       sizeof(wmi_peer_create_mlo_params));
235*5113495bSYour Name 	buf_ptr += sizeof(uint32_t);
236*5113495bSYour Name 
237*5113495bSYour Name 	mlo_params = (wmi_peer_create_mlo_params *)buf_ptr;
238*5113495bSYour Name 	WMITLV_SET_HDR(&mlo_params->tlv_header,
239*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_peer_create_mlo_params,
240*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_peer_create_mlo_params));
241*5113495bSYour Name 
242*5113495bSYour Name 	mlo_params->mlo_flags.mlo_flags = 0;
243*5113495bSYour Name 	WMI_MLO_FLAGS_SET_ENABLED(mlo_params->mlo_flags.mlo_flags,
244*5113495bSYour Name 				  req->mlo_enabled);
245*5113495bSYour Name 	WMI_MLO_FLAGS_SET_BRIDGE_PEER(mlo_params->mlo_flags.mlo_flags,
246*5113495bSYour Name 				      req->mlo_bridge_peer);
247*5113495bSYour Name 
248*5113495bSYour Name 	return buf_ptr + sizeof(wmi_peer_create_mlo_params);
249*5113495bSYour Name }
250*5113495bSYour Name 
peer_assoc_mlo_params_size(struct peer_assoc_params * req)251*5113495bSYour Name size_t peer_assoc_mlo_params_size(struct peer_assoc_params *req)
252*5113495bSYour Name {
253*5113495bSYour Name 	size_t peer_assoc_mlo_size = sizeof(wmi_peer_assoc_mlo_params) +
254*5113495bSYour Name 			WMI_TLV_HDR_SIZE +
255*5113495bSYour Name 			((req->ml_links.num_links) *
256*5113495bSYour Name 			sizeof(wmi_peer_assoc_mlo_partner_link_params)) +
257*5113495bSYour Name 			WMI_TLV_HDR_SIZE;
258*5113495bSYour Name 
259*5113495bSYour Name 	if (req->is_assoc_vdev)
260*5113495bSYour Name 		peer_assoc_mlo_size = peer_assoc_mlo_size +
261*5113495bSYour Name 			sizeof(wmi_peer_assoc_mlo_partner_link_params);
262*5113495bSYour Name 
263*5113495bSYour Name 	return peer_assoc_mlo_size;
264*5113495bSYour Name }
265*5113495bSYour Name 
peer_assoc_add_mlo_params(uint8_t * buf_ptr,struct peer_assoc_params * req)266*5113495bSYour Name uint8_t *peer_assoc_add_mlo_params(uint8_t *buf_ptr,
267*5113495bSYour Name 				   struct peer_assoc_params *req)
268*5113495bSYour Name {
269*5113495bSYour Name 	wmi_peer_assoc_mlo_params *mlo_params;
270*5113495bSYour Name 
271*5113495bSYour Name 	/* Add WMI peer assoc mlo params */
272*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
273*5113495bSYour Name 		       sizeof(wmi_peer_assoc_mlo_params));
274*5113495bSYour Name 	buf_ptr += sizeof(uint32_t);
275*5113495bSYour Name 
276*5113495bSYour Name 	mlo_params = (wmi_peer_assoc_mlo_params *)buf_ptr;
277*5113495bSYour Name 	WMITLV_SET_HDR(&mlo_params->tlv_header,
278*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_peer_assoc_mlo_params,
279*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_peer_assoc_mlo_params));
280*5113495bSYour Name 
281*5113495bSYour Name 	mlo_params->mlo_flags.mlo_flags = 0;
282*5113495bSYour Name 	WMI_MLO_FLAGS_SET_ENABLED(mlo_params->mlo_flags.mlo_flags,
283*5113495bSYour Name 				  req->mlo_params.mlo_enabled);
284*5113495bSYour Name 	WMI_MLO_FLAGS_SET_ASSOC_LINK(mlo_params->mlo_flags.mlo_flags,
285*5113495bSYour Name 				     req->mlo_params.mlo_assoc_link);
286*5113495bSYour Name 	WMI_MLO_FLAGS_SET_PRIMARY_UMAC(mlo_params->mlo_flags.mlo_flags,
287*5113495bSYour Name 				       req->mlo_params.mlo_primary_umac);
288*5113495bSYour Name 	WMI_MLO_FLAGS_SET_LINK_INDEX_VALID(mlo_params->mlo_flags.mlo_flags,
289*5113495bSYour Name 					   req->mlo_params.mlo_logical_link_index_valid);
290*5113495bSYour Name 	WMI_MLO_FLAGS_SET_PEER_ID_VALID(mlo_params->mlo_flags.mlo_flags,
291*5113495bSYour Name 					req->mlo_params.mlo_peer_id_valid);
292*5113495bSYour Name 	WMI_MLO_FLAGS_SET_BRIDGE_PEER(mlo_params->mlo_flags.mlo_flags,
293*5113495bSYour Name 				      req->mlo_params.mlo_bridge_peer);
294*5113495bSYour Name 	mlo_params->mlo_flags.emlsr_support = req->mlo_params.emlsr_support;
295*5113495bSYour Name 
296*5113495bSYour Name 	mlo_params->mlo_flags.mlo_force_link_inactive =
297*5113495bSYour Name 			req->mlo_params.mlo_force_link_inactive;
298*5113495bSYour Name 
299*5113495bSYour Name 	WMI_CHAR_ARRAY_TO_MAC_ADDR(req->mlo_params.mld_mac,
300*5113495bSYour Name 				   &mlo_params->mld_macaddr);
301*5113495bSYour Name 	mlo_params->logical_link_index = req->mlo_params.logical_link_index;
302*5113495bSYour Name 	mlo_params->mld_peer_id = req->mlo_params.ml_peer_id;
303*5113495bSYour Name 
304*5113495bSYour Name 	mlo_params->ieee_link_id = req->mlo_params.ieee_link_id;
305*5113495bSYour Name 	mlo_params->emlsr_trans_timeout_us = req->mlo_params.trans_timeout_us;
306*5113495bSYour Name 	mlo_params->emlsr_trans_delay_us = req->mlo_params.emlsr_trans_delay_us;
307*5113495bSYour Name 	mlo_params->emlsr_padding_delay_us = req->mlo_params.emlsr_pad_delay_us;
308*5113495bSYour Name 
309*5113495bSYour Name 	mlo_params->msd_dur_subfield = req->mlo_params.medium_sync_duration;
310*5113495bSYour Name 	mlo_params->msd_ofdm_ed_thr =
311*5113495bSYour Name 			req->mlo_params.medium_sync_ofdm_ed_thresh;
312*5113495bSYour Name 	mlo_params->msd_max_num_txops =
313*5113495bSYour Name 			req->mlo_params.medium_sync_max_txop_num;
314*5113495bSYour Name 
315*5113495bSYour Name 	mlo_params->max_num_simultaneous_links =
316*5113495bSYour Name 			req->mlo_params.max_num_simultaneous_links;
317*5113495bSYour Name 	mlo_params->mlo_flags.nstr_bitmap_present =
318*5113495bSYour Name 			req->mlo_params.nstr_bitmap_present;
319*5113495bSYour Name 	mlo_params->mlo_flags.nstr_bitmap_size =
320*5113495bSYour Name 			req->mlo_params.nstr_bitmap_size;
321*5113495bSYour Name 	mlo_params->mlo_flags.mlo_link_switch =
322*5113495bSYour Name 			req->mlo_params.link_switch_in_progress;
323*5113495bSYour Name 	mlo_params->nstr_indication_bitmap =
324*5113495bSYour Name 		req->mlo_params.nstr_indication_bitmap;
325*5113495bSYour Name 	mlo_params->recommended_max_num_simultaneous_links =
326*5113495bSYour Name 		req->mlo_params.rec_max_simultaneous_links;
327*5113495bSYour Name 
328*5113495bSYour Name 	wmi_debug("emlsr_support %d mlo_flags 0x%x logical_link_index %d mld_peer_id %d ieee_link_id %d "
329*5113495bSYour Name 		  "emlsr_trans_timeout_us %d emlsr_trans_delay_us %d "
330*5113495bSYour Name 		  "emlsr_padding_delay_us %d msd_dur_subfield %d msd_ofdm_ed_thr %d msd_max_num_txops %d "
331*5113495bSYour Name 		  "max_num_simultaneous_links %d nstr_bitmap_present %d nstr_bitmap_size %d "
332*5113495bSYour Name 		  "mlo_link_switch %d "
333*5113495bSYour Name 		  "nstr_indication_bitmap 0x%x MLD addr " QDF_MAC_ADDR_FMT,
334*5113495bSYour Name 		  mlo_params->mlo_flags.emlsr_support,
335*5113495bSYour Name 		  mlo_params->mlo_flags.mlo_flags,
336*5113495bSYour Name 		  mlo_params->logical_link_index,
337*5113495bSYour Name 		  mlo_params->mld_peer_id, mlo_params->ieee_link_id,
338*5113495bSYour Name 		  mlo_params->emlsr_trans_timeout_us,
339*5113495bSYour Name 		  mlo_params->emlsr_trans_delay_us,
340*5113495bSYour Name 		  mlo_params->emlsr_padding_delay_us,
341*5113495bSYour Name 		  mlo_params->msd_dur_subfield, mlo_params->msd_ofdm_ed_thr,
342*5113495bSYour Name 		  mlo_params->msd_max_num_txops, mlo_params->max_num_simultaneous_links,
343*5113495bSYour Name 		  mlo_params->mlo_flags.nstr_bitmap_present,
344*5113495bSYour Name 		  mlo_params->mlo_flags.nstr_bitmap_size,
345*5113495bSYour Name 		  mlo_params->mlo_flags.mlo_link_switch,
346*5113495bSYour Name 		  mlo_params->nstr_indication_bitmap,
347*5113495bSYour Name 		  QDF_MAC_ADDR_REF(req->mlo_params.mld_mac));
348*5113495bSYour Name 
349*5113495bSYour Name 	return buf_ptr + sizeof(wmi_peer_assoc_mlo_params);
350*5113495bSYour Name }
351*5113495bSYour Name 
wmi_copy_chan_info(wmi_channel * dst_chan,struct wlan_channel * src_chan)352*5113495bSYour Name static inline void wmi_copy_chan_info(wmi_channel *dst_chan,
353*5113495bSYour Name 				      struct wlan_channel *src_chan)
354*5113495bSYour Name {
355*5113495bSYour Name 	WMI_HOST_WLAN_PHY_MODE fw_phy_mode;
356*5113495bSYour Name 
357*5113495bSYour Name 	dst_chan->mhz = src_chan->ch_freq;
358*5113495bSYour Name 	dst_chan->band_center_freq1 = src_chan->ch_cfreq1;
359*5113495bSYour Name 	dst_chan->band_center_freq2 = src_chan->ch_cfreq2;
360*5113495bSYour Name 	fw_phy_mode = wmi_host_to_fw_phymode(src_chan->ch_phymode);
361*5113495bSYour Name 	WMI_SET_CHANNEL_MODE(dst_chan, fw_phy_mode);
362*5113495bSYour Name }
363*5113495bSYour Name 
364*5113495bSYour Name static inline void
peer_assoc_update_assoc_link_info(uint8_t ** buf_ptr,struct peer_assoc_params * req)365*5113495bSYour Name peer_assoc_update_assoc_link_info(uint8_t **buf_ptr,
366*5113495bSYour Name 				  struct peer_assoc_params *req)
367*5113495bSYour Name {
368*5113495bSYour Name 	wmi_peer_assoc_mlo_partner_link_params *ml_partner_link;
369*5113495bSYour Name 
370*5113495bSYour Name 	if (!req->is_assoc_vdev)
371*5113495bSYour Name 		return;
372*5113495bSYour Name 
373*5113495bSYour Name 	ml_partner_link = (wmi_peer_assoc_mlo_partner_link_params *)(*buf_ptr);
374*5113495bSYour Name 
375*5113495bSYour Name 	/* Fill Assoc link info */
376*5113495bSYour Name 	WMITLV_SET_HDR(&ml_partner_link->tlv_header,
377*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_peer_assoc_mlo_partner_link_params,
378*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_peer_assoc_mlo_partner_link_params));
379*5113495bSYour Name 	ml_partner_link->vdev_id = req->mlo_params.vdev_id;
380*5113495bSYour Name 	ml_partner_link->ieee_link_id = req->mlo_params.ieee_link_id;
381*5113495bSYour Name 	WMI_CHAR_ARRAY_TO_MAC_ADDR(req->mlo_params.bssid.bytes,
382*5113495bSYour Name 				   &ml_partner_link->bss_id);
383*5113495bSYour Name 	WMI_CHAR_ARRAY_TO_MAC_ADDR(req->mlo_params.mac_addr.bytes,
384*5113495bSYour Name 				   &ml_partner_link->self_mac);
385*5113495bSYour Name 	wmi_copy_chan_info(&ml_partner_link->wmi_chan, &req->mlo_params.chan);
386*5113495bSYour Name 
387*5113495bSYour Name 	wmi_debug("Send Link info with link_id: %d vdev_id: %d AP link addr: "QDF_MAC_ADDR_FMT ", STA addr: "QDF_MAC_ADDR_FMT,
388*5113495bSYour Name 		  ml_partner_link->ieee_link_id, ml_partner_link->vdev_id,
389*5113495bSYour Name 		  QDF_MAC_ADDR_REF(req->mlo_params.bssid.bytes),
390*5113495bSYour Name 		  QDF_MAC_ADDR_REF(req->mlo_params.mac_addr.bytes));
391*5113495bSYour Name 
392*5113495bSYour Name 	ml_partner_link++;
393*5113495bSYour Name 	*buf_ptr = (uint8_t *)ml_partner_link;
394*5113495bSYour Name }
395*5113495bSYour Name 
peer_assoc_add_ml_partner_links(uint8_t * buf_ptr,struct peer_assoc_params * req)396*5113495bSYour Name uint8_t *peer_assoc_add_ml_partner_links(uint8_t *buf_ptr,
397*5113495bSYour Name 					 struct peer_assoc_params *req)
398*5113495bSYour Name {
399*5113495bSYour Name 	wmi_peer_assoc_mlo_partner_link_params *ml_partner_link;
400*5113495bSYour Name 	struct ml_partner_info *partner_info;
401*5113495bSYour Name 	uint8_t i;
402*5113495bSYour Name 
403*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
404*5113495bSYour Name 		       ((req->ml_links.num_links + req->is_assoc_vdev) *
405*5113495bSYour Name 		       sizeof(wmi_peer_assoc_mlo_partner_link_params)));
406*5113495bSYour Name 	buf_ptr += sizeof(uint32_t);
407*5113495bSYour Name 
408*5113495bSYour Name 	ml_partner_link = (wmi_peer_assoc_mlo_partner_link_params *)buf_ptr;
409*5113495bSYour Name 	peer_assoc_update_assoc_link_info((uint8_t **)&ml_partner_link, req);
410*5113495bSYour Name 	partner_info = req->ml_links.partner_info;
411*5113495bSYour Name 	for (i = 0; i < req->ml_links.num_links; i++) {
412*5113495bSYour Name 		WMITLV_SET_HDR(&ml_partner_link->tlv_header,
413*5113495bSYour Name 			       WMITLV_TAG_STRUC_wmi_peer_assoc_mlo_partner_link_params,
414*5113495bSYour Name 			       WMITLV_GET_STRUCT_TLVLEN(wmi_peer_assoc_mlo_partner_link_params));
415*5113495bSYour Name 		ml_partner_link->vdev_id = partner_info[i].vdev_id;
416*5113495bSYour Name 		ml_partner_link->hw_mld_link_id = partner_info[i].hw_mld_link_id;
417*5113495bSYour Name 		WMI_MLO_FLAGS_SET_ENABLED(ml_partner_link->mlo_flags.mlo_flags,
418*5113495bSYour Name 					  partner_info[i].mlo_enabled);
419*5113495bSYour Name 		WMI_MLO_FLAGS_SET_ASSOC_LINK(ml_partner_link->mlo_flags.mlo_flags,
420*5113495bSYour Name 					     partner_info[i].mlo_assoc_link);
421*5113495bSYour Name 		WMI_MLO_FLAGS_SET_PRIMARY_UMAC(ml_partner_link->mlo_flags.mlo_flags,
422*5113495bSYour Name 					       partner_info[i].mlo_primary_umac);
423*5113495bSYour Name 		WMI_MLO_FLAGS_SET_LINK_INDEX_VALID(ml_partner_link->mlo_flags.mlo_flags,
424*5113495bSYour Name 						   partner_info[i].mlo_logical_link_index_valid);
425*5113495bSYour Name 		WMI_MLO_FLAGS_SET_BRIDGE_PEER(ml_partner_link->mlo_flags.mlo_flags,
426*5113495bSYour Name 					      partner_info[i].mlo_bridge_peer);
427*5113495bSYour Name 		ml_partner_link->mlo_flags.emlsr_support = partner_info[i].emlsr_support;
428*5113495bSYour Name 		ml_partner_link->logical_link_index = partner_info[i].logical_link_index;
429*5113495bSYour Name 		ml_partner_link->ieee_link_id = partner_info[i].link_id;
430*5113495bSYour Name 		WMI_CHAR_ARRAY_TO_MAC_ADDR(partner_info[i].bssid.bytes,
431*5113495bSYour Name 					   &ml_partner_link->bss_id);
432*5113495bSYour Name 		WMI_CHAR_ARRAY_TO_MAC_ADDR(partner_info[i].mac_addr.bytes,
433*5113495bSYour Name 					   &ml_partner_link->self_mac);
434*5113495bSYour Name 
435*5113495bSYour Name 		wmi_debug("Send Link info with link_id: %d vdev_id: %d AP link addr: "QDF_MAC_ADDR_FMT ", STA addr: "QDF_MAC_ADDR_FMT,
436*5113495bSYour Name 			  ml_partner_link->ieee_link_id,
437*5113495bSYour Name 			  ml_partner_link->vdev_id,
438*5113495bSYour Name 			  QDF_MAC_ADDR_REF(partner_info[i].bssid.bytes),
439*5113495bSYour Name 			  QDF_MAC_ADDR_REF(partner_info[i].mac_addr.bytes));
440*5113495bSYour Name 		wmi_copy_chan_info(&ml_partner_link->wmi_chan,
441*5113495bSYour Name 				   &partner_info[i].chan);
442*5113495bSYour Name 
443*5113495bSYour Name 		ml_partner_link++;
444*5113495bSYour Name 	}
445*5113495bSYour Name 
446*5113495bSYour Name 	return buf_ptr +
447*5113495bSYour Name 	       ((req->ml_links.num_links + req->is_assoc_vdev) *
448*5113495bSYour Name 		sizeof(wmi_peer_assoc_mlo_partner_link_params));
449*5113495bSYour Name }
450*5113495bSYour Name 
peer_delete_mlo_params_size(struct peer_delete_cmd_params * req)451*5113495bSYour Name size_t peer_delete_mlo_params_size(struct peer_delete_cmd_params *req)
452*5113495bSYour Name {
453*5113495bSYour Name 	if (!req->hw_link_id_bitmap && !req->is_mlo_link_switch)
454*5113495bSYour Name 		return WMI_TLV_HDR_SIZE;
455*5113495bSYour Name 
456*5113495bSYour Name 	return sizeof(wmi_peer_delete_mlo_params) + WMI_TLV_HDR_SIZE;
457*5113495bSYour Name }
458*5113495bSYour Name 
peer_delete_add_mlo_params(uint8_t * buf_ptr,struct peer_delete_cmd_params * req)459*5113495bSYour Name uint8_t *peer_delete_add_mlo_params(uint8_t *buf_ptr,
460*5113495bSYour Name 				    struct peer_delete_cmd_params *req)
461*5113495bSYour Name {
462*5113495bSYour Name 	wmi_peer_delete_mlo_params *mlo_params;
463*5113495bSYour Name 
464*5113495bSYour Name 	if (!req->hw_link_id_bitmap && !req->is_mlo_link_switch) {
465*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, 0);
466*5113495bSYour Name 		return buf_ptr + WMI_TLV_HDR_SIZE;
467*5113495bSYour Name 	}
468*5113495bSYour Name 
469*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
470*5113495bSYour Name 		       sizeof(wmi_peer_delete_mlo_params));
471*5113495bSYour Name 	buf_ptr += sizeof(uint32_t);
472*5113495bSYour Name 
473*5113495bSYour Name 	mlo_params = (wmi_peer_delete_mlo_params *)buf_ptr;
474*5113495bSYour Name 	WMITLV_SET_HDR(&mlo_params->tlv_header,
475*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_peer_delete_mlo_params,
476*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_peer_delete_mlo_params));
477*5113495bSYour Name 	mlo_params->mlo_hw_link_id_bitmap = req->hw_link_id_bitmap;
478*5113495bSYour Name 	WMI_MLO_FLAGS_SET_MLO_LINK_SWITCH(mlo_params->mlo_flags.mlo_flags,
479*5113495bSYour Name 					  req->is_mlo_link_switch);
480*5113495bSYour Name 
481*5113495bSYour Name 	return buf_ptr + sizeof(wmi_peer_delete_mlo_params);
482*5113495bSYour Name }
483*5113495bSYour Name 
vdev_stop_mlo_params_size(struct vdev_stop_params * params)484*5113495bSYour Name size_t vdev_stop_mlo_params_size(struct vdev_stop_params *params)
485*5113495bSYour Name {
486*5113495bSYour Name 	if (!params->is_mlo_link_switch)
487*5113495bSYour Name 		return WMI_TLV_HDR_SIZE;
488*5113495bSYour Name 
489*5113495bSYour Name 	return sizeof(wmi_vdev_stop_mlo_params) + WMI_TLV_HDR_SIZE;
490*5113495bSYour Name }
491*5113495bSYour Name 
vdev_stop_add_mlo_params(uint8_t * buf_ptr,struct vdev_stop_params * params)492*5113495bSYour Name uint8_t *vdev_stop_add_mlo_params(uint8_t *buf_ptr,
493*5113495bSYour Name 				  struct vdev_stop_params *params)
494*5113495bSYour Name {
495*5113495bSYour Name 	wmi_vdev_stop_mlo_params *mlo_params;
496*5113495bSYour Name 
497*5113495bSYour Name 	if (!params->is_mlo_link_switch) {
498*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, 0);
499*5113495bSYour Name 		return buf_ptr + WMI_TLV_HDR_SIZE;
500*5113495bSYour Name 	}
501*5113495bSYour Name 
502*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
503*5113495bSYour Name 		       sizeof(wmi_vdev_stop_mlo_params));
504*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
505*5113495bSYour Name 
506*5113495bSYour Name 	mlo_params = (wmi_vdev_stop_mlo_params *)buf_ptr;
507*5113495bSYour Name 	WMITLV_SET_HDR(&mlo_params->tlv_header,
508*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_vdev_stop_mlo_params,
509*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_vdev_stop_mlo_params));
510*5113495bSYour Name 	WMI_MLO_FLAGS_SET_MLO_LINK_SWITCH(mlo_params->mlo_flags.mlo_flags,
511*5113495bSYour Name 					  params->is_mlo_link_switch);
512*5113495bSYour Name 
513*5113495bSYour Name 	return buf_ptr + sizeof(wmi_vdev_stop_mlo_params);
514*5113495bSYour Name }
515*5113495bSYour Name 
516*5113495bSYour Name /**
517*5113495bSYour Name  * force_mode_host_to_fw() - translate force mode for MLO link set active
518*5113495bSYour Name  *  command
519*5113495bSYour Name  * @host_mode: force mode defined by host
520*5113495bSYour Name  * @fw_mode: buffer to store force mode defined by FW
521*5113495bSYour Name  *
522*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL otherwise
523*5113495bSYour Name  */
524*5113495bSYour Name static inline QDF_STATUS
force_mode_host_to_fw(enum mlo_link_force_mode host_mode,WMI_MLO_LINK_FORCE_MODE * fw_mode)525*5113495bSYour Name force_mode_host_to_fw(enum mlo_link_force_mode host_mode,
526*5113495bSYour Name 		      WMI_MLO_LINK_FORCE_MODE *fw_mode)
527*5113495bSYour Name {
528*5113495bSYour Name 	switch (host_mode) {
529*5113495bSYour Name 	case MLO_LINK_FORCE_MODE_ACTIVE:
530*5113495bSYour Name 		*fw_mode = WMI_MLO_LINK_FORCE_ACTIVE;
531*5113495bSYour Name 		break;
532*5113495bSYour Name 	case MLO_LINK_FORCE_MODE_INACTIVE:
533*5113495bSYour Name 		*fw_mode = WMI_MLO_LINK_FORCE_INACTIVE;
534*5113495bSYour Name 		break;
535*5113495bSYour Name 	case MLO_LINK_FORCE_MODE_ACTIVE_INACTIVE:
536*5113495bSYour Name 		*fw_mode = WMI_MLO_LINK_FORCE_ACTIVE_INACTIVE;
537*5113495bSYour Name 		break;
538*5113495bSYour Name 	case MLO_LINK_FORCE_MODE_ACTIVE_NUM:
539*5113495bSYour Name 		*fw_mode = WMI_MLO_LINK_FORCE_ACTIVE_LINK_NUM;
540*5113495bSYour Name 		break;
541*5113495bSYour Name 	case MLO_LINK_FORCE_MODE_INACTIVE_NUM:
542*5113495bSYour Name 		*fw_mode = WMI_MLO_LINK_FORCE_INACTIVE_LINK_NUM;
543*5113495bSYour Name 		break;
544*5113495bSYour Name 	case MLO_LINK_FORCE_MODE_NO_FORCE:
545*5113495bSYour Name 		*fw_mode = WMI_MLO_LINK_NO_FORCE;
546*5113495bSYour Name 		break;
547*5113495bSYour Name 	default:
548*5113495bSYour Name 		wmi_err("Invalid force mode: %d", host_mode);
549*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
550*5113495bSYour Name 	}
551*5113495bSYour Name 
552*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
553*5113495bSYour Name }
554*5113495bSYour Name 
555*5113495bSYour Name /**
556*5113495bSYour Name  * force_reason_host_to_fw() - translate force reason for MLO link set active
557*5113495bSYour Name  *  command
558*5113495bSYour Name  * @host_reason: force reason defined by host
559*5113495bSYour Name  * @fw_reason: buffer to store force reason defined by FW
560*5113495bSYour Name  *
561*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_INVAL otherwise
562*5113495bSYour Name  */
563*5113495bSYour Name static inline QDF_STATUS
force_reason_host_to_fw(enum mlo_link_force_reason host_reason,WMI_MLO_LINK_FORCE_REASON * fw_reason)564*5113495bSYour Name force_reason_host_to_fw(enum mlo_link_force_reason host_reason,
565*5113495bSYour Name 			WMI_MLO_LINK_FORCE_REASON *fw_reason)
566*5113495bSYour Name {
567*5113495bSYour Name 	switch (host_reason) {
568*5113495bSYour Name 	case MLO_LINK_FORCE_REASON_CONNECT:
569*5113495bSYour Name 		*fw_reason = WMI_MLO_LINK_FORCE_REASON_NEW_CONNECT;
570*5113495bSYour Name 		break;
571*5113495bSYour Name 	case MLO_LINK_FORCE_REASON_DISCONNECT:
572*5113495bSYour Name 		*fw_reason = WMI_MLO_LINK_FORCE_REASON_NEW_DISCONNECT;
573*5113495bSYour Name 		break;
574*5113495bSYour Name 	case MLO_LINK_FORCE_REASON_TDLS:
575*5113495bSYour Name 		*fw_reason = WMI_MLO_LINK_FORCE_REASON_TDLS;
576*5113495bSYour Name 		break;
577*5113495bSYour Name 	case MLO_LINK_FORCE_REASON_LINK_REMOVAL:
578*5113495bSYour Name 		*fw_reason =  WMI_MLO_LINK_FORCE_REASON_LINK_REMOVAL;
579*5113495bSYour Name 		break;
580*5113495bSYour Name 	default:
581*5113495bSYour Name 		wmi_err("Invalid force reason: %d", host_reason);
582*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
583*5113495bSYour Name 	}
584*5113495bSYour Name 
585*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
586*5113495bSYour Name }
587*5113495bSYour Name 
588*5113495bSYour Name /**
589*5113495bSYour Name  * send_mlo_link_set_active_id_cmd_tlv() - send mlo link set active command
590*5113495bSYour Name  * by link id bitmap
591*5113495bSYour Name  * @wmi_handle: wmi handle
592*5113495bSYour Name  * @param: Pointer to mlo link set active param
593*5113495bSYour Name  *
594*5113495bSYour Name  * This API will populate link bitmap for corresponding force mode and
595*5113495bSYour Name  * send command to target.
596*5113495bSYour Name  * Previous API send_mlo_link_set_active_cmd_tlv can only handle vdev
597*5113495bSYour Name  * bitmap, if some associated links have no vdev attached, we have to use
598*5113495bSYour Name  * this API to do link force active/inactive.
599*5113495bSYour Name  * Note: no vdev associated links can be "non forced" state, so that target
600*5113495bSYour Name  * can repurpose vdev to such link.
601*5113495bSYour Name  * If link with no vdev attached is forced inactive for such concurrency
602*5113495bSYour Name  * reason, target will not switch to such link.
603*5113495bSYour Name  *
604*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS for success or QDF_STATUS_E_* for error
605*5113495bSYour Name  */
606*5113495bSYour Name static QDF_STATUS
send_mlo_link_set_active_id_cmd_tlv(wmi_unified_t wmi_handle,struct mlo_link_set_active_param * param)607*5113495bSYour Name send_mlo_link_set_active_id_cmd_tlv(wmi_unified_t wmi_handle,
608*5113495bSYour Name 				    struct mlo_link_set_active_param *param)
609*5113495bSYour Name {
610*5113495bSYour Name 	QDF_STATUS status;
611*5113495bSYour Name 	wmi_mlo_link_set_active_cmd_fixed_param *cmd;
612*5113495bSYour Name 	wmi_mlo_set_active_link_number_param *link_num_param;
613*5113495bSYour Name 	uint32_t *link_bitmap;
614*5113495bSYour Name 	uint32_t num_link_num_param = 0, num_link_bitmap = 0, tlv_len;
615*5113495bSYour Name 	uint32_t num_inactive_link_bitmap = 0;
616*5113495bSYour Name 	wmi_buf_t buf;
617*5113495bSYour Name 	uint8_t *buf_ptr;
618*5113495bSYour Name 	uint32_t len;
619*5113495bSYour Name 	WMITLV_TAG_ID tag_id;
620*5113495bSYour Name 	WMI_MLO_LINK_FORCE_MODE force_mode;
621*5113495bSYour Name 	WMI_MLO_LINK_FORCE_REASON force_reason;
622*5113495bSYour Name 
623*5113495bSYour Name 	status = force_mode_host_to_fw(param->force_mode, &force_mode);
624*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status))
625*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
626*5113495bSYour Name 
627*5113495bSYour Name 	status = force_reason_host_to_fw(param->reason, &force_reason);
628*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status))
629*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
630*5113495bSYour Name 
631*5113495bSYour Name 	switch (force_mode) {
632*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_ACTIVE_LINK_NUM:
633*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_INACTIVE_LINK_NUM:
634*5113495bSYour Name 		num_link_num_param = 1;
635*5113495bSYour Name 		fallthrough;
636*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_ACTIVE:
637*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_INACTIVE:
638*5113495bSYour Name 	case WMI_MLO_LINK_NO_FORCE:
639*5113495bSYour Name 		num_link_bitmap = 1;
640*5113495bSYour Name 		break;
641*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_ACTIVE_INACTIVE:
642*5113495bSYour Name 		num_link_bitmap = 1;
643*5113495bSYour Name 		num_inactive_link_bitmap = 1;
644*5113495bSYour Name 		break;
645*5113495bSYour Name 	default:
646*5113495bSYour Name 		wmi_err("Invalid force reason: %d", force_mode);
647*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
648*5113495bSYour Name 	}
649*5113495bSYour Name 
650*5113495bSYour Name 	len = sizeof(*cmd) +
651*5113495bSYour Name 	      WMI_TLV_HDR_SIZE + WMI_TLV_HDR_SIZE +
652*5113495bSYour Name 	      WMI_TLV_HDR_SIZE + sizeof(*link_num_param) * num_link_num_param +
653*5113495bSYour Name 	      WMI_TLV_HDR_SIZE + sizeof(*link_bitmap) * num_link_bitmap;
654*5113495bSYour Name 	if (force_mode == WMI_MLO_LINK_FORCE_ACTIVE_INACTIVE)
655*5113495bSYour Name 		len += WMI_TLV_HDR_SIZE +
656*5113495bSYour Name 		sizeof(*link_bitmap) * num_inactive_link_bitmap;
657*5113495bSYour Name 
658*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, len);
659*5113495bSYour Name 	if (!buf)
660*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
661*5113495bSYour Name 
662*5113495bSYour Name 	buf_ptr = (uint8_t *)wmi_buf_data(buf);
663*5113495bSYour Name 	cmd = (wmi_mlo_link_set_active_cmd_fixed_param *)buf_ptr;
664*5113495bSYour Name 	tlv_len = WMITLV_GET_STRUCT_TLVLEN
665*5113495bSYour Name 			(wmi_mlo_link_set_active_cmd_fixed_param);
666*5113495bSYour Name 
667*5113495bSYour Name 	tag_id = WMITLV_TAG_STRUC_wmi_mlo_link_set_active_cmd_fixed_param;
668*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header, tag_id, tlv_len);
669*5113495bSYour Name 	cmd->force_mode = force_mode;
670*5113495bSYour Name 	cmd->reason = force_reason;
671*5113495bSYour Name 	cmd->use_ieee_link_id_bitmap = 1;
672*5113495bSYour Name 	WMI_CHAR_ARRAY_TO_MAC_ADDR(param->force_cmd.ap_mld_mac_addr.bytes,
673*5113495bSYour Name 				   &cmd->ap_mld_mac_addr);
674*5113495bSYour Name 	if (force_mode == WMI_MLO_LINK_FORCE_ACTIVE) {
675*5113495bSYour Name 		cmd->ctrl_flags.overwrite_force_active_bitmap =
676*5113495bSYour Name 			param->control_flags.overwrite_force_active_bitmap;
677*5113495bSYour Name 	} else if (force_mode == WMI_MLO_LINK_FORCE_INACTIVE) {
678*5113495bSYour Name 		cmd->ctrl_flags.overwrite_force_inactive_bitmap =
679*5113495bSYour Name 			param->control_flags.overwrite_force_inactive_bitmap;
680*5113495bSYour Name 	} else if (force_mode == WMI_MLO_LINK_FORCE_ACTIVE_INACTIVE) {
681*5113495bSYour Name 		cmd->ctrl_flags.overwrite_force_active_bitmap =
682*5113495bSYour Name 			param->control_flags.overwrite_force_active_bitmap;
683*5113495bSYour Name 		cmd->ctrl_flags.overwrite_force_inactive_bitmap =
684*5113495bSYour Name 			param->control_flags.overwrite_force_inactive_bitmap;
685*5113495bSYour Name 	} else {
686*5113495bSYour Name 		cmd->ctrl_flags.dynamic_force_link_num =
687*5113495bSYour Name 			param->control_flags.dynamic_force_link_num;
688*5113495bSYour Name 	}
689*5113495bSYour Name 
690*5113495bSYour Name 	wmi_debug("mode %d reason %d num_link_num_param %d num_link_bitmap %d num_inactive %d overwrite %d %d %d",
691*5113495bSYour Name 		  cmd->force_mode, cmd->reason, num_link_num_param,
692*5113495bSYour Name 		  num_link_bitmap, num_inactive_link_bitmap,
693*5113495bSYour Name 		  cmd->ctrl_flags.overwrite_force_active_bitmap,
694*5113495bSYour Name 		  cmd->ctrl_flags.overwrite_force_inactive_bitmap,
695*5113495bSYour Name 		  cmd->ctrl_flags.dynamic_force_link_num);
696*5113495bSYour Name 	wmi_debug("ap mld mac addr: "QDF_MAC_ADDR_FMT,
697*5113495bSYour Name 		  QDF_MAC_ADDR_REF(param->force_cmd.ap_mld_mac_addr.bytes));
698*5113495bSYour Name 
699*5113495bSYour Name 	buf_ptr += sizeof(*cmd);
700*5113495bSYour Name 
701*5113495bSYour Name 	/* set num of link tlv */
702*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
703*5113495bSYour Name 		       sizeof(*link_num_param) * num_link_num_param);
704*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
705*5113495bSYour Name 
706*5113495bSYour Name 	if (num_link_num_param) {
707*5113495bSYour Name 		link_num_param =
708*5113495bSYour Name 			(wmi_mlo_set_active_link_number_param *)buf_ptr;
709*5113495bSYour Name 		tlv_len = WMITLV_GET_STRUCT_TLVLEN
710*5113495bSYour Name 				(wmi_mlo_set_active_link_number_param);
711*5113495bSYour Name 
712*5113495bSYour Name 		WMITLV_SET_HDR(&link_num_param->tlv_header, 0, tlv_len);
713*5113495bSYour Name 		link_num_param->num_of_link = param->force_cmd.link_num;
714*5113495bSYour Name 		wmi_debug("entry[0]: num_of_link %d",
715*5113495bSYour Name 			  link_num_param->num_of_link);
716*5113495bSYour Name 
717*5113495bSYour Name 		buf_ptr += sizeof(*link_num_param) * 1;
718*5113495bSYour Name 	}
719*5113495bSYour Name 	/* add empty vdev bitmap tlv */
720*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_UINT32, 0);
721*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
722*5113495bSYour Name 	/* add empty vdev bitmap2 tlv */
723*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_UINT32, 0);
724*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
725*5113495bSYour Name 
726*5113495bSYour Name 	/* add link bitmap tlv */
727*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_UINT32,
728*5113495bSYour Name 		       sizeof(*link_bitmap) * num_link_bitmap);
729*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
730*5113495bSYour Name 
731*5113495bSYour Name 	if (num_link_bitmap) {
732*5113495bSYour Name 		link_bitmap = (A_UINT32 *)(buf_ptr);
733*5113495bSYour Name 
734*5113495bSYour Name 		link_bitmap[0] = param->force_cmd.ieee_link_id_bitmap;
735*5113495bSYour Name 		wmi_debug("entry[0]: link_bitmap 0x%x ", link_bitmap[0]);
736*5113495bSYour Name 
737*5113495bSYour Name 		buf_ptr += sizeof(*link_bitmap) * 1;
738*5113495bSYour Name 	}
739*5113495bSYour Name 	/* add link bitmap2 tlv */
740*5113495bSYour Name 	if (force_mode == WMI_MLO_LINK_FORCE_ACTIVE_INACTIVE) {
741*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_UINT32,
742*5113495bSYour Name 			       sizeof(*link_bitmap) *
743*5113495bSYour Name 			       num_inactive_link_bitmap);
744*5113495bSYour Name 		buf_ptr += WMI_TLV_HDR_SIZE;
745*5113495bSYour Name 
746*5113495bSYour Name 		if (num_inactive_link_bitmap) {
747*5113495bSYour Name 			link_bitmap = (A_UINT32 *)(buf_ptr);
748*5113495bSYour Name 			link_bitmap[0] = param->force_cmd.ieee_link_id_bitmap2;
749*5113495bSYour Name 			wmi_debug("entry[0]: link_bitmap2 0x%x ",
750*5113495bSYour Name 				  link_bitmap[0]);
751*5113495bSYour Name 
752*5113495bSYour Name 			buf_ptr += sizeof(*link_bitmap) * 1;
753*5113495bSYour Name 		}
754*5113495bSYour Name 	}
755*5113495bSYour Name 
756*5113495bSYour Name 	wmi_mtrace(WMI_MLO_LINK_SET_ACTIVE_CMDID, 0, cmd->force_mode);
757*5113495bSYour Name 	status = wmi_unified_cmd_send(wmi_handle, buf, len,
758*5113495bSYour Name 				      WMI_MLO_LINK_SET_ACTIVE_CMDID);
759*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status)) {
760*5113495bSYour Name 		wmi_err("Failed to send MLO link set active command to FW: %d",
761*5113495bSYour Name 			status);
762*5113495bSYour Name 		wmi_buf_free(buf);
763*5113495bSYour Name 	}
764*5113495bSYour Name 
765*5113495bSYour Name 	return status;
766*5113495bSYour Name }
767*5113495bSYour Name 
768*5113495bSYour Name /**
769*5113495bSYour Name  * send_mlo_link_set_active_cmd_tlv() - send mlo link set active command
770*5113495bSYour Name  * @wmi_handle: wmi handle
771*5113495bSYour Name  * @param: Pointer to mlo link set active param
772*5113495bSYour Name  *
773*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS for success or QDF_STATUS_E_* for error
774*5113495bSYour Name  */
775*5113495bSYour Name static QDF_STATUS
send_mlo_link_set_active_cmd_tlv(wmi_unified_t wmi_handle,struct mlo_link_set_active_param * param)776*5113495bSYour Name send_mlo_link_set_active_cmd_tlv(wmi_unified_t wmi_handle,
777*5113495bSYour Name 				 struct mlo_link_set_active_param *param)
778*5113495bSYour Name {
779*5113495bSYour Name 	QDF_STATUS status;
780*5113495bSYour Name 	wmi_mlo_link_set_active_cmd_fixed_param *cmd;
781*5113495bSYour Name 	wmi_mlo_set_active_link_number_param *link_num_param;
782*5113495bSYour Name 	uint32_t *vdev_bitmap;
783*5113495bSYour Name 	uint32_t num_link_num_param = 0, num_vdev_bitmap = 0, tlv_len;
784*5113495bSYour Name 	uint32_t num_inactive_vdev_bitmap = 0;
785*5113495bSYour Name 	wmi_buf_t buf;
786*5113495bSYour Name 	uint8_t *buf_ptr;
787*5113495bSYour Name 	uint32_t len;
788*5113495bSYour Name 	int i;
789*5113495bSYour Name 	WMITLV_TAG_ID tag_id;
790*5113495bSYour Name 	WMI_MLO_LINK_FORCE_MODE force_mode;
791*5113495bSYour Name 	WMI_MLO_LINK_FORCE_REASON force_reason;
792*5113495bSYour Name 
793*5113495bSYour Name 	/* If use_ieee_link_id = true, use new API
794*5113495bSYour Name 	 * send_mlo_link_set_active_id_cmd_tlv to fill link bitamp
795*5113495bSYour Name 	 * to wmi buffer.
796*5113495bSYour Name 	 * And target will indicate event with same flag set to true
797*5113495bSYour Name 	 * to indicate link bitmap included in the event.
798*5113495bSYour Name 	 */
799*5113495bSYour Name 	if (param->use_ieee_link_id)
800*5113495bSYour Name 		return send_mlo_link_set_active_id_cmd_tlv(wmi_handle,
801*5113495bSYour Name 							   param);
802*5113495bSYour Name 
803*5113495bSYour Name 	if (!param->num_vdev_bitmap && !param->num_link_entry) {
804*5113495bSYour Name 		wmi_err("No entry is provided vdev bit map %d link entry %d",
805*5113495bSYour Name 			param->num_vdev_bitmap,
806*5113495bSYour Name 			param->num_link_entry);
807*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
808*5113495bSYour Name 	}
809*5113495bSYour Name 
810*5113495bSYour Name 	status = force_mode_host_to_fw(param->force_mode, &force_mode);
811*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status))
812*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
813*5113495bSYour Name 
814*5113495bSYour Name 	status = force_reason_host_to_fw(param->reason, &force_reason);
815*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status))
816*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
817*5113495bSYour Name 
818*5113495bSYour Name 	switch (force_mode) {
819*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_ACTIVE_LINK_NUM:
820*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_INACTIVE_LINK_NUM:
821*5113495bSYour Name 		num_link_num_param = param->num_link_entry;
822*5113495bSYour Name 		fallthrough;
823*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_ACTIVE:
824*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_INACTIVE:
825*5113495bSYour Name 	case WMI_MLO_LINK_NO_FORCE:
826*5113495bSYour Name 		num_vdev_bitmap = param->num_vdev_bitmap;
827*5113495bSYour Name 		break;
828*5113495bSYour Name 	case WMI_MLO_LINK_FORCE_ACTIVE_INACTIVE:
829*5113495bSYour Name 		num_vdev_bitmap = param->num_vdev_bitmap;
830*5113495bSYour Name 		num_inactive_vdev_bitmap = param->num_inactive_vdev_bitmap;
831*5113495bSYour Name 		break;
832*5113495bSYour Name 	default:
833*5113495bSYour Name 		wmi_err("Invalid force reason: %d", force_mode);
834*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
835*5113495bSYour Name 	}
836*5113495bSYour Name 
837*5113495bSYour Name 	len = sizeof(*cmd) +
838*5113495bSYour Name 	      WMI_TLV_HDR_SIZE + sizeof(*link_num_param) * num_link_num_param +
839*5113495bSYour Name 	      WMI_TLV_HDR_SIZE + sizeof(*vdev_bitmap) * num_vdev_bitmap;
840*5113495bSYour Name 	if (force_mode == WMI_MLO_LINK_FORCE_ACTIVE_INACTIVE)
841*5113495bSYour Name 		len += WMI_TLV_HDR_SIZE +
842*5113495bSYour Name 		sizeof(*vdev_bitmap) * num_inactive_vdev_bitmap;
843*5113495bSYour Name 
844*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, len);
845*5113495bSYour Name 	if (!buf)
846*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
847*5113495bSYour Name 
848*5113495bSYour Name 	buf_ptr = (uint8_t *)wmi_buf_data(buf);
849*5113495bSYour Name 	cmd = (wmi_mlo_link_set_active_cmd_fixed_param *)buf_ptr;
850*5113495bSYour Name 	tlv_len = WMITLV_GET_STRUCT_TLVLEN
851*5113495bSYour Name 			(wmi_mlo_link_set_active_cmd_fixed_param);
852*5113495bSYour Name 
853*5113495bSYour Name 	tag_id = WMITLV_TAG_STRUC_wmi_mlo_link_set_active_cmd_fixed_param;
854*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header, tag_id, tlv_len);
855*5113495bSYour Name 	cmd->force_mode = force_mode;
856*5113495bSYour Name 	cmd->reason = force_reason;
857*5113495bSYour Name 	wmi_debug("mode %d reason %d num_link_num_param %d num_vdev_bitmap %d inactive %d",
858*5113495bSYour Name 		  cmd->force_mode, cmd->reason, num_link_num_param,
859*5113495bSYour Name 		  num_vdev_bitmap, num_inactive_vdev_bitmap);
860*5113495bSYour Name 	buf_ptr += sizeof(*cmd);
861*5113495bSYour Name 
862*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
863*5113495bSYour Name 		       sizeof(*link_num_param) * num_link_num_param);
864*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
865*5113495bSYour Name 
866*5113495bSYour Name 	if (num_link_num_param) {
867*5113495bSYour Name 		cmd->ctrl_flags.dynamic_force_link_num =
868*5113495bSYour Name 				param->control_flags.dynamic_force_link_num;
869*5113495bSYour Name 		link_num_param =
870*5113495bSYour Name 			(wmi_mlo_set_active_link_number_param *)buf_ptr;
871*5113495bSYour Name 		tlv_len = WMITLV_GET_STRUCT_TLVLEN
872*5113495bSYour Name 				(wmi_mlo_set_active_link_number_param);
873*5113495bSYour Name 		for (i = 0; i < num_link_num_param; i++) {
874*5113495bSYour Name 			WMITLV_SET_HDR(&link_num_param->tlv_header, 0, tlv_len);
875*5113495bSYour Name 			link_num_param->num_of_link =
876*5113495bSYour Name 				param->link_num[i].num_of_link;
877*5113495bSYour Name 			link_num_param->vdev_type =
878*5113495bSYour Name 				param->link_num[i].vdev_type;
879*5113495bSYour Name 			link_num_param->vdev_subtype =
880*5113495bSYour Name 				param->link_num[i].vdev_subtype;
881*5113495bSYour Name 			link_num_param->home_freq =
882*5113495bSYour Name 				param->link_num[i].home_freq;
883*5113495bSYour Name 			wmi_debug("entry[%d]: num_of_link %d vdev type %d subtype %d freq %d, control_flags:%d",
884*5113495bSYour Name 				  i, link_num_param->num_of_link,
885*5113495bSYour Name 				  link_num_param->vdev_type,
886*5113495bSYour Name 				  link_num_param->vdev_subtype,
887*5113495bSYour Name 				  link_num_param->home_freq,
888*5113495bSYour Name 				  cmd->ctrl_flags.control_flags);
889*5113495bSYour Name 			link_num_param++;
890*5113495bSYour Name 		}
891*5113495bSYour Name 
892*5113495bSYour Name 		buf_ptr += sizeof(*link_num_param) * num_link_num_param;
893*5113495bSYour Name 	}
894*5113495bSYour Name 
895*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_UINT32,
896*5113495bSYour Name 		       sizeof(*vdev_bitmap) * num_vdev_bitmap);
897*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
898*5113495bSYour Name 
899*5113495bSYour Name 	if (num_vdev_bitmap) {
900*5113495bSYour Name 		vdev_bitmap = (A_UINT32 *)(buf_ptr);
901*5113495bSYour Name 		for (i = 0; i < num_vdev_bitmap; i++) {
902*5113495bSYour Name 			vdev_bitmap[i] = param->vdev_bitmap[i];
903*5113495bSYour Name 			wmi_debug("entry[%d]: vdev_id_bitmap 0x%x ",
904*5113495bSYour Name 				  i, vdev_bitmap[i]);
905*5113495bSYour Name 		}
906*5113495bSYour Name 
907*5113495bSYour Name 		buf_ptr += sizeof(*vdev_bitmap) * num_vdev_bitmap;
908*5113495bSYour Name 	}
909*5113495bSYour Name 	if (force_mode == WMI_MLO_LINK_FORCE_ACTIVE_INACTIVE) {
910*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_UINT32,
911*5113495bSYour Name 			       sizeof(*vdev_bitmap) *
912*5113495bSYour Name 			       num_inactive_vdev_bitmap);
913*5113495bSYour Name 		buf_ptr += WMI_TLV_HDR_SIZE;
914*5113495bSYour Name 
915*5113495bSYour Name 		if (num_inactive_vdev_bitmap) {
916*5113495bSYour Name 			vdev_bitmap = (A_UINT32 *)(buf_ptr);
917*5113495bSYour Name 			for (i = 0; i < num_inactive_vdev_bitmap; i++) {
918*5113495bSYour Name 				vdev_bitmap[i] =
919*5113495bSYour Name 					param->inactive_vdev_bitmap[i];
920*5113495bSYour Name 				wmi_debug("entry[%d]: inactive_vdev_id_bitmap 0x%x ",
921*5113495bSYour Name 					  i, vdev_bitmap[i]);
922*5113495bSYour Name 			}
923*5113495bSYour Name 
924*5113495bSYour Name 			buf_ptr += sizeof(*vdev_bitmap) *
925*5113495bSYour Name 				num_inactive_vdev_bitmap;
926*5113495bSYour Name 		}
927*5113495bSYour Name 	}
928*5113495bSYour Name 
929*5113495bSYour Name 	wmi_mtrace(WMI_MLO_LINK_SET_ACTIVE_CMDID, 0, cmd->force_mode);
930*5113495bSYour Name 	status = wmi_unified_cmd_send(wmi_handle, buf, len,
931*5113495bSYour Name 				      WMI_MLO_LINK_SET_ACTIVE_CMDID);
932*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status)) {
933*5113495bSYour Name 		wmi_err("Failed to send MLO link set active command to FW: %d",
934*5113495bSYour Name 			status);
935*5113495bSYour Name 		wmi_buf_free(buf);
936*5113495bSYour Name 	}
937*5113495bSYour Name 
938*5113495bSYour Name 	return status;
939*5113495bSYour Name }
940*5113495bSYour Name 
941*5113495bSYour Name /**
942*5113495bSYour Name  * extract_mlo_link_set_active_resp_tlv() - extract mlo link set active resp
943*5113495bSYour Name  *  from event
944*5113495bSYour Name  * @wmi_handle: wmi handle
945*5113495bSYour Name  * @evt_buf: pointer to event buffer
946*5113495bSYour Name  * @resp: Pointer to hold mlo link set active resp
947*5113495bSYour Name  *
948*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS for success or QDF_STATUS_E_* for error
949*5113495bSYour Name  */
950*5113495bSYour Name static QDF_STATUS
extract_mlo_link_set_active_resp_tlv(wmi_unified_t wmi_handle,void * evt_buf,struct mlo_link_set_active_resp * resp)951*5113495bSYour Name extract_mlo_link_set_active_resp_tlv(wmi_unified_t wmi_handle, void *evt_buf,
952*5113495bSYour Name 				     struct mlo_link_set_active_resp *resp)
953*5113495bSYour Name {
954*5113495bSYour Name 	wmi_mlo_link_set_active_resp_event_fixed_param *evt;
955*5113495bSYour Name 	WMI_MLO_LINK_SET_ACTIVE_RESP_EVENTID_param_tlvs *param_buf;
956*5113495bSYour Name 	uint32_t entry_num, *bitmap;
957*5113495bSYour Name 	int i;
958*5113495bSYour Name 
959*5113495bSYour Name 	param_buf = evt_buf;
960*5113495bSYour Name 	if (!param_buf || !resp) {
961*5113495bSYour Name 		wmi_err("Invalid param");
962*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
963*5113495bSYour Name 	}
964*5113495bSYour Name 
965*5113495bSYour Name 	evt = param_buf->fixed_param;
966*5113495bSYour Name 	resp->status = evt->status;
967*5113495bSYour Name 	WMI_MAC_ADDR_TO_CHAR_ARRAY(&evt->ap_mld_mac_addr,
968*5113495bSYour Name 				   resp->ap_mld_mac_addr.bytes);
969*5113495bSYour Name 	wmi_debug("status: %u use linkid %d ap mld:"QDF_MAC_ADDR_FMT,
970*5113495bSYour Name 		  resp->status,
971*5113495bSYour Name 		  evt->use_ieee_link_id_bitmap,
972*5113495bSYour Name 		  QDF_MAC_ADDR_REF(resp->ap_mld_mac_addr.bytes));
973*5113495bSYour Name 
974*5113495bSYour Name 	bitmap = param_buf->current_active_ieee_link_id_bitmap;
975*5113495bSYour Name 	if (bitmap &&
976*5113495bSYour Name 	    param_buf->num_current_active_ieee_link_id_bitmap > 0)
977*5113495bSYour Name 		resp->curr_active_linkid_bitmap = bitmap[0];
978*5113495bSYour Name 	bitmap = param_buf->current_inactive_ieee_link_id_bitmap;
979*5113495bSYour Name 	if (bitmap &&
980*5113495bSYour Name 	    param_buf->num_current_inactive_ieee_link_id_bitmap > 0)
981*5113495bSYour Name 		resp->curr_inactive_linkid_bitmap = bitmap[0];
982*5113495bSYour Name 	wmi_debug("curr active links: 0x%x inactive links: 0x%x num: %x %x",
983*5113495bSYour Name 		  resp->curr_active_linkid_bitmap,
984*5113495bSYour Name 		  resp->curr_inactive_linkid_bitmap,
985*5113495bSYour Name 		  param_buf->num_current_active_ieee_link_id_bitmap,
986*5113495bSYour Name 		  param_buf->num_current_inactive_ieee_link_id_bitmap);
987*5113495bSYour Name 
988*5113495bSYour Name 	if (evt->use_ieee_link_id_bitmap) {
989*5113495bSYour Name 		bitmap = param_buf->force_active_ieee_link_id_bitmap;
990*5113495bSYour Name 		if (bitmap &&
991*5113495bSYour Name 		    param_buf->num_force_active_ieee_link_id_bitmap > 0)
992*5113495bSYour Name 			resp->active_linkid_bitmap = bitmap[0];
993*5113495bSYour Name 
994*5113495bSYour Name 		bitmap = param_buf->force_inactive_ieee_link_id_bitmap;
995*5113495bSYour Name 		if (bitmap &&
996*5113495bSYour Name 		    param_buf->num_force_inactive_ieee_link_id_bitmap > 0)
997*5113495bSYour Name 			resp->inactive_linkid_bitmap = bitmap[0];
998*5113495bSYour Name 		resp->use_ieee_link_id = true;
999*5113495bSYour Name 		wmi_debug("forced active links: 0x%x inactive links: 0x%x num: %x %x",
1000*5113495bSYour Name 			  resp->active_linkid_bitmap,
1001*5113495bSYour Name 			  resp->inactive_linkid_bitmap,
1002*5113495bSYour Name 			  param_buf->num_force_active_ieee_link_id_bitmap,
1003*5113495bSYour Name 			  param_buf->num_force_inactive_ieee_link_id_bitmap);
1004*5113495bSYour Name 		return QDF_STATUS_SUCCESS;
1005*5113495bSYour Name 	}
1006*5113495bSYour Name 
1007*5113495bSYour Name 	bitmap = param_buf->force_active_vdev_bitmap;
1008*5113495bSYour Name 	entry_num = qdf_min(param_buf->num_force_active_vdev_bitmap,
1009*5113495bSYour Name 			    (uint32_t)MLO_VDEV_BITMAP_SZ);
1010*5113495bSYour Name 	resp->active_sz = entry_num;
1011*5113495bSYour Name 	for (i = 0; i < entry_num; i++) {
1012*5113495bSYour Name 		resp->active[i] = bitmap[i];
1013*5113495bSYour Name 		wmi_debug("vdev active[%d]: 0x%x", i, resp->active[i]);
1014*5113495bSYour Name 	}
1015*5113495bSYour Name 
1016*5113495bSYour Name 	bitmap = param_buf->force_inactive_vdev_bitmap;
1017*5113495bSYour Name 	entry_num = qdf_min(param_buf->num_force_inactive_vdev_bitmap,
1018*5113495bSYour Name 			    (uint32_t)MLO_VDEV_BITMAP_SZ);
1019*5113495bSYour Name 	resp->inactive_sz = entry_num;
1020*5113495bSYour Name 	for (i = 0; i < entry_num; i++) {
1021*5113495bSYour Name 		resp->inactive[i] = bitmap[i];
1022*5113495bSYour Name 		wmi_debug("vdev inactive[%d]: 0x%x", i, resp->inactive[i]);
1023*5113495bSYour Name 	}
1024*5113495bSYour Name 
1025*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1026*5113495bSYour Name }
1027*5113495bSYour Name 
1028*5113495bSYour Name /**
1029*5113495bSYour Name  * send_mlo_link_removal_cmd_tlv() - Send WMI command for MLO link removal
1030*5113495bSYour Name  * @wmi_handle: wmi handle
1031*5113495bSYour Name  * @params: MLO link removal command parameters
1032*5113495bSYour Name  *
1033*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS of operation
1034*5113495bSYour Name  */
send_mlo_link_removal_cmd_tlv(wmi_unified_t wmi_handle,const struct mlo_link_removal_cmd_params * params)1035*5113495bSYour Name static QDF_STATUS send_mlo_link_removal_cmd_tlv(
1036*5113495bSYour Name 	wmi_unified_t wmi_handle,
1037*5113495bSYour Name 	const struct mlo_link_removal_cmd_params *params)
1038*5113495bSYour Name {
1039*5113495bSYour Name 	wmi_mlo_link_removal_cmd_fixed_param *fixed_params;
1040*5113495bSYour Name 	wmi_buf_t buf;
1041*5113495bSYour Name 	uint8_t *buf_ptr;
1042*5113495bSYour Name 	uint32_t buf_len = 0;
1043*5113495bSYour Name 	uint32_t ie_len_aligned = 0;
1044*5113495bSYour Name 	QDF_STATUS ret;
1045*5113495bSYour Name 
1046*5113495bSYour Name 	if (!params) {
1047*5113495bSYour Name 		wmi_err("command params is NULL");
1048*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1049*5113495bSYour Name 	}
1050*5113495bSYour Name 
1051*5113495bSYour Name 	ie_len_aligned = roundup(params->reconfig_ml_ie_size, sizeof(uint32_t));
1052*5113495bSYour Name 
1053*5113495bSYour Name 	buf_len = sizeof(wmi_mlo_link_removal_cmd_fixed_param) +
1054*5113495bSYour Name 		  WMI_TLV_HDR_SIZE + ie_len_aligned;
1055*5113495bSYour Name 
1056*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, buf_len);
1057*5113495bSYour Name 	if (!buf) {
1058*5113495bSYour Name 		wmi_err("wmi buf alloc failed for link removal cmd: psoc (%pK) vdev(%u)",
1059*5113495bSYour Name 			wmi_handle->soc->wmi_psoc, params->vdev_id);
1060*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
1061*5113495bSYour Name 	}
1062*5113495bSYour Name 
1063*5113495bSYour Name 	buf_ptr = (uint8_t *)wmi_buf_data(buf);
1064*5113495bSYour Name 
1065*5113495bSYour Name 	/* Populate fixed params TLV */
1066*5113495bSYour Name 	fixed_params = (wmi_mlo_link_removal_cmd_fixed_param *)buf_ptr;
1067*5113495bSYour Name 	WMITLV_SET_HDR(&fixed_params->tlv_header,
1068*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_mlo_link_removal_cmd_fixed_param,
1069*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(
1070*5113495bSYour Name 			   wmi_mlo_link_removal_cmd_fixed_param));
1071*5113495bSYour Name 	fixed_params->vdev_id = params->vdev_id;
1072*5113495bSYour Name 	fixed_params->reconfig_ml_ie_num_bytes_valid =
1073*5113495bSYour Name 		params->reconfig_ml_ie_size;
1074*5113495bSYour Name 	buf_ptr += sizeof(*fixed_params);
1075*5113495bSYour Name 
1076*5113495bSYour Name 	/* Populate the array of bytes TLV */
1077*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE, ie_len_aligned);
1078*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
1079*5113495bSYour Name 
1080*5113495bSYour Name 	/* Populate ML reconfiguration element in raw bytes */
1081*5113495bSYour Name 	qdf_mem_copy(buf_ptr, params->reconfig_ml_ie,
1082*5113495bSYour Name 		     params->reconfig_ml_ie_size);
1083*5113495bSYour Name 
1084*5113495bSYour Name 	wmi_mtrace(WMI_MLO_LINK_REMOVAL_CMDID, fixed_params->vdev_id, 0);
1085*5113495bSYour Name 	ret = wmi_unified_cmd_send(wmi_handle, buf, buf_len,
1086*5113495bSYour Name 				   WMI_MLO_LINK_REMOVAL_CMDID);
1087*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(ret)) {
1088*5113495bSYour Name 		wmi_err("Failed to send MLO link removal cmd: psoc (%pK) vdev(%u)",
1089*5113495bSYour Name 			wmi_handle->soc->wmi_psoc, params->vdev_id);
1090*5113495bSYour Name 		wmi_buf_free(buf);
1091*5113495bSYour Name 	}
1092*5113495bSYour Name 
1093*5113495bSYour Name 	return ret;
1094*5113495bSYour Name }
1095*5113495bSYour Name 
1096*5113495bSYour Name /**
1097*5113495bSYour Name  * send_mlo_vdev_pause_cmd_tlv() - Send WMI command for MLO vdev pause
1098*5113495bSYour Name  * @wmi_handle: wmi handle
1099*5113495bSYour Name  * @info: MLO vdev pause information
1100*5113495bSYour Name  *
1101*5113495bSYour Name  * Return: QDF_STATUS of operation
1102*5113495bSYour Name  */
send_mlo_vdev_pause_cmd_tlv(wmi_unified_t wmi_handle,struct mlo_vdev_pause * info)1103*5113495bSYour Name static QDF_STATUS send_mlo_vdev_pause_cmd_tlv(wmi_unified_t wmi_handle,
1104*5113495bSYour Name 					      struct mlo_vdev_pause *info)
1105*5113495bSYour Name {
1106*5113495bSYour Name 	wmi_vdev_pause_cmd_fixed_param *fixed_params;
1107*5113495bSYour Name 	wmi_buf_t buf;
1108*5113495bSYour Name 	uint32_t buf_len = 0;
1109*5113495bSYour Name 	QDF_STATUS ret;
1110*5113495bSYour Name 
1111*5113495bSYour Name 	if (!info) {
1112*5113495bSYour Name 		wmi_err("ML vdev pause info is NULL");
1113*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1114*5113495bSYour Name 	}
1115*5113495bSYour Name 
1116*5113495bSYour Name 	buf_len = sizeof(*fixed_params);
1117*5113495bSYour Name 
1118*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, buf_len);
1119*5113495bSYour Name 	if (!buf) {
1120*5113495bSYour Name 		wmi_err("wmi buf alloc failed for vdev pause cmd: psoc (%pK) vdev(%u)",
1121*5113495bSYour Name 			wmi_handle->soc->wmi_psoc, info->vdev_id);
1122*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
1123*5113495bSYour Name 	}
1124*5113495bSYour Name 
1125*5113495bSYour Name 	/* Populate fixed params TLV */
1126*5113495bSYour Name 	fixed_params = (wmi_vdev_pause_cmd_fixed_param *)wmi_buf_data(buf);
1127*5113495bSYour Name 	WMITLV_SET_HDR(&fixed_params->tlv_header,
1128*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_vdev_pause_cmd_fixed_param,
1129*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_vdev_pause_cmd_fixed_param));
1130*5113495bSYour Name 	fixed_params->vdev_id = info->vdev_id;
1131*5113495bSYour Name 	fixed_params->pause_dur_ms = info->vdev_pause_duration;
1132*5113495bSYour Name 	fixed_params->pause_type = WMI_VDEV_PAUSE_TYPE_MLO_LINK;
1133*5113495bSYour Name 	wmi_debug("vdev id: %d pause duration: %d pause type %d",
1134*5113495bSYour Name 		  fixed_params->vdev_id, fixed_params->pause_dur_ms,
1135*5113495bSYour Name 		  fixed_params->pause_type);
1136*5113495bSYour Name 
1137*5113495bSYour Name 	wmi_mtrace(WMI_VDEV_PAUSE_CMDID, fixed_params->vdev_id, 0);
1138*5113495bSYour Name 	ret = wmi_unified_cmd_send(wmi_handle, buf, buf_len,
1139*5113495bSYour Name 				   WMI_VDEV_PAUSE_CMDID);
1140*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(ret)) {
1141*5113495bSYour Name 		wmi_err("Failed to send vdev pause cmd: psoc (%pK) vdev(%u)",
1142*5113495bSYour Name 			wmi_handle->soc->wmi_psoc, info->vdev_id);
1143*5113495bSYour Name 		wmi_buf_free(buf);
1144*5113495bSYour Name 	}
1145*5113495bSYour Name 
1146*5113495bSYour Name 	return ret;
1147*5113495bSYour Name }
1148*5113495bSYour Name 
1149*5113495bSYour Name /**
1150*5113495bSYour Name  * extract_mlo_link_removal_evt_fixed_param_tlv() - Extract fixed parameters TLV
1151*5113495bSYour Name  * from the MLO link removal WMI  event
1152*5113495bSYour Name  * @wmi_handle: wmi handle
1153*5113495bSYour Name  * @buf: pointer to event buffer
1154*5113495bSYour Name  * @params: MLO link removal event parameters
1155*5113495bSYour Name  *
1156*5113495bSYour Name  * Return: QDF_STATUS of operation
1157*5113495bSYour Name  */
1158*5113495bSYour Name static QDF_STATUS
extract_mlo_link_removal_evt_fixed_param_tlv(struct wmi_unified * wmi_handle,void * buf,struct mlo_link_removal_evt_params * params)1159*5113495bSYour Name extract_mlo_link_removal_evt_fixed_param_tlv(
1160*5113495bSYour Name 	struct wmi_unified *wmi_handle,
1161*5113495bSYour Name 	void *buf,
1162*5113495bSYour Name 	struct mlo_link_removal_evt_params *params)
1163*5113495bSYour Name {
1164*5113495bSYour Name 	WMI_MLO_LINK_REMOVAL_EVENTID_param_tlvs *param_buf = buf;
1165*5113495bSYour Name 	wmi_mlo_link_removal_evt_fixed_param *ev;
1166*5113495bSYour Name 
1167*5113495bSYour Name 	if (!param_buf) {
1168*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
1169*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1170*5113495bSYour Name 	}
1171*5113495bSYour Name 
1172*5113495bSYour Name 	if (!params) {
1173*5113495bSYour Name 		wmi_err_rl("params is NULL");
1174*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1175*5113495bSYour Name 	}
1176*5113495bSYour Name 
1177*5113495bSYour Name 	ev = param_buf->fixed_param;
1178*5113495bSYour Name 	params->vdev_id = ev->vdev_id;
1179*5113495bSYour Name 
1180*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1181*5113495bSYour Name }
1182*5113495bSYour Name 
1183*5113495bSYour Name /**
1184*5113495bSYour Name  * extract_mlo_link_removal_tbtt_update_tlv() - Extract TBTT update TLV
1185*5113495bSYour Name  * from the MLO link removal WMI  event
1186*5113495bSYour Name  * @wmi_handle: wmi handle
1187*5113495bSYour Name  * @buf: pointer to event buffer
1188*5113495bSYour Name  * @tbtt_info: TBTT information to be populated
1189*5113495bSYour Name  *
1190*5113495bSYour Name  * Return: QDF_STATUS of operation
1191*5113495bSYour Name  */
1192*5113495bSYour Name static QDF_STATUS
extract_mlo_link_removal_tbtt_update_tlv(struct wmi_unified * wmi_handle,void * buf,struct mlo_link_removal_tbtt_info * tbtt_info)1193*5113495bSYour Name extract_mlo_link_removal_tbtt_update_tlv(
1194*5113495bSYour Name 	struct wmi_unified *wmi_handle,
1195*5113495bSYour Name 	void *buf,
1196*5113495bSYour Name 	struct mlo_link_removal_tbtt_info *tbtt_info)
1197*5113495bSYour Name {
1198*5113495bSYour Name 	WMI_MLO_LINK_REMOVAL_EVENTID_param_tlvs *param_buf = buf;
1199*5113495bSYour Name 	wmi_mlo_link_removal_tbtt_update *tlv;
1200*5113495bSYour Name 
1201*5113495bSYour Name 	if (!param_buf) {
1202*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
1203*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1204*5113495bSYour Name 	}
1205*5113495bSYour Name 
1206*5113495bSYour Name 	if (!tbtt_info) {
1207*5113495bSYour Name 		wmi_err_rl("Writable argument is NULL");
1208*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1209*5113495bSYour Name 	}
1210*5113495bSYour Name 
1211*5113495bSYour Name 	tlv = param_buf->tbtt_update;
1212*5113495bSYour Name 
1213*5113495bSYour Name 	tbtt_info->tbtt_count = tlv->tbtt_count;
1214*5113495bSYour Name 	tbtt_info->tsf = ((uint64_t)tlv->tsf_high << 32) | tlv->tsf_low;
1215*5113495bSYour Name 	tbtt_info->qtimer_reading =
1216*5113495bSYour Name 		((uint64_t)tlv->qtimer_ts_high << 32) | tlv->qtimer_ts_low;
1217*5113495bSYour Name 
1218*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1219*5113495bSYour Name }
1220*5113495bSYour Name 
1221*5113495bSYour Name /**
1222*5113495bSYour Name  * extract_mgmt_rx_mlo_link_removal_info_tlv() - Extract MLO link removal info
1223*5113495bSYour Name  * from MGMT Rx event
1224*5113495bSYour Name  * @wmi_handle: wmi handle
1225*5113495bSYour Name  * @buf: event buffer
1226*5113495bSYour Name  * @link_removal_info: link removal information array to be populated
1227*5113495bSYour Name  * @num_link_removal_info: Number of elements in @link_removal_info
1228*5113495bSYour Name  *
1229*5113495bSYour Name  * Return: QDF_STATUS of operation
1230*5113495bSYour Name  */
1231*5113495bSYour Name static QDF_STATUS
extract_mgmt_rx_mlo_link_removal_info_tlv(struct wmi_unified * wmi_handle,void * buf,struct mgmt_rx_mlo_link_removal_info * link_removal_info,int num_link_removal_info)1232*5113495bSYour Name extract_mgmt_rx_mlo_link_removal_info_tlv(
1233*5113495bSYour Name 	struct wmi_unified *wmi_handle,
1234*5113495bSYour Name 	void *buf,
1235*5113495bSYour Name 	struct mgmt_rx_mlo_link_removal_info *link_removal_info,
1236*5113495bSYour Name 	int num_link_removal_info)
1237*5113495bSYour Name {
1238*5113495bSYour Name 	WMI_MGMT_RX_EVENTID_param_tlvs *param_buf = buf;
1239*5113495bSYour Name 	wmi_mlo_link_removal_tbtt_count *tlv_arr;
1240*5113495bSYour Name 	int tlv_idx = 0;
1241*5113495bSYour Name 	struct mgmt_rx_mlo_link_removal_info *info;
1242*5113495bSYour Name 
1243*5113495bSYour Name 	if (!param_buf) {
1244*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
1245*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1246*5113495bSYour Name 	}
1247*5113495bSYour Name 
1248*5113495bSYour Name 	if (!link_removal_info) {
1249*5113495bSYour Name 		wmi_err_rl("Writable argument is NULL");
1250*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1251*5113495bSYour Name 	}
1252*5113495bSYour Name 
1253*5113495bSYour Name 	if (num_link_removal_info != param_buf->num_link_removal_tbtt_count) {
1254*5113495bSYour Name 		wmi_err_rl("link_removal_info array size (%d) is not equal to"
1255*5113495bSYour Name 			   "number of corresponding TLVs(%d) present in event",
1256*5113495bSYour Name 			   num_link_removal_info,
1257*5113495bSYour Name 			   param_buf->num_link_removal_tbtt_count);
1258*5113495bSYour Name 		return QDF_STATUS_E_RANGE;
1259*5113495bSYour Name 	}
1260*5113495bSYour Name 
1261*5113495bSYour Name 	tlv_arr = param_buf->link_removal_tbtt_count;
1262*5113495bSYour Name 	for (; tlv_idx < param_buf->num_link_removal_tbtt_count; tlv_idx++) {
1263*5113495bSYour Name 		info = &link_removal_info[tlv_idx];
1264*5113495bSYour Name 
1265*5113495bSYour Name 		info->hw_link_id = WMI_MLO_LINK_REMOVAL_GET_LINKID(
1266*5113495bSYour Name 					tlv_arr[tlv_idx].tbtt_info);
1267*5113495bSYour Name 		info->vdev_id = WMI_MLO_LINK_REMOVAL_GET_VDEVID(
1268*5113495bSYour Name 					tlv_arr[tlv_idx].tbtt_info);
1269*5113495bSYour Name 		info->tbtt_count = WMI_MLO_LINK_REMOVAL_GET_TBTT_COUNT(
1270*5113495bSYour Name 					tlv_arr[tlv_idx].tbtt_info);
1271*5113495bSYour Name 	}
1272*5113495bSYour Name 
1273*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1274*5113495bSYour Name }
1275*5113495bSYour Name 
1276*5113495bSYour Name /**
1277*5113495bSYour Name  * extract_mlo_link_disable_request_evt_param_tlv() - Extract fixed
1278*5113495bSYour Name  * parameters TLV from the MLO link removal WMI  event
1279*5113495bSYour Name  * @wmi_handle: wmi handle
1280*5113495bSYour Name  * @buf: pointer to event buffer
1281*5113495bSYour Name  * @params: MLO link removal event parameters
1282*5113495bSYour Name  *
1283*5113495bSYour Name  * Return: QDF_STATUS of operation
1284*5113495bSYour Name  */
1285*5113495bSYour Name static QDF_STATUS
extract_mlo_link_disable_request_evt_param_tlv(struct wmi_unified * wmi_handle,void * buf,struct mlo_link_disable_request_evt_params * params)1286*5113495bSYour Name extract_mlo_link_disable_request_evt_param_tlv(
1287*5113495bSYour Name 	struct wmi_unified *wmi_handle,
1288*5113495bSYour Name 	void *buf,
1289*5113495bSYour Name 	struct mlo_link_disable_request_evt_params *params)
1290*5113495bSYour Name {
1291*5113495bSYour Name 	WMI_MLO_LINK_DISABLE_REQUEST_EVENTID_param_tlvs *param_buf = buf;
1292*5113495bSYour Name 	wmi_mlo_link_disable_request_event_fixed_param *ev;
1293*5113495bSYour Name 
1294*5113495bSYour Name 	if (!param_buf) {
1295*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
1296*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1297*5113495bSYour Name 	}
1298*5113495bSYour Name 
1299*5113495bSYour Name 	if (!params) {
1300*5113495bSYour Name 		wmi_err_rl("params is NULL");
1301*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1302*5113495bSYour Name 	}
1303*5113495bSYour Name 
1304*5113495bSYour Name 	ev = param_buf->fixed_param;
1305*5113495bSYour Name 	WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->mld_addr,
1306*5113495bSYour Name 				   params->mld_addr.bytes);
1307*5113495bSYour Name 
1308*5113495bSYour Name 	params->link_id_bitmap = ev->linkid_bitmap;
1309*5113495bSYour Name 
1310*5113495bSYour Name 	wmi_debug("Link id bitmap 0x%x MLD addr " QDF_MAC_ADDR_FMT,
1311*5113495bSYour Name 		  params->link_id_bitmap,
1312*5113495bSYour Name 		  QDF_MAC_ADDR_REF(params->mld_addr.bytes));
1313*5113495bSYour Name 
1314*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1315*5113495bSYour Name }
1316*5113495bSYour Name 
1317*5113495bSYour Name #ifdef WLAN_FEATURE_11BE_MLO_ADV_FEATURE
1318*5113495bSYour Name static QDF_STATUS
extract_mlo_link_state_switch_event_tlv(struct wmi_unified * wmi_handle,void * evt_buf,uint8_t len,struct mlo_link_switch_state_info * info)1319*5113495bSYour Name extract_mlo_link_state_switch_event_tlv(struct wmi_unified *wmi_handle,
1320*5113495bSYour Name 					void *evt_buf, uint8_t len,
1321*5113495bSYour Name 					struct mlo_link_switch_state_info *info)
1322*5113495bSYour Name {
1323*5113495bSYour Name 	WMI_MLO_LINK_STATE_SWITCH_EVENTID_param_tlvs *param_buf = evt_buf;
1324*5113495bSYour Name 	wmi_mlo_link_state_switch_req_evt_fixed_param *fixed_param;
1325*5113495bSYour Name 	wmi_mlo_link_state_switch_trigger_reason *lnk_switch_param;
1326*5113495bSYour Name 	uint8_t i, num_tlv, rem_len;
1327*5113495bSYour Name 
1328*5113495bSYour Name 	if (!param_buf) {
1329*5113495bSYour Name 		wmi_err("param buf is NULL");
1330*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1331*5113495bSYour Name 	}
1332*5113495bSYour Name 
1333*5113495bSYour Name 	fixed_param = param_buf->fixed_param;
1334*5113495bSYour Name 	if (!fixed_param) {
1335*5113495bSYour Name 		wmi_err("fixed param is NULL");
1336*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1337*5113495bSYour Name 	}
1338*5113495bSYour Name 
1339*5113495bSYour Name 	num_tlv = fixed_param->link_state_switch_count;
1340*5113495bSYour Name 	if (num_tlv > MAX_LINK_SWITCH_TLV)
1341*5113495bSYour Name 		num_tlv = MAX_LINK_SWITCH_TLV;
1342*5113495bSYour Name 
1343*5113495bSYour Name 	rem_len = len - sizeof(*fixed_param);
1344*5113495bSYour Name 	if (rem_len <
1345*5113495bSYour Name 	    num_tlv * sizeof(wmi_mlo_link_state_switch_trigger_reason)) {
1346*5113495bSYour Name 		wmi_err_rl("Invalid link state switch TLVs rem_len:%d num_tlv:%d",
1347*5113495bSYour Name 			   rem_len, num_tlv);
1348*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
1349*5113495bSYour Name 	}
1350*5113495bSYour Name 
1351*5113495bSYour Name 	lnk_switch_param = param_buf->switch_trigger_reason;
1352*5113495bSYour Name 	if (!lnk_switch_param) {
1353*5113495bSYour Name 		wmi_err_rl("No TLV is present");
1354*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
1355*5113495bSYour Name 	}
1356*5113495bSYour Name 
1357*5113495bSYour Name 	info->num_params = num_tlv;
1358*5113495bSYour Name 	for (i = 0; i < num_tlv; i++) {
1359*5113495bSYour Name 		WMI_MAC_ADDR_TO_CHAR_ARRAY(&lnk_switch_param->ml_bssid,
1360*5113495bSYour Name 					   info->link_switch_param[i].mld_addr.bytes);
1361*5113495bSYour Name 
1362*5113495bSYour Name 		info->link_switch_param[i].active_link_bitmap =
1363*5113495bSYour Name 			lnk_switch_param->cur_active_ieee_bitmap;
1364*5113495bSYour Name 		info->link_switch_param[i].prev_link_bitmap =
1365*5113495bSYour Name 			lnk_switch_param->prev_active_ieee_bitmap;
1366*5113495bSYour Name 		info->link_switch_param[i].fw_timestamp =
1367*5113495bSYour Name 			lnk_switch_param->host_ref_fw_timestamp_ms;
1368*5113495bSYour Name 		info->link_switch_param[i].reason_code =
1369*5113495bSYour Name 			lnk_switch_param->reason_code;
1370*5113495bSYour Name 		wmi_debug("i:%d active_link_bmap:0x%x prev_bmap:0x%x reason_code:%d MLD addr: "QDF_MAC_ADDR_FMT,
1371*5113495bSYour Name 			  i, info->link_switch_param[i].active_link_bitmap,
1372*5113495bSYour Name 			  info->link_switch_param[i].prev_link_bitmap,
1373*5113495bSYour Name 			  info->link_switch_param[i].reason_code,
1374*5113495bSYour Name 			  QDF_MAC_ADDR_REF(info->link_switch_param[i].mld_addr.bytes));
1375*5113495bSYour Name 
1376*5113495bSYour Name 		lnk_switch_param++;
1377*5113495bSYour Name 	}
1378*5113495bSYour Name 
1379*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1380*5113495bSYour Name }
1381*5113495bSYour Name #endif
1382*5113495bSYour Name 
1383*5113495bSYour Name #ifdef WLAN_FEATURE_11BE
peer_assoc_t2lm_params_size(struct peer_assoc_params * req)1384*5113495bSYour Name size_t peer_assoc_t2lm_params_size(struct peer_assoc_params *req)
1385*5113495bSYour Name {
1386*5113495bSYour Name 	size_t peer_assoc_t2lm_size = WMI_TLV_HDR_SIZE +
1387*5113495bSYour Name 		(req->t2lm_params.num_dir * T2LM_MAX_NUM_TIDS *
1388*5113495bSYour Name 		 (sizeof(wmi_peer_assoc_tid_to_link_map)));
1389*5113495bSYour Name 
1390*5113495bSYour Name 	return peer_assoc_t2lm_size;
1391*5113495bSYour Name }
1392*5113495bSYour Name 
peer_assoc_populate_t2lm_tlv(wmi_peer_assoc_tid_to_link_map * cmd,struct wlan_host_t2lm_of_tids * t2lm,uint8_t tid_num)1393*5113495bSYour Name static void peer_assoc_populate_t2lm_tlv(wmi_peer_assoc_tid_to_link_map *cmd,
1394*5113495bSYour Name 				  struct wlan_host_t2lm_of_tids *t2lm,
1395*5113495bSYour Name 				  uint8_t tid_num)
1396*5113495bSYour Name {
1397*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header,
1398*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_peer_assoc_tid_to_link_map,
1399*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(
1400*5113495bSYour Name 				   wmi_peer_assoc_tid_to_link_map));
1401*5113495bSYour Name 
1402*5113495bSYour Name 	/* Populate TID number */
1403*5113495bSYour Name 	WMI_TID_TO_LINK_MAP_TID_NUM_SET(cmd->tid_to_link_map_info, tid_num);
1404*5113495bSYour Name 
1405*5113495bSYour Name 	/* Populate the direction */
1406*5113495bSYour Name 	WMI_TID_TO_LINK_MAP_DIR_SET(cmd->tid_to_link_map_info,
1407*5113495bSYour Name 				    t2lm->direction);
1408*5113495bSYour Name 
1409*5113495bSYour Name 	/* Populate the default link mapping value */
1410*5113495bSYour Name 	WMI_TID_TO_LINK_MAP_DEFAULT_MAPPING_SET(
1411*5113495bSYour Name 			cmd->tid_to_link_map_info,
1412*5113495bSYour Name 			t2lm->default_link_mapping);
1413*5113495bSYour Name 
1414*5113495bSYour Name 	/* Populate the T2LM provisioned links for the corresponding TID
1415*5113495bSYour Name 	 * number.
1416*5113495bSYour Name 	 */
1417*5113495bSYour Name 	WMI_TID_TO_LINK_MAP_LINK_MASK_SET(
1418*5113495bSYour Name 			cmd->tid_to_link_map_info,
1419*5113495bSYour Name 			t2lm->t2lm_provisioned_links[tid_num]);
1420*5113495bSYour Name 
1421*5113495bSYour Name 	wmi_debug("Add T2LM TLV: tid_to_link_map_info:%x",
1422*5113495bSYour Name 		  cmd->tid_to_link_map_info);
1423*5113495bSYour Name }
1424*5113495bSYour Name 
peer_assoc_add_tid_to_link_map(uint8_t * buf_ptr,struct peer_assoc_params * req)1425*5113495bSYour Name uint8_t *peer_assoc_add_tid_to_link_map(uint8_t *buf_ptr,
1426*5113495bSYour Name 					struct peer_assoc_params *req)
1427*5113495bSYour Name {
1428*5113495bSYour Name 	struct wmi_host_tid_to_link_map_params *t2lm_params = &req->t2lm_params;
1429*5113495bSYour Name 	wmi_peer_assoc_tid_to_link_map *cmd;
1430*5113495bSYour Name 	uint8_t dir = 0;
1431*5113495bSYour Name 	uint8_t tid_num = 0;
1432*5113495bSYour Name 
1433*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
1434*5113495bSYour Name 		       (req->t2lm_params.num_dir * T2LM_MAX_NUM_TIDS *
1435*5113495bSYour Name 		       sizeof(wmi_peer_assoc_tid_to_link_map)));
1436*5113495bSYour Name 	buf_ptr += sizeof(uint32_t);
1437*5113495bSYour Name 
1438*5113495bSYour Name 	for (dir = 0; dir < t2lm_params->num_dir; dir++) {
1439*5113495bSYour Name 		wmi_debug("Add T2LM TLV for peer: " QDF_MAC_ADDR_FMT " direction:%d",
1440*5113495bSYour Name 				QDF_MAC_ADDR_REF(t2lm_params->peer_macaddr),
1441*5113495bSYour Name 				t2lm_params->t2lm_info[dir].direction);
1442*5113495bSYour Name 		for (tid_num = 0; tid_num < T2LM_MAX_NUM_TIDS; tid_num++) {
1443*5113495bSYour Name 			cmd = (wmi_peer_assoc_tid_to_link_map *)buf_ptr;
1444*5113495bSYour Name 			peer_assoc_populate_t2lm_tlv(
1445*5113495bSYour Name 					cmd, &t2lm_params->t2lm_info[dir],
1446*5113495bSYour Name 					tid_num);
1447*5113495bSYour Name 			buf_ptr += sizeof(wmi_peer_assoc_tid_to_link_map);
1448*5113495bSYour Name 		}
1449*5113495bSYour Name 	}
1450*5113495bSYour Name 
1451*5113495bSYour Name 	return buf_ptr;
1452*5113495bSYour Name }
1453*5113495bSYour Name 
1454*5113495bSYour Name #ifdef WMI_AP_SUPPORT
find_buf_len_pref_link(struct wmi_host_tid_to_link_map_params * params,bool t2lm_info)1455*5113495bSYour Name static uint32_t find_buf_len_pref_link(
1456*5113495bSYour Name 		struct wmi_host_tid_to_link_map_params *params,
1457*5113495bSYour Name 		bool t2lm_info)
1458*5113495bSYour Name {
1459*5113495bSYour Name 	uint32_t buf_len = 0;
1460*5113495bSYour Name 
1461*5113495bSYour Name 	buf_len = sizeof(wmi_peer_tid_to_link_map_fixed_param);
1462*5113495bSYour Name 
1463*5113495bSYour Name 	/* Update the length for T2LM info TLV */
1464*5113495bSYour Name 	if (t2lm_info) {
1465*5113495bSYour Name 		buf_len += (WMI_TLV_HDR_SIZE +
1466*5113495bSYour Name 				(params->num_dir * T2LM_MAX_NUM_TIDS *
1467*5113495bSYour Name 				sizeof(wmi_tid_to_link_map)));
1468*5113495bSYour Name 	} else {
1469*5113495bSYour Name 		buf_len += WMI_TLV_HDR_SIZE;
1470*5113495bSYour Name 	}
1471*5113495bSYour Name 
1472*5113495bSYour Name 	/* Update the length for Preferred Link TLV.
1473*5113495bSYour Name 	 * The Link Preference TLV is planned to be deprecated,
1474*5113495bSYour Name 	 * so the TLV is going to be exlcuded by default
1475*5113495bSYour Name 	 */
1476*5113495bSYour Name 	buf_len += WMI_TLV_HDR_SIZE;
1477*5113495bSYour Name 
1478*5113495bSYour Name 	/* Update the length for Link control TLV */
1479*5113495bSYour Name 	if (params->preferred_links.num_pref_links) {
1480*5113495bSYour Name 		buf_len += (WMI_TLV_HDR_SIZE +
1481*5113495bSYour Name 			sizeof(wmi_mlo_peer_link_control_param));
1482*5113495bSYour Name 	} else {
1483*5113495bSYour Name 		buf_len += WMI_TLV_HDR_SIZE;
1484*5113495bSYour Name 	}
1485*5113495bSYour Name 
1486*5113495bSYour Name 	return buf_len;
1487*5113495bSYour Name }
1488*5113495bSYour Name 
populate_link_control_tlv(uint8_t * buf_ptr,struct wmi_host_tid_to_link_map_params * params)1489*5113495bSYour Name static uint8_t *populate_link_control_tlv(
1490*5113495bSYour Name 		uint8_t *buf_ptr,
1491*5113495bSYour Name 		struct wmi_host_tid_to_link_map_params *params)
1492*5113495bSYour Name {
1493*5113495bSYour Name 	wmi_mlo_peer_link_control_param *link_control;
1494*5113495bSYour Name 	uint8_t pref_link = 0;
1495*5113495bSYour Name 	uint8_t latency = 0;
1496*5113495bSYour Name 	uint8_t links = 0;
1497*5113495bSYour Name 
1498*5113495bSYour Name 	/* The Link Preference TLV is planned to be deprecated,
1499*5113495bSYour Name 	 * so the TLV is going to be exlcuded by default.
1500*5113495bSYour Name 	 */
1501*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, 0);
1502*5113495bSYour Name 	buf_ptr = buf_ptr + WMI_TLV_HDR_SIZE;
1503*5113495bSYour Name 
1504*5113495bSYour Name 	if (params->preferred_links.num_pref_links) {
1505*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
1506*5113495bSYour Name 			sizeof(wmi_mlo_peer_link_control_param));
1507*5113495bSYour Name 		buf_ptr += sizeof(uint32_t);
1508*5113495bSYour Name 
1509*5113495bSYour Name 		link_control = (wmi_mlo_peer_link_control_param *)buf_ptr;
1510*5113495bSYour Name 
1511*5113495bSYour Name 		WMITLV_SET_HDR(&link_control->tlv_header,
1512*5113495bSYour Name 			WMITLV_TAG_STRUC_wmi_mlo_peer_link_control_param,
1513*5113495bSYour Name 			WMITLV_GET_STRUCT_TLVLEN(wmi_mlo_peer_link_control_param));
1514*5113495bSYour Name 
1515*5113495bSYour Name 		link_control->num_links = params->preferred_links.num_pref_links;
1516*5113495bSYour Name 		links = params->preferred_links.num_pref_links;
1517*5113495bSYour Name 
1518*5113495bSYour Name 		for (pref_link = 0; pref_link < links; pref_link++) {
1519*5113495bSYour Name 			link_control->link_priority_order[pref_link] =
1520*5113495bSYour Name 			    params->preferred_links.preffered_link_order[pref_link];
1521*5113495bSYour Name 			wmi_debug("Add preference link TLV: preffered_link_order: %d",
1522*5113495bSYour Name 			    link_control->link_priority_order[pref_link]);
1523*5113495bSYour Name 		}
1524*5113495bSYour Name 
1525*5113495bSYour Name 		link_control->flags =
1526*5113495bSYour Name 			params->preferred_links.link_control_flags;
1527*5113495bSYour Name 		link_control->tx_link_tuple_bitmap =
1528*5113495bSYour Name 			params->preferred_links.tlt_characterization_params;
1529*5113495bSYour Name 
1530*5113495bSYour Name 		for (latency = 0; latency < WLAN_MAX_AC; latency++) {
1531*5113495bSYour Name 			link_control->max_timeout_ms[latency] =
1532*5113495bSYour Name 			    params->preferred_links.timeout[latency];
1533*5113495bSYour Name 			wmi_debug("Add preference link TLV: expected_timeout_ms: %d",
1534*5113495bSYour Name 			    link_control->max_timeout_ms[latency]);
1535*5113495bSYour Name 		}
1536*5113495bSYour Name 		buf_ptr += sizeof(wmi_mlo_peer_link_control_param);
1537*5113495bSYour Name 	} else {
1538*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, 0);
1539*5113495bSYour Name 		buf_ptr = buf_ptr + WMI_TLV_HDR_SIZE;
1540*5113495bSYour Name 	}
1541*5113495bSYour Name 
1542*5113495bSYour Name 	return buf_ptr;
1543*5113495bSYour Name }
1544*5113495bSYour Name 
1545*5113495bSYour Name static void
populate_fill_t2lm_timer_tlv(wmi_peer_tid_to_link_map_fixed_param * cmd,struct wmi_host_tid_to_link_map_params * params)1546*5113495bSYour Name populate_fill_t2lm_timer_tlv(wmi_peer_tid_to_link_map_fixed_param *cmd,
1547*5113495bSYour Name 			     struct wmi_host_tid_to_link_map_params *params)
1548*5113495bSYour Name {
1549*5113495bSYour Name }
1550*5113495bSYour Name #else
find_buf_len_pref_link(struct wmi_host_tid_to_link_map_params * params,bool t2lm_info)1551*5113495bSYour Name static uint32_t find_buf_len_pref_link(
1552*5113495bSYour Name 		struct wmi_host_tid_to_link_map_params *params,
1553*5113495bSYour Name 		bool t2lm_info)
1554*5113495bSYour Name {
1555*5113495bSYour Name 	uint32_t buf_len = 0;
1556*5113495bSYour Name 
1557*5113495bSYour Name 	buf_len = sizeof(wmi_peer_tid_to_link_map_fixed_param) +
1558*5113495bSYour Name 		WMI_TLV_HDR_SIZE + (params->num_dir * T2LM_MAX_NUM_TIDS *
1559*5113495bSYour Name 		 sizeof(wmi_tid_to_link_map));
1560*5113495bSYour Name 	return buf_len;
1561*5113495bSYour Name }
1562*5113495bSYour Name 
populate_link_control_tlv(uint8_t * buf_ptr,struct wmi_host_tid_to_link_map_params * params)1563*5113495bSYour Name static uint8_t *populate_link_control_tlv(
1564*5113495bSYour Name 		uint8_t *buf_ptr,
1565*5113495bSYour Name 		struct wmi_host_tid_to_link_map_params *params)
1566*5113495bSYour Name {
1567*5113495bSYour Name 	return buf_ptr;
1568*5113495bSYour Name }
1569*5113495bSYour Name 
1570*5113495bSYour Name static void
populate_fill_t2lm_timer_tlv(wmi_peer_tid_to_link_map_fixed_param * cmd,struct wmi_host_tid_to_link_map_params * params)1571*5113495bSYour Name populate_fill_t2lm_timer_tlv(wmi_peer_tid_to_link_map_fixed_param *cmd,
1572*5113495bSYour Name 			     struct wmi_host_tid_to_link_map_params *params)
1573*5113495bSYour Name {
1574*5113495bSYour Name 	cmd->mapping_switch_time = params->mapping_switch_time;
1575*5113495bSYour Name 	cmd->expected_duration = params->expected_duration;
1576*5113495bSYour Name }
1577*5113495bSYour Name #endif
1578*5113495bSYour Name 
1579*5113495bSYour Name #ifdef WLAN_FEATURE_11BE_MLO_ADV_FEATURE
1580*5113495bSYour Name /**
1581*5113495bSYour Name  * extract_mlo_link_switch_request_event_tlv() - Extract fixed
1582*5113495bSYour Name  * params TLV from MLO link switch request WMI event.
1583*5113495bSYour Name  * @wmi_handle: wmi handle
1584*5113495bSYour Name  * @buf: Pointer to event buffer.
1585*5113495bSYour Name  * @req: MLO Link switch event parameters.
1586*5113495bSYour Name  *
1587*5113495bSYour Name  * Return: QDF_STATUS
1588*5113495bSYour Name  */
1589*5113495bSYour Name static QDF_STATUS
extract_mlo_link_switch_request_event_tlv(struct wmi_unified * wmi_handle,void * buf,struct wlan_mlo_link_switch_req * req)1590*5113495bSYour Name extract_mlo_link_switch_request_event_tlv(struct wmi_unified *wmi_handle,
1591*5113495bSYour Name 					  void *buf,
1592*5113495bSYour Name 					  struct wlan_mlo_link_switch_req *req)
1593*5113495bSYour Name {
1594*5113495bSYour Name 	WMI_MLO_LINK_SWITCH_REQUEST_EVENTID_param_tlvs *param_buf = buf;
1595*5113495bSYour Name 	wmi_mlo_link_switch_req_evt_fixed_param *ev;
1596*5113495bSYour Name 
1597*5113495bSYour Name 	if (!param_buf) {
1598*5113495bSYour Name 		wmi_err_rl("buf is NULL");
1599*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1600*5113495bSYour Name 	}
1601*5113495bSYour Name 
1602*5113495bSYour Name 	if (!req) {
1603*5113495bSYour Name 		wmi_err_rl("req is NULL");
1604*5113495bSYour Name 		return QDF_STATUS_E_NULL_VALUE;
1605*5113495bSYour Name 	}
1606*5113495bSYour Name 
1607*5113495bSYour Name 	ev = param_buf->fixed_param;
1608*5113495bSYour Name 	req->vdev_id = ev->vdev_id;
1609*5113495bSYour Name 	req->curr_ieee_link_id = ev->curr_ieee_link_id;
1610*5113495bSYour Name 	req->new_ieee_link_id = ev->new_ieee_link_id;
1611*5113495bSYour Name 	req->new_primary_freq = ev->new_primary_freq;
1612*5113495bSYour Name 	req->new_phymode = ev->new_phymode;
1613*5113495bSYour Name 	req->reason = ev->reason;
1614*5113495bSYour Name 
1615*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1616*5113495bSYour Name }
1617*5113495bSYour Name 
1618*5113495bSYour Name static QDF_STATUS
send_link_switch_request_cnf_cmd_tlv(wmi_unified_t wmi_handle,struct wlan_mlo_link_switch_cnf * params)1619*5113495bSYour Name send_link_switch_request_cnf_cmd_tlv(wmi_unified_t wmi_handle,
1620*5113495bSYour Name 				     struct wlan_mlo_link_switch_cnf *params)
1621*5113495bSYour Name {
1622*5113495bSYour Name 	wmi_mlo_link_switch_cnf_fixed_param *cmd;
1623*5113495bSYour Name 	wmi_buf_t buf;
1624*5113495bSYour Name 	uint8_t *buf_ptr;
1625*5113495bSYour Name 	QDF_STATUS ret = QDF_STATUS_SUCCESS;
1626*5113495bSYour Name 	uint32_t buf_len;
1627*5113495bSYour Name 
1628*5113495bSYour Name 	buf_len = sizeof(wmi_mlo_link_switch_cnf_fixed_param);
1629*5113495bSYour Name 
1630*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, buf_len);
1631*5113495bSYour Name 	if (!buf) {
1632*5113495bSYour Name 		wmi_err("wmi buf alloc failed for vdev id %d while link state cmd send: ",
1633*5113495bSYour Name 			params->vdev_id);
1634*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
1635*5113495bSYour Name 	}
1636*5113495bSYour Name 
1637*5113495bSYour Name 	buf_ptr = (uint8_t *)wmi_buf_data(buf);
1638*5113495bSYour Name 	cmd = (wmi_mlo_link_switch_cnf_fixed_param *)buf_ptr;
1639*5113495bSYour Name 
1640*5113495bSYour Name 	WMITLV_SET_HDR(
1641*5113495bSYour Name 		&cmd->tlv_header,
1642*5113495bSYour Name 		WMITLV_TAG_STRUC_wmi_mlo_link_switch_cnf_fixed_param,
1643*5113495bSYour Name 		WMITLV_GET_STRUCT_TLVLEN(
1644*5113495bSYour Name 			wmi_mlo_link_switch_cnf_fixed_param));
1645*5113495bSYour Name 
1646*5113495bSYour Name 	cmd->vdev_id = params->vdev_id;
1647*5113495bSYour Name 	cmd->status = params->status;
1648*5113495bSYour Name 	cmd->reason = params->reason;
1649*5113495bSYour Name 	buf_ptr += sizeof(wmi_mlo_link_switch_cnf_fixed_param);
1650*5113495bSYour Name 	wmi_mtrace(WMI_MLO_LINK_SWITCH_CONF_CMDID, cmd->vdev_id, 0);
1651*5113495bSYour Name 	ret = wmi_unified_cmd_send(wmi_handle, buf, buf_len,
1652*5113495bSYour Name 				   WMI_MLO_LINK_SWITCH_CONF_CMDID);
1653*5113495bSYour Name 	if (ret) {
1654*5113495bSYour Name 		wmi_err("Failed to send ml link switch cnf command to FW: %d vdev id %d",
1655*5113495bSYour Name 			ret, cmd->vdev_id);
1656*5113495bSYour Name 		wmi_buf_free(buf);
1657*5113495bSYour Name 	}
1658*5113495bSYour Name 	return ret;
1659*5113495bSYour Name }
1660*5113495bSYour Name #endif /* WLAN_FEATURE_11BE_MLO_ADV_FEATURE */
1661*5113495bSYour Name 
1662*5113495bSYour Name static QDF_STATUS
send_link_state_request_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_host_link_state_params * params)1663*5113495bSYour Name send_link_state_request_cmd_tlv(wmi_unified_t wmi_handle,
1664*5113495bSYour Name 				struct wmi_host_link_state_params *params)
1665*5113495bSYour Name {
1666*5113495bSYour Name 	wmi_mlo_vdev_get_link_info_cmd_fixed_param *cmd;
1667*5113495bSYour Name 	wmi_buf_t buf;
1668*5113495bSYour Name 	uint8_t *buf_ptr;
1669*5113495bSYour Name 	QDF_STATUS ret = QDF_STATUS_SUCCESS;
1670*5113495bSYour Name 	uint32_t buf_len = 0;
1671*5113495bSYour Name 
1672*5113495bSYour Name 	buf_len = sizeof(wmi_mlo_vdev_get_link_info_cmd_fixed_param);
1673*5113495bSYour Name 
1674*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, buf_len);
1675*5113495bSYour Name 	if (!buf) {
1676*5113495bSYour Name 		wmi_err("wmi buf alloc failed for vdev id %d while link state cmd send: ",
1677*5113495bSYour Name 			params->vdev_id);
1678*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
1679*5113495bSYour Name 	}
1680*5113495bSYour Name 
1681*5113495bSYour Name 	buf_ptr = (uint8_t *)wmi_buf_data(buf);
1682*5113495bSYour Name 	cmd = (wmi_mlo_vdev_get_link_info_cmd_fixed_param *)buf_ptr;
1683*5113495bSYour Name 
1684*5113495bSYour Name 	WMITLV_SET_HDR(
1685*5113495bSYour Name 		&cmd->tlv_header,
1686*5113495bSYour Name 		WMITLV_TAG_STRUC_wmi_mlo_vdev_get_link_info_cmd_fixed_param,
1687*5113495bSYour Name 		WMITLV_GET_STRUCT_TLVLEN(
1688*5113495bSYour Name 		wmi_mlo_vdev_get_link_info_cmd_fixed_param));
1689*5113495bSYour Name 
1690*5113495bSYour Name 	cmd->vdev_id = params->vdev_id;
1691*5113495bSYour Name 	WMI_CHAR_ARRAY_TO_MAC_ADDR(params->mld_mac, &cmd->mld_macaddr);
1692*5113495bSYour Name 	buf_ptr += sizeof(wmi_mlo_vdev_get_link_info_cmd_fixed_param);
1693*5113495bSYour Name 	wmi_mtrace(WMI_MLO_VDEV_GET_LINK_INFO_CMDID, cmd->vdev_id, 0);
1694*5113495bSYour Name 	ret = wmi_unified_cmd_send(wmi_handle, buf, buf_len,
1695*5113495bSYour Name 				   WMI_MLO_VDEV_GET_LINK_INFO_CMDID);
1696*5113495bSYour Name 	if (ret) {
1697*5113495bSYour Name 		wmi_err("Failed to send ml link state command to FW: %d vdev id %d",
1698*5113495bSYour Name 			ret, cmd->vdev_id);
1699*5113495bSYour Name 		wmi_buf_free(buf);
1700*5113495bSYour Name 	}
1701*5113495bSYour Name 	return ret;
1702*5113495bSYour Name }
1703*5113495bSYour Name 
1704*5113495bSYour Name static QDF_STATUS
send_link_set_bss_params_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_host_link_bss_params * params)1705*5113495bSYour Name send_link_set_bss_params_cmd_tlv(wmi_unified_t wmi_handle,
1706*5113495bSYour Name 				 struct wmi_host_link_bss_params *params)
1707*5113495bSYour Name {
1708*5113495bSYour Name 	QDF_STATUS status;
1709*5113495bSYour Name 	wmi_buf_t buf;
1710*5113495bSYour Name 	wmi_mlo_set_link_bss_params_cmd_fixed_param *cmd;
1711*5113495bSYour Name 	uint8_t *buf_ptr;
1712*5113495bSYour Name 	wmi_mlo_link_bss_param *bss_param;
1713*5113495bSYour Name 		WMI_HOST_WLAN_PHY_MODE fw_phy_mode;
1714*5113495bSYour Name 
1715*5113495bSYour Name 	size_t len = sizeof(*cmd) +
1716*5113495bSYour Name 		     sizeof(wmi_mlo_link_bss_param) +
1717*5113495bSYour Name 		     WMI_TLV_HDR_SIZE;
1718*5113495bSYour Name 
1719*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, len);
1720*5113495bSYour Name 	if (!buf) {
1721*5113495bSYour Name 		wmi_err("wmi_buf_alloc failed");
1722*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
1723*5113495bSYour Name 	}
1724*5113495bSYour Name 	buf_ptr = (uint8_t *)wmi_buf_data(buf);
1725*5113495bSYour Name 	cmd =
1726*5113495bSYour Name 	(wmi_mlo_set_link_bss_params_cmd_fixed_param *)buf_ptr;
1727*5113495bSYour Name 	WMITLV_SET_HDR(
1728*5113495bSYour Name 		&cmd->tlv_header,
1729*5113495bSYour Name 		WMITLV_TAG_STRUC_wmi_mlo_set_link_bss_params_cmd_fixed_param,
1730*5113495bSYour Name 		WMITLV_GET_STRUCT_TLVLEN(
1731*5113495bSYour Name 		wmi_mlo_set_link_bss_params_cmd_fixed_param));
1732*5113495bSYour Name 
1733*5113495bSYour Name 	WMI_CHAR_ARRAY_TO_MAC_ADDR(params->ap_mld_mac, &cmd->ap_mld_macaddr);
1734*5113495bSYour Name 
1735*5113495bSYour Name 	buf_ptr += sizeof(wmi_mlo_set_link_bss_params_cmd_fixed_param);
1736*5113495bSYour Name 
1737*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
1738*5113495bSYour Name 		       (sizeof(wmi_mlo_link_bss_param)));
1739*5113495bSYour Name 	buf_ptr += WMI_TLV_HDR_SIZE;
1740*5113495bSYour Name 
1741*5113495bSYour Name 	bss_param =
1742*5113495bSYour Name 		(wmi_mlo_link_bss_param *)buf_ptr;
1743*5113495bSYour Name 
1744*5113495bSYour Name 	WMITLV_SET_HDR(&bss_param->tlv_header,
1745*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_mlo_link_bss_param,
1746*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_mlo_link_bss_param));
1747*5113495bSYour Name 
1748*5113495bSYour Name 	bss_param->ieee_link_id = params->link_id;
1749*5113495bSYour Name 
1750*5113495bSYour Name 	bss_param->wmi_chan.mhz = params->chan.ch_freq;
1751*5113495bSYour Name 	bss_param->wmi_chan.band_center_freq1 = params->chan.ch_cfreq1;
1752*5113495bSYour Name 	bss_param->wmi_chan.band_center_freq2 = params->chan.ch_cfreq2;
1753*5113495bSYour Name 	fw_phy_mode = wmi_host_to_fw_phymode(params->chan.ch_phymode);
1754*5113495bSYour Name 	WMI_SET_CHANNEL_MODE(&bss_param->wmi_chan, fw_phy_mode);
1755*5113495bSYour Name 	wmi_debug("ap mld mac: " QDF_MAC_ADDR_FMT " link id %d chan freq %d cfreq1 %d cfreq2 %d fw phymode %d",
1756*5113495bSYour Name 		  QDF_MAC_ADDR_REF(params->ap_mld_mac), bss_param->ieee_link_id,
1757*5113495bSYour Name 		  bss_param->wmi_chan.mhz,
1758*5113495bSYour Name 		  bss_param->wmi_chan.band_center_freq1,
1759*5113495bSYour Name 		  bss_param->wmi_chan.band_center_freq2,
1760*5113495bSYour Name 		  fw_phy_mode);
1761*5113495bSYour Name 
1762*5113495bSYour Name 	buf_ptr += sizeof(wmi_mlo_link_bss_param);
1763*5113495bSYour Name 
1764*5113495bSYour Name 	wmi_mtrace(WMI_MLO_LINK_SET_BSS_PARAMS_CMDID, 0, 0);
1765*5113495bSYour Name 	status = wmi_unified_cmd_send(wmi_handle, buf, len,
1766*5113495bSYour Name 				      WMI_MLO_LINK_SET_BSS_PARAMS_CMDID);
1767*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status)) {
1768*5113495bSYour Name 		wmi_err("Failed to send link set bss command ret = %d", status);
1769*5113495bSYour Name 		wmi_buf_free(buf);
1770*5113495bSYour Name 	}
1771*5113495bSYour Name 
1772*5113495bSYour Name 	return status;
1773*5113495bSYour Name }
1774*5113495bSYour Name 
1775*5113495bSYour Name static QDF_STATUS
extract_mlo_link_state_event_tlv(struct wmi_unified * wmi_handle,void * buf,struct ml_link_state_info_event * params)1776*5113495bSYour Name extract_mlo_link_state_event_tlv(struct wmi_unified *wmi_handle,
1777*5113495bSYour Name 				 void *buf,
1778*5113495bSYour Name 				 struct  ml_link_state_info_event *params)
1779*5113495bSYour Name {
1780*5113495bSYour Name 	WMI_MLO_VDEV_LINK_INFO_EVENTID_param_tlvs *param_buf;
1781*5113495bSYour Name 	wmi_mlo_vdev_link_info_event_fixed_param *ev;
1782*5113495bSYour Name 	wmi_mlo_vdev_link_info  *link_info = NULL;
1783*5113495bSYour Name 	int num_info = 0;
1784*5113495bSYour Name 	uint8_t *mld_addr;
1785*5113495bSYour Name 	uint32_t num_link_info = 0;
1786*5113495bSYour Name 
1787*5113495bSYour Name 	param_buf = (WMI_MLO_VDEV_LINK_INFO_EVENTID_param_tlvs *)buf;
1788*5113495bSYour Name 
1789*5113495bSYour Name 	if (!param_buf) {
1790*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
1791*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
1792*5113495bSYour Name 	}
1793*5113495bSYour Name 
1794*5113495bSYour Name 	ev = (wmi_mlo_vdev_link_info_event_fixed_param *)
1795*5113495bSYour Name 	param_buf->fixed_param;
1796*5113495bSYour Name 	link_info = (wmi_mlo_vdev_link_info *)param_buf->mlo_vdev_link_info;
1797*5113495bSYour Name 
1798*5113495bSYour Name 	num_link_info = param_buf->num_mlo_vdev_link_info;
1799*5113495bSYour Name 	params->status = ev->status;
1800*5113495bSYour Name 	params->vdev_id = ev->vdev_id;
1801*5113495bSYour Name 	params->hw_mode_index = ev->hw_mode_index;
1802*5113495bSYour Name 	params->num_mlo_vdev_link_info = num_link_info;
1803*5113495bSYour Name 	mld_addr = params->mldaddr.bytes;
1804*5113495bSYour Name 	WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->mld_macaddr, mld_addr);
1805*5113495bSYour Name 
1806*5113495bSYour Name 	if (params->num_mlo_vdev_link_info > WLAN_MAX_ML_BSS_LINKS) {
1807*5113495bSYour Name 		wmi_err_rl("Invalid number of vdev link info");
1808*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
1809*5113495bSYour Name 	}
1810*5113495bSYour Name 
1811*5113495bSYour Name 	for (num_info = 0; num_info < num_link_info; num_info++) {
1812*5113495bSYour Name 		params->link_info[num_info].vdev_id =
1813*5113495bSYour Name 		WMI_MLO_VDEV_LINK_INFO_GET_VDEVID(link_info->link_info);
1814*5113495bSYour Name 
1815*5113495bSYour Name 		params->link_info[num_info].link_id =
1816*5113495bSYour Name 		WMI_MLO_VDEV_LINK_INFO_GET_LINKID(link_info->link_info);
1817*5113495bSYour Name 
1818*5113495bSYour Name 		params->link_info[num_info].link_status =
1819*5113495bSYour Name 		WMI_MLO_VDEV_LINK_INFO_GET_LINK_STATUS(link_info->link_info);
1820*5113495bSYour Name 
1821*5113495bSYour Name 		params->link_info[num_info].chan_freq =
1822*5113495bSYour Name 		link_info->chan_freq;
1823*5113495bSYour Name 
1824*5113495bSYour Name 		link_info++;
1825*5113495bSYour Name 	}
1826*5113495bSYour Name 
1827*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1828*5113495bSYour Name }
1829*5113495bSYour Name 
send_mlo_peer_tid_to_link_map_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_host_tid_to_link_map_params * params,bool t2lm_info)1830*5113495bSYour Name static QDF_STATUS send_mlo_peer_tid_to_link_map_cmd_tlv(
1831*5113495bSYour Name 		wmi_unified_t wmi_handle,
1832*5113495bSYour Name 		struct wmi_host_tid_to_link_map_params *params,
1833*5113495bSYour Name 		bool t2lm_info)
1834*5113495bSYour Name {
1835*5113495bSYour Name 	wmi_peer_tid_to_link_map_fixed_param *cmd;
1836*5113495bSYour Name 	wmi_tid_to_link_map *t2lm;
1837*5113495bSYour Name 	wmi_buf_t buf;
1838*5113495bSYour Name 	uint8_t *buf_ptr;
1839*5113495bSYour Name 	QDF_STATUS ret = QDF_STATUS_SUCCESS;
1840*5113495bSYour Name 	uint32_t buf_len = 0;
1841*5113495bSYour Name 	uint8_t dir = 0;
1842*5113495bSYour Name 	uint8_t tid_num = 0;
1843*5113495bSYour Name 
1844*5113495bSYour Name 	buf_len = find_buf_len_pref_link(params, t2lm_info);
1845*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, buf_len);
1846*5113495bSYour Name 	if (!buf) {
1847*5113495bSYour Name 		wmi_err("wmi buf alloc failed for mlo_peer_mac: "
1848*5113495bSYour Name 				QDF_MAC_ADDR_FMT,
1849*5113495bSYour Name 				QDF_MAC_ADDR_REF(params->peer_macaddr));
1850*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
1851*5113495bSYour Name 	}
1852*5113495bSYour Name 
1853*5113495bSYour Name 	buf_ptr = (uint8_t *)wmi_buf_data(buf);
1854*5113495bSYour Name 	cmd = (wmi_peer_tid_to_link_map_fixed_param *)buf_ptr;
1855*5113495bSYour Name 
1856*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header,
1857*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_peer_tid_to_link_map_fixed_param,
1858*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(
1859*5113495bSYour Name 			   wmi_peer_tid_to_link_map_fixed_param));
1860*5113495bSYour Name 
1861*5113495bSYour Name 	cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(
1862*5113495bSYour Name 			wmi_handle, params->pdev_id);
1863*5113495bSYour Name 
1864*5113495bSYour Name 	WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr, &cmd->link_macaddr);
1865*5113495bSYour Name 
1866*5113495bSYour Name 	buf_ptr += sizeof(wmi_peer_tid_to_link_map_fixed_param);
1867*5113495bSYour Name 	populate_fill_t2lm_timer_tlv(cmd, params);
1868*5113495bSYour Name 
1869*5113495bSYour Name 	if (t2lm_info) {
1870*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
1871*5113495bSYour Name 		       (params->num_dir * T2LM_MAX_NUM_TIDS *
1872*5113495bSYour Name 		       sizeof(wmi_tid_to_link_map)));
1873*5113495bSYour Name 		buf_ptr += sizeof(uint32_t);
1874*5113495bSYour Name 
1875*5113495bSYour Name 		for (dir = 0; dir < params->num_dir; dir++) {
1876*5113495bSYour Name 			wmi_debug("Add T2LM TLV for peer: " QDF_MAC_ADDR_FMT " direction:%d",
1877*5113495bSYour Name 				QDF_MAC_ADDR_REF(params->peer_macaddr),
1878*5113495bSYour Name 				params->t2lm_info[dir].direction);
1879*5113495bSYour Name 
1880*5113495bSYour Name 			for (tid_num = 0; tid_num < T2LM_MAX_NUM_TIDS; tid_num++) {
1881*5113495bSYour Name 				t2lm = (wmi_tid_to_link_map *)buf_ptr;
1882*5113495bSYour Name 
1883*5113495bSYour Name 				WMITLV_SET_HDR(&t2lm->tlv_header,
1884*5113495bSYour Name 				       WMITLV_TAG_STRUC_wmi_tid_to_link_map,
1885*5113495bSYour Name 				       WMITLV_GET_STRUCT_TLVLEN(
1886*5113495bSYour Name 					   wmi_tid_to_link_map));
1887*5113495bSYour Name 
1888*5113495bSYour Name 				/* Populate TID number */
1889*5113495bSYour Name 				WMI_TID_TO_LINK_MAP_TID_NUM_SET(
1890*5113495bSYour Name 					t2lm->tid_to_link_map_info, tid_num);
1891*5113495bSYour Name 
1892*5113495bSYour Name 				/* Populate the direction */
1893*5113495bSYour Name 				WMI_TID_TO_LINK_MAP_DIR_SET(
1894*5113495bSYour Name 					t2lm->tid_to_link_map_info,
1895*5113495bSYour Name 					params->t2lm_info[dir].direction);
1896*5113495bSYour Name 
1897*5113495bSYour Name 				/* Populate the default link mapping value */
1898*5113495bSYour Name 				WMI_TID_TO_LINK_MAP_DEFAULT_MAPPING_SET(
1899*5113495bSYour Name 					t2lm->tid_to_link_map_info,
1900*5113495bSYour Name 					params->t2lm_info[dir].default_link_mapping);
1901*5113495bSYour Name 
1902*5113495bSYour Name 				/* Populate the T2LM provisioned links for the
1903*5113495bSYour Name 				 * corresponding TID number.
1904*5113495bSYour Name 				 */
1905*5113495bSYour Name 				WMI_TID_TO_LINK_MAP_LINK_MASK_SET(
1906*5113495bSYour Name 					t2lm->tid_to_link_map_info,
1907*5113495bSYour Name 					params->t2lm_info[dir].t2lm_provisioned_links[tid_num]);
1908*5113495bSYour Name 
1909*5113495bSYour Name 				buf_ptr += sizeof(wmi_tid_to_link_map);
1910*5113495bSYour Name 
1911*5113495bSYour Name 				wmi_debug("Add T2LM TLV: tid_to_link_map_info:%x",
1912*5113495bSYour Name 				  t2lm->tid_to_link_map_info);
1913*5113495bSYour Name 			}
1914*5113495bSYour Name 		}
1915*5113495bSYour Name 	} else {
1916*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, 0);
1917*5113495bSYour Name 		buf_ptr = buf_ptr + WMI_TLV_HDR_SIZE;
1918*5113495bSYour Name 	}
1919*5113495bSYour Name 
1920*5113495bSYour Name 	buf_ptr = populate_link_control_tlv(buf_ptr, params);
1921*5113495bSYour Name 	wmi_mtrace(WMI_MLO_PEER_TID_TO_LINK_MAP_CMDID, cmd->pdev_id, 0);
1922*5113495bSYour Name 	ret = wmi_unified_cmd_send(wmi_handle, buf, buf_len,
1923*5113495bSYour Name 				   WMI_MLO_PEER_TID_TO_LINK_MAP_CMDID);
1924*5113495bSYour Name 	if (ret) {
1925*5113495bSYour Name 		wmi_err("Failed to send T2LM command to FW: %d mlo_peer_mac: " QDF_MAC_ADDR_FMT,
1926*5113495bSYour Name 				ret, QDF_MAC_ADDR_REF(params->peer_macaddr));
1927*5113495bSYour Name 		wmi_buf_free(buf);
1928*5113495bSYour Name 	}
1929*5113495bSYour Name 
1930*5113495bSYour Name 	return ret;
1931*5113495bSYour Name }
1932*5113495bSYour Name 
update_t2lm_ie_info_params(wmi_mlo_ap_vdev_tid_to_link_map_ie_info * info,struct wlan_t2lm_info * params)1933*5113495bSYour Name static void update_t2lm_ie_info_params(
1934*5113495bSYour Name 		wmi_mlo_ap_vdev_tid_to_link_map_ie_info * info,
1935*5113495bSYour Name 		struct wlan_t2lm_info *params)
1936*5113495bSYour Name {
1937*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_CTRL_DIR_SET(
1938*5113495bSYour Name 			info->tid_to_link_map_ctrl,
1939*5113495bSYour Name 			params->direction);
1940*5113495bSYour Name 
1941*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_CTRL_DEF_LINK_SET(
1942*5113495bSYour Name 			info->tid_to_link_map_ctrl,
1943*5113495bSYour Name 			params->default_link_mapping);
1944*5113495bSYour Name 
1945*5113495bSYour Name 	info->map_switch_time = params->mapping_switch_time;
1946*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_CTRL_SWT_TIME_SET(
1947*5113495bSYour Name 			info->tid_to_link_map_ctrl,
1948*5113495bSYour Name 			params->mapping_switch_time_present);
1949*5113495bSYour Name 
1950*5113495bSYour Name 	info->expected_duration = params->expected_duration;
1951*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_CTRL_DUR_TIME_SET(
1952*5113495bSYour Name 			info->tid_to_link_map_ctrl,
1953*5113495bSYour Name 			params->expected_duration_present);
1954*5113495bSYour Name 
1955*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_CTRL_LINK_MAP_SIZE_SET(
1956*5113495bSYour Name 			info->tid_to_link_map_ctrl,
1957*5113495bSYour Name 			params->link_mapping_size);
1958*5113495bSYour Name 
1959*5113495bSYour Name 	wmi_debug("tid_to_link_map_ctrl:%x map_switch_time:%d expected_duration:%d",
1960*5113495bSYour Name 		  info->tid_to_link_map_ctrl, info->map_switch_time,
1961*5113495bSYour Name 		  info->expected_duration);
1962*5113495bSYour Name 
1963*5113495bSYour Name 	/* Do not fill link mapping values when default mapping is set to 1 */
1964*5113495bSYour Name 	if (params->default_link_mapping)
1965*5113495bSYour Name 		return;
1966*5113495bSYour Name 
1967*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_CTRL_LINK_MAP_PRE_SET(
1968*5113495bSYour Name 			info->tid_to_link_map_ctrl, 0xff);
1969*5113495bSYour Name 
1970*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_IEEE_LINK_ID_0_SET(
1971*5113495bSYour Name 			info->ieee_tid_0_1_link_map,
1972*5113495bSYour Name 			params->ieee_link_map_tid[0]);
1973*5113495bSYour Name 
1974*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_IEEE_LINK_ID_1_SET(
1975*5113495bSYour Name 			info->ieee_tid_0_1_link_map,
1976*5113495bSYour Name 			params->ieee_link_map_tid[1]);
1977*5113495bSYour Name 
1978*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_IEEE_LINK_ID_2_SET(
1979*5113495bSYour Name 			info->ieee_tid_2_3_link_map,
1980*5113495bSYour Name 			params->ieee_link_map_tid[2]);
1981*5113495bSYour Name 
1982*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_IEEE_LINK_ID_3_SET(
1983*5113495bSYour Name 			info->ieee_tid_2_3_link_map,
1984*5113495bSYour Name 			params->ieee_link_map_tid[3]);
1985*5113495bSYour Name 
1986*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_IEEE_LINK_ID_4_SET(
1987*5113495bSYour Name 			info->ieee_tid_4_5_link_map,
1988*5113495bSYour Name 			params->ieee_link_map_tid[4]);
1989*5113495bSYour Name 
1990*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_IEEE_LINK_ID_5_SET(
1991*5113495bSYour Name 			info->ieee_tid_4_5_link_map,
1992*5113495bSYour Name 			params->ieee_link_map_tid[5]);
1993*5113495bSYour Name 
1994*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_IEEE_LINK_ID_6_SET(
1995*5113495bSYour Name 			info->ieee_tid_6_7_link_map,
1996*5113495bSYour Name 			params->ieee_link_map_tid[6]);
1997*5113495bSYour Name 
1998*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_IEEE_LINK_ID_7_SET(
1999*5113495bSYour Name 			info->ieee_tid_6_7_link_map,
2000*5113495bSYour Name 			params->ieee_link_map_tid[7]);
2001*5113495bSYour Name 
2002*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_HW_LINK_ID_0_SET(
2003*5113495bSYour Name 			info->hw_tid_0_1_link_map,
2004*5113495bSYour Name 			params->hw_link_map_tid[0]);
2005*5113495bSYour Name 
2006*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_HW_LINK_ID_1_SET(
2007*5113495bSYour Name 			info->hw_tid_0_1_link_map,
2008*5113495bSYour Name 			params->hw_link_map_tid[1]);
2009*5113495bSYour Name 
2010*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_HW_LINK_ID_2_SET(
2011*5113495bSYour Name 			info->hw_tid_2_3_link_map,
2012*5113495bSYour Name 			params->hw_link_map_tid[2]);
2013*5113495bSYour Name 
2014*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_HW_LINK_ID_3_SET(
2015*5113495bSYour Name 			info->hw_tid_2_3_link_map,
2016*5113495bSYour Name 			params->hw_link_map_tid[3]);
2017*5113495bSYour Name 
2018*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_HW_LINK_ID_4_SET(
2019*5113495bSYour Name 			info->hw_tid_4_5_link_map,
2020*5113495bSYour Name 			params->hw_link_map_tid[4]);
2021*5113495bSYour Name 
2022*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_HW_LINK_ID_5_SET(
2023*5113495bSYour Name 			info->hw_tid_4_5_link_map,
2024*5113495bSYour Name 			params->hw_link_map_tid[5]);
2025*5113495bSYour Name 
2026*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_HW_LINK_ID_6_SET(
2027*5113495bSYour Name 			info->hw_tid_6_7_link_map,
2028*5113495bSYour Name 			params->hw_link_map_tid[6]);
2029*5113495bSYour Name 
2030*5113495bSYour Name 	WMI_MLO_VDEV_TID_TO_LINK_MAP_HW_LINK_ID_7_SET(
2031*5113495bSYour Name 			info->hw_tid_6_7_link_map,
2032*5113495bSYour Name 			params->hw_link_map_tid[7]);
2033*5113495bSYour Name 
2034*5113495bSYour Name 	wmi_debug("tid_to_link_map_ctrl:%x", info->tid_to_link_map_ctrl);
2035*5113495bSYour Name 	wmi_debug("ieee_link_map: tid_0_1:%x tid_2_3:%x tid_4_5:%x tid_6_7:%x",
2036*5113495bSYour Name 		  info->ieee_tid_0_1_link_map, info->ieee_tid_2_3_link_map,
2037*5113495bSYour Name 		  info->ieee_tid_4_5_link_map, info->ieee_tid_6_7_link_map);
2038*5113495bSYour Name 	wmi_debug("hw_link_map: tid_0_1:%x tid_2_3:%x tid_4_5:%x tid_6_7:%x",
2039*5113495bSYour Name 		  info->hw_tid_0_1_link_map, info->hw_tid_2_3_link_map,
2040*5113495bSYour Name 		  info->hw_tid_4_5_link_map, info->hw_tid_6_7_link_map);
2041*5113495bSYour Name }
2042*5113495bSYour Name 
send_mlo_vdev_tid_to_link_map_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_host_tid_to_link_map_ap_params * params)2043*5113495bSYour Name static QDF_STATUS send_mlo_vdev_tid_to_link_map_cmd_tlv(
2044*5113495bSYour Name 		wmi_unified_t wmi_handle,
2045*5113495bSYour Name 		struct wmi_host_tid_to_link_map_ap_params *params)
2046*5113495bSYour Name {
2047*5113495bSYour Name 	wmi_mlo_ap_vdev_tid_to_link_map_cmd_fixed_param *cmd;
2048*5113495bSYour Name 	wmi_mlo_ap_vdev_tid_to_link_map_ie_info *info;
2049*5113495bSYour Name 	wmi_buf_t buf;
2050*5113495bSYour Name 	uint8_t *buf_ptr;
2051*5113495bSYour Name 	QDF_STATUS ret = QDF_STATUS_SUCCESS;
2052*5113495bSYour Name 	uint32_t buf_len = 0;
2053*5113495bSYour Name 	uint32_t num_info = 0;
2054*5113495bSYour Name 
2055*5113495bSYour Name 	if (params->num_t2lm_info > WLAN_MAX_T2LM_IE) {
2056*5113495bSYour Name 		wmi_err("Failed to send T2LM command to FW for vdev id %d as t2lm info %d is greater than max %d",
2057*5113495bSYour Name 			params->vdev_id,
2058*5113495bSYour Name 			params->num_t2lm_info,
2059*5113495bSYour Name 			WLAN_MAX_T2LM_IE);
2060*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
2061*5113495bSYour Name 	}
2062*5113495bSYour Name 
2063*5113495bSYour Name 	buf_len = sizeof(wmi_mlo_ap_vdev_tid_to_link_map_cmd_fixed_param) +
2064*5113495bSYour Name 		WMI_TLV_HDR_SIZE + (params->num_t2lm_info *
2065*5113495bSYour Name 		 sizeof(wmi_mlo_ap_vdev_tid_to_link_map_ie_info));
2066*5113495bSYour Name 
2067*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, buf_len);
2068*5113495bSYour Name 	if (!buf) {
2069*5113495bSYour Name 		wmi_err("wmi buf alloc failed for vdev id %d while t2lm map cmd send: ",
2070*5113495bSYour Name 			params->vdev_id);
2071*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
2072*5113495bSYour Name 	}
2073*5113495bSYour Name 
2074*5113495bSYour Name 	buf_ptr = (uint8_t *)wmi_buf_data(buf);
2075*5113495bSYour Name 	cmd = (wmi_mlo_ap_vdev_tid_to_link_map_cmd_fixed_param *)buf_ptr;
2076*5113495bSYour Name 
2077*5113495bSYour Name 	WMITLV_SET_HDR(
2078*5113495bSYour Name 	       &cmd->tlv_header,
2079*5113495bSYour Name 	       WMITLV_TAG_STRUC_wmi_mlo_ap_vdev_tid_to_link_map_cmd_fixed_param,
2080*5113495bSYour Name 	       WMITLV_GET_STRUCT_TLVLEN(
2081*5113495bSYour Name 	       wmi_mlo_ap_vdev_tid_to_link_map_cmd_fixed_param));
2082*5113495bSYour Name 
2083*5113495bSYour Name 	cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(
2084*5113495bSYour Name 			wmi_handle, params->pdev_id);
2085*5113495bSYour Name 	cmd->vdev_id = params->vdev_id;
2086*5113495bSYour Name 	cmd->disabled_link_bitmap = params->disabled_link_bitmap;
2087*5113495bSYour Name 	wmi_debug("pdev_id:%d vdev_id:%d disabled_link_bitmap:%x num_t2lm_info:%d",
2088*5113495bSYour Name 		  cmd->pdev_id, cmd->vdev_id, cmd->disabled_link_bitmap,
2089*5113495bSYour Name 		  params->num_t2lm_info);
2090*5113495bSYour Name 
2091*5113495bSYour Name 	buf_ptr += sizeof(wmi_mlo_ap_vdev_tid_to_link_map_cmd_fixed_param);
2092*5113495bSYour Name 
2093*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
2094*5113495bSYour Name 		       (params->num_t2lm_info *
2095*5113495bSYour Name 			sizeof(wmi_mlo_ap_vdev_tid_to_link_map_ie_info)));
2096*5113495bSYour Name 	buf_ptr += sizeof(uint32_t);
2097*5113495bSYour Name 
2098*5113495bSYour Name 	for (num_info = 0; num_info < params->num_t2lm_info; num_info++) {
2099*5113495bSYour Name 		info = (wmi_mlo_ap_vdev_tid_to_link_map_ie_info *)buf_ptr;
2100*5113495bSYour Name 
2101*5113495bSYour Name 		WMITLV_SET_HDR(
2102*5113495bSYour Name 		       &info->tlv_header,
2103*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_mlo_ap_vdev_tid_to_link_map_ie_info,
2104*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(
2105*5113495bSYour Name 		       wmi_mlo_ap_vdev_tid_to_link_map_ie_info));
2106*5113495bSYour Name 		update_t2lm_ie_info_params(info, &params->info[num_info]);
2107*5113495bSYour Name 		buf_ptr += sizeof(wmi_mlo_ap_vdev_tid_to_link_map_ie_info);
2108*5113495bSYour Name 	}
2109*5113495bSYour Name 
2110*5113495bSYour Name 	wmi_mtrace(WMI_MLO_AP_VDEV_TID_TO_LINK_MAP_CMDID, cmd->vdev_id, 0);
2111*5113495bSYour Name 	ret = wmi_unified_cmd_send(wmi_handle, buf, buf_len,
2112*5113495bSYour Name 				   WMI_MLO_AP_VDEV_TID_TO_LINK_MAP_CMDID);
2113*5113495bSYour Name 	if (ret) {
2114*5113495bSYour Name 		wmi_err("Failed to send T2LM command to FW: %d vdev id %d",
2115*5113495bSYour Name 			ret, cmd->vdev_id);
2116*5113495bSYour Name 		wmi_buf_free(buf);
2117*5113495bSYour Name 	}
2118*5113495bSYour Name 
2119*5113495bSYour Name 	return ret;
2120*5113495bSYour Name }
2121*5113495bSYour Name 
2122*5113495bSYour Name static QDF_STATUS
extract_mlo_vdev_tid_to_link_map_event_tlv(struct wmi_unified * wmi_handle,uint8_t * buf,struct mlo_vdev_host_tid_to_link_map_resp * params)2123*5113495bSYour Name extract_mlo_vdev_tid_to_link_map_event_tlv(
2124*5113495bSYour Name 		struct wmi_unified *wmi_handle,
2125*5113495bSYour Name 		uint8_t *buf,
2126*5113495bSYour Name 		struct mlo_vdev_host_tid_to_link_map_resp *params)
2127*5113495bSYour Name {
2128*5113495bSYour Name 	WMI_MLO_AP_VDEV_TID_TO_LINK_MAP_EVENTID_param_tlvs *param_buf;
2129*5113495bSYour Name 	wmi_mlo_ap_vdev_tid_to_link_map_evt_fixed_param *ev;
2130*5113495bSYour Name 
2131*5113495bSYour Name 	param_buf = (WMI_MLO_AP_VDEV_TID_TO_LINK_MAP_EVENTID_param_tlvs *)buf;
2132*5113495bSYour Name 	if (!param_buf) {
2133*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
2134*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
2135*5113495bSYour Name 	}
2136*5113495bSYour Name 
2137*5113495bSYour Name 	ev = (wmi_mlo_ap_vdev_tid_to_link_map_evt_fixed_param *)
2138*5113495bSYour Name 		param_buf->fixed_param;
2139*5113495bSYour Name 
2140*5113495bSYour Name 	params->vdev_id = ev->vdev_id;
2141*5113495bSYour Name 	params->status  = ev->status_type;
2142*5113495bSYour Name 	params->mapping_switch_tsf = ev->mapping_switch_tsf;
2143*5113495bSYour Name 
2144*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2145*5113495bSYour Name }
2146*5113495bSYour Name 
2147*5113495bSYour Name static QDF_STATUS
extract_mlo_vdev_bcast_tid_to_link_map_event_tlv(struct wmi_unified * wmi_handle,void * buf,struct mlo_bcast_t2lm_info * bcast_info)2148*5113495bSYour Name extract_mlo_vdev_bcast_tid_to_link_map_event_tlv(
2149*5113495bSYour Name 				struct wmi_unified *wmi_handle,
2150*5113495bSYour Name 				void *buf,
2151*5113495bSYour Name 				struct mlo_bcast_t2lm_info *bcast_info)
2152*5113495bSYour Name {
2153*5113495bSYour Name 	WMI_MGMT_RX_EVENTID_param_tlvs *param_tlvs;
2154*5113495bSYour Name 	wmi_mlo_bcast_t2lm_info *info;
2155*5113495bSYour Name 	int i;
2156*5113495bSYour Name 
2157*5113495bSYour Name 	param_tlvs = (WMI_MGMT_RX_EVENTID_param_tlvs *)buf;
2158*5113495bSYour Name 	if (!param_tlvs) {
2159*5113495bSYour Name 		wmi_err(" MGMT RX param_tlvs is NULL");
2160*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
2161*5113495bSYour Name 	}
2162*5113495bSYour Name 
2163*5113495bSYour Name 	if (param_tlvs->num_mlo_bcast_t2lm_info > MAX_AP_MLDS_PER_LINK) {
2164*5113495bSYour Name 		wmi_err("num_mlo_bcast_t2lm_info is greater than %d",
2165*5113495bSYour Name 			MAX_AP_MLDS_PER_LINK);
2166*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
2167*5113495bSYour Name 	}
2168*5113495bSYour Name 
2169*5113495bSYour Name 	info = param_tlvs->mlo_bcast_t2lm_info;
2170*5113495bSYour Name 	if (!info) {
2171*5113495bSYour Name 		wmi_debug("mlo_bcast_t2lm_info is not applicable");
2172*5113495bSYour Name 		return QDF_STATUS_SUCCESS;
2173*5113495bSYour Name 	}
2174*5113495bSYour Name 
2175*5113495bSYour Name 	bcast_info->num_vdevs = param_tlvs->num_mlo_bcast_t2lm_info;
2176*5113495bSYour Name 	wmi_debug("num_vdevs:%d", bcast_info->num_vdevs);
2177*5113495bSYour Name 	for (i = 0; i < param_tlvs->num_mlo_bcast_t2lm_info; i++) {
2178*5113495bSYour Name 		bcast_info->vdev_id[i] =
2179*5113495bSYour Name 			WMI_MLO_BROADCAST_TID_TO_LINK_MAP_INFO_VDEV_ID_GET(
2180*5113495bSYour Name 					info->vdev_id_expec_dur);
2181*5113495bSYour Name 
2182*5113495bSYour Name 		bcast_info->expected_duration[i] =
2183*5113495bSYour Name 			WMI_MLO_BROADCAST_TID_TO_LINK_MAP_INFO_EXP_DUR_GET(
2184*5113495bSYour Name 					info->vdev_id_expec_dur);
2185*5113495bSYour Name 		wmi_debug("vdev_id:%d expected_duration:%d",
2186*5113495bSYour Name 			  bcast_info->vdev_id[i],
2187*5113495bSYour Name 			  bcast_info->expected_duration[i]);
2188*5113495bSYour Name 	}
2189*5113495bSYour Name 
2190*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2191*5113495bSYour Name }
2192*5113495bSYour Name #else
peer_assoc_t2lm_params_size(struct peer_assoc_params * req)2193*5113495bSYour Name size_t peer_assoc_t2lm_params_size(struct peer_assoc_params *req)
2194*5113495bSYour Name {
2195*5113495bSYour Name 	return WMI_TLV_HDR_SIZE;
2196*5113495bSYour Name }
2197*5113495bSYour Name 
peer_assoc_add_tid_to_link_map(uint8_t * buf_ptr,struct peer_assoc_params * req)2198*5113495bSYour Name uint8_t *peer_assoc_add_tid_to_link_map(uint8_t *buf_ptr,
2199*5113495bSYour Name 					       struct peer_assoc_params *req)
2200*5113495bSYour Name {
2201*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, 0);
2202*5113495bSYour Name 	return buf_ptr + WMI_TLV_HDR_SIZE;
2203*5113495bSYour Name }
2204*5113495bSYour Name #endif /* WLAN_FEATURE_11BE */
2205*5113495bSYour Name 
2206*5113495bSYour Name #ifdef WLAN_MLO_MULTI_CHIP
mlo_setup_cmd_send_tlv(struct wmi_unified * wmi_handle,struct wmi_mlo_setup_params * param)2207*5113495bSYour Name QDF_STATUS mlo_setup_cmd_send_tlv(struct wmi_unified *wmi_handle,
2208*5113495bSYour Name 				  struct wmi_mlo_setup_params *param)
2209*5113495bSYour Name {
2210*5113495bSYour Name 	QDF_STATUS ret;
2211*5113495bSYour Name 	wmi_mlo_setup_cmd_fixed_param *cmd;
2212*5113495bSYour Name 	wmi_buf_t buf;
2213*5113495bSYour Name 	int32_t len;
2214*5113495bSYour Name 	uint8_t *buf_ptr;
2215*5113495bSYour Name 	uint32_t *partner_links;
2216*5113495bSYour Name 	uint8_t idx;
2217*5113495bSYour Name 
2218*5113495bSYour Name 	if (param->num_valid_hw_links > MAX_LINK_IN_MLO)
2219*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
2220*5113495bSYour Name 
2221*5113495bSYour Name 	len = sizeof(*cmd) +
2222*5113495bSYour Name 		(param->num_valid_hw_links * sizeof(uint32_t)) +
2223*5113495bSYour Name 		WMI_TLV_HDR_SIZE;
2224*5113495bSYour Name 
2225*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, len);
2226*5113495bSYour Name 	if (!buf)
2227*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
2228*5113495bSYour Name 
2229*5113495bSYour Name 	cmd = (wmi_mlo_setup_cmd_fixed_param *)wmi_buf_data(buf);
2230*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header,
2231*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_mlo_setup_cmd_fixed_param,
2232*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_mlo_setup_cmd_fixed_param));
2233*5113495bSYour Name 
2234*5113495bSYour Name 	cmd->mld_group_id = param->mld_grp_id;
2235*5113495bSYour Name 	cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(
2236*5113495bSYour Name 								wmi_handle,
2237*5113495bSYour Name 								param->pdev_id);
2238*5113495bSYour Name 	buf_ptr = (uint8_t *)cmd + sizeof(*cmd);
2239*5113495bSYour Name 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_UINT32,
2240*5113495bSYour Name 		       (sizeof(uint32_t) * param->num_valid_hw_links));
2241*5113495bSYour Name 	partner_links = (uint32_t *)(buf_ptr + WMI_TLV_HDR_SIZE);
2242*5113495bSYour Name 	for (idx = 0; idx < param->num_valid_hw_links; idx++)
2243*5113495bSYour Name 		partner_links[idx] = param->partner_links[idx];
2244*5113495bSYour Name 
2245*5113495bSYour Name 	wmi_mtrace(WMI_MLO_SETUP_CMDID, NO_SESSION, 0);
2246*5113495bSYour Name 	ret = wmi_unified_cmd_send(wmi_handle, buf, len, WMI_MLO_SETUP_CMDID);
2247*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(ret)) {
2248*5113495bSYour Name 		wmi_err("Failed to send MLO setup command ret = %d", ret);
2249*5113495bSYour Name 		wmi_buf_free(buf);
2250*5113495bSYour Name 	}
2251*5113495bSYour Name 
2252*5113495bSYour Name 	return ret;
2253*5113495bSYour Name }
2254*5113495bSYour Name 
mlo_ready_cmd_send_tlv(struct wmi_unified * wmi_handle,struct wmi_mlo_ready_params * param)2255*5113495bSYour Name QDF_STATUS mlo_ready_cmd_send_tlv(struct wmi_unified *wmi_handle,
2256*5113495bSYour Name 				  struct wmi_mlo_ready_params *param)
2257*5113495bSYour Name {
2258*5113495bSYour Name 	QDF_STATUS ret;
2259*5113495bSYour Name 	wmi_mlo_ready_cmd_fixed_param *cmd;
2260*5113495bSYour Name 	wmi_buf_t buf;
2261*5113495bSYour Name 	int32_t len;
2262*5113495bSYour Name 
2263*5113495bSYour Name 	len = sizeof(*cmd);
2264*5113495bSYour Name 
2265*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, len);
2266*5113495bSYour Name 	if (!buf)
2267*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
2268*5113495bSYour Name 
2269*5113495bSYour Name 	cmd = (wmi_mlo_ready_cmd_fixed_param *)wmi_buf_data(buf);
2270*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header,
2271*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_mlo_ready_cmd_fixed_param,
2272*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_mlo_ready_cmd_fixed_param));
2273*5113495bSYour Name 
2274*5113495bSYour Name 	cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(
2275*5113495bSYour Name 								wmi_handle,
2276*5113495bSYour Name 								param->pdev_id);
2277*5113495bSYour Name 
2278*5113495bSYour Name 	wmi_mtrace(WMI_MLO_READY_CMDID, NO_SESSION, 0);
2279*5113495bSYour Name 	ret = wmi_unified_cmd_send(wmi_handle, buf, len, WMI_MLO_READY_CMDID);
2280*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(ret)) {
2281*5113495bSYour Name 		wmi_err("Failed to send MLO ready command ret = %d", ret);
2282*5113495bSYour Name 		wmi_buf_free(buf);
2283*5113495bSYour Name 	}
2284*5113495bSYour Name 
2285*5113495bSYour Name 	return ret;
2286*5113495bSYour Name }
2287*5113495bSYour Name 
mlo_teardown_cmd_send_tlv(struct wmi_unified * wmi_handle,struct wmi_mlo_teardown_params * param)2288*5113495bSYour Name QDF_STATUS mlo_teardown_cmd_send_tlv(struct wmi_unified *wmi_handle,
2289*5113495bSYour Name 				     struct wmi_mlo_teardown_params *param)
2290*5113495bSYour Name {
2291*5113495bSYour Name 	QDF_STATUS ret;
2292*5113495bSYour Name 	wmi_mlo_teardown_fixed_param *cmd;
2293*5113495bSYour Name 	wmi_buf_t buf;
2294*5113495bSYour Name 	int32_t len;
2295*5113495bSYour Name 
2296*5113495bSYour Name 	len = sizeof(*cmd);
2297*5113495bSYour Name 
2298*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, len);
2299*5113495bSYour Name 	if (!buf)
2300*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
2301*5113495bSYour Name 
2302*5113495bSYour Name 	cmd = (wmi_mlo_teardown_fixed_param *)wmi_buf_data(buf);
2303*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header,
2304*5113495bSYour Name 		       WMITLV_TAG_STRUC_wmi_mlo_teardown_fixed_param,
2305*5113495bSYour Name 		       WMITLV_GET_STRUCT_TLVLEN(wmi_mlo_teardown_fixed_param));
2306*5113495bSYour Name 
2307*5113495bSYour Name 	cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(
2308*5113495bSYour Name 								wmi_handle,
2309*5113495bSYour Name 								param->pdev_id);
2310*5113495bSYour Name 	switch (param->reason) {
2311*5113495bSYour Name 	case WMI_HOST_MLO_TEARDOWN_REASON_SSR:
2312*5113495bSYour Name 	case WMI_HOST_MLO_TEARDOWN_REASON_MODE1_SSR:
2313*5113495bSYour Name 		cmd->reason_code = WMI_MLO_TEARDOWN_SSR_REASON;
2314*5113495bSYour Name 		break;
2315*5113495bSYour Name 	case WMI_HOST_MLO_TEARDOWN_REASON_STANDBY:
2316*5113495bSYour Name 		cmd->reason_code = WMI_MLO_TEARDOWN_REASON_STANDBY_DOWN;
2317*5113495bSYour Name 		break;
2318*5113495bSYour Name 	case WMI_HOST_MLO_TEARDOWN_REASON_DOWN:
2319*5113495bSYour Name 	default:
2320*5113495bSYour Name 		cmd->reason_code = WMI_MLO_TEARDOWN_SSR_REASON + 1;
2321*5113495bSYour Name 		break;
2322*5113495bSYour Name 	}
2323*5113495bSYour Name 
2324*5113495bSYour Name 	cmd->trigger_umac_reset = param->umac_reset;
2325*5113495bSYour Name 	cmd->erp_standby_mode = param->standby_active;
2326*5113495bSYour Name 
2327*5113495bSYour Name 	wmi_mtrace(WMI_MLO_TEARDOWN_CMDID, NO_SESSION, 0);
2328*5113495bSYour Name 	ret = wmi_unified_cmd_send(wmi_handle, buf, len,
2329*5113495bSYour Name 				   WMI_MLO_TEARDOWN_CMDID);
2330*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(ret)) {
2331*5113495bSYour Name 		wmi_err("Failed to send MLO Teardown command ret = %d", ret);
2332*5113495bSYour Name 		wmi_buf_free(buf);
2333*5113495bSYour Name 	}
2334*5113495bSYour Name 
2335*5113495bSYour Name 	return ret;
2336*5113495bSYour Name }
2337*5113495bSYour Name 
2338*5113495bSYour Name QDF_STATUS
extract_mlo_setup_cmpl_event_tlv(struct wmi_unified * wmi_handle,uint8_t * buf,struct wmi_mlo_setup_complete_params * params)2339*5113495bSYour Name extract_mlo_setup_cmpl_event_tlv(struct wmi_unified *wmi_handle,
2340*5113495bSYour Name 				 uint8_t *buf,
2341*5113495bSYour Name 				 struct wmi_mlo_setup_complete_params *params)
2342*5113495bSYour Name {
2343*5113495bSYour Name 	WMI_MLO_SETUP_COMPLETE_EVENTID_param_tlvs *param_buf;
2344*5113495bSYour Name 	wmi_mlo_setup_complete_event_fixed_param *ev;
2345*5113495bSYour Name 
2346*5113495bSYour Name 	param_buf = (WMI_MLO_SETUP_COMPLETE_EVENTID_param_tlvs *)buf;
2347*5113495bSYour Name 	if (!param_buf) {
2348*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
2349*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
2350*5113495bSYour Name 	}
2351*5113495bSYour Name 	ev = (wmi_mlo_setup_complete_event_fixed_param *)param_buf->fixed_param;
2352*5113495bSYour Name 
2353*5113495bSYour Name 	params->pdev_id = wmi_handle->ops->convert_pdev_id_target_to_host(
2354*5113495bSYour Name 								wmi_handle,
2355*5113495bSYour Name 								ev->pdev_id);
2356*5113495bSYour Name 	if (!ev->status)
2357*5113495bSYour Name 		params->status = WMI_HOST_MLO_SETUP_STATUS_SUCCESS;
2358*5113495bSYour Name 	else
2359*5113495bSYour Name 		params->status = WMI_HOST_MLO_SETUP_STATUS_FAILURE;
2360*5113495bSYour Name 
2361*5113495bSYour Name 	params->max_ml_peer_ids = ev->max_ml_peer_ids;
2362*5113495bSYour Name 
2363*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2364*5113495bSYour Name }
2365*5113495bSYour Name 
2366*5113495bSYour Name QDF_STATUS
extract_mlo_teardown_cmpl_event_tlv(struct wmi_unified * wmi_handle,uint8_t * buf,struct wmi_mlo_teardown_cmpl_params * params)2367*5113495bSYour Name extract_mlo_teardown_cmpl_event_tlv(struct wmi_unified *wmi_handle,
2368*5113495bSYour Name 				    uint8_t *buf,
2369*5113495bSYour Name 				    struct wmi_mlo_teardown_cmpl_params *params)
2370*5113495bSYour Name {
2371*5113495bSYour Name 	WMI_MLO_TEARDOWN_COMPLETE_EVENTID_param_tlvs *param_buf;
2372*5113495bSYour Name 	wmi_mlo_teardown_complete_fixed_param *ev;
2373*5113495bSYour Name 
2374*5113495bSYour Name 	param_buf = (WMI_MLO_TEARDOWN_COMPLETE_EVENTID_param_tlvs *)buf;
2375*5113495bSYour Name 	if (!param_buf) {
2376*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
2377*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
2378*5113495bSYour Name 	}
2379*5113495bSYour Name 	ev = (wmi_mlo_teardown_complete_fixed_param *)param_buf->fixed_param;
2380*5113495bSYour Name 
2381*5113495bSYour Name 	params->pdev_id = wmi_handle->ops->convert_pdev_id_target_to_host(
2382*5113495bSYour Name 								wmi_handle,
2383*5113495bSYour Name 								ev->pdev_id);
2384*5113495bSYour Name 	if (!ev->status)
2385*5113495bSYour Name 		params->status = WMI_HOST_MLO_TEARDOWN_STATUS_SUCCESS;
2386*5113495bSYour Name 	else
2387*5113495bSYour Name 		params->status = WMI_HOST_MLO_TEARDOWN_STATUS_FAILURE;
2388*5113495bSYour Name 
2389*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2390*5113495bSYour Name }
2391*5113495bSYour Name 
wmi_11be_attach_mlo_setup_tlv(wmi_unified_t wmi_handle)2392*5113495bSYour Name static void wmi_11be_attach_mlo_setup_tlv(wmi_unified_t wmi_handle)
2393*5113495bSYour Name {
2394*5113495bSYour Name 	struct wmi_ops *ops = wmi_handle->ops;
2395*5113495bSYour Name 
2396*5113495bSYour Name 	ops->mlo_setup_cmd_send = mlo_setup_cmd_send_tlv;
2397*5113495bSYour Name 	ops->mlo_teardown_cmd_send = mlo_teardown_cmd_send_tlv;
2398*5113495bSYour Name 	ops->mlo_ready_cmd_send = mlo_ready_cmd_send_tlv;
2399*5113495bSYour Name 	ops->extract_mlo_setup_cmpl_event = extract_mlo_setup_cmpl_event_tlv;
2400*5113495bSYour Name 	ops->extract_mlo_teardown_cmpl_event =
2401*5113495bSYour Name 					extract_mlo_teardown_cmpl_event_tlv;
2402*5113495bSYour Name }
2403*5113495bSYour Name 
2404*5113495bSYour Name #else /*WLAN_MLO_MULTI_CHIP*/
2405*5113495bSYour Name 
wmi_11be_attach_mlo_setup_tlv(wmi_unified_t wmi_handle)2406*5113495bSYour Name static void wmi_11be_attach_mlo_setup_tlv(wmi_unified_t wmi_handle)
2407*5113495bSYour Name {}
2408*5113495bSYour Name 
2409*5113495bSYour Name #endif /*WLAN_MLO_MULTI_CHIP*/
2410*5113495bSYour Name 
2411*5113495bSYour Name /**
2412*5113495bSYour Name  * extract_mgmt_rx_ml_cu_params_tlv() - extract MGMT Critical Update params
2413*5113495bSYour Name  * from MGMT_RX_EVENT_ID
2414*5113495bSYour Name  * @wmi_handle: wmi handle
2415*5113495bSYour Name  * @evt_buf: pointer to event buffer
2416*5113495bSYour Name  * @cu_params: Pointer to MGMT Critical update parameters
2417*5113495bSYour Name  *
2418*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS for success or error code
2419*5113495bSYour Name  */
2420*5113495bSYour Name static
extract_mgmt_rx_ml_cu_params_tlv(wmi_unified_t wmi_handle,void * evt_buf,struct mlo_mgmt_ml_info * cu_params)2421*5113495bSYour Name QDF_STATUS extract_mgmt_rx_ml_cu_params_tlv(wmi_unified_t wmi_handle,
2422*5113495bSYour Name 					    void *evt_buf,
2423*5113495bSYour Name 					    struct mlo_mgmt_ml_info *cu_params)
2424*5113495bSYour Name {
2425*5113495bSYour Name 	WMI_MGMT_RX_EVENTID_param_tlvs *param_tlvs;
2426*5113495bSYour Name 	wmi_mgmt_ml_info *cu_params_tlv;
2427*5113495bSYour Name 	wmi_mgmt_rx_hdr *ev_hdr;
2428*5113495bSYour Name 	uint32_t num_bpcc_bufp;
2429*5113495bSYour Name 
2430*5113495bSYour Name 	param_tlvs = evt_buf;
2431*5113495bSYour Name 	if (!param_tlvs) {
2432*5113495bSYour Name 		wmi_err(" MGMT RX param_tlvs is NULL");
2433*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
2434*5113495bSYour Name 	}
2435*5113495bSYour Name 
2436*5113495bSYour Name 	ev_hdr = param_tlvs->hdr;
2437*5113495bSYour Name 	if (!ev_hdr) {
2438*5113495bSYour Name 		wmi_err("Rx event is NULL");
2439*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
2440*5113495bSYour Name 	}
2441*5113495bSYour Name 
2442*5113495bSYour Name 	if (!cu_params) {
2443*5113495bSYour Name 		wmi_debug("MGMT Rx CU params is NULL");
2444*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
2445*5113495bSYour Name 	}
2446*5113495bSYour Name 
2447*5113495bSYour Name 	cu_params_tlv = param_tlvs->ml_info;
2448*5113495bSYour Name 	if (!cu_params_tlv) {
2449*5113495bSYour Name 		wmi_debug("mgmt_ml_info TLV is not sent by FW");
2450*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
2451*5113495bSYour Name 	}
2452*5113495bSYour Name 
2453*5113495bSYour Name 	cu_params->cu_vdev_map[0] =
2454*5113495bSYour Name 		cu_params_tlv->cu_vdev_map_1 & CU_VDEV_MAP_MASK;
2455*5113495bSYour Name 	cu_params->cu_vdev_map[1] =
2456*5113495bSYour Name 		(cu_params_tlv->cu_vdev_map_1 >> 16) & CU_VDEV_MAP_MASK;
2457*5113495bSYour Name 	cu_params->cu_vdev_map[2] =
2458*5113495bSYour Name 		cu_params_tlv->cu_vdev_map_2 & CU_VDEV_MAP_MASK;
2459*5113495bSYour Name 	cu_params->cu_vdev_map[3] =
2460*5113495bSYour Name 		(cu_params_tlv->cu_vdev_map_2 >> 16) & CU_VDEV_MAP_MASK;
2461*5113495bSYour Name 	cu_params->cu_vdev_map[4] =
2462*5113495bSYour Name 		cu_params_tlv->cu_vdev_map_3 & CU_VDEV_MAP_MASK;
2463*5113495bSYour Name 	cu_params->cu_vdev_map[5] =
2464*5113495bSYour Name 		(cu_params_tlv->cu_vdev_map_3 >> 16) & CU_VDEV_MAP_MASK;
2465*5113495bSYour Name 
2466*5113495bSYour Name 	/* At present MAX_LINKS_SUPPORTED are 6.
2467*5113495bSYour Name 	 * cu_vdev_map_4 which required for links
2468*5113495bSYour Name 	 * 7 and 8 is unused.
2469*5113495bSYour Name 	 */
2470*5113495bSYour Name 	num_bpcc_bufp = param_tlvs->num_bpcc_bufp;
2471*5113495bSYour Name 	if (param_tlvs->num_bpcc_bufp > sizeof(cu_params->vdev_bpcc)) {
2472*5113495bSYour Name 		wmi_err("Invalid num_bpcc_bufp:%u", num_bpcc_bufp);
2473*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
2474*5113495bSYour Name 	}
2475*5113495bSYour Name 	qdf_mem_copy(cu_params->vdev_bpcc, param_tlvs->bpcc_bufp,
2476*5113495bSYour Name 		     num_bpcc_bufp);
2477*5113495bSYour Name 
2478*5113495bSYour Name 	qdf_trace_hex_dump(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
2479*5113495bSYour Name 			   param_tlvs->bpcc_bufp, num_bpcc_bufp);
2480*5113495bSYour Name 
2481*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2482*5113495bSYour Name }
2483*5113495bSYour Name 
2484*5113495bSYour Name #ifdef QCA_SUPPORT_PRIMARY_LINK_MIGRATE
2485*5113495bSYour Name /**
2486*5113495bSYour Name  * send_peer_ptqm_migrate_cmd_tlv() - send PEER ptqm migrate command to fw
2487*5113495bSYour Name  * @wmi_handle: wmi handle
2488*5113495bSYour Name  * @param: pointer to hold peer ptqm migrate parameter
2489*5113495bSYour Name  *
2490*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS for success else error code
2491*5113495bSYour Name  */
send_peer_ptqm_migrate_cmd_tlv(wmi_unified_t wmi_handle,struct peer_ptqm_migrate_params * param)2492*5113495bSYour Name static QDF_STATUS send_peer_ptqm_migrate_cmd_tlv(
2493*5113495bSYour Name 				wmi_unified_t wmi_handle,
2494*5113495bSYour Name 				struct peer_ptqm_migrate_params *param)
2495*5113495bSYour Name {
2496*5113495bSYour Name 	/* Todo: copy send_peer_delete_all_cmd_tlv */
2497*5113495bSYour Name 	uint16_t i = 0;
2498*5113495bSYour Name 	wmi_buf_t buf;
2499*5113495bSYour Name 	uint8_t *buf_ptr;
2500*5113495bSYour Name 	wmi_mlo_primary_link_peer_migration_fixed_param *cmd;
2501*5113495bSYour Name 	uint32_t len = sizeof(*cmd);
2502*5113495bSYour Name 	uint16_t num_entry = 0;
2503*5113495bSYour Name 	uint16_t max_entry_per_cmd = 0, max_entry_cnt = 0;
2504*5113495bSYour Name 	struct peer_ptqm_migrate_entry *param_list = param->peer_list;
2505*5113495bSYour Name 	wmi_mlo_new_primary_link_peer_info *entry;
2506*5113495bSYour Name 	uint32_t pending_cnt = param->num_peers;
2507*5113495bSYour Name 
2508*5113495bSYour Name 	/* Get max entries which can be send in a single WMI command.
2509*5113495bSYour Name 	 * If no. of entries is more than max entries supported, multiple
2510*5113495bSYour Name 	 * WMI commands will be send.
2511*5113495bSYour Name 	 */
2512*5113495bSYour Name 	max_entry_per_cmd = (wmi_get_max_msg_len(wmi_handle) -
2513*5113495bSYour Name 			     sizeof(*cmd) - WMI_TLV_HDR_SIZE) /
2514*5113495bSYour Name 			     (sizeof(wmi_mlo_new_primary_link_peer_info));
2515*5113495bSYour Name 
2516*5113495bSYour Name 	if (param->num_peers > max_entry_per_cmd)
2517*5113495bSYour Name 		max_entry_cnt = max_entry_per_cmd;
2518*5113495bSYour Name 	else
2519*5113495bSYour Name 		max_entry_cnt = param->num_peers;
2520*5113495bSYour Name 
2521*5113495bSYour Name 	wmi_debug("Setting max entry limit as %u", max_entry_cnt);
2522*5113495bSYour Name 	while (pending_cnt > 0) {
2523*5113495bSYour Name 		len = sizeof(*cmd) + WMI_TLV_HDR_SIZE;
2524*5113495bSYour Name 		if (pending_cnt >= max_entry_cnt)
2525*5113495bSYour Name 			num_entry = max_entry_cnt;
2526*5113495bSYour Name 		else
2527*5113495bSYour Name 			num_entry = pending_cnt;
2528*5113495bSYour Name 
2529*5113495bSYour Name 		len += num_entry * sizeof(wmi_mlo_new_primary_link_peer_info);
2530*5113495bSYour Name 		buf = wmi_buf_alloc(wmi_handle, len);
2531*5113495bSYour Name 		if (!buf)
2532*5113495bSYour Name 			return QDF_STATUS_E_NOMEM;
2533*5113495bSYour Name 
2534*5113495bSYour Name 		buf_ptr = (uint8_t *)wmi_buf_data(buf);
2535*5113495bSYour Name 
2536*5113495bSYour Name 		cmd = (wmi_mlo_primary_link_peer_migration_fixed_param *)
2537*5113495bSYour Name 						wmi_buf_data(buf);
2538*5113495bSYour Name 		WMITLV_SET_HDR(
2539*5113495bSYour Name 			&cmd->tlv_header,
2540*5113495bSYour Name 			WMITLV_TAG_STRUC_wmi_mlo_primary_link_peer_migration_fixed_param,
2541*5113495bSYour Name 			WMITLV_GET_STRUCT_TLVLEN
2542*5113495bSYour Name 			(wmi_mlo_primary_link_peer_migration_fixed_param));
2543*5113495bSYour Name 		buf_ptr += sizeof(*cmd);
2544*5113495bSYour Name 		cmd->vdev_id = param->vdev_id;
2545*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
2546*5113495bSYour Name 			       num_entry * sizeof(wmi_mlo_new_primary_link_peer_info));
2547*5113495bSYour Name 		buf_ptr += WMI_TLV_HDR_SIZE;
2548*5113495bSYour Name 		entry = (wmi_mlo_new_primary_link_peer_info *)buf_ptr;
2549*5113495bSYour Name 		for (i = 0; i < num_entry; i++) {
2550*5113495bSYour Name 			WMITLV_SET_HDR(&entry[i].tlv_header,
2551*5113495bSYour Name 				       WMITLV_TAG_STRUC_wmi_mlo_new_primary_link_peer_info,
2552*5113495bSYour Name 				       WMITLV_GET_STRUCT_TLVLEN(wmi_mlo_new_primary_link_peer_info));
2553*5113495bSYour Name 			WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_ML_PEER_ID_SET(
2554*5113495bSYour Name 					entry[i].new_link_info,
2555*5113495bSYour Name 					param_list[i].ml_peer_id);
2556*5113495bSYour Name 			WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_HW_LINK_ID_SET(
2557*5113495bSYour Name 					entry[i].new_link_info,
2558*5113495bSYour Name 					param_list[i].hw_link_id);
2559*5113495bSYour Name 			wmi_debug("i:%d, ml_peer_id:%d, hw_link_id:%d",
2560*5113495bSYour Name 				  i, entry[i].ml_peer_id, entry[i].hw_link_id);
2561*5113495bSYour Name 		}
2562*5113495bSYour Name 
2563*5113495bSYour Name 		wmi_mtrace(WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_CMDID,
2564*5113495bSYour Name 			   cmd->vdev_id, 0);
2565*5113495bSYour Name 
2566*5113495bSYour Name 		if (wmi_unified_cmd_send(wmi_handle, buf, len,
2567*5113495bSYour Name 					 WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_CMDID)) {
2568*5113495bSYour Name 			wmi_err("num_entries:%d failed!",
2569*5113495bSYour Name 				pending_cnt);
2570*5113495bSYour Name 			wmi_buf_free(buf);
2571*5113495bSYour Name 			param->num_peers_failed = pending_cnt;
2572*5113495bSYour Name 			return QDF_STATUS_E_FAILURE;
2573*5113495bSYour Name 		}
2574*5113495bSYour Name 		wmi_debug("num_entries:%d done!",
2575*5113495bSYour Name 			  num_entry);
2576*5113495bSYour Name 
2577*5113495bSYour Name 		pending_cnt -= num_entry;
2578*5113495bSYour Name 		param_list += num_entry;
2579*5113495bSYour Name 	}
2580*5113495bSYour Name 
2581*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2582*5113495bSYour Name }
2583*5113495bSYour Name 
2584*5113495bSYour Name static QDF_STATUS
extract_peer_ptqm_migrate_evt_param_tlv(struct wmi_unified * wmi_handle,uint8_t * buf,struct peer_ptqm_migrate_event_params * params)2585*5113495bSYour Name extract_peer_ptqm_migrate_evt_param_tlv(
2586*5113495bSYour Name 		struct wmi_unified *wmi_handle,
2587*5113495bSYour Name 		uint8_t *buf,
2588*5113495bSYour Name 		struct peer_ptqm_migrate_event_params *params)
2589*5113495bSYour Name {
2590*5113495bSYour Name 	WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_EVENTID_param_tlvs *param_buf;
2591*5113495bSYour Name 	wmi_mlo_primary_link_peer_migration_compl_fixed_param *ev;
2592*5113495bSYour Name 
2593*5113495bSYour Name 	param_buf =
2594*5113495bSYour Name 		(WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_EVENTID_param_tlvs *)buf;
2595*5113495bSYour Name 	if (!param_buf) {
2596*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
2597*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
2598*5113495bSYour Name 	}
2599*5113495bSYour Name 
2600*5113495bSYour Name 	if (!param_buf->primary_link_peer_migration_status) {
2601*5113495bSYour Name 		wmi_err_rl("primary_link_peer_migration_status not present in event");
2602*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
2603*5113495bSYour Name 	}
2604*5113495bSYour Name 
2605*5113495bSYour Name 	ev = (wmi_mlo_primary_link_peer_migration_compl_fixed_param *)
2606*5113495bSYour Name 		param_buf->fixed_param;
2607*5113495bSYour Name 
2608*5113495bSYour Name 	params->vdev_id = ev->vdev_id;
2609*5113495bSYour Name 	params->num_peers = param_buf->num_primary_link_peer_migration_status;
2610*5113495bSYour Name 
2611*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2612*5113495bSYour Name }
2613*5113495bSYour Name 
2614*5113495bSYour Name static QDF_STATUS
extract_peer_entry_ptqm_migrate_evt_param_tlv(struct wmi_unified * wmi_handle,uint8_t * buf,uint32_t index,struct peer_entry_ptqm_migrate_event_params * params)2615*5113495bSYour Name extract_peer_entry_ptqm_migrate_evt_param_tlv(
2616*5113495bSYour Name 		struct wmi_unified *wmi_handle,
2617*5113495bSYour Name 		uint8_t *buf,
2618*5113495bSYour Name 		uint32_t index,
2619*5113495bSYour Name 		struct peer_entry_ptqm_migrate_event_params *params)
2620*5113495bSYour Name {
2621*5113495bSYour Name 	WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_EVENTID_param_tlvs *param_buf;
2622*5113495bSYour Name 
2623*5113495bSYour Name 	param_buf =
2624*5113495bSYour Name 		(WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_EVENTID_param_tlvs *)buf;
2625*5113495bSYour Name 	if (!param_buf) {
2626*5113495bSYour Name 		wmi_err_rl("Param_buf is NULL");
2627*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
2628*5113495bSYour Name 	}
2629*5113495bSYour Name 
2630*5113495bSYour Name 	if (index > param_buf->num_primary_link_peer_migration_status) {
2631*5113495bSYour Name 		wmi_err_rl("Index greater than total peer entries");
2632*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
2633*5113495bSYour Name 	}
2634*5113495bSYour Name 
2635*5113495bSYour Name 	if (!param_buf->primary_link_peer_migration_status) {
2636*5113495bSYour Name 		wmi_err_rl("primary_link_peer_migration_status not present in event");
2637*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
2638*5113495bSYour Name 	}
2639*5113495bSYour Name 
2640*5113495bSYour Name 	params->ml_peer_id =
2641*5113495bSYour Name 		WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_STATUS_ML_PEER_ID_GET(
2642*5113495bSYour Name 			param_buf->primary_link_peer_migration_status[index].status_info);
2643*5113495bSYour Name 
2644*5113495bSYour Name 	params->status =
2645*5113495bSYour Name 		WMI_MLO_PRIMARY_LINK_PEER_MIGRATION_STATUS_STATUS_GET(
2646*5113495bSYour Name 			param_buf->primary_link_peer_migration_status[index].status_info);
2647*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2648*5113495bSYour Name }
2649*5113495bSYour Name #endif /* QCA_SUPPORT_PRIMARY_LINK_MIGRATE */
2650*5113495bSYour Name 
wmi_11be_attach_tlv(wmi_unified_t wmi_handle)2651*5113495bSYour Name void wmi_11be_attach_tlv(wmi_unified_t wmi_handle)
2652*5113495bSYour Name {
2653*5113495bSYour Name 	struct wmi_ops *ops = wmi_handle->ops;
2654*5113495bSYour Name 
2655*5113495bSYour Name 	wmi_11be_attach_mlo_setup_tlv(wmi_handle);
2656*5113495bSYour Name 	ops->extract_mlo_link_set_active_resp =
2657*5113495bSYour Name 		extract_mlo_link_set_active_resp_tlv;
2658*5113495bSYour Name 	ops->send_mlo_link_set_active_cmd =
2659*5113495bSYour Name 		send_mlo_link_set_active_cmd_tlv;
2660*5113495bSYour Name #ifdef WLAN_FEATURE_11BE
2661*5113495bSYour Name 	ops->send_mlo_peer_tid_to_link_map =
2662*5113495bSYour Name 		send_mlo_peer_tid_to_link_map_cmd_tlv;
2663*5113495bSYour Name 	ops->send_mlo_vdev_tid_to_link_map =
2664*5113495bSYour Name 		send_mlo_vdev_tid_to_link_map_cmd_tlv;
2665*5113495bSYour Name 	ops->send_mlo_link_state_request =
2666*5113495bSYour Name 		send_link_state_request_cmd_tlv;
2667*5113495bSYour Name 	ops->send_link_set_bss_params_cmd =
2668*5113495bSYour Name 		send_link_set_bss_params_cmd_tlv;
2669*5113495bSYour Name 	ops->extract_mlo_vdev_tid_to_link_map_event =
2670*5113495bSYour Name 		extract_mlo_vdev_tid_to_link_map_event_tlv;
2671*5113495bSYour Name 	ops->extract_mlo_vdev_bcast_tid_to_link_map_event =
2672*5113495bSYour Name 		extract_mlo_vdev_bcast_tid_to_link_map_event_tlv;
2673*5113495bSYour Name 	ops->extract_mlo_link_state_event =
2674*5113495bSYour Name 		extract_mlo_link_state_event_tlv;
2675*5113495bSYour Name #endif /* WLAN_FEATURE_11BE */
2676*5113495bSYour Name 	ops->extract_mgmt_rx_ml_cu_params =
2677*5113495bSYour Name 		extract_mgmt_rx_ml_cu_params_tlv;
2678*5113495bSYour Name 	ops->send_mlo_link_removal_cmd = send_mlo_link_removal_cmd_tlv;
2679*5113495bSYour Name 	ops->extract_mlo_link_removal_evt_fixed_param =
2680*5113495bSYour Name 			extract_mlo_link_removal_evt_fixed_param_tlv;
2681*5113495bSYour Name 	ops->extract_mlo_link_removal_tbtt_update =
2682*5113495bSYour Name 			extract_mlo_link_removal_tbtt_update_tlv;
2683*5113495bSYour Name 	ops->extract_mgmt_rx_mlo_link_removal_info =
2684*5113495bSYour Name 			extract_mgmt_rx_mlo_link_removal_info_tlv;
2685*5113495bSYour Name 	ops->extract_mlo_link_disable_request_evt_param =
2686*5113495bSYour Name 			extract_mlo_link_disable_request_evt_param_tlv;
2687*5113495bSYour Name 	ops->send_mlo_vdev_pause =
2688*5113495bSYour Name 			send_mlo_vdev_pause_cmd_tlv;
2689*5113495bSYour Name #ifdef QCA_SUPPORT_PRIMARY_LINK_MIGRATE
2690*5113495bSYour Name 	ops->send_peer_ptqm_migrate_cmd = send_peer_ptqm_migrate_cmd_tlv;
2691*5113495bSYour Name 	ops->extract_peer_ptqm_migrate_event = extract_peer_ptqm_migrate_evt_param_tlv;
2692*5113495bSYour Name 	ops->extract_peer_entry_ptqm_migrate_event = extract_peer_entry_ptqm_migrate_evt_param_tlv;
2693*5113495bSYour Name #endif /* QCA_SUPPORT_PRIMARY_LINK_MIGRATE */
2694*5113495bSYour Name #ifdef WLAN_FEATURE_11BE_MLO_ADV_FEATURE
2695*5113495bSYour Name 	ops->extract_mlo_link_switch_request_event =
2696*5113495bSYour Name 			extract_mlo_link_switch_request_event_tlv;
2697*5113495bSYour Name 	ops->send_mlo_link_switch_req_cnf_cmd =
2698*5113495bSYour Name 			send_link_switch_request_cnf_cmd_tlv;
2699*5113495bSYour Name 	ops->extract_mlo_link_state_switch_evt =
2700*5113495bSYour Name 		extract_mlo_link_state_switch_event_tlv;
2701*5113495bSYour Name #endif /* WLAN_FEATURE_11BE_MLO_ADV_FEATURE */
2702*5113495bSYour Name }
2703