2 * This file is part of wl1271
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
30 enum wl1271_cmd_ps_mode mode)
33 u16 timeout = wl->conf.conn.dynamic_ps_timeout;
36 case STATION_AUTO_PS_MODE:
37 case STATION_POWER_SAVE_MODE:
38 wl1271_debug(DEBUG_PSM, "entering psm (mode=%d,timeout=%u)",
41 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
42 wl->conf.conn.wake_up_event,
43 wl->conf.conn.listen_interval);
45 wl1271_error("couldn't set wake up conditions");
49 ret = wl1271_cmd_ps_mode(wl, wlvif, mode, timeout);
53 set_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
56 * enable beacon early termination.
57 * Not relevant for 5GHz and for high rates.
59 if ((wlvif->band == NL80211_BAND_2GHZ) &&
60 (wlvif->basic_rate < CONF_HW_BIT_RATE_9MBPS)) {
61 ret = wl1271_acx_bet_enable(wl, wlvif, true);
66 case STATION_ACTIVE_MODE:
67 wl1271_debug(DEBUG_PSM, "leaving psm");
69 /* disable beacon early termination */
70 if ((wlvif->band == NL80211_BAND_2GHZ) &&
71 (wlvif->basic_rate < CONF_HW_BIT_RATE_9MBPS)) {
72 ret = wl1271_acx_bet_enable(wl, wlvif, false);
77 ret = wl1271_cmd_ps_mode(wl, wlvif, mode, 0);
81 clear_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
84 wl1271_warning("trying to set ps to unsupported mode %d", mode);
91 static void wl1271_ps_filter_frames(struct wl1271 *wl, u8 hlid)
95 struct ieee80211_tx_info *info;
97 int filtered[NUM_TX_QUEUES];
98 struct wl1271_link *lnk = &wl->links[hlid];
100 /* filter all frames currently in the low level queues for this hlid */
101 for (i = 0; i < NUM_TX_QUEUES; i++) {
103 while ((skb = skb_dequeue(&lnk->tx_queue[i]))) {
106 if (WARN_ON(wl12xx_is_dummy_packet(wl, skb)))
109 info = IEEE80211_SKB_CB(skb);
110 info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
111 info->status.rates[0].idx = -1;
112 ieee80211_tx_status_ni(wl->hw, skb);
116 spin_lock_irqsave(&wl->wl_lock, flags);
117 for (i = 0; i < NUM_TX_QUEUES; i++) {
118 wl->tx_queue_count[i] -= filtered[i];
120 lnk->wlvif->tx_queue_count[i] -= filtered[i];
122 spin_unlock_irqrestore(&wl->wl_lock, flags);
124 wl1271_handle_tx_low_watermark(wl);
127 void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
128 u8 hlid, bool clean_queues)
130 struct ieee80211_sta *sta;
131 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
133 if (WARN_ON_ONCE(wlvif->bss_type != BSS_TYPE_AP_BSS))
136 if (!test_bit(hlid, wlvif->ap.sta_hlid_map) ||
137 test_bit(hlid, &wl->ap_ps_map))
140 wl1271_debug(DEBUG_PSM, "start mac80211 PSM on hlid %d pkts %d "
141 "clean_queues %d", hlid, wl->links[hlid].allocated_pkts,
145 sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
147 wl1271_error("could not find sta %pM for starting ps",
148 wl->links[hlid].addr);
153 ieee80211_sta_ps_transition_ni(sta, true);
156 /* do we want to filter all frames from this link's queues? */
158 wl1271_ps_filter_frames(wl, hlid);
160 __set_bit(hlid, &wl->ap_ps_map);
163 void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
165 struct ieee80211_sta *sta;
166 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
168 if (!test_bit(hlid, &wl->ap_ps_map))
171 wl1271_debug(DEBUG_PSM, "end mac80211 PSM on hlid %d", hlid);
173 __clear_bit(hlid, &wl->ap_ps_map);
176 sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
178 wl1271_error("could not find sta %pM for ending ps",
179 wl->links[hlid].addr);
183 ieee80211_sta_ps_transition_ni(sta, false);