2013-01-24 21:25:36 +08:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* This file is provided under a dual BSD/GPLv2 license. When using or
|
|
|
|
* redistributing this file, you may do so under either license.
|
|
|
|
*
|
|
|
|
* GPL LICENSE SUMMARY
|
|
|
|
*
|
|
|
|
* Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
* The full GNU General Public License is included in this distribution
|
2013-02-18 15:22:28 +08:00
|
|
|
* in the file called COPYING.
|
2013-01-24 21:25:36 +08:00
|
|
|
*
|
|
|
|
* Contact Information:
|
|
|
|
* Intel Linux Wireless <ilw@linux.intel.com>
|
|
|
|
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
|
|
*
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <net/mac80211.h>
|
|
|
|
|
|
|
|
#include "iwl-notif-wait.h"
|
|
|
|
#include "iwl-trans.h"
|
|
|
|
#include "fw-api.h"
|
|
|
|
#include "time-event.h"
|
|
|
|
#include "mvm.h"
|
|
|
|
#include "iwl-io.h"
|
|
|
|
#include "iwl-prph.h"
|
|
|
|
|
|
|
|
/* A TimeUnit is 1024 microsecond */
|
|
|
|
#define TU_TO_JIFFIES(_tu) (usecs_to_jiffies((_tu) * 1024))
|
|
|
|
#define MSEC_TO_TU(_msec) (_msec*1000/1024)
|
|
|
|
|
2013-02-13 17:05:18 +08:00
|
|
|
/*
|
|
|
|
* For the high priority TE use a time event type that has similar priority to
|
|
|
|
* the FW's action scan priority.
|
2013-02-04 20:09:37 +08:00
|
|
|
*/
|
2013-02-13 17:05:18 +08:00
|
|
|
#define IWL_MVM_ROC_TE_TYPE_NORMAL TE_P2P_DEVICE_DISCOVERABLE
|
|
|
|
#define IWL_MVM_ROC_TE_TYPE_MGMT_TX TE_P2P_CLIENT_ASSOC
|
2013-02-04 20:09:37 +08:00
|
|
|
|
2013-01-24 21:25:36 +08:00
|
|
|
void iwl_mvm_te_clear_data(struct iwl_mvm *mvm,
|
|
|
|
struct iwl_mvm_time_event_data *te_data)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&mvm->time_event_lock);
|
|
|
|
|
|
|
|
if (te_data->id == TE_MAX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_del(&te_data->list);
|
|
|
|
te_data->running = false;
|
|
|
|
te_data->uid = 0;
|
|
|
|
te_data->id = TE_MAX;
|
|
|
|
te_data->vif = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iwl_mvm_roc_done_wk(struct work_struct *wk)
|
|
|
|
{
|
|
|
|
struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, roc_done_wk);
|
|
|
|
|
|
|
|
synchronize_net();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush the offchannel queue -- this is called when the time
|
|
|
|
* event finishes or is cancelled, so that frames queued for it
|
|
|
|
* won't get stuck on the queue and be transmitted in the next
|
|
|
|
* time event.
|
|
|
|
* We have to send the command asynchronously since this cannot
|
|
|
|
* be under the mutex for locking reasons, but that's not an
|
|
|
|
* issue as it will have to complete before the next command is
|
|
|
|
* executed, and a new time event means a new command.
|
|
|
|
*/
|
2013-03-13 21:20:35 +08:00
|
|
|
iwl_mvm_flush_tx_path(mvm, BIT(IWL_MVM_OFFCHANNEL_QUEUE), false);
|
2013-01-24 21:25:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void iwl_mvm_roc_finished(struct iwl_mvm *mvm)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* First, clear the ROC_RUNNING status bit. This will cause the TX
|
|
|
|
* path to drop offchannel transmissions. That would also be done
|
|
|
|
* by mac80211, but it is racy, in particular in the case that the
|
|
|
|
* time event actually completed in the firmware (which is handled
|
|
|
|
* in iwl_mvm_te_handle_notif).
|
|
|
|
*/
|
|
|
|
clear_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Of course, our status bit is just as racy as mac80211, so in
|
|
|
|
* addition, fire off the work struct which will drop all frames
|
|
|
|
* from the hardware queues that made it through the race. First
|
|
|
|
* it will of course synchronize the TX path to make sure that
|
|
|
|
* any *new* TX will be rejected.
|
|
|
|
*/
|
|
|
|
schedule_work(&mvm->roc_done_wk);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handles a FW notification for an event that is known to the driver.
|
|
|
|
*
|
|
|
|
* @mvm: the mvm component
|
|
|
|
* @te_data: the time event data
|
|
|
|
* @notif: the notification data corresponding the time event data.
|
|
|
|
*/
|
|
|
|
static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm,
|
|
|
|
struct iwl_mvm_time_event_data *te_data,
|
|
|
|
struct iwl_time_event_notif *notif)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&mvm->time_event_lock);
|
|
|
|
|
|
|
|
IWL_DEBUG_TE(mvm, "Handle time event notif - UID = 0x%x action %d\n",
|
|
|
|
le32_to_cpu(notif->unique_id),
|
|
|
|
le32_to_cpu(notif->action));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The FW sends the start/end time event notifications even for events
|
|
|
|
* that it fails to schedule. This is indicated in the status field of
|
|
|
|
* the notification. This happens in cases that the scheduler cannot
|
|
|
|
* find a schedule that can handle the event (for example requesting a
|
|
|
|
* P2P Device discoveribility, while there are other higher priority
|
|
|
|
* events in the system).
|
|
|
|
*/
|
|
|
|
WARN_ONCE(!le32_to_cpu(notif->status),
|
|
|
|
"Failed to schedule time event\n");
|
|
|
|
|
2013-03-19 22:28:56 +08:00
|
|
|
if (le32_to_cpu(notif->action) & TE_NOTIF_HOST_EVENT_END) {
|
2013-01-24 21:25:36 +08:00
|
|
|
IWL_DEBUG_TE(mvm,
|
|
|
|
"TE ended - current time %lu, estimated end %lu\n",
|
|
|
|
jiffies, te_data->end_jiffies);
|
|
|
|
|
|
|
|
if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
|
|
|
|
ieee80211_remain_on_channel_expired(mvm->hw);
|
|
|
|
iwl_mvm_roc_finished(mvm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* By now, we should have finished association
|
|
|
|
* and know the dtim period.
|
|
|
|
*/
|
|
|
|
if (te_data->vif->type == NL80211_IFTYPE_STATION &&
|
|
|
|
(!te_data->vif->bss_conf.assoc ||
|
2013-01-25 06:48:23 +08:00
|
|
|
!te_data->vif->bss_conf.dtim_period)) {
|
2013-01-24 21:25:36 +08:00
|
|
|
IWL_ERR(mvm,
|
|
|
|
"No assocation and the time event is over already...\n");
|
2013-01-25 06:48:23 +08:00
|
|
|
ieee80211_connection_loss(te_data->vif);
|
|
|
|
}
|
2013-01-24 21:25:36 +08:00
|
|
|
|
|
|
|
iwl_mvm_te_clear_data(mvm, te_data);
|
2013-03-19 22:28:56 +08:00
|
|
|
} else if (le32_to_cpu(notif->action) & TE_NOTIF_HOST_EVENT_START) {
|
2013-01-24 21:25:36 +08:00
|
|
|
te_data->running = true;
|
|
|
|
te_data->end_jiffies = jiffies +
|
|
|
|
TU_TO_JIFFIES(te_data->duration);
|
|
|
|
|
|
|
|
if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
|
|
|
|
set_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
|
|
|
|
ieee80211_ready_on_channel(mvm->hw);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
IWL_WARN(mvm, "Got TE with unknown action\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The Rx handler for time event notifications
|
|
|
|
*/
|
|
|
|
int iwl_mvm_rx_time_event_notif(struct iwl_mvm *mvm,
|
|
|
|
struct iwl_rx_cmd_buffer *rxb,
|
|
|
|
struct iwl_device_cmd *cmd)
|
|
|
|
{
|
|
|
|
struct iwl_rx_packet *pkt = rxb_addr(rxb);
|
|
|
|
struct iwl_time_event_notif *notif = (void *)pkt->data;
|
|
|
|
struct iwl_mvm_time_event_data *te_data, *tmp;
|
|
|
|
|
|
|
|
IWL_DEBUG_TE(mvm, "Time event notification - UID = 0x%x action %d\n",
|
|
|
|
le32_to_cpu(notif->unique_id),
|
|
|
|
le32_to_cpu(notif->action));
|
|
|
|
|
|
|
|
spin_lock_bh(&mvm->time_event_lock);
|
|
|
|
list_for_each_entry_safe(te_data, tmp, &mvm->time_event_list, list) {
|
|
|
|
if (le32_to_cpu(notif->unique_id) == te_data->uid)
|
|
|
|
iwl_mvm_te_handle_notif(mvm, te_data, notif);
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&mvm->time_event_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
static bool iwl_mvm_time_event_response(struct iwl_notif_wait_data *notif_wait,
|
|
|
|
struct iwl_rx_packet *pkt, void *data)
|
2013-01-24 21:25:36 +08:00
|
|
|
{
|
|
|
|
struct iwl_mvm *mvm =
|
|
|
|
container_of(notif_wait, struct iwl_mvm, notif_wait);
|
|
|
|
struct iwl_mvm_time_event_data *te_data = data;
|
|
|
|
struct iwl_time_event_resp *resp;
|
2013-01-29 22:28:17 +08:00
|
|
|
int resp_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
|
2013-01-24 21:25:36 +08:00
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
if (WARN_ON(pkt->hdr.cmd != TIME_EVENT_CMD))
|
|
|
|
return true;
|
2013-01-24 21:25:36 +08:00
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
if (WARN_ON_ONCE(resp_len != sizeof(pkt->hdr) + sizeof(*resp))) {
|
|
|
|
IWL_ERR(mvm, "Invalid TIME_EVENT_CMD response\n");
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-24 21:25:36 +08:00
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
resp = (void *)pkt->data;
|
iwlwifi: mvm: fix time event command handling race
Occasionally, we would run into this warning:
iwlwifi 0000:02:00.0: U iwl_mvm_protect_session extend 0x2601: only 200 ms left
iwlwifi 0000:02:00.0: U iwl_mvm_remove_time_event Removing TE 0x2601
iwlwifi 0000:02:00.0: I iwl_pcie_enqueue_hcmd Sending command TIME_EVENT_CMD (#29), seq: 0x0925, 60 bytes at 37[5]:9
iwlwifi 0000:02:00.0: U iwl_pcie_send_hcmd_sync Attempting to send sync command TIME_EVENT_CMD
iwlwifi 0000:02:00.0: U iwl_pcie_send_hcmd_sync Setting HCMD_ACTIVE for command TIME_EVENT_CMD
iwlwifi 0000:02:00.0: I iwl_pcie_enqueue_hcmd Sending command TIME_EVENT_CMD (#29), seq: 0x0926, 60 bytes at 38[6]:9
iwlwifi 0000:02:00.0: U iwl_mvm_time_event_response TIME_EVENT_CMD response - UID = 0x2601
iwlwifi 0000:02:00.0: I iwl_pcie_hcmd_complete Clearing HCMD_ACTIVE for command TIME_EVENT_CMD
iwlwifi 0000:02:00.0: U iwl_mvm_rx_time_event_notif Time event notification - UID = 0x2701 action 1
wlan0: associate with 00:0a:b8:55:a8:30 (try 2/3)
------------[ cut here ]------------
WARNING: at drivers/net/wireless/iwlwifi/mvm/time-event.c:269 iwl_mvm_time_event_send_add+0x163/0x1a0 [iwlmvm]()
Modules linked in: [...]
Call Trace:
[<c1046e42>] warn_slowpath_common+0x72/0xa0
[<c1046e92>] warn_slowpath_null+0x22/0x30
[<f8cad913>] iwl_mvm_time_event_send_add+0x163/0x1a0 [iwlmvm]
[<f8cadead>] iwl_mvm_protect_session+0xcd/0x1c0 [iwlmvm]
[<f8ca2087>] iwl_mvm_mac_mgd_prepare_tx+0x67/0xa0 [iwlmvm]
[<f882a130>] ieee80211_sta_work+0x8f0/0x1070 [mac80211]
The reason is a problem with asynchronous vs. synchronous
commands, what happens here is the following:
* TE 0x2601 is removed, the TIME_EVENT_CMD for that is async
* a new TE (will be 0x2701) is created, the TIME_EVENT_CMD
for that is sync and also uses a notification wait for the
response (to avoid another race condition)
* the response for the TE 0x2601 removal comes from the
firmware, and is handled by the notification wait handler
that's really waiting for the second response, but can't
tell the difference, we therefore see the message
"TIME_EVENT_CMD response - UID = 0x2601" instead of
"TIME_EVENT_CMD response - UID = 0x2701".
Fix this issue by making the TE removal synchronous as well,
this means that we wait for the response to that command
first, before there's any chance of sending a new one.
Also, to detect such issues more easily in the future, add
a warning to the notification handler that detects them.
Reviewed-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2013-02-16 07:11:34 +08:00
|
|
|
|
|
|
|
/* we should never get a response to another TIME_EVENT_CMD here */
|
|
|
|
if (WARN_ON_ONCE(le32_to_cpu(resp->id) != te_data->id))
|
|
|
|
return false;
|
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
te_data->uid = le32_to_cpu(resp->unique_id);
|
|
|
|
IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
|
|
|
|
te_data->uid);
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-24 21:25:36 +08:00
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
static int iwl_mvm_time_event_send_add(struct iwl_mvm *mvm,
|
|
|
|
struct ieee80211_vif *vif,
|
|
|
|
struct iwl_mvm_time_event_data *te_data,
|
|
|
|
struct iwl_time_event_cmd *te_cmd)
|
|
|
|
{
|
|
|
|
static const u8 time_event_response[] = { TIME_EVENT_CMD };
|
|
|
|
struct iwl_notification_wait wait_time_event;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
lockdep_assert_held(&mvm->mutex);
|
|
|
|
|
2013-02-16 06:54:10 +08:00
|
|
|
IWL_DEBUG_TE(mvm, "Add new TE, duration %d TU\n",
|
|
|
|
le32_to_cpu(te_cmd->duration));
|
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
spin_lock_bh(&mvm->time_event_lock);
|
|
|
|
if (WARN_ON(te_data->id != TE_MAX)) {
|
|
|
|
spin_unlock_bh(&mvm->time_event_lock);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
te_data->vif = vif;
|
|
|
|
te_data->duration = le32_to_cpu(te_cmd->duration);
|
|
|
|
te_data->id = le32_to_cpu(te_cmd->id);
|
|
|
|
list_add_tail(&te_data->list, &mvm->time_event_list);
|
|
|
|
spin_unlock_bh(&mvm->time_event_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use a notification wait, which really just processes the
|
|
|
|
* command response and doesn't wait for anything, in order
|
|
|
|
* to be able to process the response and get the UID inside
|
|
|
|
* the RX path. Using CMD_WANT_SKB doesn't work because it
|
|
|
|
* stores the buffer and then wakes up this thread, by which
|
|
|
|
* time another notification (that the time event started)
|
|
|
|
* might already be processed unsuccessfully.
|
|
|
|
*/
|
|
|
|
iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
|
|
|
|
time_event_response,
|
|
|
|
ARRAY_SIZE(time_event_response),
|
|
|
|
iwl_mvm_time_event_response, te_data);
|
|
|
|
|
|
|
|
ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
|
|
|
|
sizeof(*te_cmd), te_cmd);
|
|
|
|
if (ret) {
|
|
|
|
IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret);
|
|
|
|
iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
|
|
|
|
goto out_clear_te;
|
|
|
|
}
|
2013-01-24 21:25:36 +08:00
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
/* No need to wait for anything, so just pass 1 (0 isn't valid) */
|
|
|
|
ret = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
|
|
|
|
/* should never fail */
|
|
|
|
WARN_ON_ONCE(ret);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
out_clear_te:
|
|
|
|
spin_lock_bh(&mvm->time_event_lock);
|
|
|
|
iwl_mvm_te_clear_data(mvm, te_data);
|
|
|
|
spin_unlock_bh(&mvm->time_event_lock);
|
|
|
|
}
|
|
|
|
return ret;
|
2013-01-24 21:25:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void iwl_mvm_protect_session(struct iwl_mvm *mvm,
|
|
|
|
struct ieee80211_vif *vif,
|
|
|
|
u32 duration, u32 min_duration)
|
|
|
|
{
|
|
|
|
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
|
|
|
|
struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
|
|
|
|
struct iwl_time_event_cmd time_cmd = {};
|
|
|
|
|
|
|
|
lockdep_assert_held(&mvm->mutex);
|
|
|
|
|
|
|
|
if (te_data->running &&
|
|
|
|
time_after(te_data->end_jiffies,
|
|
|
|
jiffies + TU_TO_JIFFIES(min_duration))) {
|
|
|
|
IWL_DEBUG_TE(mvm, "We have enough time in the current TE: %u\n",
|
|
|
|
jiffies_to_msecs(te_data->end_jiffies - jiffies));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (te_data->running) {
|
|
|
|
IWL_DEBUG_TE(mvm, "extend 0x%x: only %u ms left\n",
|
|
|
|
te_data->uid,
|
|
|
|
jiffies_to_msecs(te_data->end_jiffies - jiffies));
|
|
|
|
/*
|
|
|
|
* we don't have enough time
|
|
|
|
* cancel the current TE and issue a new one
|
|
|
|
* Of course it would be better to remove the old one only
|
|
|
|
* when the new one is added, but we don't care if we are off
|
|
|
|
* channel for a bit. All we need to do, is not to return
|
|
|
|
* before we actually begin to be on the channel.
|
|
|
|
*/
|
|
|
|
iwl_mvm_stop_session_protection(mvm, vif);
|
|
|
|
}
|
|
|
|
|
|
|
|
time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
|
|
|
|
time_cmd.id_and_color =
|
|
|
|
cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
|
|
|
|
time_cmd.id = cpu_to_le32(TE_BSS_STA_AGGRESSIVE_ASSOC);
|
|
|
|
|
|
|
|
time_cmd.apply_time =
|
|
|
|
cpu_to_le32(iwl_read_prph(mvm->trans, DEVICE_SYSTEM_TIME_REG));
|
2013-01-29 22:28:17 +08:00
|
|
|
|
2013-01-24 21:25:36 +08:00
|
|
|
time_cmd.dep_policy = TE_INDEPENDENT;
|
|
|
|
time_cmd.is_present = cpu_to_le32(1);
|
|
|
|
time_cmd.max_frags = cpu_to_le32(TE_FRAG_NONE);
|
|
|
|
time_cmd.max_delay = cpu_to_le32(500);
|
|
|
|
/* TODO: why do we need to interval = bi if it is not periodic? */
|
|
|
|
time_cmd.interval = cpu_to_le32(1);
|
|
|
|
time_cmd.interval_reciprocal = cpu_to_le32(iwl_mvm_reciprocal(1));
|
|
|
|
time_cmd.duration = cpu_to_le32(duration);
|
|
|
|
time_cmd.repeat = cpu_to_le32(1);
|
2013-03-19 22:28:56 +08:00
|
|
|
time_cmd.notify = cpu_to_le32(TE_NOTIF_HOST_EVENT_START |
|
|
|
|
TE_NOTIF_HOST_EVENT_END);
|
2013-01-24 21:25:36 +08:00
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
|
2013-01-24 21:25:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Explicit request to remove a time event. The removal of a time event needs to
|
|
|
|
* be synchronized with the flow of a time event's end notification, which also
|
|
|
|
* removes the time event from the op mode data structures.
|
|
|
|
*/
|
|
|
|
void iwl_mvm_remove_time_event(struct iwl_mvm *mvm,
|
|
|
|
struct iwl_mvm_vif *mvmvif,
|
|
|
|
struct iwl_mvm_time_event_data *te_data)
|
|
|
|
{
|
|
|
|
struct iwl_time_event_cmd time_cmd = {};
|
|
|
|
u32 id, uid;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is possible that by the time we got to this point the time
|
|
|
|
* event was already removed.
|
|
|
|
*/
|
|
|
|
spin_lock_bh(&mvm->time_event_lock);
|
|
|
|
|
|
|
|
/* Save time event uid before clearing its data */
|
|
|
|
uid = te_data->uid;
|
|
|
|
id = te_data->id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The clear_data function handles time events that were already removed
|
|
|
|
*/
|
|
|
|
iwl_mvm_te_clear_data(mvm, te_data);
|
|
|
|
spin_unlock_bh(&mvm->time_event_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is possible that by the time we try to remove it, the time event
|
|
|
|
* has already ended and removed. In such a case there is no need to
|
|
|
|
* send a removal command.
|
|
|
|
*/
|
|
|
|
if (id == TE_MAX) {
|
|
|
|
IWL_DEBUG_TE(mvm, "TE 0x%x has already ended\n", uid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* When we remove a TE, the UID is to be set in the id field */
|
|
|
|
time_cmd.id = cpu_to_le32(uid);
|
|
|
|
time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
|
|
|
|
time_cmd.id_and_color =
|
|
|
|
cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
|
|
|
|
|
|
|
|
IWL_DEBUG_TE(mvm, "Removing TE 0x%x\n", le32_to_cpu(time_cmd.id));
|
iwlwifi: mvm: fix time event command handling race
Occasionally, we would run into this warning:
iwlwifi 0000:02:00.0: U iwl_mvm_protect_session extend 0x2601: only 200 ms left
iwlwifi 0000:02:00.0: U iwl_mvm_remove_time_event Removing TE 0x2601
iwlwifi 0000:02:00.0: I iwl_pcie_enqueue_hcmd Sending command TIME_EVENT_CMD (#29), seq: 0x0925, 60 bytes at 37[5]:9
iwlwifi 0000:02:00.0: U iwl_pcie_send_hcmd_sync Attempting to send sync command TIME_EVENT_CMD
iwlwifi 0000:02:00.0: U iwl_pcie_send_hcmd_sync Setting HCMD_ACTIVE for command TIME_EVENT_CMD
iwlwifi 0000:02:00.0: I iwl_pcie_enqueue_hcmd Sending command TIME_EVENT_CMD (#29), seq: 0x0926, 60 bytes at 38[6]:9
iwlwifi 0000:02:00.0: U iwl_mvm_time_event_response TIME_EVENT_CMD response - UID = 0x2601
iwlwifi 0000:02:00.0: I iwl_pcie_hcmd_complete Clearing HCMD_ACTIVE for command TIME_EVENT_CMD
iwlwifi 0000:02:00.0: U iwl_mvm_rx_time_event_notif Time event notification - UID = 0x2701 action 1
wlan0: associate with 00:0a:b8:55:a8:30 (try 2/3)
------------[ cut here ]------------
WARNING: at drivers/net/wireless/iwlwifi/mvm/time-event.c:269 iwl_mvm_time_event_send_add+0x163/0x1a0 [iwlmvm]()
Modules linked in: [...]
Call Trace:
[<c1046e42>] warn_slowpath_common+0x72/0xa0
[<c1046e92>] warn_slowpath_null+0x22/0x30
[<f8cad913>] iwl_mvm_time_event_send_add+0x163/0x1a0 [iwlmvm]
[<f8cadead>] iwl_mvm_protect_session+0xcd/0x1c0 [iwlmvm]
[<f8ca2087>] iwl_mvm_mac_mgd_prepare_tx+0x67/0xa0 [iwlmvm]
[<f882a130>] ieee80211_sta_work+0x8f0/0x1070 [mac80211]
The reason is a problem with asynchronous vs. synchronous
commands, what happens here is the following:
* TE 0x2601 is removed, the TIME_EVENT_CMD for that is async
* a new TE (will be 0x2701) is created, the TIME_EVENT_CMD
for that is sync and also uses a notification wait for the
response (to avoid another race condition)
* the response for the TE 0x2601 removal comes from the
firmware, and is handled by the notification wait handler
that's really waiting for the second response, but can't
tell the difference, we therefore see the message
"TIME_EVENT_CMD response - UID = 0x2601" instead of
"TIME_EVENT_CMD response - UID = 0x2701".
Fix this issue by making the TE removal synchronous as well,
this means that we wait for the response to that command
first, before there's any chance of sending a new one.
Also, to detect such issues more easily in the future, add
a warning to the notification handler that detects them.
Reviewed-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2013-02-16 07:11:34 +08:00
|
|
|
ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
|
2013-01-24 21:25:36 +08:00
|
|
|
sizeof(time_cmd), &time_cmd);
|
|
|
|
if (WARN_ON(ret))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iwl_mvm_stop_session_protection(struct iwl_mvm *mvm,
|
|
|
|
struct ieee80211_vif *vif)
|
|
|
|
{
|
|
|
|
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
|
|
|
|
struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
|
|
|
|
|
|
|
|
lockdep_assert_held(&mvm->mutex);
|
|
|
|
iwl_mvm_remove_time_event(mvm, mvmvif, te_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
|
2013-02-13 17:05:18 +08:00
|
|
|
int duration, enum ieee80211_roc_type type)
|
2013-01-24 21:25:36 +08:00
|
|
|
{
|
|
|
|
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
|
|
|
|
struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
|
|
|
|
struct iwl_time_event_cmd time_cmd = {};
|
|
|
|
|
|
|
|
lockdep_assert_held(&mvm->mutex);
|
|
|
|
if (te_data->running) {
|
|
|
|
IWL_WARN(mvm, "P2P_DEVICE remain on channel already running\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush the done work, just in case it's still pending, so that
|
|
|
|
* the work it does can complete and we can accept new frames.
|
|
|
|
*/
|
|
|
|
flush_work(&mvm->roc_done_wk);
|
|
|
|
|
|
|
|
time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
|
|
|
|
time_cmd.id_and_color =
|
|
|
|
cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
|
2013-02-13 17:05:18 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case IEEE80211_ROC_TYPE_NORMAL:
|
|
|
|
time_cmd.id = cpu_to_le32(IWL_MVM_ROC_TE_TYPE_NORMAL);
|
|
|
|
break;
|
|
|
|
case IEEE80211_ROC_TYPE_MGMT_TX:
|
|
|
|
time_cmd.id = cpu_to_le32(IWL_MVM_ROC_TE_TYPE_MGMT_TX);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "Got an invalid ROC type\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-01-24 21:25:36 +08:00
|
|
|
|
|
|
|
time_cmd.apply_time = cpu_to_le32(0);
|
|
|
|
time_cmd.dep_policy = cpu_to_le32(TE_INDEPENDENT);
|
|
|
|
time_cmd.is_present = cpu_to_le32(1);
|
|
|
|
time_cmd.interval = cpu_to_le32(1);
|
|
|
|
|
|
|
|
/*
|
2013-02-13 17:05:18 +08:00
|
|
|
* The P2P Device TEs can have lower priority than other events
|
2013-01-24 21:25:36 +08:00
|
|
|
* that are being scheduled by the driver/fw, and thus it might not be
|
2013-02-13 17:05:18 +08:00
|
|
|
* scheduled. To improve the chances of it being scheduled, allow them
|
|
|
|
* to be fragmented, and in addition allow them to be delayed.
|
2013-01-24 21:25:36 +08:00
|
|
|
*/
|
|
|
|
time_cmd.max_frags = cpu_to_le32(MSEC_TO_TU(duration)/20);
|
|
|
|
time_cmd.max_delay = cpu_to_le32(MSEC_TO_TU(duration/2));
|
|
|
|
time_cmd.duration = cpu_to_le32(MSEC_TO_TU(duration));
|
|
|
|
time_cmd.repeat = cpu_to_le32(1);
|
2013-03-19 22:28:56 +08:00
|
|
|
time_cmd.notify = cpu_to_le32(TE_NOTIF_HOST_EVENT_START |
|
|
|
|
TE_NOTIF_HOST_EVENT_END);
|
2013-01-24 21:25:36 +08:00
|
|
|
|
2013-01-29 22:28:17 +08:00
|
|
|
return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
|
2013-01-24 21:25:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void iwl_mvm_stop_p2p_roc(struct iwl_mvm *mvm)
|
|
|
|
{
|
|
|
|
struct iwl_mvm_vif *mvmvif;
|
|
|
|
struct iwl_mvm_time_event_data *te_data;
|
|
|
|
|
|
|
|
lockdep_assert_held(&mvm->mutex);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over the list of time events and find the time event that is
|
|
|
|
* associated with a P2P_DEVICE interface.
|
|
|
|
* This assumes that a P2P_DEVICE interface can have only a single time
|
|
|
|
* event at any given time and this time event coresponds to a ROC
|
|
|
|
* request
|
|
|
|
*/
|
|
|
|
mvmvif = NULL;
|
|
|
|
spin_lock_bh(&mvm->time_event_lock);
|
|
|
|
list_for_each_entry(te_data, &mvm->time_event_list, list) {
|
|
|
|
if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
|
|
|
|
mvmvif = iwl_mvm_vif_from_mac80211(te_data->vif);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&mvm->time_event_lock);
|
|
|
|
|
|
|
|
if (!mvmvif) {
|
|
|
|
IWL_WARN(mvm, "P2P_DEVICE no remain on channel event\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iwl_mvm_remove_time_event(mvm, mvmvif, te_data);
|
|
|
|
|
|
|
|
iwl_mvm_roc_finished(mvm);
|
|
|
|
}
|