1*246fe9f1SLee Jones /* 2ce86893fSKarun Eagalapati * Copyright (c) 2014 Redpine Signals Inc. 3ce86893fSKarun Eagalapati * 4ce86893fSKarun Eagalapati * Permission to use, copy, modify, and/or distribute this software for any 5ce86893fSKarun Eagalapati * purpose with or without fee is hereby granted, provided that the above 6ce86893fSKarun Eagalapati * copyright notice and this permission notice appear in all copies. 7ce86893fSKarun Eagalapati * 8ce86893fSKarun Eagalapati * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9ce86893fSKarun Eagalapati * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10ce86893fSKarun Eagalapati * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11ce86893fSKarun Eagalapati * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12ce86893fSKarun Eagalapati * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13ce86893fSKarun Eagalapati * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14ce86893fSKarun Eagalapati * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15ce86893fSKarun Eagalapati */ 16ce86893fSKarun Eagalapati 17ce86893fSKarun Eagalapati #include <linux/etherdevice.h> 18ce86893fSKarun Eagalapati #include <linux/if.h> 19ce86893fSKarun Eagalapati #include "rsi_debugfs.h" 20ce86893fSKarun Eagalapati #include "rsi_mgmt.h" 21ce86893fSKarun Eagalapati #include "rsi_common.h" 22ce86893fSKarun Eagalapati #include "rsi_ps.h" 23ce86893fSKarun Eagalapati 24ce86893fSKarun Eagalapati char *str_psstate(enum ps_state state) 25ce86893fSKarun Eagalapati { 26ce86893fSKarun Eagalapati switch (state) { 27ce86893fSKarun Eagalapati case PS_NONE: 28ce86893fSKarun Eagalapati return "PS_NONE"; 29ce86893fSKarun Eagalapati case PS_DISABLE_REQ_SENT: 30ce86893fSKarun Eagalapati return "PS_DISABLE_REQ_SENT"; 31ce86893fSKarun Eagalapati case PS_ENABLE_REQ_SENT: 32ce86893fSKarun Eagalapati return "PS_ENABLE_REQ_SENT"; 33ce86893fSKarun Eagalapati case PS_ENABLED: 34ce86893fSKarun Eagalapati return "PS_ENABLED"; 35ce86893fSKarun Eagalapati default: 36ce86893fSKarun Eagalapati return "INVALID_STATE"; 37ce86893fSKarun Eagalapati } 38ce86893fSKarun Eagalapati } 39ce86893fSKarun Eagalapati 40ce86893fSKarun Eagalapati static inline void rsi_modify_ps_state(struct rsi_hw *adapter, 41ce86893fSKarun Eagalapati enum ps_state nstate) 42ce86893fSKarun Eagalapati { 43ce86893fSKarun Eagalapati rsi_dbg(INFO_ZONE, "PS state changed %s => %s\n", 44ce86893fSKarun Eagalapati str_psstate(adapter->ps_state), 45ce86893fSKarun Eagalapati str_psstate(nstate)); 46ce86893fSKarun Eagalapati 47ce86893fSKarun Eagalapati adapter->ps_state = nstate; 48ce86893fSKarun Eagalapati } 49ce86893fSKarun Eagalapati 50ce86893fSKarun Eagalapati void rsi_default_ps_params(struct rsi_hw *adapter) 51ce86893fSKarun Eagalapati { 52ce86893fSKarun Eagalapati struct rsi_ps_info *ps_info = &adapter->ps_info; 53ce86893fSKarun Eagalapati 54ce86893fSKarun Eagalapati ps_info->enabled = true; 55ce86893fSKarun Eagalapati ps_info->sleep_type = RSI_SLEEP_TYPE_LP; 56ce86893fSKarun Eagalapati ps_info->tx_threshold = 0; 57ce86893fSKarun Eagalapati ps_info->rx_threshold = 0; 58ce86893fSKarun Eagalapati ps_info->tx_hysterisis = 0; 59ce86893fSKarun Eagalapati ps_info->rx_hysterisis = 0; 60ce86893fSKarun Eagalapati ps_info->monitor_interval = 0; 61ce86893fSKarun Eagalapati ps_info->listen_interval = RSI_DEF_LISTEN_INTERVAL; 62ce86893fSKarun Eagalapati ps_info->num_bcns_per_lis_int = 0; 63ce86893fSKarun Eagalapati ps_info->dtim_interval_duration = 0; 64ce86893fSKarun Eagalapati ps_info->num_dtims_per_sleep = 0; 65ce86893fSKarun Eagalapati ps_info->deep_sleep_wakeup_period = RSI_DEF_DS_WAKEUP_PERIOD; 66ce86893fSKarun Eagalapati } 67ce86893fSKarun Eagalapati 68efe877aaSPrameela Rani Garnepudi void rsi_enable_ps(struct rsi_hw *adapter, struct ieee80211_vif *vif) 69ce86893fSKarun Eagalapati { 70ce86893fSKarun Eagalapati if (adapter->ps_state != PS_NONE) { 71ce86893fSKarun Eagalapati rsi_dbg(ERR_ZONE, 72ce86893fSKarun Eagalapati "%s: Cannot accept enable PS in %s state\n", 73ce86893fSKarun Eagalapati __func__, str_psstate(adapter->ps_state)); 74ce86893fSKarun Eagalapati return; 75ce86893fSKarun Eagalapati } 76ce86893fSKarun Eagalapati 77efe877aaSPrameela Rani Garnepudi if (rsi_send_ps_request(adapter, true, vif)) { 78ce86893fSKarun Eagalapati rsi_dbg(ERR_ZONE, 79ce86893fSKarun Eagalapati "%s: Failed to send PS request to device\n", 80ce86893fSKarun Eagalapati __func__); 81ce86893fSKarun Eagalapati return; 82ce86893fSKarun Eagalapati } 83ce86893fSKarun Eagalapati 84ce86893fSKarun Eagalapati rsi_modify_ps_state(adapter, PS_ENABLE_REQ_SENT); 85ce86893fSKarun Eagalapati } 86ce86893fSKarun Eagalapati 87efe877aaSPrameela Rani Garnepudi /* This function is used to disable power save */ 88efe877aaSPrameela Rani Garnepudi void rsi_disable_ps(struct rsi_hw *adapter, struct ieee80211_vif *vif) 89ce86893fSKarun Eagalapati { 90ce86893fSKarun Eagalapati if (adapter->ps_state != PS_ENABLED) { 91ce86893fSKarun Eagalapati rsi_dbg(ERR_ZONE, 92ce86893fSKarun Eagalapati "%s: Cannot accept disable PS in %s state\n", 93ce86893fSKarun Eagalapati __func__, str_psstate(adapter->ps_state)); 94ce86893fSKarun Eagalapati return; 95ce86893fSKarun Eagalapati } 96ce86893fSKarun Eagalapati 97efe877aaSPrameela Rani Garnepudi if (rsi_send_ps_request(adapter, false, vif)) { 98ce86893fSKarun Eagalapati rsi_dbg(ERR_ZONE, 99ce86893fSKarun Eagalapati "%s: Failed to send PS request to device\n", 100ce86893fSKarun Eagalapati __func__); 101ce86893fSKarun Eagalapati return; 102ce86893fSKarun Eagalapati } 103ce86893fSKarun Eagalapati 104ce86893fSKarun Eagalapati rsi_modify_ps_state(adapter, PS_DISABLE_REQ_SENT); 105ce86893fSKarun Eagalapati } 106ce86893fSKarun Eagalapati 107efe877aaSPrameela Rani Garnepudi void rsi_conf_uapsd(struct rsi_hw *adapter, struct ieee80211_vif *vif) 108db07971dSKarun Eagalapati { 109db07971dSKarun Eagalapati int ret; 110db07971dSKarun Eagalapati 111db07971dSKarun Eagalapati if (adapter->ps_state != PS_ENABLED) 112db07971dSKarun Eagalapati return; 113db07971dSKarun Eagalapati 114efe877aaSPrameela Rani Garnepudi ret = rsi_send_ps_request(adapter, false, vif); 115db07971dSKarun Eagalapati if (!ret) 116efe877aaSPrameela Rani Garnepudi ret = rsi_send_ps_request(adapter, true, vif); 117db07971dSKarun Eagalapati if (ret) 118db07971dSKarun Eagalapati rsi_dbg(ERR_ZONE, 119db07971dSKarun Eagalapati "%s: Failed to send PS request to device\n", 120db07971dSKarun Eagalapati __func__); 121db07971dSKarun Eagalapati } 122db07971dSKarun Eagalapati 123ce86893fSKarun Eagalapati int rsi_handle_ps_confirm(struct rsi_hw *adapter, u8 *msg) 124ce86893fSKarun Eagalapati { 125ce86893fSKarun Eagalapati u16 cfm_type = get_unaligned_le16(msg + PS_CONFIRM_INDEX); 126ce86893fSKarun Eagalapati 127ce86893fSKarun Eagalapati switch (cfm_type) { 128ce86893fSKarun Eagalapati case RSI_SLEEP_REQUEST: 129ce86893fSKarun Eagalapati if (adapter->ps_state == PS_ENABLE_REQ_SENT) 130ce86893fSKarun Eagalapati rsi_modify_ps_state(adapter, PS_ENABLED); 131ce86893fSKarun Eagalapati break; 132ce86893fSKarun Eagalapati case RSI_WAKEUP_REQUEST: 133ce86893fSKarun Eagalapati if (adapter->ps_state == PS_DISABLE_REQ_SENT) 134ce86893fSKarun Eagalapati rsi_modify_ps_state(adapter, PS_NONE); 135ce86893fSKarun Eagalapati break; 136ce86893fSKarun Eagalapati default: 137ce86893fSKarun Eagalapati rsi_dbg(ERR_ZONE, 138ce86893fSKarun Eagalapati "Invalid PS confirm type %x in state %s\n", 139ce86893fSKarun Eagalapati cfm_type, str_psstate(adapter->ps_state)); 140ce86893fSKarun Eagalapati return -1; 141ce86893fSKarun Eagalapati } 142ce86893fSKarun Eagalapati 143ce86893fSKarun Eagalapati return 0; 144ce86893fSKarun Eagalapati } 145db07971dSKarun Eagalapati 146