2 * Copyright (c) 2014 Redpine Signals Inc.
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.
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.
17 #include <linux/etherdevice.h>
19 #include "rsi_debugfs.h"
21 #include "rsi_common.h"
24 char *str_psstate(enum ps_state state
)
29 case PS_DISABLE_REQ_SENT
:
30 return "PS_DISABLE_REQ_SENT";
31 case PS_ENABLE_REQ_SENT
:
32 return "PS_ENABLE_REQ_SENT";
36 return "INVALID_STATE";
40 static inline void rsi_modify_ps_state(struct rsi_hw
*adapter
,
43 rsi_dbg(INFO_ZONE
, "PS state changed %s => %s\n",
44 str_psstate(adapter
->ps_state
),
47 adapter
->ps_state
= nstate
;
50 void rsi_default_ps_params(struct rsi_hw
*adapter
)
52 struct rsi_ps_info
*ps_info
= &adapter
->ps_info
;
54 ps_info
->enabled
= true;
55 ps_info
->sleep_type
= RSI_SLEEP_TYPE_LP
;
56 ps_info
->tx_threshold
= 0;
57 ps_info
->rx_threshold
= 0;
58 ps_info
->tx_hysterisis
= 0;
59 ps_info
->rx_hysterisis
= 0;
60 ps_info
->monitor_interval
= 0;
61 ps_info
->listen_interval
= RSI_DEF_LISTEN_INTERVAL
;
62 ps_info
->num_bcns_per_lis_int
= 0;
63 ps_info
->dtim_interval_duration
= 0;
64 ps_info
->num_dtims_per_sleep
= 0;
65 ps_info
->deep_sleep_wakeup_period
= RSI_DEF_DS_WAKEUP_PERIOD
;
68 void rsi_enable_ps(struct rsi_hw
*adapter
, struct ieee80211_vif
*vif
)
70 if (adapter
->ps_state
!= PS_NONE
) {
72 "%s: Cannot accept enable PS in %s state\n",
73 __func__
, str_psstate(adapter
->ps_state
));
77 if (rsi_send_ps_request(adapter
, true, vif
)) {
79 "%s: Failed to send PS request to device\n",
84 rsi_modify_ps_state(adapter
, PS_ENABLE_REQ_SENT
);
87 /* This function is used to disable power save */
88 void rsi_disable_ps(struct rsi_hw
*adapter
, struct ieee80211_vif
*vif
)
90 if (adapter
->ps_state
!= PS_ENABLED
) {
92 "%s: Cannot accept disable PS in %s state\n",
93 __func__
, str_psstate(adapter
->ps_state
));
97 if (rsi_send_ps_request(adapter
, false, vif
)) {
99 "%s: Failed to send PS request to device\n",
104 rsi_modify_ps_state(adapter
, PS_DISABLE_REQ_SENT
);
107 void rsi_conf_uapsd(struct rsi_hw
*adapter
, struct ieee80211_vif
*vif
)
111 if (adapter
->ps_state
!= PS_ENABLED
)
114 ret
= rsi_send_ps_request(adapter
, false, vif
);
116 ret
= rsi_send_ps_request(adapter
, true, vif
);
119 "%s: Failed to send PS request to device\n",
123 int rsi_handle_ps_confirm(struct rsi_hw
*adapter
, u8
*msg
)
125 u16 cfm_type
= get_unaligned_le16(msg
+ PS_CONFIRM_INDEX
);
128 case RSI_SLEEP_REQUEST
:
129 if (adapter
->ps_state
== PS_ENABLE_REQ_SENT
)
130 rsi_modify_ps_state(adapter
, PS_ENABLED
);
132 case RSI_WAKEUP_REQUEST
:
133 if (adapter
->ps_state
== PS_DISABLE_REQ_SENT
)
134 rsi_modify_ps_state(adapter
, PS_NONE
);
138 "Invalid PS confirm type %x in state %s\n",
139 cfm_type
, str_psstate(adapter
->ps_state
));