1e705c121SKalle Valo /****************************************************************************** 2e705c121SKalle Valo * 3e705c121SKalle Valo * This file is provided under a dual BSD/GPLv2 license. When using or 4e705c121SKalle Valo * redistributing this file, you may do so under either license. 5e705c121SKalle Valo * 6e705c121SKalle Valo * GPL LICENSE SUMMARY 7e705c121SKalle Valo * 8e705c121SKalle Valo * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 9e705c121SKalle Valo * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 10e705c121SKalle Valo * 11e705c121SKalle Valo * This program is free software; you can redistribute it and/or modify 12e705c121SKalle Valo * it under the terms of version 2 of the GNU General Public License as 13e705c121SKalle Valo * published by the Free Software Foundation. 14e705c121SKalle Valo * 15e705c121SKalle Valo * This program is distributed in the hope that it will be useful, but 16e705c121SKalle Valo * WITHOUT ANY WARRANTY; without even the implied warranty of 17e705c121SKalle Valo * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18e705c121SKalle Valo * General Public License for more details. 19e705c121SKalle Valo * 20e705c121SKalle Valo * You should have received a copy of the GNU General Public License 21e705c121SKalle Valo * along with this program; if not, write to the Free Software 22e705c121SKalle Valo * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 23e705c121SKalle Valo * USA 24e705c121SKalle Valo * 25e705c121SKalle Valo * The full GNU General Public License is included in this distribution 26e705c121SKalle Valo * in the file called COPYING. 27e705c121SKalle Valo * 28e705c121SKalle Valo * Contact Information: 29d01c5366SEmmanuel Grumbach * Intel Linux Wireless <linuxwifi@intel.com> 30e705c121SKalle Valo * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 31e705c121SKalle Valo * 32e705c121SKalle Valo * BSD LICENSE 33e705c121SKalle Valo * 34e705c121SKalle Valo * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 35e705c121SKalle Valo * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 36e705c121SKalle Valo * All rights reserved. 37e705c121SKalle Valo * 38e705c121SKalle Valo * Redistribution and use in source and binary forms, with or without 39e705c121SKalle Valo * modification, are permitted provided that the following conditions 40e705c121SKalle Valo * are met: 41e705c121SKalle Valo * 42e705c121SKalle Valo * * Redistributions of source code must retain the above copyright 43e705c121SKalle Valo * notice, this list of conditions and the following disclaimer. 44e705c121SKalle Valo * * Redistributions in binary form must reproduce the above copyright 45e705c121SKalle Valo * notice, this list of conditions and the following disclaimer in 46e705c121SKalle Valo * the documentation and/or other materials provided with the 47e705c121SKalle Valo * distribution. 48e705c121SKalle Valo * * Neither the name Intel Corporation nor the names of its 49e705c121SKalle Valo * contributors may be used to endorse or promote products derived 50e705c121SKalle Valo * from this software without specific prior written permission. 51e705c121SKalle Valo * 52e705c121SKalle Valo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 53e705c121SKalle Valo * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 54e705c121SKalle Valo * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 55e705c121SKalle Valo * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 56e705c121SKalle Valo * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 57e705c121SKalle Valo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 58e705c121SKalle Valo * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 59e705c121SKalle Valo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 60e705c121SKalle Valo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 61e705c121SKalle Valo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 62e705c121SKalle Valo * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 63e705c121SKalle Valo * 64e705c121SKalle Valo *****************************************************************************/ 65e705c121SKalle Valo 66e705c121SKalle Valo #ifndef __time_event_h__ 67e705c121SKalle Valo #define __time_event_h__ 68e705c121SKalle Valo 69e705c121SKalle Valo #include "fw-api.h" 70e705c121SKalle Valo 71e705c121SKalle Valo #include "mvm.h" 72e705c121SKalle Valo 73e705c121SKalle Valo /** 74e705c121SKalle Valo * DOC: Time Events - what is it? 75e705c121SKalle Valo * 76e705c121SKalle Valo * Time Events are a fw feature that allows the driver to control the presence 77e705c121SKalle Valo * of the device on the channel. Since the fw supports multiple channels 78e705c121SKalle Valo * concurrently, the fw may choose to jump to another channel at any time. 79e705c121SKalle Valo * In order to make sure that the fw is on a specific channel at a certain time 80e705c121SKalle Valo * and for a certain duration, the driver needs to issue a time event. 81e705c121SKalle Valo * 82e705c121SKalle Valo * The simplest example is for BSS association. The driver issues a time event, 83e705c121SKalle Valo * waits for it to start, and only then tells mac80211 that we can start the 84e705c121SKalle Valo * association. This way, we make sure that the association will be done 85e705c121SKalle Valo * smoothly and won't be interrupted by channel switch decided within the fw. 86e705c121SKalle Valo */ 87e705c121SKalle Valo 88e705c121SKalle Valo /** 89e705c121SKalle Valo * DOC: The flow against the fw 90e705c121SKalle Valo * 91e705c121SKalle Valo * When the driver needs to make sure we are in a certain channel, at a certain 92e705c121SKalle Valo * time and for a certain duration, it sends a Time Event. The flow against the 93e705c121SKalle Valo * fw goes like this: 94e705c121SKalle Valo * 1) Driver sends a TIME_EVENT_CMD to the fw 95e705c121SKalle Valo * 2) Driver gets the response for that command. This response contains the 96e705c121SKalle Valo * Unique ID (UID) of the event. 97e705c121SKalle Valo * 3) The fw sends notification when the event starts. 98e705c121SKalle Valo * 99e705c121SKalle Valo * Of course the API provides various options that allow to cover parameters 100e705c121SKalle Valo * of the flow. 101e705c121SKalle Valo * What is the duration of the event? 102e705c121SKalle Valo * What is the start time of the event? 103e705c121SKalle Valo * Is there an end-time for the event? 104e705c121SKalle Valo * How much can the event be delayed? 105e705c121SKalle Valo * Can the event be split? 106e705c121SKalle Valo * If yes what is the maximal number of chunks? 107e705c121SKalle Valo * etc... 108e705c121SKalle Valo */ 109e705c121SKalle Valo 110e705c121SKalle Valo /** 111e705c121SKalle Valo * DOC: Abstraction to the driver 112e705c121SKalle Valo * 113e705c121SKalle Valo * In order to simplify the use of time events to the rest of the driver, 114e705c121SKalle Valo * we abstract the use of time events. This component provides the functions 115e705c121SKalle Valo * needed by the driver. 116e705c121SKalle Valo */ 117e705c121SKalle Valo 118e705c121SKalle Valo #define IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS 500 119e705c121SKalle Valo #define IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS 400 120e705c121SKalle Valo 121e705c121SKalle Valo /** 122e705c121SKalle Valo * iwl_mvm_protect_session - start / extend the session protection. 123e705c121SKalle Valo * @mvm: the mvm component 124e705c121SKalle Valo * @vif: the virtual interface for which the session is issued 125e705c121SKalle Valo * @duration: the duration of the session in TU. 126e705c121SKalle Valo * @min_duration: will start a new session if the current session will end 127e705c121SKalle Valo * in less than min_duration. 128e705c121SKalle Valo * @max_delay: maximum delay before starting the time event (in TU) 129e705c121SKalle Valo * @wait_for_notif: true if it is required that a time event notification be 130e705c121SKalle Valo * waited for (that the time event has been scheduled before returning) 131e705c121SKalle Valo * 132e705c121SKalle Valo * This function can be used to start a session protection which means that the 133e705c121SKalle Valo * fw will stay on the channel for %duration_ms milliseconds. This function 134e705c121SKalle Valo * can block (sleep) until the session starts. This function can also be used 135e705c121SKalle Valo * to extend a currently running session. 136e705c121SKalle Valo * This function is meant to be used for BSS association for example, where we 137e705c121SKalle Valo * want to make sure that the fw stays on the channel during the association. 138e705c121SKalle Valo */ 139e705c121SKalle Valo void iwl_mvm_protect_session(struct iwl_mvm *mvm, 140e705c121SKalle Valo struct ieee80211_vif *vif, 141e705c121SKalle Valo u32 duration, u32 min_duration, 142e705c121SKalle Valo u32 max_delay, bool wait_for_notif); 143e705c121SKalle Valo 144e705c121SKalle Valo /** 145e705c121SKalle Valo * iwl_mvm_stop_session_protection - cancel the session protection. 146e705c121SKalle Valo * @mvm: the mvm component 147e705c121SKalle Valo * @vif: the virtual interface for which the session is issued 148e705c121SKalle Valo * 149e705c121SKalle Valo * This functions cancels the session protection which is an act of good 150e705c121SKalle Valo * citizenship. If it is not needed any more it should be canceled because 151e705c121SKalle Valo * the other bindings wait for the medium during that time. 152e705c121SKalle Valo * This funtions doesn't sleep. 153e705c121SKalle Valo */ 154e705c121SKalle Valo void iwl_mvm_stop_session_protection(struct iwl_mvm *mvm, 155e705c121SKalle Valo struct ieee80211_vif *vif); 156e705c121SKalle Valo 157e705c121SKalle Valo /* 158e705c121SKalle Valo * iwl_mvm_rx_time_event_notif - handles %TIME_EVENT_NOTIFICATION. 159e705c121SKalle Valo */ 160e705c121SKalle Valo void iwl_mvm_rx_time_event_notif(struct iwl_mvm *mvm, 161e705c121SKalle Valo struct iwl_rx_cmd_buffer *rxb); 162e705c121SKalle Valo 163e705c121SKalle Valo /** 164e705c121SKalle Valo * iwl_mvm_start_p2p_roc - start remain on channel for p2p device functionality 165e705c121SKalle Valo * @mvm: the mvm component 166e705c121SKalle Valo * @vif: the virtual interface for which the roc is requested. It is assumed 167e705c121SKalle Valo * that the vif type is NL80211_IFTYPE_P2P_DEVICE 168e705c121SKalle Valo * @duration: the requested duration in millisecond for the fw to be on the 169e705c121SKalle Valo * channel that is bound to the vif. 170e705c121SKalle Valo * @type: the remain on channel request type 171e705c121SKalle Valo * 172e705c121SKalle Valo * This function can be used to issue a remain on channel session, 173e705c121SKalle Valo * which means that the fw will stay in the channel for the request %duration 174e705c121SKalle Valo * milliseconds. The function is async, meaning that it only issues the ROC 175e705c121SKalle Valo * request but does not wait for it to start. Once the FW is ready to serve the 176e705c121SKalle Valo * ROC request, it will issue a notification to the driver that it is on the 177e705c121SKalle Valo * requested channel. Once the FW completes the ROC request it will issue 178e705c121SKalle Valo * another notification to the driver. 179e705c121SKalle Valo */ 180e705c121SKalle Valo int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 181e705c121SKalle Valo int duration, enum ieee80211_roc_type type); 182e705c121SKalle Valo 183e705c121SKalle Valo /** 184e705c121SKalle Valo * iwl_mvm_stop_roc - stop remain on channel functionality 185e705c121SKalle Valo * @mvm: the mvm component 186e705c121SKalle Valo * 187e705c121SKalle Valo * This function can be used to cancel an ongoing ROC session. 188e705c121SKalle Valo * The function is async, it will instruct the FW to stop serving the ROC 189e705c121SKalle Valo * session, but will not wait for the actual stopping of the session. 190e705c121SKalle Valo */ 191e705c121SKalle Valo void iwl_mvm_stop_roc(struct iwl_mvm *mvm); 192e705c121SKalle Valo 193e705c121SKalle Valo /** 194e705c121SKalle Valo * iwl_mvm_remove_time_event - general function to clean up of time event 195e705c121SKalle Valo * @mvm: the mvm component 196e705c121SKalle Valo * @vif: the vif to which the time event belongs 197e705c121SKalle Valo * @te_data: the time event data that corresponds to that time event 198e705c121SKalle Valo * 199e705c121SKalle Valo * This function can be used to cancel a time event regardless its type. 200e705c121SKalle Valo * It is useful for cleaning up time events running before removing an 201e705c121SKalle Valo * interface. 202e705c121SKalle Valo */ 203e705c121SKalle Valo void iwl_mvm_remove_time_event(struct iwl_mvm *mvm, 204e705c121SKalle Valo struct iwl_mvm_vif *mvmvif, 205e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data); 206e705c121SKalle Valo 207e705c121SKalle Valo /** 208e705c121SKalle Valo * iwl_mvm_te_clear_data - remove time event from list 209e705c121SKalle Valo * @mvm: the mvm component 210e705c121SKalle Valo * @te_data: the time event data to remove 211e705c121SKalle Valo * 212e705c121SKalle Valo * This function is mostly internal, it is made available here only 213e705c121SKalle Valo * for firmware restart purposes. 214e705c121SKalle Valo */ 215e705c121SKalle Valo void iwl_mvm_te_clear_data(struct iwl_mvm *mvm, 216e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data); 217e705c121SKalle Valo 218e705c121SKalle Valo void iwl_mvm_roc_done_wk(struct work_struct *wk); 219e705c121SKalle Valo 220e705c121SKalle Valo /** 221e705c121SKalle Valo * iwl_mvm_schedule_csa_period - request channel switch absence period 222e705c121SKalle Valo * @mvm: the mvm component 223e705c121SKalle Valo * @vif: the virtual interface for which the channel switch is issued 224e705c121SKalle Valo * @duration: the duration of the NoA in TU. 225e705c121SKalle Valo * @apply_time: NoA start time in GP2. 226e705c121SKalle Valo * 227e705c121SKalle Valo * This function is used to schedule NoA time event and is used to perform 228e705c121SKalle Valo * the channel switch flow. 229e705c121SKalle Valo */ 230e705c121SKalle Valo int iwl_mvm_schedule_csa_period(struct iwl_mvm *mvm, 231e705c121SKalle Valo struct ieee80211_vif *vif, 232e705c121SKalle Valo u32 duration, u32 apply_time); 233e705c121SKalle Valo 234e705c121SKalle Valo /** 235e705c121SKalle Valo * iwl_mvm_te_scheduled - check if the fw received the TE cmd 236e705c121SKalle Valo * @te_data: the time event data that corresponds to that time event 237e705c121SKalle Valo * 238e705c121SKalle Valo * This function returns true iff this TE is added to the fw. 239e705c121SKalle Valo */ 240e705c121SKalle Valo static inline bool 241e705c121SKalle Valo iwl_mvm_te_scheduled(struct iwl_mvm_time_event_data *te_data) 242e705c121SKalle Valo { 243e705c121SKalle Valo if (!te_data) 244e705c121SKalle Valo return false; 245e705c121SKalle Valo 246e705c121SKalle Valo return !!te_data->uid; 247e705c121SKalle Valo } 248e705c121SKalle Valo 249e705c121SKalle Valo #endif /* __time_event_h__ */ 250