xref: /wlan-driver/qca-wifi-host-cmn/wmi/src/wmi_unified_apf_tlv.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  *
4*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
5*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
6*5113495bSYour Name  * above copyright notice and this permission notice appear in all
7*5113495bSYour Name  * copies.
8*5113495bSYour Name  *
9*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
17*5113495bSYour Name  */
18*5113495bSYour Name 
19*5113495bSYour Name #include <wmi_unified_priv.h>
20*5113495bSYour Name #include "wmi_unified_apf_tlv.h"
21*5113495bSYour Name #include "wmi.h"
22*5113495bSYour Name 
wmi_send_set_active_apf_mode_cmd_tlv(wmi_unified_t wmi_handle,uint8_t vdev_id,enum wmi_host_active_apf_mode ucast_mode,enum wmi_host_active_apf_mode mcast_bcast_mode)23*5113495bSYour Name QDF_STATUS wmi_send_set_active_apf_mode_cmd_tlv(wmi_unified_t wmi_handle,
24*5113495bSYour Name 					    uint8_t vdev_id,
25*5113495bSYour Name 					    enum wmi_host_active_apf_mode
26*5113495bSYour Name 								     ucast_mode,
27*5113495bSYour Name 					    enum wmi_host_active_apf_mode
28*5113495bSYour Name 							       mcast_bcast_mode)
29*5113495bSYour Name {
30*5113495bSYour Name 	const WMITLV_TAG_ID tag_id =
31*5113495bSYour Name 		WMITLV_TAG_STRUC_wmi_bpf_set_vdev_active_mode_cmd_fixed_param;
32*5113495bSYour Name 	const uint32_t tlv_len = WMITLV_GET_STRUCT_TLVLEN(
33*5113495bSYour Name 				wmi_bpf_set_vdev_active_mode_cmd_fixed_param);
34*5113495bSYour Name 	QDF_STATUS status;
35*5113495bSYour Name 	wmi_bpf_set_vdev_active_mode_cmd_fixed_param *cmd;
36*5113495bSYour Name 	wmi_buf_t buf;
37*5113495bSYour Name 
38*5113495bSYour Name 	wmi_debug("Sending WMI_BPF_SET_VDEV_ACTIVE_MODE_CMDID(%u, %d, %d)",
39*5113495bSYour Name 		 vdev_id, ucast_mode, mcast_bcast_mode);
40*5113495bSYour Name 
41*5113495bSYour Name 	/* allocate command buffer */
42*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
43*5113495bSYour Name 	if (!buf) {
44*5113495bSYour Name 		wmi_err("wmi_buf_alloc failed");
45*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
46*5113495bSYour Name 	}
47*5113495bSYour Name 
48*5113495bSYour Name 	/* set TLV header */
49*5113495bSYour Name 	cmd = (wmi_bpf_set_vdev_active_mode_cmd_fixed_param *)wmi_buf_data(buf);
50*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header, tag_id, tlv_len);
51*5113495bSYour Name 
52*5113495bSYour Name 	/* populate data */
53*5113495bSYour Name 	cmd->vdev_id = vdev_id;
54*5113495bSYour Name 	cmd->uc_mode = ucast_mode;
55*5113495bSYour Name 	cmd->mcbc_mode = mcast_bcast_mode;
56*5113495bSYour Name 
57*5113495bSYour Name 	/* send to FW */
58*5113495bSYour Name 	status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
59*5113495bSYour Name 				      WMI_BPF_SET_VDEV_ACTIVE_MODE_CMDID);
60*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status)) {
61*5113495bSYour Name 		wmi_err("Failed to send WMI_BPF_SET_VDEV_ACTIVE_MODE_CMDID:%d",
62*5113495bSYour Name 			 status);
63*5113495bSYour Name 		wmi_buf_free(buf);
64*5113495bSYour Name 		return status;
65*5113495bSYour Name 	}
66*5113495bSYour Name 
67*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
68*5113495bSYour Name }
69*5113495bSYour Name 
wmi_send_apf_enable_cmd_tlv(wmi_unified_t wmi_handle,uint32_t vdev_id,bool enable)70*5113495bSYour Name QDF_STATUS wmi_send_apf_enable_cmd_tlv(wmi_unified_t wmi_handle,
71*5113495bSYour Name 				       uint32_t vdev_id,
72*5113495bSYour Name 				       bool enable)
73*5113495bSYour Name {
74*5113495bSYour Name 	wmi_bpf_set_vdev_enable_cmd_fixed_param *cmd;
75*5113495bSYour Name 	wmi_buf_t buf;
76*5113495bSYour Name 
77*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
78*5113495bSYour Name 	if (!buf) {
79*5113495bSYour Name 		wmi_err("wmi_buf_alloc failed");
80*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
81*5113495bSYour Name 	}
82*5113495bSYour Name 
83*5113495bSYour Name 	cmd = (wmi_bpf_set_vdev_enable_cmd_fixed_param *) wmi_buf_data(buf);
84*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header,
85*5113495bSYour Name 		WMITLV_TAG_STRUC_wmi_bpf_set_vdev_enable_cmd_fixed_param,
86*5113495bSYour Name 		WMITLV_GET_STRUCT_TLVLEN(
87*5113495bSYour Name 			wmi_bpf_set_vdev_enable_cmd_fixed_param));
88*5113495bSYour Name 	cmd->vdev_id = vdev_id;
89*5113495bSYour Name 	cmd->is_enabled = enable;
90*5113495bSYour Name 
91*5113495bSYour Name 	if (wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
92*5113495bSYour Name 				 WMI_BPF_SET_VDEV_ENABLE_CMDID)) {
93*5113495bSYour Name 		wmi_err("Failed to enable/disable APF interpreter");
94*5113495bSYour Name 		wmi_buf_free(buf);
95*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
96*5113495bSYour Name 	}
97*5113495bSYour Name 
98*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
99*5113495bSYour Name }
100*5113495bSYour Name 
101*5113495bSYour Name QDF_STATUS
wmi_send_apf_write_work_memory_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_apf_write_memory_params * apf_write_params)102*5113495bSYour Name wmi_send_apf_write_work_memory_cmd_tlv(wmi_unified_t wmi_handle,
103*5113495bSYour Name 				       struct wmi_apf_write_memory_params
104*5113495bSYour Name 							      *apf_write_params)
105*5113495bSYour Name {
106*5113495bSYour Name 	wmi_bpf_set_vdev_work_memory_cmd_fixed_param *cmd;
107*5113495bSYour Name 	uint32_t wmi_buf_len;
108*5113495bSYour Name 	wmi_buf_t buf;
109*5113495bSYour Name 	uint8_t *buf_ptr;
110*5113495bSYour Name 	uint32_t aligned_len = 0;
111*5113495bSYour Name 
112*5113495bSYour Name 	wmi_buf_len = sizeof(*cmd);
113*5113495bSYour Name 	if (apf_write_params->length) {
114*5113495bSYour Name 		aligned_len = roundup(apf_write_params->length,
115*5113495bSYour Name 				      sizeof(A_UINT32));
116*5113495bSYour Name 
117*5113495bSYour Name 		wmi_buf_len += WMI_TLV_HDR_SIZE + aligned_len;
118*5113495bSYour Name 
119*5113495bSYour Name 	}
120*5113495bSYour Name 
121*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, wmi_buf_len);
122*5113495bSYour Name 	if (!buf) {
123*5113495bSYour Name 		wmi_err("wmi_buf_alloc failed");
124*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
125*5113495bSYour Name 	}
126*5113495bSYour Name 
127*5113495bSYour Name 	buf_ptr = wmi_buf_data(buf);
128*5113495bSYour Name 	cmd = (wmi_bpf_set_vdev_work_memory_cmd_fixed_param *)buf_ptr;
129*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header,
130*5113495bSYour Name 		WMITLV_TAG_STRUC_wmi_bpf_set_vdev_work_memory_cmd_fixed_param,
131*5113495bSYour Name 		WMITLV_GET_STRUCT_TLVLEN(
132*5113495bSYour Name 			wmi_bpf_set_vdev_work_memory_cmd_fixed_param));
133*5113495bSYour Name 	cmd->vdev_id = apf_write_params->vdev_id;
134*5113495bSYour Name 	cmd->bpf_version = apf_write_params->apf_version;
135*5113495bSYour Name 	cmd->program_len = apf_write_params->program_len;
136*5113495bSYour Name 	cmd->addr_offset = apf_write_params->addr_offset;
137*5113495bSYour Name 	cmd->length = apf_write_params->length;
138*5113495bSYour Name 
139*5113495bSYour Name 	if (apf_write_params->length) {
140*5113495bSYour Name 		buf_ptr += sizeof(*cmd);
141*5113495bSYour Name 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
142*5113495bSYour Name 			       aligned_len);
143*5113495bSYour Name 		buf_ptr += WMI_TLV_HDR_SIZE;
144*5113495bSYour Name 		qdf_mem_copy(buf_ptr, apf_write_params->buf,
145*5113495bSYour Name 			     apf_write_params->length);
146*5113495bSYour Name 	}
147*5113495bSYour Name 
148*5113495bSYour Name 	if (wmi_unified_cmd_send(wmi_handle, buf, wmi_buf_len,
149*5113495bSYour Name 				 WMI_BPF_SET_VDEV_WORK_MEMORY_CMDID)) {
150*5113495bSYour Name 		wmi_err("Failed to write APF work memory");
151*5113495bSYour Name 		wmi_buf_free(buf);
152*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
153*5113495bSYour Name 	}
154*5113495bSYour Name 
155*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
156*5113495bSYour Name }
157*5113495bSYour Name 
158*5113495bSYour Name QDF_STATUS
wmi_send_apf_read_work_memory_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_apf_read_memory_params * apf_read_params)159*5113495bSYour Name wmi_send_apf_read_work_memory_cmd_tlv(wmi_unified_t wmi_handle,
160*5113495bSYour Name 				      struct wmi_apf_read_memory_params
161*5113495bSYour Name 							       *apf_read_params)
162*5113495bSYour Name {
163*5113495bSYour Name 	wmi_bpf_get_vdev_work_memory_cmd_fixed_param *cmd;
164*5113495bSYour Name 	wmi_buf_t buf;
165*5113495bSYour Name 
166*5113495bSYour Name 	buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
167*5113495bSYour Name 	if (!buf) {
168*5113495bSYour Name 		wmi_err("wmi_buf_alloc failed");
169*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
170*5113495bSYour Name 	}
171*5113495bSYour Name 
172*5113495bSYour Name 	cmd = (wmi_bpf_get_vdev_work_memory_cmd_fixed_param *)
173*5113495bSYour Name 							wmi_buf_data(buf);
174*5113495bSYour Name 
175*5113495bSYour Name 	WMITLV_SET_HDR(&cmd->tlv_header,
176*5113495bSYour Name 		WMITLV_TAG_STRUC_wmi_bpf_get_vdev_work_memory_cmd_fixed_param,
177*5113495bSYour Name 		WMITLV_GET_STRUCT_TLVLEN(
178*5113495bSYour Name 			wmi_bpf_get_vdev_work_memory_cmd_fixed_param));
179*5113495bSYour Name 	cmd->vdev_id = apf_read_params->vdev_id;
180*5113495bSYour Name 	cmd->addr_offset = apf_read_params->addr_offset;
181*5113495bSYour Name 	cmd->length = apf_read_params->length;
182*5113495bSYour Name 
183*5113495bSYour Name 	if (wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
184*5113495bSYour Name 				 WMI_BPF_GET_VDEV_WORK_MEMORY_CMDID)) {
185*5113495bSYour Name 		wmi_err("Failed to get APF work memory");
186*5113495bSYour Name 		wmi_buf_free(buf);
187*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
188*5113495bSYour Name 	}
189*5113495bSYour Name 
190*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
191*5113495bSYour Name }
192*5113495bSYour Name 
193*5113495bSYour Name QDF_STATUS
wmi_extract_apf_read_memory_resp_event_tlv(wmi_unified_t wmi_handle,void * evt_buf,struct wmi_apf_read_memory_resp_event_params * resp)194*5113495bSYour Name wmi_extract_apf_read_memory_resp_event_tlv(wmi_unified_t wmi_handle,
195*5113495bSYour Name 				void *evt_buf,
196*5113495bSYour Name 				struct wmi_apf_read_memory_resp_event_params
197*5113495bSYour Name 									  *resp)
198*5113495bSYour Name {
199*5113495bSYour Name 	WMI_BPF_GET_VDEV_WORK_MEMORY_RESP_EVENTID_param_tlvs *param_buf;
200*5113495bSYour Name 	wmi_bpf_get_vdev_work_memory_resp_evt_fixed_param *data_event;
201*5113495bSYour Name 
202*5113495bSYour Name 	param_buf = evt_buf;
203*5113495bSYour Name 	if (!param_buf) {
204*5113495bSYour Name 		wmi_err("encrypt decrypt resp evt_buf is NULL");
205*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
206*5113495bSYour Name 	}
207*5113495bSYour Name 
208*5113495bSYour Name 	data_event = param_buf->fixed_param;
209*5113495bSYour Name 
210*5113495bSYour Name 	resp->vdev_id = data_event->vdev_id;
211*5113495bSYour Name 	resp->offset = data_event->offset;
212*5113495bSYour Name 	resp->more_data = data_event->fragment;
213*5113495bSYour Name 
214*5113495bSYour Name 	if (data_event->length > param_buf->num_data) {
215*5113495bSYour Name 		wmi_err("FW msg data_len %d more than TLV hdr %d",
216*5113495bSYour Name 			 data_event->length,
217*5113495bSYour Name 			 param_buf->num_data);
218*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
219*5113495bSYour Name 	}
220*5113495bSYour Name 
221*5113495bSYour Name 	if (data_event->length && param_buf->data) {
222*5113495bSYour Name 		resp->length = data_event->length;
223*5113495bSYour Name 		resp->data = (uint8_t *)param_buf->data;
224*5113495bSYour Name 	}
225*5113495bSYour Name 
226*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
227*5113495bSYour Name }
228