xref: /wlan-driver/qca-wifi-host-cmn/target_if/twt/src/target_if_twt_cmd.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
3*5113495bSYour Name  *
4*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for any
5*5113495bSYour Name  * purpose with or without fee is hereby granted, provided that the above
6*5113495bSYour Name  * copyright notice and this permission notice appear in all copies.
7*5113495bSYour Name  *
8*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*5113495bSYour Name  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*5113495bSYour Name  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*5113495bSYour Name  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*5113495bSYour Name  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*5113495bSYour Name  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*5113495bSYour Name  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*5113495bSYour Name  */
16*5113495bSYour Name 
17*5113495bSYour Name /**
18*5113495bSYour Name  *  DOC: target_if_twt_cmd.c
19*5113495bSYour Name  *  This file contains twt component's target related function definitions
20*5113495bSYour Name  */
21*5113495bSYour Name #include <target_if_twt.h>
22*5113495bSYour Name #include <target_if_twt_cmd.h>
23*5113495bSYour Name #include <target_if_ext_twt.h>
24*5113495bSYour Name #include "twt/core/src/wlan_twt_common.h"
25*5113495bSYour Name 
26*5113495bSYour Name QDF_STATUS
target_if_twt_enable_req(struct wlan_objmgr_psoc * psoc,struct twt_enable_param * req)27*5113495bSYour Name target_if_twt_enable_req(struct wlan_objmgr_psoc *psoc,
28*5113495bSYour Name 			 struct twt_enable_param *req)
29*5113495bSYour Name {
30*5113495bSYour Name 	QDF_STATUS ret;
31*5113495bSYour Name 	struct wmi_unified *wmi_handle;
32*5113495bSYour Name 	struct wlan_objmgr_pdev *pdev;
33*5113495bSYour Name 
34*5113495bSYour Name 	if (!psoc) {
35*5113495bSYour Name 		target_if_err("null psoc");
36*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
37*5113495bSYour Name 	}
38*5113495bSYour Name 
39*5113495bSYour Name 	pdev = wlan_objmgr_get_pdev_by_id(psoc, req->pdev_id,
40*5113495bSYour Name 					  WLAN_TWT_ID);
41*5113495bSYour Name 	if (!pdev) {
42*5113495bSYour Name 		target_if_err("null pdev");
43*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
44*5113495bSYour Name 	}
45*5113495bSYour Name 
46*5113495bSYour Name 	wmi_handle = get_wmi_unified_hdl_from_pdev(pdev);
47*5113495bSYour Name 	if (!wmi_handle) {
48*5113495bSYour Name 		target_if_err("null wmi handle");
49*5113495bSYour Name 		wlan_objmgr_pdev_release_ref(pdev, WLAN_TWT_ID);
50*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
51*5113495bSYour Name 	}
52*5113495bSYour Name 
53*5113495bSYour Name 	ret = wmi_unified_twt_enable_cmd(wmi_handle, req);
54*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(ret))
55*5113495bSYour Name 		target_if_err("Failed to enable TWT(ret=%d)", ret);
56*5113495bSYour Name 
57*5113495bSYour Name 	wlan_objmgr_pdev_release_ref(pdev, WLAN_TWT_ID);
58*5113495bSYour Name 
59*5113495bSYour Name 	return ret;
60*5113495bSYour Name }
61*5113495bSYour Name 
62*5113495bSYour Name QDF_STATUS
target_if_twt_disable_req(struct wlan_objmgr_psoc * psoc,struct twt_disable_param * req)63*5113495bSYour Name target_if_twt_disable_req(struct wlan_objmgr_psoc *psoc,
64*5113495bSYour Name 			  struct twt_disable_param *req)
65*5113495bSYour Name {
66*5113495bSYour Name 	QDF_STATUS ret;
67*5113495bSYour Name 	struct wmi_unified *wmi_handle;
68*5113495bSYour Name 	struct wlan_objmgr_pdev *pdev;
69*5113495bSYour Name 
70*5113495bSYour Name 	if (!psoc) {
71*5113495bSYour Name 		target_if_err("null psoc");
72*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
73*5113495bSYour Name 	}
74*5113495bSYour Name 
75*5113495bSYour Name 	pdev = wlan_objmgr_get_pdev_by_id(psoc, req->pdev_id,
76*5113495bSYour Name 					  WLAN_TWT_ID);
77*5113495bSYour Name 	if (!pdev) {
78*5113495bSYour Name 		target_if_err("null pdev");
79*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
80*5113495bSYour Name 	}
81*5113495bSYour Name 
82*5113495bSYour Name 	wmi_handle = get_wmi_unified_hdl_from_pdev(pdev);
83*5113495bSYour Name 	if (!wmi_handle) {
84*5113495bSYour Name 		target_if_err("null wmi handle");
85*5113495bSYour Name 		wlan_objmgr_pdev_release_ref(pdev, WLAN_TWT_ID);
86*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
87*5113495bSYour Name 	}
88*5113495bSYour Name 
89*5113495bSYour Name 	ret = wmi_unified_twt_disable_cmd(wmi_handle, req);
90*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(ret))
91*5113495bSYour Name 		target_if_err("Failed to disable TWT(ret=%d)", ret);
92*5113495bSYour Name 
93*5113495bSYour Name 	wlan_objmgr_pdev_release_ref(pdev, WLAN_TWT_ID);
94*5113495bSYour Name 
95*5113495bSYour Name 	return ret;
96*5113495bSYour Name }
97*5113495bSYour Name 
98