1f48f6960SAdrian Chadd /*- 2f48f6960SAdrian Chadd * Based on BSD-licensed source modules in the Linux iwlwifi driver, 3f48f6960SAdrian Chadd * which were used as the reference documentation for this implementation. 4f48f6960SAdrian Chadd * 5f48f6960SAdrian Chadd * Driver version we are currently based off of is 6f48f6960SAdrian Chadd * Linux 4.7.3 (tag id d7f6728f57e3ecbb7ef34eb7d9f564d514775d75) 7f48f6960SAdrian Chadd * 8f48f6960SAdrian Chadd *********************************************************************** 9f48f6960SAdrian Chadd * 10f48f6960SAdrian Chadd * 11f48f6960SAdrian Chadd * This file is provided under a dual BSD/GPLv2 license. When using or 12f48f6960SAdrian Chadd * redistributing this file, you may do so under either license. 13f48f6960SAdrian Chadd * 14f48f6960SAdrian Chadd * GPL LICENSE SUMMARY 15f48f6960SAdrian Chadd * 16f48f6960SAdrian Chadd * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 17f48f6960SAdrian Chadd * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 18f48f6960SAdrian Chadd * Copyright(c) 2015 - 2016 Intel Deutschland GmbH 19f48f6960SAdrian Chadd * 20f48f6960SAdrian Chadd * This program is free software; you can redistribute it and/or modify 21f48f6960SAdrian Chadd * it under the terms of version 2 of the GNU General Public License as 22f48f6960SAdrian Chadd * published by the Free Software Foundation. 23f48f6960SAdrian Chadd * 24f48f6960SAdrian Chadd * This program is distributed in the hope that it will be useful, but 25f48f6960SAdrian Chadd * WITHOUT ANY WARRANTY; without even the implied warranty of 26f48f6960SAdrian Chadd * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27f48f6960SAdrian Chadd * General Public License for more details. 28f48f6960SAdrian Chadd * 29f48f6960SAdrian Chadd * You should have received a copy of the GNU General Public License 30f48f6960SAdrian Chadd * along with this program; if not, write to the Free Software 31f48f6960SAdrian Chadd * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 32f48f6960SAdrian Chadd * USA 33f48f6960SAdrian Chadd * 34f48f6960SAdrian Chadd * The full GNU General Public License is included in this distribution 35f48f6960SAdrian Chadd * in the file called COPYING. 36f48f6960SAdrian Chadd * 37f48f6960SAdrian Chadd * Contact Information: 38f48f6960SAdrian Chadd * Intel Linux Wireless <linuxwifi@intel.com> 39f48f6960SAdrian Chadd * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 40f48f6960SAdrian Chadd * 41f48f6960SAdrian Chadd * BSD LICENSE 42f48f6960SAdrian Chadd * 43f48f6960SAdrian Chadd * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 44f48f6960SAdrian Chadd * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 45f48f6960SAdrian Chadd * Copyright(c) 2015 - 2016 Intel Deutschland GmbH 46f48f6960SAdrian Chadd * All rights reserved. 47f48f6960SAdrian Chadd * 48f48f6960SAdrian Chadd * Redistribution and use in source and binary forms, with or without 49f48f6960SAdrian Chadd * modification, are permitted provided that the following conditions 50f48f6960SAdrian Chadd * are met: 51f48f6960SAdrian Chadd * 52f48f6960SAdrian Chadd * * Redistributions of source code must retain the above copyright 53f48f6960SAdrian Chadd * notice, this list of conditions and the following disclaimer. 54f48f6960SAdrian Chadd * * Redistributions in binary form must reproduce the above copyright 55f48f6960SAdrian Chadd * notice, this list of conditions and the following disclaimer in 56f48f6960SAdrian Chadd * the documentation and/or other materials provided with the 57f48f6960SAdrian Chadd * distribution. 58f48f6960SAdrian Chadd * * Neither the name Intel Corporation nor the names of its 59f48f6960SAdrian Chadd * contributors may be used to endorse or promote products derived 60f48f6960SAdrian Chadd * from this software without specific prior written permission. 61f48f6960SAdrian Chadd * 62f48f6960SAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 63f48f6960SAdrian Chadd * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 64f48f6960SAdrian Chadd * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 65f48f6960SAdrian Chadd * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 66f48f6960SAdrian Chadd * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 67f48f6960SAdrian Chadd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 68f48f6960SAdrian Chadd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 69f48f6960SAdrian Chadd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 70f48f6960SAdrian Chadd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 71f48f6960SAdrian Chadd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 72f48f6960SAdrian Chadd * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 73f48f6960SAdrian Chadd * 74f48f6960SAdrian Chadd *****************************************************************************/ 75f48f6960SAdrian Chadd 76f48f6960SAdrian Chadd /* $FreeBSD$ */ 77f48f6960SAdrian Chadd 78f48f6960SAdrian Chadd #ifndef __IF_IWM_STA_H__ 79f48f6960SAdrian Chadd #define __IF_IWM_STA_H__ 80f48f6960SAdrian Chadd 81f48f6960SAdrian Chadd /** 82f48f6960SAdrian Chadd * DOC: station table - introduction 83f48f6960SAdrian Chadd * 84f48f6960SAdrian Chadd * The station table is a list of data structure that reprensent the stations. 85f48f6960SAdrian Chadd * In STA/P2P client mode, the driver will hold one station for the AP/ GO. 86f48f6960SAdrian Chadd * In GO/AP mode, the driver will have as many stations as associated clients. 87f48f6960SAdrian Chadd * All these stations are reflected in the fw's station table. The driver 88f48f6960SAdrian Chadd * keeps the fw's station table up to date with the ADD_STA command. Stations 89f48f6960SAdrian Chadd * can be removed by the REMOVE_STA command. 90f48f6960SAdrian Chadd * 91*e7065dd1SMark Johnston * All the data related to a station is held in the structure %iwl_sta 92f48f6960SAdrian Chadd * which is embed in the mac80211's %ieee80211_sta (in the drv_priv) area. 93f48f6960SAdrian Chadd * This data includes the index of the station in the fw, per tid information 94f48f6960SAdrian Chadd * (sequence numbers, Block-ack state machine, etc...). The stations are 95f48f6960SAdrian Chadd * created and deleted by the %sta_state callback from %ieee80211_ops. 96f48f6960SAdrian Chadd * 97f48f6960SAdrian Chadd * The driver holds a map: %fw_id_to_mac_id that allows to fetch a 98*e7065dd1SMark Johnston * %ieee80211_sta (and the %iwl_sta embedded into it) based on a fw 99f48f6960SAdrian Chadd * station index. That way, the driver is able to get the tid related data in 100f48f6960SAdrian Chadd * O(1) in time sensitive paths (Tx / Tx response / BA notification). These 101f48f6960SAdrian Chadd * paths are triggered by the fw, and the driver needs to get a pointer to the 102f48f6960SAdrian Chadd * %ieee80211 structure. This map helps to get that pointer quickly. 103f48f6960SAdrian Chadd */ 104f48f6960SAdrian Chadd 105f48f6960SAdrian Chadd /** 106f48f6960SAdrian Chadd * DOC: station table - locking 107f48f6960SAdrian Chadd * 108f48f6960SAdrian Chadd * As stated before, the station is created / deleted by mac80211's %sta_state 109f48f6960SAdrian Chadd * callback from %ieee80211_ops which can sleep. The next paragraph explains 110f48f6960SAdrian Chadd * the locking of a single stations, the next ones relates to the station 111f48f6960SAdrian Chadd * table. 112f48f6960SAdrian Chadd * 113f48f6960SAdrian Chadd * The station holds the sequence number per tid. So this data needs to be 114f48f6960SAdrian Chadd * accessed in the Tx path (which is softIRQ). It also holds the Block-Ack 115f48f6960SAdrian Chadd * information (the state machine / and the logic that checks if the queues 116f48f6960SAdrian Chadd * were drained), so it also needs to be accessible from the Tx response flow. 117f48f6960SAdrian Chadd * In short, the station needs to be access from sleepable context as well as 118f48f6960SAdrian Chadd * from tasklets, so the station itself needs a spinlock. 119f48f6960SAdrian Chadd * 120f48f6960SAdrian Chadd * The writers of %fw_id_to_mac_id map are serialized by the global mutex of 121f48f6960SAdrian Chadd * the mvm op_mode. This is possible since %sta_state can sleep. 122f48f6960SAdrian Chadd * The pointers in this map are RCU protected, hence we won't replace the 123f48f6960SAdrian Chadd * station while we have Tx / Tx response / BA notification running. 124f48f6960SAdrian Chadd * 125f48f6960SAdrian Chadd * If a station is deleted while it still has packets in its A-MPDU queues, 126f48f6960SAdrian Chadd * then the reclaim flow will notice that there is no station in the map for 127f48f6960SAdrian Chadd * sta_id and it will dump the responses. 128f48f6960SAdrian Chadd */ 129f48f6960SAdrian Chadd 130f48f6960SAdrian Chadd /** 131f48f6960SAdrian Chadd * DOC: station table - internal stations 132f48f6960SAdrian Chadd * 133f48f6960SAdrian Chadd * The FW needs a few internal stations that are not reflected in 134f48f6960SAdrian Chadd * mac80211, such as broadcast station in AP / GO mode, or AUX sta for 135f48f6960SAdrian Chadd * scanning and P2P device (during the GO negotiation). 136*e7065dd1SMark Johnston * For these kind of stations we have %iwl_int_sta struct which holds the 137*e7065dd1SMark Johnston * data relevant for them from both %iwl_sta and %ieee80211_sta. 138f48f6960SAdrian Chadd * Usually the data for these stations is static, so no locking is required, 139f48f6960SAdrian Chadd * and no TID data as this is also not needed. 140f48f6960SAdrian Chadd * One thing to note, is that these stations have an ID in the fw, but not 141f48f6960SAdrian Chadd * in mac80211. In order to "reserve" them a sta_id in %fw_id_to_mac_id 142f48f6960SAdrian Chadd * we fill ERR_PTR(EINVAL) in this mapping and all other dereferencing of 143f48f6960SAdrian Chadd * pointers from this mapping need to check that the value is not error 144f48f6960SAdrian Chadd * or NULL. 145f48f6960SAdrian Chadd * 146f48f6960SAdrian Chadd * Currently there is only one auxiliary station for scanning, initialized 147f48f6960SAdrian Chadd * on init. 148f48f6960SAdrian Chadd */ 149f48f6960SAdrian Chadd 150f48f6960SAdrian Chadd /** 151f48f6960SAdrian Chadd * DOC: station table - AP Station in STA mode 152f48f6960SAdrian Chadd * 153*e7065dd1SMark Johnston * %iwl_vif includes the index of the AP station in the fw's STA table: 154f48f6960SAdrian Chadd * %ap_sta_id. To get the point to the corresponding %ieee80211_sta, 155f48f6960SAdrian Chadd * &fw_id_to_mac_id can be used. Due to the way the fw works, we must not remove 156f48f6960SAdrian Chadd * the AP station from the fw before setting the MAC context as unassociated. 157f48f6960SAdrian Chadd * Hence, %fw_id_to_mac_id[%ap_sta_id] will be NULLed when the AP station is 158f48f6960SAdrian Chadd * removed by mac80211, but the station won't be removed in the fw until the 159f48f6960SAdrian Chadd * VIF is set as unassociated. Then, %ap_sta_id will be invalidated. 160f48f6960SAdrian Chadd */ 161f48f6960SAdrian Chadd 162f48f6960SAdrian Chadd /** 163f48f6960SAdrian Chadd * DOC: station table - Drain vs. Flush 164f48f6960SAdrian Chadd * 165f48f6960SAdrian Chadd * Flush means that all the frames in the SCD queue are dumped regardless the 166f48f6960SAdrian Chadd * station to which they were sent. We do that when we disassociate and before 167f48f6960SAdrian Chadd * we remove the STA of the AP. The flush can be done synchronously against the 168f48f6960SAdrian Chadd * fw. 169f48f6960SAdrian Chadd * Drain means that the fw will drop all the frames sent to a specific station. 170f48f6960SAdrian Chadd * This is useful when a client (if we are IBSS / GO or AP) disassociates. In 171f48f6960SAdrian Chadd * that case, we need to drain all the frames for that client from the AC queues 172f48f6960SAdrian Chadd * that are shared with the other clients. Only then, we can remove the STA in 173f48f6960SAdrian Chadd * the fw. In order to do so, we track the non-AMPDU packets for each station. 174f48f6960SAdrian Chadd * If mac80211 removes a STA and if it still has non-AMPDU packets pending in 175f48f6960SAdrian Chadd * the queues, we mark this station as %EBUSY in %fw_id_to_mac_id, and drop all 176*e7065dd1SMark Johnston * the frames for this STA (%iwl_rm_sta). When the last frame is dropped 177f48f6960SAdrian Chadd * (we know about it with its Tx response), we remove the station in fw and set 178f48f6960SAdrian Chadd * it as %NULL in %fw_id_to_mac_id: this is the purpose of 179*e7065dd1SMark Johnston * %iwl_sta_drained_wk. 180f48f6960SAdrian Chadd */ 181f48f6960SAdrian Chadd 182f48f6960SAdrian Chadd /** 183f48f6960SAdrian Chadd * DOC: station table - fw restart 184f48f6960SAdrian Chadd * 185f48f6960SAdrian Chadd * When the fw asserts, or we have any other issue that requires to reset the 186f48f6960SAdrian Chadd * driver, we require mac80211 to reconfigure the driver. Since the private 187f48f6960SAdrian Chadd * data of the stations is embed in mac80211's %ieee80211_sta, that data will 188f48f6960SAdrian Chadd * not be zeroed and needs to be reinitialized manually. 189*e7065dd1SMark Johnston * %IWL_STATUS_IN_HW_RESTART is set during restart and that will hint us 190f48f6960SAdrian Chadd * that we must not allocate a new sta_id but reuse the previous one. This 191f48f6960SAdrian Chadd * means that the stations being re-added after the reset will have the same 192f48f6960SAdrian Chadd * place in the fw as before the reset. We do need to zero the %fw_id_to_mac_id 193f48f6960SAdrian Chadd * map, since the stations aren't in the fw any more. Internal stations that 194f48f6960SAdrian Chadd * are not added by mac80211 will be re-added in the init flow that is called 195*e7065dd1SMark Johnston * after the restart: mac80211 call's %iwl_mac_start which calls to 196*e7065dd1SMark Johnston * %iwl_up. 197f48f6960SAdrian Chadd */ 198f48f6960SAdrian Chadd 199f48f6960SAdrian Chadd /** 200f48f6960SAdrian Chadd * Send the STA info to the FW. 201f48f6960SAdrian Chadd * 202f48f6960SAdrian Chadd * @sc: the iwm_softc* to use 203f48f6960SAdrian Chadd * @sta: the STA 204f48f6960SAdrian Chadd * @update: this is true if the FW is being updated about a STA it already knows 205f48f6960SAdrian Chadd * about. Otherwise (if this is a new STA), this should be false. 206f48f6960SAdrian Chadd * @flags: if update==true, this marks what is being changed via ORs of values 207f48f6960SAdrian Chadd * from enum iwm_sta_modify_flag. Otherwise, this is ignored. 208f48f6960SAdrian Chadd */ 209*e7065dd1SMark Johnston extern int iwm_sta_send_to_fw(struct iwm_softc *sc, struct iwm_node *in, 210f48f6960SAdrian Chadd boolean_t update); 211*e7065dd1SMark Johnston extern int iwm_add_sta(struct iwm_softc *sc, struct iwm_node *in); 212*e7065dd1SMark Johnston extern int iwm_update_sta(struct iwm_softc *sc, struct iwm_node *in); 213*e7065dd1SMark Johnston extern int iwm_rm_sta(struct iwm_softc *sc, struct ieee80211vap *vap, 214c0487367SAdrian Chadd boolean_t is_assoc); 215*e7065dd1SMark Johnston extern int iwm_rm_sta_id(struct iwm_softc *sc, struct ieee80211vap *vap); 216f48f6960SAdrian Chadd 217*e7065dd1SMark Johnston extern int iwm_add_aux_sta(struct iwm_softc *sc); 218*e7065dd1SMark Johnston extern void iwm_del_aux_sta(struct iwm_softc *sc); 219f48f6960SAdrian Chadd 220*e7065dd1SMark Johnston extern int iwm_drain_sta(struct iwm_softc *sc, struct iwm_vap *ivp, 221f48f6960SAdrian Chadd boolean_t drain); 222f48f6960SAdrian Chadd 223f48f6960SAdrian Chadd #endif /* __IF_IWM_STA_H__ */ 224