18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
118c2ecf20Sopenharmony_ci * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
138c2ecf20Sopenharmony_ci * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include "wcn36xx.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciint wcn36xx_pmc_enter_bmps_state(struct wcn36xx *wcn,
228c2ecf20Sopenharmony_ci				 struct ieee80211_vif *vif)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	int ret = 0;
258c2ecf20Sopenharmony_ci	struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
268c2ecf20Sopenharmony_ci	/* TODO: Make sure the TX chain clean */
278c2ecf20Sopenharmony_ci	ret = wcn36xx_smd_enter_bmps(wcn, vif);
288c2ecf20Sopenharmony_ci	if (!ret) {
298c2ecf20Sopenharmony_ci		wcn36xx_dbg(WCN36XX_DBG_PMC, "Entered BMPS\n");
308c2ecf20Sopenharmony_ci		vif_priv->pw_state = WCN36XX_BMPS;
318c2ecf20Sopenharmony_ci		vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
328c2ecf20Sopenharmony_ci	} else {
338c2ecf20Sopenharmony_ci		/*
348c2ecf20Sopenharmony_ci		 * One of the reasons why HW will not enter BMPS is because
358c2ecf20Sopenharmony_ci		 * driver is trying to enter bmps before first beacon was
368c2ecf20Sopenharmony_ci		 * received just after auth complete
378c2ecf20Sopenharmony_ci		 */
388c2ecf20Sopenharmony_ci		wcn36xx_err("Can not enter BMPS!\n");
398c2ecf20Sopenharmony_ci	}
408c2ecf20Sopenharmony_ci	return ret;
418c2ecf20Sopenharmony_ci}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciint wcn36xx_pmc_exit_bmps_state(struct wcn36xx *wcn,
448c2ecf20Sopenharmony_ci				struct ieee80211_vif *vif)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	if (WCN36XX_BMPS != vif_priv->pw_state) {
498c2ecf20Sopenharmony_ci		/* Unbalanced call or last BMPS enter failed */
508c2ecf20Sopenharmony_ci		wcn36xx_dbg(WCN36XX_DBG_PMC,
518c2ecf20Sopenharmony_ci			    "Not in BMPS mode, no need to exit\n");
528c2ecf20Sopenharmony_ci		return -EALREADY;
538c2ecf20Sopenharmony_ci	}
548c2ecf20Sopenharmony_ci	wcn36xx_smd_exit_bmps(wcn, vif);
558c2ecf20Sopenharmony_ci	vif_priv->pw_state = WCN36XX_FULL_POWER;
568c2ecf20Sopenharmony_ci	vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
578c2ecf20Sopenharmony_ci	return 0;
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciint wcn36xx_enable_keep_alive_null_packet(struct wcn36xx *wcn,
618c2ecf20Sopenharmony_ci					  struct ieee80211_vif *vif)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci	wcn36xx_dbg(WCN36XX_DBG_PMC, "%s\n", __func__);
648c2ecf20Sopenharmony_ci	return wcn36xx_smd_keep_alive_req(wcn, vif,
658c2ecf20Sopenharmony_ci					  WCN36XX_HAL_KEEP_ALIVE_NULL_PKT);
668c2ecf20Sopenharmony_ci}
67