Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
| 8 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 22 | * USA |
| 23 | * |
| 24 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 25 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 26 | * |
| 27 | * Contact Information: |
| 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
| 33 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. |
| 34 | * All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * |
| 40 | * * Redistributions of source code must retain the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer. |
| 42 | * * Redistributions in binary form must reproduce the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer in |
| 44 | * the documentation and/or other materials provided with the |
| 45 | * distribution. |
| 46 | * * Neither the name Intel Corporation nor the names of its |
| 47 | * contributors may be used to endorse or promote products derived |
| 48 | * from this software without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 | * |
| 62 | *****************************************************************************/ |
| 63 | |
| 64 | #include <linux/jiffies.h> |
| 65 | #include <net/mac80211.h> |
| 66 | |
| 67 | #include "iwl-notif-wait.h" |
| 68 | #include "iwl-trans.h" |
| 69 | #include "fw-api.h" |
| 70 | #include "time-event.h" |
| 71 | #include "mvm.h" |
| 72 | #include "iwl-io.h" |
| 73 | #include "iwl-prph.h" |
| 74 | |
| 75 | /* A TimeUnit is 1024 microsecond */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 76 | #define MSEC_TO_TU(_msec) (_msec*1000/1024) |
| 77 | |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 78 | /* |
| 79 | * For the high priority TE use a time event type that has similar priority to |
| 80 | * the FW's action scan priority. |
Ilan Peer | 456f6dd | 2013-02-04 14:09:37 +0200 | [diff] [blame] | 81 | */ |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 82 | #define IWL_MVM_ROC_TE_TYPE_NORMAL TE_P2P_DEVICE_DISCOVERABLE |
| 83 | #define IWL_MVM_ROC_TE_TYPE_MGMT_TX TE_P2P_CLIENT_ASSOC |
Ilan Peer | 456f6dd | 2013-02-04 14:09:37 +0200 | [diff] [blame] | 84 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 85 | void iwl_mvm_te_clear_data(struct iwl_mvm *mvm, |
| 86 | struct iwl_mvm_time_event_data *te_data) |
| 87 | { |
| 88 | lockdep_assert_held(&mvm->time_event_lock); |
| 89 | |
| 90 | if (te_data->id == TE_MAX) |
| 91 | return; |
| 92 | |
| 93 | list_del(&te_data->list); |
| 94 | te_data->running = false; |
| 95 | te_data->uid = 0; |
| 96 | te_data->id = TE_MAX; |
| 97 | te_data->vif = NULL; |
| 98 | } |
| 99 | |
| 100 | void iwl_mvm_roc_done_wk(struct work_struct *wk) |
| 101 | { |
| 102 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, roc_done_wk); |
| 103 | |
| 104 | synchronize_net(); |
| 105 | |
| 106 | /* |
| 107 | * Flush the offchannel queue -- this is called when the time |
| 108 | * event finishes or is cancelled, so that frames queued for it |
| 109 | * won't get stuck on the queue and be transmitted in the next |
| 110 | * time event. |
| 111 | * We have to send the command asynchronously since this cannot |
| 112 | * be under the mutex for locking reasons, but that's not an |
| 113 | * issue as it will have to complete before the next command is |
| 114 | * executed, and a new time event means a new command. |
| 115 | */ |
Ilan Peer | 398e8c6 | 2013-03-13 15:20:35 +0200 | [diff] [blame] | 116 | iwl_mvm_flush_tx_path(mvm, BIT(IWL_MVM_OFFCHANNEL_QUEUE), false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static void iwl_mvm_roc_finished(struct iwl_mvm *mvm) |
| 120 | { |
| 121 | /* |
| 122 | * First, clear the ROC_RUNNING status bit. This will cause the TX |
| 123 | * path to drop offchannel transmissions. That would also be done |
| 124 | * by mac80211, but it is racy, in particular in the case that the |
| 125 | * time event actually completed in the firmware (which is handled |
| 126 | * in iwl_mvm_te_handle_notif). |
| 127 | */ |
| 128 | clear_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status); |
| 129 | |
| 130 | /* |
| 131 | * Of course, our status bit is just as racy as mac80211, so in |
| 132 | * addition, fire off the work struct which will drop all frames |
| 133 | * from the hardware queues that made it through the race. First |
| 134 | * it will of course synchronize the TX path to make sure that |
| 135 | * any *new* TX will be rejected. |
| 136 | */ |
| 137 | schedule_work(&mvm->roc_done_wk); |
| 138 | } |
| 139 | |
Johannes Berg | 0573979 | 2013-07-25 18:39:30 +0200 | [diff] [blame] | 140 | static bool iwl_mvm_te_check_disconnect(struct iwl_mvm *mvm, |
| 141 | struct ieee80211_vif *vif, |
| 142 | const char *errmsg) |
| 143 | { |
| 144 | if (vif->type != NL80211_IFTYPE_STATION) |
| 145 | return false; |
| 146 | if (vif->bss_conf.assoc && vif->bss_conf.dtim_period) |
| 147 | return false; |
| 148 | if (errmsg) |
| 149 | IWL_ERR(mvm, "%s\n", errmsg); |
| 150 | ieee80211_connection_loss(vif); |
| 151 | return true; |
| 152 | } |
| 153 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 154 | /* |
| 155 | * Handles a FW notification for an event that is known to the driver. |
| 156 | * |
| 157 | * @mvm: the mvm component |
| 158 | * @te_data: the time event data |
| 159 | * @notif: the notification data corresponding the time event data. |
| 160 | */ |
| 161 | static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm, |
| 162 | struct iwl_mvm_time_event_data *te_data, |
| 163 | struct iwl_time_event_notif *notif) |
| 164 | { |
| 165 | lockdep_assert_held(&mvm->time_event_lock); |
| 166 | |
| 167 | IWL_DEBUG_TE(mvm, "Handle time event notif - UID = 0x%x action %d\n", |
| 168 | le32_to_cpu(notif->unique_id), |
| 169 | le32_to_cpu(notif->action)); |
| 170 | |
| 171 | /* |
| 172 | * The FW sends the start/end time event notifications even for events |
| 173 | * that it fails to schedule. This is indicated in the status field of |
| 174 | * the notification. This happens in cases that the scheduler cannot |
| 175 | * find a schedule that can handle the event (for example requesting a |
| 176 | * P2P Device discoveribility, while there are other higher priority |
| 177 | * events in the system). |
| 178 | */ |
Johannes Berg | 0573979 | 2013-07-25 18:39:30 +0200 | [diff] [blame] | 179 | if (WARN_ONCE(!le32_to_cpu(notif->status), |
| 180 | "Failed to schedule time event\n")) { |
| 181 | if (iwl_mvm_te_check_disconnect(mvm, te_data->vif, NULL)) { |
| 182 | iwl_mvm_te_clear_data(mvm, te_data); |
| 183 | return; |
| 184 | } |
| 185 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 186 | |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 187 | if (le32_to_cpu(notif->action) & TE_V2_NOTIF_HOST_EVENT_END) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 188 | IWL_DEBUG_TE(mvm, |
| 189 | "TE ended - current time %lu, estimated end %lu\n", |
| 190 | jiffies, te_data->end_jiffies); |
| 191 | |
| 192 | if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 193 | ieee80211_remain_on_channel_expired(mvm->hw); |
| 194 | iwl_mvm_roc_finished(mvm); |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * By now, we should have finished association |
| 199 | * and know the dtim period. |
| 200 | */ |
Johannes Berg | 0573979 | 2013-07-25 18:39:30 +0200 | [diff] [blame] | 201 | iwl_mvm_te_check_disconnect(mvm, te_data->vif, |
| 202 | "No assocation and the time event is over already..."); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 203 | iwl_mvm_te_clear_data(mvm, te_data); |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 204 | } else if (le32_to_cpu(notif->action) & TE_V2_NOTIF_HOST_EVENT_START) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 205 | te_data->running = true; |
Johannes Berg | e7f1935 | 2013-07-25 21:45:17 +0200 | [diff] [blame] | 206 | te_data->end_jiffies = TU_TO_EXP_TIME(te_data->duration); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 207 | |
| 208 | if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 209 | set_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status); |
| 210 | ieee80211_ready_on_channel(mvm->hw); |
| 211 | } |
| 212 | } else { |
| 213 | IWL_WARN(mvm, "Got TE with unknown action\n"); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * The Rx handler for time event notifications |
| 219 | */ |
| 220 | int iwl_mvm_rx_time_event_notif(struct iwl_mvm *mvm, |
| 221 | struct iwl_rx_cmd_buffer *rxb, |
| 222 | struct iwl_device_cmd *cmd) |
| 223 | { |
| 224 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 225 | struct iwl_time_event_notif *notif = (void *)pkt->data; |
| 226 | struct iwl_mvm_time_event_data *te_data, *tmp; |
| 227 | |
| 228 | IWL_DEBUG_TE(mvm, "Time event notification - UID = 0x%x action %d\n", |
| 229 | le32_to_cpu(notif->unique_id), |
| 230 | le32_to_cpu(notif->action)); |
| 231 | |
| 232 | spin_lock_bh(&mvm->time_event_lock); |
| 233 | list_for_each_entry_safe(te_data, tmp, &mvm->time_event_list, list) { |
| 234 | if (le32_to_cpu(notif->unique_id) == te_data->uid) |
| 235 | iwl_mvm_te_handle_notif(mvm, te_data, notif); |
| 236 | } |
| 237 | spin_unlock_bh(&mvm->time_event_lock); |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 242 | static bool iwl_mvm_time_event_response(struct iwl_notif_wait_data *notif_wait, |
| 243 | struct iwl_rx_packet *pkt, void *data) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 244 | { |
| 245 | struct iwl_mvm *mvm = |
| 246 | container_of(notif_wait, struct iwl_mvm, notif_wait); |
| 247 | struct iwl_mvm_time_event_data *te_data = data; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 248 | struct iwl_time_event_resp *resp; |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 249 | int resp_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 250 | |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 251 | if (WARN_ON(pkt->hdr.cmd != TIME_EVENT_CMD)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 252 | return true; |
| 253 | |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 254 | if (WARN_ON_ONCE(resp_len != sizeof(pkt->hdr) + sizeof(*resp))) { |
| 255 | IWL_ERR(mvm, "Invalid TIME_EVENT_CMD response\n"); |
| 256 | return true; |
| 257 | } |
| 258 | |
| 259 | resp = (void *)pkt->data; |
Johannes Berg | e372282 | 2013-02-16 00:11:34 +0100 | [diff] [blame] | 260 | |
| 261 | /* we should never get a response to another TIME_EVENT_CMD here */ |
| 262 | if (WARN_ON_ONCE(le32_to_cpu(resp->id) != te_data->id)) |
| 263 | return false; |
| 264 | |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 265 | te_data->uid = le32_to_cpu(resp->unique_id); |
| 266 | IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", |
| 267 | te_data->uid); |
| 268 | return true; |
| 269 | } |
| 270 | |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 271 | /* used to convert from time event API v2 to v1 */ |
| 272 | #define TE_V2_DEP_POLICY_MSK (TE_V2_DEP_OTHER | TE_V2_DEP_TSF |\ |
| 273 | TE_V2_EVENT_SOCIOPATHIC) |
| 274 | static inline u16 te_v2_get_notify(__le16 policy) |
| 275 | { |
| 276 | return le16_to_cpu(policy) & TE_V2_NOTIF_MSK; |
| 277 | } |
| 278 | |
| 279 | static inline u16 te_v2_get_dep_policy(__le16 policy) |
| 280 | { |
| 281 | return (le16_to_cpu(policy) & TE_V2_DEP_POLICY_MSK) >> |
| 282 | TE_V2_PLACEMENT_POS; |
| 283 | } |
| 284 | |
| 285 | static inline u16 te_v2_get_absence(__le16 policy) |
| 286 | { |
| 287 | return (le16_to_cpu(policy) & TE_V2_ABSENCE) >> TE_V2_ABSENCE_POS; |
| 288 | } |
| 289 | |
| 290 | static void iwl_mvm_te_v2_to_v1(const struct iwl_time_event_cmd_v2 *cmd_v2, |
| 291 | struct iwl_time_event_cmd_v1 *cmd_v1) |
| 292 | { |
| 293 | cmd_v1->id_and_color = cmd_v2->id_and_color; |
| 294 | cmd_v1->action = cmd_v2->action; |
| 295 | cmd_v1->id = cmd_v2->id; |
| 296 | cmd_v1->apply_time = cmd_v2->apply_time; |
| 297 | cmd_v1->max_delay = cmd_v2->max_delay; |
| 298 | cmd_v1->depends_on = cmd_v2->depends_on; |
| 299 | cmd_v1->interval = cmd_v2->interval; |
| 300 | cmd_v1->duration = cmd_v2->duration; |
| 301 | if (cmd_v2->repeat == TE_V2_REPEAT_ENDLESS) |
| 302 | cmd_v1->repeat = cpu_to_le32(TE_V1_REPEAT_ENDLESS); |
| 303 | else |
| 304 | cmd_v1->repeat = cpu_to_le32(cmd_v2->repeat); |
| 305 | cmd_v1->max_frags = cpu_to_le32(cmd_v2->max_frags); |
| 306 | cmd_v1->interval_reciprocal = 0; /* unused */ |
| 307 | |
| 308 | cmd_v1->dep_policy = cpu_to_le32(te_v2_get_dep_policy(cmd_v2->policy)); |
| 309 | cmd_v1->is_present = cpu_to_le32(!te_v2_get_absence(cmd_v2->policy)); |
| 310 | cmd_v1->notify = cpu_to_le32(te_v2_get_notify(cmd_v2->policy)); |
| 311 | } |
| 312 | |
| 313 | static int iwl_mvm_send_time_event_cmd(struct iwl_mvm *mvm, |
| 314 | const struct iwl_time_event_cmd_v2 *cmd) |
| 315 | { |
| 316 | struct iwl_time_event_cmd_v1 cmd_v1; |
| 317 | |
| 318 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_TIME_EVENT_API_V2) |
| 319 | return iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC, |
| 320 | sizeof(*cmd), cmd); |
| 321 | |
| 322 | iwl_mvm_te_v2_to_v1(cmd, &cmd_v1); |
| 323 | return iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC, |
| 324 | sizeof(cmd_v1), &cmd_v1); |
| 325 | } |
| 326 | |
| 327 | |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 328 | static int iwl_mvm_time_event_send_add(struct iwl_mvm *mvm, |
| 329 | struct ieee80211_vif *vif, |
| 330 | struct iwl_mvm_time_event_data *te_data, |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 331 | struct iwl_time_event_cmd_v2 *te_cmd) |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 332 | { |
| 333 | static const u8 time_event_response[] = { TIME_EVENT_CMD }; |
| 334 | struct iwl_notification_wait wait_time_event; |
| 335 | int ret; |
| 336 | |
| 337 | lockdep_assert_held(&mvm->mutex); |
| 338 | |
Johannes Berg | 93630dc | 2013-02-15 23:54:10 +0100 | [diff] [blame] | 339 | IWL_DEBUG_TE(mvm, "Add new TE, duration %d TU\n", |
| 340 | le32_to_cpu(te_cmd->duration)); |
| 341 | |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 342 | spin_lock_bh(&mvm->time_event_lock); |
| 343 | if (WARN_ON(te_data->id != TE_MAX)) { |
| 344 | spin_unlock_bh(&mvm->time_event_lock); |
| 345 | return -EIO; |
| 346 | } |
| 347 | te_data->vif = vif; |
| 348 | te_data->duration = le32_to_cpu(te_cmd->duration); |
| 349 | te_data->id = le32_to_cpu(te_cmd->id); |
| 350 | list_add_tail(&te_data->list, &mvm->time_event_list); |
| 351 | spin_unlock_bh(&mvm->time_event_lock); |
| 352 | |
| 353 | /* |
| 354 | * Use a notification wait, which really just processes the |
| 355 | * command response and doesn't wait for anything, in order |
| 356 | * to be able to process the response and get the UID inside |
| 357 | * the RX path. Using CMD_WANT_SKB doesn't work because it |
| 358 | * stores the buffer and then wakes up this thread, by which |
| 359 | * time another notification (that the time event started) |
| 360 | * might already be processed unsuccessfully. |
| 361 | */ |
| 362 | iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, |
| 363 | time_event_response, |
| 364 | ARRAY_SIZE(time_event_response), |
| 365 | iwl_mvm_time_event_response, te_data); |
| 366 | |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 367 | ret = iwl_mvm_send_time_event_cmd(mvm, te_cmd); |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 368 | if (ret) { |
| 369 | IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret); |
| 370 | iwl_remove_notification(&mvm->notif_wait, &wait_time_event); |
| 371 | goto out_clear_te; |
| 372 | } |
| 373 | |
| 374 | /* No need to wait for anything, so just pass 1 (0 isn't valid) */ |
| 375 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); |
| 376 | /* should never fail */ |
| 377 | WARN_ON_ONCE(ret); |
| 378 | |
| 379 | if (ret) { |
| 380 | out_clear_te: |
| 381 | spin_lock_bh(&mvm->time_event_lock); |
| 382 | iwl_mvm_te_clear_data(mvm, te_data); |
| 383 | spin_unlock_bh(&mvm->time_event_lock); |
| 384 | } |
| 385 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | void iwl_mvm_protect_session(struct iwl_mvm *mvm, |
| 389 | struct ieee80211_vif *vif, |
| 390 | u32 duration, u32 min_duration) |
| 391 | { |
| 392 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 393 | struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data; |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 394 | struct iwl_time_event_cmd_v2 time_cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 395 | |
| 396 | lockdep_assert_held(&mvm->mutex); |
| 397 | |
| 398 | if (te_data->running && |
Johannes Berg | e7f1935 | 2013-07-25 21:45:17 +0200 | [diff] [blame] | 399 | time_after(te_data->end_jiffies, TU_TO_EXP_TIME(min_duration))) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 400 | IWL_DEBUG_TE(mvm, "We have enough time in the current TE: %u\n", |
| 401 | jiffies_to_msecs(te_data->end_jiffies - jiffies)); |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | if (te_data->running) { |
| 406 | IWL_DEBUG_TE(mvm, "extend 0x%x: only %u ms left\n", |
| 407 | te_data->uid, |
| 408 | jiffies_to_msecs(te_data->end_jiffies - jiffies)); |
| 409 | /* |
| 410 | * we don't have enough time |
| 411 | * cancel the current TE and issue a new one |
| 412 | * Of course it would be better to remove the old one only |
| 413 | * when the new one is added, but we don't care if we are off |
| 414 | * channel for a bit. All we need to do, is not to return |
| 415 | * before we actually begin to be on the channel. |
| 416 | */ |
| 417 | iwl_mvm_stop_session_protection(mvm, vif); |
| 418 | } |
| 419 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 420 | time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD); |
| 421 | time_cmd.id_and_color = |
| 422 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)); |
| 423 | time_cmd.id = cpu_to_le32(TE_BSS_STA_AGGRESSIVE_ASSOC); |
| 424 | |
| 425 | time_cmd.apply_time = |
| 426 | cpu_to_le32(iwl_read_prph(mvm->trans, DEVICE_SYSTEM_TIME_REG)); |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 427 | |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 428 | time_cmd.max_frags = TE_V2_FRAG_NONE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 429 | time_cmd.max_delay = cpu_to_le32(500); |
| 430 | /* TODO: why do we need to interval = bi if it is not periodic? */ |
| 431 | time_cmd.interval = cpu_to_le32(1); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 432 | time_cmd.duration = cpu_to_le32(duration); |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 433 | time_cmd.repeat = 1; |
| 434 | time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START | |
| 435 | TE_V2_NOTIF_HOST_EVENT_END); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 436 | |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 437 | iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /* |
| 441 | * Explicit request to remove a time event. The removal of a time event needs to |
| 442 | * be synchronized with the flow of a time event's end notification, which also |
| 443 | * removes the time event from the op mode data structures. |
| 444 | */ |
| 445 | void iwl_mvm_remove_time_event(struct iwl_mvm *mvm, |
| 446 | struct iwl_mvm_vif *mvmvif, |
| 447 | struct iwl_mvm_time_event_data *te_data) |
| 448 | { |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 449 | struct iwl_time_event_cmd_v2 time_cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 450 | u32 id, uid; |
| 451 | int ret; |
| 452 | |
| 453 | /* |
| 454 | * It is possible that by the time we got to this point the time |
| 455 | * event was already removed. |
| 456 | */ |
| 457 | spin_lock_bh(&mvm->time_event_lock); |
| 458 | |
| 459 | /* Save time event uid before clearing its data */ |
| 460 | uid = te_data->uid; |
| 461 | id = te_data->id; |
| 462 | |
| 463 | /* |
| 464 | * The clear_data function handles time events that were already removed |
| 465 | */ |
| 466 | iwl_mvm_te_clear_data(mvm, te_data); |
| 467 | spin_unlock_bh(&mvm->time_event_lock); |
| 468 | |
| 469 | /* |
| 470 | * It is possible that by the time we try to remove it, the time event |
| 471 | * has already ended and removed. In such a case there is no need to |
| 472 | * send a removal command. |
| 473 | */ |
| 474 | if (id == TE_MAX) { |
| 475 | IWL_DEBUG_TE(mvm, "TE 0x%x has already ended\n", uid); |
| 476 | return; |
| 477 | } |
| 478 | |
| 479 | /* When we remove a TE, the UID is to be set in the id field */ |
| 480 | time_cmd.id = cpu_to_le32(uid); |
| 481 | time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE); |
| 482 | time_cmd.id_and_color = |
| 483 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)); |
| 484 | |
| 485 | IWL_DEBUG_TE(mvm, "Removing TE 0x%x\n", le32_to_cpu(time_cmd.id)); |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 486 | ret = iwl_mvm_send_time_event_cmd(mvm, &time_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 487 | if (WARN_ON(ret)) |
| 488 | return; |
| 489 | } |
| 490 | |
| 491 | void iwl_mvm_stop_session_protection(struct iwl_mvm *mvm, |
| 492 | struct ieee80211_vif *vif) |
| 493 | { |
| 494 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 495 | struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data; |
| 496 | |
| 497 | lockdep_assert_held(&mvm->mutex); |
| 498 | iwl_mvm_remove_time_event(mvm, mvmvif, te_data); |
| 499 | } |
| 500 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 501 | int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 502 | int duration, enum ieee80211_roc_type type) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 503 | { |
| 504 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 505 | struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data; |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 506 | struct iwl_time_event_cmd_v2 time_cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 507 | |
| 508 | lockdep_assert_held(&mvm->mutex); |
| 509 | if (te_data->running) { |
| 510 | IWL_WARN(mvm, "P2P_DEVICE remain on channel already running\n"); |
| 511 | return -EBUSY; |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * Flush the done work, just in case it's still pending, so that |
| 516 | * the work it does can complete and we can accept new frames. |
| 517 | */ |
| 518 | flush_work(&mvm->roc_done_wk); |
| 519 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 520 | time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD); |
| 521 | time_cmd.id_and_color = |
| 522 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)); |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 523 | |
| 524 | switch (type) { |
| 525 | case IEEE80211_ROC_TYPE_NORMAL: |
| 526 | time_cmd.id = cpu_to_le32(IWL_MVM_ROC_TE_TYPE_NORMAL); |
| 527 | break; |
| 528 | case IEEE80211_ROC_TYPE_MGMT_TX: |
| 529 | time_cmd.id = cpu_to_le32(IWL_MVM_ROC_TE_TYPE_MGMT_TX); |
| 530 | break; |
| 531 | default: |
| 532 | WARN_ONCE(1, "Got an invalid ROC type\n"); |
| 533 | return -EINVAL; |
| 534 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 535 | |
| 536 | time_cmd.apply_time = cpu_to_le32(0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 537 | time_cmd.interval = cpu_to_le32(1); |
| 538 | |
| 539 | /* |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 540 | * The P2P Device TEs can have lower priority than other events |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 541 | * that are being scheduled by the driver/fw, and thus it might not be |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 542 | * scheduled. To improve the chances of it being scheduled, allow them |
| 543 | * to be fragmented, and in addition allow them to be delayed. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 544 | */ |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 545 | time_cmd.max_frags = min(MSEC_TO_TU(duration)/50, TE_V2_FRAG_ENDLESS); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 546 | time_cmd.max_delay = cpu_to_le32(MSEC_TO_TU(duration/2)); |
| 547 | time_cmd.duration = cpu_to_le32(MSEC_TO_TU(duration)); |
Eytan Lifshitz | f8f03c3 | 2013-08-07 19:36:42 +0300 | [diff] [blame] | 548 | time_cmd.repeat = 1; |
| 549 | time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START | |
| 550 | TE_V2_NOTIF_HOST_EVENT_END); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 551 | |
Johannes Berg | ffdf968 | 2013-01-29 15:28:17 +0100 | [diff] [blame] | 552 | return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | void iwl_mvm_stop_p2p_roc(struct iwl_mvm *mvm) |
| 556 | { |
| 557 | struct iwl_mvm_vif *mvmvif; |
| 558 | struct iwl_mvm_time_event_data *te_data; |
| 559 | |
| 560 | lockdep_assert_held(&mvm->mutex); |
| 561 | |
| 562 | /* |
| 563 | * Iterate over the list of time events and find the time event that is |
| 564 | * associated with a P2P_DEVICE interface. |
| 565 | * This assumes that a P2P_DEVICE interface can have only a single time |
| 566 | * event at any given time and this time event coresponds to a ROC |
| 567 | * request |
| 568 | */ |
| 569 | mvmvif = NULL; |
| 570 | spin_lock_bh(&mvm->time_event_lock); |
| 571 | list_for_each_entry(te_data, &mvm->time_event_list, list) { |
| 572 | if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 573 | mvmvif = iwl_mvm_vif_from_mac80211(te_data->vif); |
| 574 | break; |
| 575 | } |
| 576 | } |
| 577 | spin_unlock_bh(&mvm->time_event_lock); |
| 578 | |
| 579 | if (!mvmvif) { |
| 580 | IWL_WARN(mvm, "P2P_DEVICE no remain on channel event\n"); |
| 581 | return; |
| 582 | } |
| 583 | |
| 584 | iwl_mvm_remove_time_event(mvm, mvmvif, te_data); |
| 585 | |
| 586 | iwl_mvm_roc_finished(mvm); |
| 587 | } |