1f46083e0SRajeev Kumar /* 2*361e1786SJeff Johnson * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved. 3f46083e0SRajeev Kumar * 4f46083e0SRajeev Kumar * Permission to use, copy, modify, and/or distribute this software for 5f46083e0SRajeev Kumar * any purpose with or without fee is hereby granted, provided that the 6f46083e0SRajeev Kumar * above copyright notice and this permission notice appear in all 7f46083e0SRajeev Kumar * copies. 8f46083e0SRajeev Kumar * 9f46083e0SRajeev Kumar * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10f46083e0SRajeev Kumar * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11f46083e0SRajeev Kumar * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12f46083e0SRajeev Kumar * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13f46083e0SRajeev Kumar * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14f46083e0SRajeev Kumar * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15f46083e0SRajeev Kumar * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16f46083e0SRajeev Kumar * PERFORMANCE OF THIS SOFTWARE. 17f46083e0SRajeev Kumar */ 18f46083e0SRajeev Kumar /** 19f46083e0SRajeev Kumar * DOC: Implements low power heart beat offload feature API's 20f46083e0SRajeev Kumar */ 21f46083e0SRajeev Kumar 22f46083e0SRajeev Kumar #include "wlan_pmo_main.h" 23f46083e0SRajeev Kumar #include "wlan_pmo_lphb.h" 24f46083e0SRajeev Kumar #include "wlan_pmo_tgt_api.h" 25f46083e0SRajeev Kumar #include "wlan_pmo_obj_mgmt_public_struct.h" 26f46083e0SRajeev Kumar 27f46083e0SRajeev Kumar #ifdef FEATURE_WLAN_LPHB 28f46083e0SRajeev Kumar /** 29f46083e0SRajeev Kumar * pmo_core_send_lphb_enable() - enable command of LPHB configuration requests 30f46083e0SRajeev Kumar * @psoc: objmgr psoc handle 31f46083e0SRajeev Kumar * @psoc_ctx: pmo private psoc ctx 32f46083e0SRajeev Kumar * @lphb_conf_req: lphb request which need s to configure in fwr 33f46083e0SRajeev Kumar * @by_user: whether this call is from user or cached resent 34f46083e0SRajeev Kumar * 35f46083e0SRajeev Kumar * Return: QDF status 36f46083e0SRajeev Kumar */ 37f46083e0SRajeev Kumar static QDF_STATUS pmo_core_send_lphb_enable(struct wlan_objmgr_psoc *psoc, 38f46083e0SRajeev Kumar struct pmo_psoc_priv_obj *psoc_ctx, 39f46083e0SRajeev Kumar struct pmo_lphb_req *lphb_conf_req, bool by_user) 40f46083e0SRajeev Kumar { 41f46083e0SRajeev Kumar QDF_STATUS qdf_status = QDF_STATUS_SUCCESS; 42f46083e0SRajeev Kumar struct pmo_lphb_enable_req *ts_lphb_enable; 43f46083e0SRajeev Kumar int i; 44f46083e0SRajeev Kumar 45*361e1786SJeff Johnson if (!lphb_conf_req) { 46f46083e0SRajeev Kumar pmo_err("LPHB configuration is NULL"); 47f46083e0SRajeev Kumar return QDF_STATUS_E_FAILURE; 48f46083e0SRajeev Kumar } 49f46083e0SRajeev Kumar 50f46083e0SRajeev Kumar ts_lphb_enable = &(lphb_conf_req->params.lphb_enable_req); 51f46083e0SRajeev Kumar qdf_status = pmo_tgt_send_lphb_enable(psoc, ts_lphb_enable); 52f46083e0SRajeev Kumar if (qdf_status != QDF_STATUS_SUCCESS) 53f46083e0SRajeev Kumar goto out; 54f46083e0SRajeev Kumar 55f46083e0SRajeev Kumar /* No need to cache non user request */ 56f46083e0SRajeev Kumar if (!by_user) { 57f46083e0SRajeev Kumar qdf_status = QDF_STATUS_SUCCESS; 58f46083e0SRajeev Kumar goto out; 59f46083e0SRajeev Kumar } 60f46083e0SRajeev Kumar 61f46083e0SRajeev Kumar /* target already configured, now cache command status */ 62b91e6eb9SNaveen Rawat if (ts_lphb_enable->enable && ts_lphb_enable->item > 0) { 63f46083e0SRajeev Kumar i = ts_lphb_enable->item - 1; 64f46083e0SRajeev Kumar qdf_spin_lock_bh(&psoc_ctx->lock); 65f46083e0SRajeev Kumar psoc_ctx->wow.lphb_cache[i].cmd 66f46083e0SRajeev Kumar = pmo_lphb_set_en_param_indid; 67f46083e0SRajeev Kumar psoc_ctx->wow.lphb_cache[i].params.lphb_enable_req.enable = 68f46083e0SRajeev Kumar ts_lphb_enable->enable; 69f46083e0SRajeev Kumar psoc_ctx->wow.lphb_cache[i].params.lphb_enable_req.item = 70f46083e0SRajeev Kumar ts_lphb_enable->item; 71f46083e0SRajeev Kumar psoc_ctx->wow.lphb_cache[i].params.lphb_enable_req.session = 72f46083e0SRajeev Kumar ts_lphb_enable->session; 73f46083e0SRajeev Kumar qdf_spin_unlock_bh(&psoc_ctx->lock); 740f87448eSDustin Brown pmo_debug("cached LPHB status in WMA context for item %d", i); 75f46083e0SRajeev Kumar } else { 76f46083e0SRajeev Kumar qdf_spin_lock_bh(&psoc_ctx->lock); 77f46083e0SRajeev Kumar qdf_mem_zero((void *)&psoc_ctx->wow.lphb_cache, 78f46083e0SRajeev Kumar sizeof(psoc_ctx->wow.lphb_cache)); 79f46083e0SRajeev Kumar qdf_spin_unlock_bh(&psoc_ctx->lock); 800f87448eSDustin Brown pmo_debug("cleared all cached LPHB status in WMA context"); 81f46083e0SRajeev Kumar } 82f46083e0SRajeev Kumar 83f46083e0SRajeev Kumar out: 84f46083e0SRajeev Kumar return qdf_status; 85f46083e0SRajeev Kumar } 86f46083e0SRajeev Kumar 87f46083e0SRajeev Kumar /** 88f46083e0SRajeev Kumar * pmo_core_send_lphb_tcp_params() - Send tcp params of LPHB requests 89f46083e0SRajeev Kumar * @psoc: objmgr psoc handle 90f46083e0SRajeev Kumar * @lphb_conf_req: lphb request which needs to be configured in fwr 91f46083e0SRajeev Kumar * 92f46083e0SRajeev Kumar * Return: QDF status 93f46083e0SRajeev Kumar */ 94f46083e0SRajeev Kumar static 95f46083e0SRajeev Kumar QDF_STATUS pmo_core_send_lphb_tcp_params(struct wlan_objmgr_psoc *psoc, 96f46083e0SRajeev Kumar struct pmo_lphb_req *lphb_conf_req) 97f46083e0SRajeev Kumar { 98f46083e0SRajeev Kumar return pmo_tgt_send_lphb_tcp_params(psoc, 99f46083e0SRajeev Kumar &lphb_conf_req->params.lphb_tcp_params); 100f46083e0SRajeev Kumar 101f46083e0SRajeev Kumar } 102f46083e0SRajeev Kumar 103f46083e0SRajeev Kumar /** 104f46083e0SRajeev Kumar * pmo_core_send_lphb_tcp_pkt_filter() - Send tcp packet filter command of LPHB 105f46083e0SRajeev Kumar * @psoc: objmgr psoc handle 106f46083e0SRajeev Kumar * @lphb_conf_req: lphb request which needs to be configured in fwr 107f46083e0SRajeev Kumar * 108f46083e0SRajeev Kumar * Return: QDF status 109f46083e0SRajeev Kumar */ 110f46083e0SRajeev Kumar static 111f46083e0SRajeev Kumar QDF_STATUS pmo_core_send_lphb_tcp_pkt_filter(struct wlan_objmgr_psoc *psoc, 112f46083e0SRajeev Kumar struct pmo_lphb_req *lphb_conf_req) 113f46083e0SRajeev Kumar { 114f46083e0SRajeev Kumar return pmo_tgt_send_lphb_tcp_pkt_filter(psoc, 115f46083e0SRajeev Kumar &lphb_conf_req->params.lphb_tcp_filter_req); 116f46083e0SRajeev Kumar } 117f46083e0SRajeev Kumar 118f46083e0SRajeev Kumar /** 119f46083e0SRajeev Kumar * pmo_core_send_lphb_udp_params() - Send udp param command of LPHB 120f46083e0SRajeev Kumar * @psoc: objmgr psoc handle 121f46083e0SRajeev Kumar * @lphb_conf_req: lphb request which needs to be configured in fwr 122f46083e0SRajeev Kumar * 123f46083e0SRajeev Kumar * Return: QDF status 124f46083e0SRajeev Kumar */ 125f46083e0SRajeev Kumar static 126f46083e0SRajeev Kumar QDF_STATUS pmo_core_send_lphb_udp_params(struct wlan_objmgr_psoc *psoc, 127f46083e0SRajeev Kumar struct pmo_lphb_req *lphb_conf_req) 128f46083e0SRajeev Kumar { 129f46083e0SRajeev Kumar return pmo_tgt_send_lphb_udp_params(psoc, 130f46083e0SRajeev Kumar &lphb_conf_req->params.lphb_udp_params); 131f46083e0SRajeev Kumar } 132f46083e0SRajeev Kumar 133f46083e0SRajeev Kumar /** 134f46083e0SRajeev Kumar * pmo_core_send_lphb_udp_pkt_filter() - Send udp pkt filter command of LPHB 135f46083e0SRajeev Kumar * @psoc: objmgr psoc handle 136f46083e0SRajeev Kumar * @lphb_conf_req: lphb request which need s to configure in fwr 137f46083e0SRajeev Kumar * 138f46083e0SRajeev Kumar * Return: QDF status 139f46083e0SRajeev Kumar */ 140f46083e0SRajeev Kumar static 141f46083e0SRajeev Kumar QDF_STATUS pmo_core_send_lphb_udp_pkt_filter(struct wlan_objmgr_psoc *psoc, 142f46083e0SRajeev Kumar struct pmo_lphb_req *lphb_conf_req) 143f46083e0SRajeev Kumar { 144f46083e0SRajeev Kumar return pmo_tgt_send_lphb_udp_pkt_filter(psoc, 145f46083e0SRajeev Kumar &lphb_conf_req->params.lphb_udp_filter_req); 146f46083e0SRajeev Kumar } 147f46083e0SRajeev Kumar 148f46083e0SRajeev Kumar /** 149f46083e0SRajeev Kumar * pmo_process_lphb_conf_req() - handle LPHB configuration requests 150f46083e0SRajeev Kumar * @psoc: objmgr psoc handle 151f46083e0SRajeev Kumar * @psoc_ctx: pmo private psoc ctx 152f46083e0SRajeev Kumar * @lphb_conf_req: lphb request which needs to be configured in fwr 153f46083e0SRajeev Kumar * 154f46083e0SRajeev Kumar * Return: QDF status 155f46083e0SRajeev Kumar */ 156f46083e0SRajeev Kumar static QDF_STATUS pmo_process_lphb_conf_req(struct wlan_objmgr_psoc *psoc, 157f46083e0SRajeev Kumar struct pmo_psoc_priv_obj *psoc_ctx, 158f46083e0SRajeev Kumar struct pmo_lphb_req *lphb_conf_req) 159f46083e0SRajeev Kumar { 160f46083e0SRajeev Kumar QDF_STATUS status = QDF_STATUS_SUCCESS; 161f46083e0SRajeev Kumar 1620f87448eSDustin Brown pmo_debug("LPHB configuration cmd id is %d", lphb_conf_req->cmd); 163f46083e0SRajeev Kumar switch (lphb_conf_req->cmd) { 164f46083e0SRajeev Kumar case pmo_lphb_set_en_param_indid: 165f46083e0SRajeev Kumar status = pmo_core_send_lphb_enable(psoc, psoc_ctx, 166f46083e0SRajeev Kumar lphb_conf_req, true); 167f46083e0SRajeev Kumar break; 168f46083e0SRajeev Kumar 169f46083e0SRajeev Kumar case pmo_lphb_set_tcp_pararm_indid: 170f46083e0SRajeev Kumar status = pmo_core_send_lphb_tcp_params(psoc, lphb_conf_req); 171f46083e0SRajeev Kumar break; 172f46083e0SRajeev Kumar 173f46083e0SRajeev Kumar case pmo_lphb_set_tcp_pkt_filter_indid: 174f46083e0SRajeev Kumar status = pmo_core_send_lphb_tcp_pkt_filter(psoc, lphb_conf_req); 175f46083e0SRajeev Kumar break; 176f46083e0SRajeev Kumar 177f46083e0SRajeev Kumar case pmo_lphb_set_udp_pararm_indid: 178f46083e0SRajeev Kumar status = pmo_core_send_lphb_udp_params(psoc, lphb_conf_req); 179f46083e0SRajeev Kumar break; 180f46083e0SRajeev Kumar 181f46083e0SRajeev Kumar case pmo_lphb_set_udp_pkt_filter_indid: 182f46083e0SRajeev Kumar status = pmo_core_send_lphb_udp_pkt_filter(psoc, lphb_conf_req); 183f46083e0SRajeev Kumar break; 184f46083e0SRajeev Kumar 185f46083e0SRajeev Kumar case pmo_lphb_set_network_info_indid: 186f46083e0SRajeev Kumar default: 187f46083e0SRajeev Kumar break; 188f46083e0SRajeev Kumar } 189f46083e0SRajeev Kumar 190f46083e0SRajeev Kumar return status; 191f46083e0SRajeev Kumar } 192f46083e0SRajeev Kumar 193f46083e0SRajeev Kumar void pmo_core_apply_lphb(struct wlan_objmgr_psoc *psoc) 194f46083e0SRajeev Kumar { 195f46083e0SRajeev Kumar int i; 196f46083e0SRajeev Kumar struct pmo_psoc_priv_obj *psoc_ctx; 197f46083e0SRajeev Kumar 198f46083e0SRajeev Kumar psoc_ctx = pmo_psoc_get_priv(psoc); 199f46083e0SRajeev Kumar 200f46083e0SRajeev Kumar pmo_debug("checking LPHB cache"); 201f46083e0SRajeev Kumar for (i = 0; i < 2; i++) { 202f46083e0SRajeev Kumar if (psoc_ctx->wow.lphb_cache[i].params.lphb_enable_req.enable) { 203f46083e0SRajeev Kumar pmo_debug("LPHB cache for item %d is marked as enable", 204f46083e0SRajeev Kumar i + 1); 205f46083e0SRajeev Kumar pmo_core_send_lphb_enable(psoc, psoc_ctx, 206f46083e0SRajeev Kumar &(psoc_ctx->wow.lphb_cache[i]), false); 207f46083e0SRajeev Kumar } 208f46083e0SRajeev Kumar } 209f46083e0SRajeev Kumar } 210f46083e0SRajeev Kumar 211f46083e0SRajeev Kumar QDF_STATUS pmo_core_lphb_config_req(struct wlan_objmgr_psoc *psoc, 212f46083e0SRajeev Kumar struct pmo_lphb_req *lphb_req, void *lphb_cb_ctx, 213f46083e0SRajeev Kumar pmo_lphb_callback callback) 214f46083e0SRajeev Kumar { 215f46083e0SRajeev Kumar struct pmo_psoc_priv_obj *psoc_ctx; 216f46083e0SRajeev Kumar 217*361e1786SJeff Johnson if (!lphb_req) { 218f46083e0SRajeev Kumar pmo_err("LPHB configuration is NULL"); 219f46083e0SRajeev Kumar return QDF_STATUS_E_NULL_VALUE; 220f46083e0SRajeev Kumar } 221f46083e0SRajeev Kumar 222f46083e0SRajeev Kumar psoc_ctx = pmo_psoc_get_priv(psoc); 223f46083e0SRajeev Kumar 224f46083e0SRajeev Kumar if (pmo_lphb_set_en_param_indid == lphb_req->cmd) { 225f46083e0SRajeev Kumar if (!lphb_cb_ctx) { 226f46083e0SRajeev Kumar pmo_err("lphb callback context is null"); 227f46083e0SRajeev Kumar return QDF_STATUS_E_NULL_VALUE; 228f46083e0SRajeev Kumar } 229f46083e0SRajeev Kumar if (!callback) { 230f46083e0SRajeev Kumar pmo_err("lphb callback function is null"); 231f46083e0SRajeev Kumar return QDF_STATUS_E_NULL_VALUE; 232f46083e0SRajeev Kumar } 233f46083e0SRajeev Kumar qdf_spin_lock_bh(&psoc_ctx->lock); 234f46083e0SRajeev Kumar psoc_ctx->wow.lphb_cb_ctx = lphb_cb_ctx; 235f46083e0SRajeev Kumar psoc_ctx->wow.lphb_cb = callback; 236f46083e0SRajeev Kumar qdf_spin_unlock_bh(&psoc_ctx->lock); 237f46083e0SRajeev Kumar } 238f46083e0SRajeev Kumar 239f46083e0SRajeev Kumar return pmo_process_lphb_conf_req(psoc, psoc_ctx, lphb_req); 240f46083e0SRajeev Kumar } 241f46083e0SRajeev Kumar 242f46083e0SRajeev Kumar #endif /* FEATURE_WLAN_LPHB */ 243f46083e0SRajeev Kumar 244