xref: /wlan-driver/qcacld-3.0/components/target_if/twt/src/target_if_ext_twt_cmd.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /**
18  *  DOC: target_if_ext_twt_cmd.c
19  *  This file contains twt component's target related function definitions
20  */
21 #include <wlan_twt_public_structs.h>
22 #include <wlan_lmac_if_def.h>
23 #include <target_if.h>
24 #include <target_if_ext_twt.h>
25 #include <wmi_unified_twt_api.h>
26 
27 QDF_STATUS
target_if_twt_setup_req(struct wlan_objmgr_psoc * psoc,struct twt_add_dialog_param * req)28 target_if_twt_setup_req(struct wlan_objmgr_psoc *psoc,
29 			struct twt_add_dialog_param *req)
30 {
31 	struct wmi_unified *wmi_handle;
32 
33 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
34 	if (!wmi_handle) {
35 		target_if_err("wmi_handle is null");
36 		return QDF_STATUS_E_NULL_VALUE;
37 	}
38 
39 	return wmi_unified_twt_add_dialog_cmd(wmi_handle, req);
40 }
41 
42 QDF_STATUS
target_if_twt_teardown_req(struct wlan_objmgr_psoc * psoc,struct twt_del_dialog_param * req)43 target_if_twt_teardown_req(struct wlan_objmgr_psoc *psoc,
44 			   struct twt_del_dialog_param *req)
45 {
46 	struct wmi_unified *wmi_handle;
47 
48 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
49 	if (!wmi_handle) {
50 		target_if_err("wmi_handle is null");
51 		return QDF_STATUS_E_NULL_VALUE;
52 	}
53 
54 	return wmi_unified_twt_del_dialog_cmd(wmi_handle, req);
55 }
56 
57 QDF_STATUS
target_if_twt_pause_req(struct wlan_objmgr_psoc * psoc,struct twt_pause_dialog_cmd_param * req)58 target_if_twt_pause_req(struct wlan_objmgr_psoc *psoc,
59 			struct twt_pause_dialog_cmd_param *req)
60 {
61 	struct wmi_unified *wmi_handle;
62 
63 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
64 	if (!wmi_handle) {
65 		target_if_err("wmi_handle is null");
66 		return QDF_STATUS_E_NULL_VALUE;
67 	}
68 
69 	return wmi_unified_twt_pause_dialog_cmd(wmi_handle, req);
70 }
71 
72 QDF_STATUS
target_if_twt_resume_req(struct wlan_objmgr_psoc * psoc,struct twt_resume_dialog_cmd_param * req)73 target_if_twt_resume_req(struct wlan_objmgr_psoc *psoc,
74 			 struct twt_resume_dialog_cmd_param *req)
75 {
76 	struct wmi_unified *wmi_handle;
77 
78 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
79 	if (!wmi_handle) {
80 		target_if_err("wmi_handle is null");
81 		return QDF_STATUS_E_NULL_VALUE;
82 	}
83 
84 	return wmi_unified_twt_resume_dialog_cmd(wmi_handle, req);
85 }
86 
87 QDF_STATUS
target_if_twt_nudge_req(struct wlan_objmgr_psoc * psoc,struct twt_nudge_dialog_cmd_param * req)88 target_if_twt_nudge_req(struct wlan_objmgr_psoc *psoc,
89 			struct twt_nudge_dialog_cmd_param *req)
90 {
91 	struct wmi_unified *wmi_handle;
92 
93 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
94 	if (!wmi_handle) {
95 		target_if_err("wmi_handle is null");
96 		return QDF_STATUS_E_NULL_VALUE;
97 	}
98 
99 	return wmi_unified_twt_nudge_dialog_cmd(wmi_handle, req);
100 }
101 
102 /**
103  * target_if_twt_convert_ac_value() - map ac setting to the value to be used in FW.
104  * @ac_value: ac value to be mapped.
105  *
106  * Return: enum wmi_traffic_ac
107  */
108 static inline
target_if_twt_convert_ac_value(enum twt_traffic_ac ac_value)109 wmi_traffic_ac target_if_twt_convert_ac_value(enum twt_traffic_ac ac_value)
110 {
111 	switch (ac_value) {
112 	case TWT_AC_BE:
113 		return WMI_AC_BE;
114 	case TWT_AC_BK:
115 		return WMI_AC_BK;
116 	case TWT_AC_VI:
117 		return WMI_AC_VI;
118 	case TWT_AC_VO:
119 		return WMI_AC_VO;
120 	case TWT_AC_MAX:
121 		return WMI_AC_MAX;
122 	}
123 	target_if_err("invalid enum: %u", ac_value);
124 	return WMI_AC_MAX;
125 }
126 
127 QDF_STATUS
target_if_twt_ac_param_send(struct wlan_objmgr_psoc * psoc,enum twt_traffic_ac twt_ac,uint8_t mac_id)128 target_if_twt_ac_param_send(struct wlan_objmgr_psoc *psoc,
129 			    enum twt_traffic_ac twt_ac, uint8_t mac_id)
130 {
131 	struct wmi_unified *wmi_handle;
132 	struct pdev_params params = {0};
133 
134 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
135 	if (!wmi_handle) {
136 		target_if_err("wmi_handle is null");
137 		return QDF_STATUS_E_NULL_VALUE;
138 	}
139 
140 	params.param_id = wmi_pdev_param_twt_ac_config;
141 	params.param_value = target_if_twt_convert_ac_value(twt_ac);
142 
143 	return wmi_unified_pdev_param_send(wmi_handle, &params, mac_id);
144 }
145 
146 QDF_STATUS
target_if_twt_register_ext_tx_ops(struct wlan_lmac_if_twt_tx_ops * twt_tx_ops)147 target_if_twt_register_ext_tx_ops(struct wlan_lmac_if_twt_tx_ops *twt_tx_ops)
148 {
149 	twt_tx_ops->setup_req = target_if_twt_setup_req;
150 	twt_tx_ops->teardown_req = target_if_twt_teardown_req;
151 	twt_tx_ops->pause_req = target_if_twt_pause_req;
152 	twt_tx_ops->resume_req = target_if_twt_resume_req;
153 	twt_tx_ops->nudge_req = target_if_twt_nudge_req;
154 	twt_tx_ops->set_ac_param = target_if_twt_ac_param_send;
155 
156 	return QDF_STATUS_SUCCESS;
157 }
158 
159