185d1c619SImre Vadász /*- 285d1c619SImre Vadász * Based on BSD-licensed source modules in the Linux iwlwifi driver, 385d1c619SImre Vadász * which were used as the reference documentation for this implementation. 485d1c619SImre Vadász * 585d1c619SImre Vadász * Driver version we are currently based off of is 685d1c619SImre Vadász * Linux 4.7.3 (tag id d7f6728f57e3ecbb7ef34eb7d9f564d514775d75) 785d1c619SImre Vadász * 885d1c619SImre Vadász *********************************************************************** 985d1c619SImre Vadász * 1085d1c619SImre Vadász * 1185d1c619SImre Vadász * This file is provided under a dual BSD/GPLv2 license. When using or 1285d1c619SImre Vadász * redistributing this file, you may do so under either license. 1385d1c619SImre Vadász * 1485d1c619SImre Vadász * GPL LICENSE SUMMARY 1585d1c619SImre Vadász * 1685d1c619SImre Vadász * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 1785d1c619SImre Vadász * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 1885d1c619SImre Vadász * Copyright(c) 2015 - 2016 Intel Deutschland GmbH 1985d1c619SImre Vadász * 2085d1c619SImre Vadász * This program is free software; you can redistribute it and/or modify 2185d1c619SImre Vadász * it under the terms of version 2 of the GNU General Public License as 2285d1c619SImre Vadász * published by the Free Software Foundation. 2385d1c619SImre Vadász * 2485d1c619SImre Vadász * This program is distributed in the hope that it will be useful, but 2585d1c619SImre Vadász * WITHOUT ANY WARRANTY; without even the implied warranty of 2685d1c619SImre Vadász * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 2785d1c619SImre Vadász * General Public License for more details. 2885d1c619SImre Vadász * 2985d1c619SImre Vadász * You should have received a copy of the GNU General Public License 3085d1c619SImre Vadász * along with this program; if not, write to the Free Software 3185d1c619SImre Vadász * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 3285d1c619SImre Vadász * USA 3385d1c619SImre Vadász * 3485d1c619SImre Vadász * The full GNU General Public License is included in this distribution 3585d1c619SImre Vadász * in the file called COPYING. 3685d1c619SImre Vadász * 3785d1c619SImre Vadász * Contact Information: 3885d1c619SImre Vadász * Intel Linux Wireless <linuxwifi@intel.com> 3985d1c619SImre Vadász * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 4085d1c619SImre Vadász * 4185d1c619SImre Vadász * BSD LICENSE 4285d1c619SImre Vadász * 4385d1c619SImre Vadász * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 4485d1c619SImre Vadász * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 4585d1c619SImre Vadász * Copyright(c) 2015 - 2016 Intel Deutschland GmbH 4685d1c619SImre Vadász * All rights reserved. 4785d1c619SImre Vadász * 4885d1c619SImre Vadász * Redistribution and use in source and binary forms, with or without 4985d1c619SImre Vadász * modification, are permitted provided that the following conditions 5085d1c619SImre Vadász * are met: 5185d1c619SImre Vadász * 5285d1c619SImre Vadász * * Redistributions of source code must retain the above copyright 5385d1c619SImre Vadász * notice, this list of conditions and the following disclaimer. 5485d1c619SImre Vadász * * Redistributions in binary form must reproduce the above copyright 5585d1c619SImre Vadász * notice, this list of conditions and the following disclaimer in 5685d1c619SImre Vadász * the documentation and/or other materials provided with the 5785d1c619SImre Vadász * distribution. 5885d1c619SImre Vadász * * Neither the name Intel Corporation nor the names of its 5985d1c619SImre Vadász * contributors may be used to endorse or promote products derived 6085d1c619SImre Vadász * from this software without specific prior written permission. 6185d1c619SImre Vadász * 6285d1c619SImre Vadász * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6385d1c619SImre Vadász * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 6485d1c619SImre Vadász * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 6585d1c619SImre Vadász * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 6685d1c619SImre Vadász * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 6785d1c619SImre Vadász * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 6885d1c619SImre Vadász * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 6985d1c619SImre Vadász * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 7085d1c619SImre Vadász * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 7185d1c619SImre Vadász * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 7285d1c619SImre Vadász * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 7385d1c619SImre Vadász * 7485d1c619SImre Vadász *****************************************************************************/ 7585d1c619SImre Vadász 76*6acbba79SMatthew Dillon 7785d1c619SImre Vadász #ifndef __IF_IWM_STA_H__ 7885d1c619SImre Vadász #define __IF_IWM_STA_H__ 7985d1c619SImre Vadász 8085d1c619SImre Vadász /** 8185d1c619SImre Vadász * DOC: station table - introduction 8285d1c619SImre Vadász * 8385d1c619SImre Vadász * The station table is a list of data structure that reprensent the stations. 8485d1c619SImre Vadász * In STA/P2P client mode, the driver will hold one station for the AP/ GO. 8585d1c619SImre Vadász * In GO/AP mode, the driver will have as many stations as associated clients. 8685d1c619SImre Vadász * All these stations are reflected in the fw's station table. The driver 8785d1c619SImre Vadász * keeps the fw's station table up to date with the ADD_STA command. Stations 8885d1c619SImre Vadász * can be removed by the REMOVE_STA command. 8985d1c619SImre Vadász * 90*6acbba79SMatthew Dillon * All the data related to a station is held in the structure %iwl_sta 9185d1c619SImre Vadász * which is embed in the mac80211's %ieee80211_sta (in the drv_priv) area. 9285d1c619SImre Vadász * This data includes the index of the station in the fw, per tid information 9385d1c619SImre Vadász * (sequence numbers, Block-ack state machine, etc...). The stations are 9485d1c619SImre Vadász * created and deleted by the %sta_state callback from %ieee80211_ops. 9585d1c619SImre Vadász * 9685d1c619SImre Vadász * The driver holds a map: %fw_id_to_mac_id that allows to fetch a 97*6acbba79SMatthew Dillon * %ieee80211_sta (and the %iwl_sta embedded into it) based on a fw 9885d1c619SImre Vadász * station index. That way, the driver is able to get the tid related data in 9985d1c619SImre Vadász * O(1) in time sensitive paths (Tx / Tx response / BA notification). These 10085d1c619SImre Vadász * paths are triggered by the fw, and the driver needs to get a pointer to the 10185d1c619SImre Vadász * %ieee80211 structure. This map helps to get that pointer quickly. 10285d1c619SImre Vadász */ 10385d1c619SImre Vadász 10485d1c619SImre Vadász /** 10585d1c619SImre Vadász * DOC: station table - locking 10685d1c619SImre Vadász * 10785d1c619SImre Vadász * As stated before, the station is created / deleted by mac80211's %sta_state 10885d1c619SImre Vadász * callback from %ieee80211_ops which can sleep. The next paragraph explains 10985d1c619SImre Vadász * the locking of a single stations, the next ones relates to the station 11085d1c619SImre Vadász * table. 11185d1c619SImre Vadász * 11285d1c619SImre Vadász * The station holds the sequence number per tid. So this data needs to be 11385d1c619SImre Vadász * accessed in the Tx path (which is softIRQ). It also holds the Block-Ack 11485d1c619SImre Vadász * information (the state machine / and the logic that checks if the queues 11585d1c619SImre Vadász * were drained), so it also needs to be accessible from the Tx response flow. 11685d1c619SImre Vadász * In short, the station needs to be access from sleepable context as well as 11785d1c619SImre Vadász * from tasklets, so the station itself needs a spinlock. 11885d1c619SImre Vadász * 11985d1c619SImre Vadász * The writers of %fw_id_to_mac_id map are serialized by the global mutex of 12085d1c619SImre Vadász * the mvm op_mode. This is possible since %sta_state can sleep. 12185d1c619SImre Vadász * The pointers in this map are RCU protected, hence we won't replace the 12285d1c619SImre Vadász * station while we have Tx / Tx response / BA notification running. 12385d1c619SImre Vadász * 12485d1c619SImre Vadász * If a station is deleted while it still has packets in its A-MPDU queues, 12585d1c619SImre Vadász * then the reclaim flow will notice that there is no station in the map for 12685d1c619SImre Vadász * sta_id and it will dump the responses. 12785d1c619SImre Vadász */ 12885d1c619SImre Vadász 12985d1c619SImre Vadász /** 13085d1c619SImre Vadász * DOC: station table - internal stations 13185d1c619SImre Vadász * 13285d1c619SImre Vadász * The FW needs a few internal stations that are not reflected in 13385d1c619SImre Vadász * mac80211, such as broadcast station in AP / GO mode, or AUX sta for 13485d1c619SImre Vadász * scanning and P2P device (during the GO negotiation). 135*6acbba79SMatthew Dillon * For these kind of stations we have %iwl_int_sta struct which holds the 136*6acbba79SMatthew Dillon * data relevant for them from both %iwl_sta and %ieee80211_sta. 13785d1c619SImre Vadász * Usually the data for these stations is static, so no locking is required, 13885d1c619SImre Vadász * and no TID data as this is also not needed. 13985d1c619SImre Vadász * One thing to note, is that these stations have an ID in the fw, but not 14085d1c619SImre Vadász * in mac80211. In order to "reserve" them a sta_id in %fw_id_to_mac_id 14185d1c619SImre Vadász * we fill ERR_PTR(EINVAL) in this mapping and all other dereferencing of 14285d1c619SImre Vadász * pointers from this mapping need to check that the value is not error 14385d1c619SImre Vadász * or NULL. 14485d1c619SImre Vadász * 14585d1c619SImre Vadász * Currently there is only one auxiliary station for scanning, initialized 14685d1c619SImre Vadász * on init. 14785d1c619SImre Vadász */ 14885d1c619SImre Vadász 14985d1c619SImre Vadász /** 15085d1c619SImre Vadász * DOC: station table - AP Station in STA mode 15185d1c619SImre Vadász * 152*6acbba79SMatthew Dillon * %iwl_vif includes the index of the AP station in the fw's STA table: 15385d1c619SImre Vadász * %ap_sta_id. To get the point to the corresponding %ieee80211_sta, 15485d1c619SImre Vadász * &fw_id_to_mac_id can be used. Due to the way the fw works, we must not remove 15585d1c619SImre Vadász * the AP station from the fw before setting the MAC context as unassociated. 15685d1c619SImre Vadász * Hence, %fw_id_to_mac_id[%ap_sta_id] will be NULLed when the AP station is 15785d1c619SImre Vadász * removed by mac80211, but the station won't be removed in the fw until the 15885d1c619SImre Vadász * VIF is set as unassociated. Then, %ap_sta_id will be invalidated. 15985d1c619SImre Vadász */ 16085d1c619SImre Vadász 16185d1c619SImre Vadász /** 16285d1c619SImre Vadász * DOC: station table - Drain vs. Flush 16385d1c619SImre Vadász * 16485d1c619SImre Vadász * Flush means that all the frames in the SCD queue are dumped regardless the 16585d1c619SImre Vadász * station to which they were sent. We do that when we disassociate and before 16685d1c619SImre Vadász * we remove the STA of the AP. The flush can be done synchronously against the 16785d1c619SImre Vadász * fw. 16885d1c619SImre Vadász * Drain means that the fw will drop all the frames sent to a specific station. 16985d1c619SImre Vadász * This is useful when a client (if we are IBSS / GO or AP) disassociates. In 17085d1c619SImre Vadász * that case, we need to drain all the frames for that client from the AC queues 17185d1c619SImre Vadász * that are shared with the other clients. Only then, we can remove the STA in 17285d1c619SImre Vadász * the fw. In order to do so, we track the non-AMPDU packets for each station. 17385d1c619SImre Vadász * If mac80211 removes a STA and if it still has non-AMPDU packets pending in 17485d1c619SImre Vadász * the queues, we mark this station as %EBUSY in %fw_id_to_mac_id, and drop all 175*6acbba79SMatthew Dillon * the frames for this STA (%iwl_rm_sta). When the last frame is dropped 17685d1c619SImre Vadász * (we know about it with its Tx response), we remove the station in fw and set 17785d1c619SImre Vadász * it as %NULL in %fw_id_to_mac_id: this is the purpose of 178*6acbba79SMatthew Dillon * %iwl_sta_drained_wk. 17985d1c619SImre Vadász */ 18085d1c619SImre Vadász 18185d1c619SImre Vadász /** 18285d1c619SImre Vadász * DOC: station table - fw restart 18385d1c619SImre Vadász * 18485d1c619SImre Vadász * When the fw asserts, or we have any other issue that requires to reset the 18585d1c619SImre Vadász * driver, we require mac80211 to reconfigure the driver. Since the private 18685d1c619SImre Vadász * data of the stations is embed in mac80211's %ieee80211_sta, that data will 18785d1c619SImre Vadász * not be zeroed and needs to be reinitialized manually. 188*6acbba79SMatthew Dillon * %IWL_STATUS_IN_HW_RESTART is set during restart and that will hint us 18985d1c619SImre Vadász * that we must not allocate a new sta_id but reuse the previous one. This 19085d1c619SImre Vadász * means that the stations being re-added after the reset will have the same 19185d1c619SImre Vadász * place in the fw as before the reset. We do need to zero the %fw_id_to_mac_id 19285d1c619SImre Vadász * map, since the stations aren't in the fw any more. Internal stations that 19385d1c619SImre Vadász * are not added by mac80211 will be re-added in the init flow that is called 194*6acbba79SMatthew Dillon * after the restart: mac80211 call's %iwl_mac_start which calls to 195*6acbba79SMatthew Dillon * %iwl_up. 19685d1c619SImre Vadász */ 19785d1c619SImre Vadász 19885d1c619SImre Vadász /** 19985d1c619SImre Vadász * Send the STA info to the FW. 20085d1c619SImre Vadász * 20185d1c619SImre Vadász * @sc: the iwm_softc* to use 20285d1c619SImre Vadász * @sta: the STA 20385d1c619SImre Vadász * @update: this is true if the FW is being updated about a STA it already knows 20485d1c619SImre Vadász * about. Otherwise (if this is a new STA), this should be false. 20585d1c619SImre Vadász * @flags: if update==true, this marks what is being changed via ORs of values 20685d1c619SImre Vadász * from enum iwm_sta_modify_flag. Otherwise, this is ignored. 20785d1c619SImre Vadász */ 208*6acbba79SMatthew Dillon extern int iwm_sta_send_to_fw(struct iwm_softc *sc, struct iwm_node *in, 20985d1c619SImre Vadász boolean_t update); 210*6acbba79SMatthew Dillon extern int iwm_add_sta(struct iwm_softc *sc, struct iwm_node *in); 211*6acbba79SMatthew Dillon extern int iwm_update_sta(struct iwm_softc *sc, struct iwm_node *in); 212*6acbba79SMatthew Dillon extern int iwm_rm_sta(struct iwm_softc *sc, struct ieee80211vap *vap, 21381b3c1feSImre Vadász boolean_t is_assoc); 214*6acbba79SMatthew Dillon extern int iwm_rm_sta_id(struct iwm_softc *sc, struct ieee80211vap *vap); 21585d1c619SImre Vadász 216*6acbba79SMatthew Dillon extern int iwm_add_aux_sta(struct iwm_softc *sc); 217*6acbba79SMatthew Dillon extern void iwm_del_aux_sta(struct iwm_softc *sc); 21885d1c619SImre Vadász 219*6acbba79SMatthew Dillon extern int iwm_drain_sta(struct iwm_softc *sc, struct iwm_vap *ivp, 22085d1c619SImre Vadász boolean_t drain); 22185d1c619SImre Vadász 22285d1c619SImre Vadász #endif /* __IF_IWM_STA_H__ */ 223