From patchwork Thu Jun 20 09:17:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasanthakumar Thiagarajan X-Patchwork-Id: 11006247 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CF5914BB for ; Thu, 20 Jun 2019 09:17:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C29A2844E for ; Thu, 20 Jun 2019 09:17:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2090A285FB; Thu, 20 Jun 2019 09:17:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 049A82844E for ; Thu, 20 Jun 2019 09:17:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BLY0tVdH9j67BDOufZ6P1DWij9qmgcf09weOKvWjBts=; b=bkEO4jXXvapyHj A6DKcTX8qF5OUMlnGEGLk5y3x6K3dt99VuhAaBCDQEF1Z58AiSUrPIGedlXTII9nVltauXCNgGhp3 SNtYiJmZ1NZc9ruC/JRbsSwrYi2kT7vGW0o8cBvj0aJbwtD3w4nMa+q4Yz1yoJPjiCskJpRt7ciLP 8MxWoV50/pTdPfMonu2dHLKqLFVNYkkn1kh+JkoinSoHozin8JMM0v1No9RYhJOKhsqyaPv/K/FD+ oTYofgwFvPErU7uhB+e2wMckgMCOWKjZ43C4Cwc9NlFh7jYL2qmM+SGposXr3ZC9khEkKPG3UA55X ZKiZSZ5qti+FqwQTr9+Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hdtCL-0000vt-5n; Thu, 20 Jun 2019 09:17:37 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hdtCF-0000sb-SB for ath11k@lists.infradead.org; Thu, 20 Jun 2019 09:17:34 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9F60C60CEC; Thu, 20 Jun 2019 09:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1561022251; bh=egS+n1+wAeRdm37boMGNyR46OlNcR2KspYsZ5lXzTmc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lSlp+HiPnxkpB6pIspROygyMfaj7aA0/AkREvLKVvw/vf8k0e8RUeodJcD5HIoruQ UR+V1HRfE0HpbJs9JOqdowTlfpC7eXis6YXnLrxIj4daTU+28UYAla4+ZR86zAKWV1 NbDi0aF2ajRq5b6lK72cSpk7W1m4UgK2wUNghElI= Received: from vasanth-lnx.qca.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vthiagar@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id D45B560AD1 for ; Thu, 20 Jun 2019 09:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1561022250; bh=egS+n1+wAeRdm37boMGNyR46OlNcR2KspYsZ5lXzTmc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=e0OWqqtlxcszQ7F1AEpdSde0mG22kO8BgUYD/zhn9bWoQ5g7EPKv7DgzsNIY2NLNn 4seoFV/aYTKQTElkRkCpvbQgYm9cLEqn7wdGgHP10yzZq8p0Mo+nDXNPQm8UITdX8J i0QWSn/O18xRaITb5kMJ+nXIRbLD9Gxchc+GfhTw= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D45B560AD1 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vthiagar@codeaurora.org From: Vasanthakumar Thiagarajan To: ath11k@lists.infradead.org Subject: [PATCH V2 2/4] ath11k: Add peer.[ch] files for peer related util functions Date: Thu, 20 Jun 2019 14:47:07 +0530 Message-Id: <1561022229-854-2-git-send-email-vthiagar@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1561022229-854-1-git-send-email-vthiagar@codeaurora.org> References: <1561022229-854-1-git-send-email-vthiagar@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190620_021731_946753_9DC6FC1B X-CRM114-Status: GOOD ( 19.66 ) X-BeenThere: ath11k@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "ath11k" Errors-To: ath11k-bounces+patchwork-ath11k=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Move peer util functions from mac.c and core.c to peer.c Signed-off-by: Vasanthakumar Thiagarajan --- drivers/net/wireless/ath/ath11k/Makefile | 3 +- drivers/net/wireless/ath/ath11k/core.c | 101 ----------- drivers/net/wireless/ath/ath11k/core.h | 22 --- drivers/net/wireless/ath/ath11k/debug.c | 1 + drivers/net/wireless/ath/ath11k/debugfs_sta.c | 1 + drivers/net/wireless/ath/ath11k/dp.c | 1 + drivers/net/wireless/ath/ath11k/dp_rx.c | 1 + drivers/net/wireless/ath/ath11k/mac.c | 131 +------------- drivers/net/wireless/ath/ath11k/peer.c | 236 ++++++++++++++++++++++++++ drivers/net/wireless/ath/ath11k/peer.h | 35 ++++ drivers/net/wireless/ath/ath11k/wmi.c | 1 + 11 files changed, 279 insertions(+), 254 deletions(-) create mode 100644 drivers/net/wireless/ath/ath11k/peer.c create mode 100644 drivers/net/wireless/ath/ath11k/peer.h diff --git a/drivers/net/wireless/ath/ath11k/Makefile b/drivers/net/wireless/ath/ath11k/Makefile index 4f86b18..6b4a5b5 100644 --- a/drivers/net/wireless/ath/ath11k/Makefile +++ b/drivers/net/wireless/ath/ath11k/Makefile @@ -14,7 +14,8 @@ ath11k-y += core.o \ dp_tx.o \ dp_rx.o \ debug.o \ - ce.o + ce.o \ + peer.o ath11k-$(CONFIG_ATH11K_DEBUGFS) += debug_htt_stats.o ath11k-$(CONFIG_MAC80211_DEBUGFS) += debugfs_sta.o diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c index 26fdcb1..c6dd9ba 100644 --- a/drivers/net/wireless/ath/ath11k/core.c +++ b/drivers/net/wireless/ath/ath11k/core.c @@ -324,107 +324,6 @@ int ath11k_core_fetch_bdf(struct ath11k_base *sc, struct ath11k_board_data *bd) } -struct ath11k_peer *ath11k_peer_find(struct ath11k_base *ab, int vdev_id, - const u8 *addr) -{ - struct ath11k_peer *peer; - - lockdep_assert_held(&ab->data_lock); - - list_for_each_entry(peer, &ab->peers, list) { - if (peer->vdev_id != vdev_id) - continue; - if (memcmp(peer->addr, addr, ETH_ALEN)) - continue; - - return peer; - } - - return NULL; -} - -struct ath11k_peer *ath11k_peer_find_by_addr(struct ath11k_base *ab, - const u8 *addr) -{ - struct ath11k_peer *peer; - - lockdep_assert_held(&ab->data_lock); - - list_for_each_entry(peer, &ab->peers, list) { - if (memcmp(peer->addr, addr, ETH_ALEN)) - continue; - - return peer; - } - - return NULL; -} - -struct ath11k_peer *ath11k_peer_find_by_id(struct ath11k_base *ab, - int peer_id) -{ - struct ath11k_peer *peer; - - lockdep_assert_held(&ab->data_lock); - - list_for_each_entry(peer, &ab->peers, list) - if (peer_id == peer->peer_id) - return peer; - - return NULL; -} - -void ath11k_peer_unmap_event(struct ath11k_base *ab, u16 peer_id) -{ - struct ath11k_peer *peer; - - spin_lock_bh(&ab->data_lock); - - peer = ath11k_peer_find_by_id(ab, peer_id); - if (!peer) { - ath11k_warn(ab, "peer-unmap-event: unknown peer id %d\n", - peer_id); - goto exit; - } - - ath11k_dbg(ab, ATH11K_DBG_DP_HTT, "htt peer unmap vdev %d peer %pM id %d\n", - peer->vdev_id, peer->addr, peer_id); - - list_del(&peer->list); - kfree(peer); - wake_up(&ab->peer_mapping_wq); - -exit: - spin_unlock_bh(&ab->data_lock); -} - -void ath11k_peer_map_event(struct ath11k_base *ab, u8 vdev_id, u16 peer_id, - u8 *mac_addr, u16 ast_hash) -{ - struct ath11k_peer *peer; - - spin_lock_bh(&ab->data_lock); - peer = ath11k_peer_find(ab, vdev_id, mac_addr); - if (!peer) { - peer = kzalloc(sizeof(*peer), GFP_ATOMIC); - if (!peer) - goto exit; - - peer->vdev_id = vdev_id; - peer->peer_id = peer_id; - peer->ast_hash = ast_hash; - ether_addr_copy(peer->addr, mac_addr); - list_add(&peer->list, &ab->peers); - wake_up(&ab->peer_mapping_wq); - } - - ath11k_dbg(ab, ATH11K_DBG_DP_HTT, "htt peer map vdev %d peer %pM id %d\n", - vdev_id, mac_addr, peer_id); - -exit: - spin_unlock_bh(&ab->data_lock); -} - static void ath11k_core_stop(struct ath11k_base *sc) { if (!test_bit(ATH11K_FLAG_CRASH_FLUSH, &sc->dev_flags)) diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h index 4d42ab40..6b3ee2a 100644 --- a/drivers/net/wireless/ath/ath11k/core.h +++ b/drivers/net/wireless/ath/ath11k/core.h @@ -240,19 +240,6 @@ struct ath11k_rx_peer_stats { u64 reception_type[HAL_RX_RECEPTION_TYPE_MAX]; }; -struct ath11k_peer { - struct list_head list; - struct ieee80211_sta *sta; - int vdev_id; - u8 addr[ETH_ALEN]; - int peer_id; - u16 ast_hash; - - /* protected by ab->data_lock */ - struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1]; - struct dp_rx_tid rx_tid[IEEE80211_NUM_TIDS + 1]; -}; - #define ATH11K_HE_MCS_NUM 12 #define ATH11K_VHT_MCS_NUM 10 #define ATH11K_BW_NUM 4 @@ -790,15 +777,6 @@ struct ath11k_fw_stats_peer_extd { u32 rx_mc_bc_cnt; }; -void ath11k_peer_unmap_event(struct ath11k_base *ab, u16 peer_id); -void ath11k_peer_map_event(struct ath11k_base *ab, u8 vdev_id, u16 peer_id, - u8 *mac_addr, u16 ast_hash); -struct ath11k_peer *ath11k_peer_find(struct ath11k_base *ab, int vdev_id, - const u8 *addr); -struct ath11k_peer *ath11k_peer_find_by_addr(struct ath11k_base *ab, - const u8 *addr); -struct ath11k_peer *ath11k_peer_find_by_id(struct ath11k_base *ab, - int peer_id); int ath11k_core_qmi_firmware_ready(struct ath11k_base *ab); int ath11k_core_init(struct ath11k_base *ath11k); void ath11k_core_deinit(struct ath11k_base *ath11k); diff --git a/drivers/net/wireless/ath/ath11k/debug.c b/drivers/net/wireless/ath/ath11k/debug.c index c004fe8..7e86c20 100644 --- a/drivers/net/wireless/ath/ath11k/debug.c +++ b/drivers/net/wireless/ath/ath11k/debug.c @@ -10,6 +10,7 @@ #include "hal_rx.h" #include "dp_tx.h" #include "debug_htt_stats.h" +#include "peer.h" void ath11k_info(struct ath11k_base *sc, const char *fmt, ...) { diff --git a/drivers/net/wireless/ath/ath11k/debugfs_sta.c b/drivers/net/wireless/ath/ath11k/debugfs_sta.c index cff6a3f..6bebe6d 100644 --- a/drivers/net/wireless/ath/ath11k/debugfs_sta.c +++ b/drivers/net/wireless/ath/ath11k/debugfs_sta.c @@ -4,6 +4,7 @@ */ #include "core.h" +#include "peer.h" #include "debug.h" void ath11k_sta_update_rx_duration(struct ath11k *ar, diff --git a/drivers/net/wireless/ath/ath11k/dp.c b/drivers/net/wireless/ath/ath11k/dp.c index be10e98..c4770bb 100644 --- a/drivers/net/wireless/ath/ath11k/dp.c +++ b/drivers/net/wireless/ath/ath11k/dp.c @@ -9,6 +9,7 @@ #include "hal_tx.h" #include "debug.h" #include "dp_rx.h" +#include "peer.h" static void ath11k_dp_htt_htc_tx_complete(struct ath11k_base *sc, struct sk_buff *skb) diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c index 54cb7a4..9f47bf4 100644 --- a/drivers/net/wireless/ath/ath11k/dp_rx.c +++ b/drivers/net/wireless/ath/ath11k/dp_rx.c @@ -11,6 +11,7 @@ #include "dp_rx.h" #include "hal_rx.h" #include "dp_tx.h" +#include "peer.h" static u8 *ath11k_dp_rx_h_80211_hdr(u8 *desc) { diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index e064d81..56afbd7 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -13,6 +13,7 @@ #include "dp_tx.h" #include "dp_rx.h" #include "testmode.h" +#include "peer.h" #define CHAN2G(_channel, _freq, _flags) { \ .band = NL80211_BAND_2GHZ, \ @@ -604,113 +605,6 @@ static int ath11k_mac_set_kickout(struct ath11k_vif *arvif) return 0; } -static int ath11k_wait_for_peer_common(struct ath11k_base *ab, int vdev_id, - const u8 *addr, bool expect_mapped) -{ - int ret; - - ret = wait_event_timeout(ab->peer_mapping_wq, ({ - bool mapped; - - spin_lock_bh(&ab->data_lock); - mapped = !!ath11k_peer_find(ab, vdev_id, addr); - spin_unlock_bh(&ab->data_lock); - - (mapped == expect_mapped || - test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags)); - }), 3 * HZ); - - if (ret <= 0) - return -ETIMEDOUT; - - return 0; -} - -static int -ath11k_wait_for_peer_created(struct ath11k *ar, int vdev_id, const u8 *addr) -{ - return ath11k_wait_for_peer_common(ar->ab, vdev_id, addr, true); -} - -static int -ath11k_wait_for_peer_deleted(struct ath11k *ar, int vdev_id, const u8 *addr) -{ - return ath11k_wait_for_peer_common(ar->ab, vdev_id, addr, false); -} - -static int ath11k_peer_create(struct ath11k *ar, struct ath11k_vif *arvif, - struct ieee80211_sta *sta, - struct peer_create_params *param) -{ - struct ath11k_peer *peer; - int ret; - - lockdep_assert_held(&ar->conf_mutex); - - if (ar->num_peers > (ar->max_num_peers - 1)) { - ath11k_warn(ar->ab, - "failed to create peer due to insufficient peer entry resource in firmware\n"); - return -ENOBUFS; - } - - ret = ath11k_wmi_send_peer_create_cmd(ar, param); - if (ret) { - ath11k_warn(ar->ab, - "failed to send peer create vdev_id %d ret %d\n", - param->vdev_id, ret); - return ret; - } - - ret = ath11k_wait_for_peer_created(ar, param->vdev_id, - param->peer_addr); - if (ret) - return ret; - - spin_lock_bh(&ar->ab->data_lock); - - peer = ath11k_peer_find(ar->ab, param->vdev_id, param->peer_addr); - if (!peer) { - spin_unlock_bh(&ar->ab->data_lock); - ath11k_warn(ar->ab, "failed to find peer %pM on vdev %i after creation\n", - param->peer_addr, param->vdev_id); - ath11k_wmi_send_peer_delete_cmd(ar, param->peer_addr, - param->vdev_id); - return -ENOENT; - } - - peer->sta = sta; - arvif->ast_hash = peer->ast_hash; - - ar->num_peers++; - - spin_unlock_bh(&ar->ab->data_lock); - - return 0; -} - -static int ath11k_peer_delete(struct ath11k *ar, u32 vdev_id, u8 *addr) -{ - int ret; - - lockdep_assert_held(&ar->conf_mutex); - - ret = ath11k_wmi_send_peer_delete_cmd(ar, addr, vdev_id); - if (ret) { - ath11k_warn(ar->ab, - "failed to delete peer vdev_id %d addr %pM ret %d\n", - vdev_id, addr, ret); - return ret; - } - - ret = ath11k_wait_for_peer_deleted(ar, vdev_id, addr); - if (ret) - return ret; - - ar->num_peers--; - - return 0; -} - void ath11k_mac_peer_cleanup_all(struct ath11k *ar) { struct ath11k_peer *peer, *tmp; @@ -730,29 +624,6 @@ void ath11k_mac_peer_cleanup_all(struct ath11k *ar) ar->num_stations = 0; } -static void ath11k_peer_cleanup(struct ath11k *ar, u32 vdev_id) -{ - struct ath11k_peer *peer, *tmp; - struct ath11k_base *ab = ar->ab; - - lockdep_assert_held(&ar->conf_mutex); - - spin_lock_bh(&ab->data_lock); - list_for_each_entry_safe(peer, tmp, &ab->peers, list) { - if (peer->vdev_id != vdev_id) - continue; - - ath11k_warn(ab, "removing stale peer %pM from vdev_id %d\n", - peer->addr, vdev_id); - - list_del(&peer->list); - kfree(peer); - ar->num_peers--; - } - - spin_unlock_bh(&ab->data_lock); -} - static int ath11k_monitor_vdev_up(struct ath11k *ar, int vdev_id) { int ret = 0; diff --git a/drivers/net/wireless/ath/ath11k/peer.c b/drivers/net/wireless/ath/ath11k/peer.c new file mode 100644 index 0000000..5e7aa96 --- /dev/null +++ b/drivers/net/wireless/ath/ath11k/peer.c @@ -0,0 +1,236 @@ +// SPDX-License-Identifier: ISC +/* + * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. + */ + +#include "core.h" +#include "peer.h" +#include "debug.h" + +struct ath11k_peer *ath11k_peer_find(struct ath11k_base *ab, int vdev_id, + const u8 *addr) +{ + struct ath11k_peer *peer; + + lockdep_assert_held(&ab->data_lock); + + list_for_each_entry(peer, &ab->peers, list) { + if (peer->vdev_id != vdev_id) + continue; + if (memcmp(peer->addr, addr, ETH_ALEN)) + continue; + + return peer; + } + + return NULL; +} + +struct ath11k_peer *ath11k_peer_find_by_addr(struct ath11k_base *ab, + const u8 *addr) +{ + struct ath11k_peer *peer; + + lockdep_assert_held(&ab->data_lock); + + list_for_each_entry(peer, &ab->peers, list) { + if (memcmp(peer->addr, addr, ETH_ALEN)) + continue; + + return peer; + } + + return NULL; +} + +struct ath11k_peer *ath11k_peer_find_by_id(struct ath11k_base *ab, + int peer_id) +{ + struct ath11k_peer *peer; + + lockdep_assert_held(&ab->data_lock); + + list_for_each_entry(peer, &ab->peers, list) + if (peer_id == peer->peer_id) + return peer; + + return NULL; +} + +void ath11k_peer_unmap_event(struct ath11k_base *ab, u16 peer_id) +{ + struct ath11k_peer *peer; + + spin_lock_bh(&ab->data_lock); + + peer = ath11k_peer_find_by_id(ab, peer_id); + if (!peer) { + ath11k_warn(ab, "peer-unmap-event: unknown peer id %d\n", + peer_id); + goto exit; + } + + ath11k_dbg(ab, ATH11K_DBG_DP_HTT, "htt peer unmap vdev %d peer %pM id %d\n", + peer->vdev_id, peer->addr, peer_id); + + list_del(&peer->list); + kfree(peer); + wake_up(&ab->peer_mapping_wq); + +exit: + spin_unlock_bh(&ab->data_lock); +} + +void ath11k_peer_map_event(struct ath11k_base *ab, u8 vdev_id, u16 peer_id, + u8 *mac_addr, u16 ast_hash) +{ + struct ath11k_peer *peer; + + spin_lock_bh(&ab->data_lock); + peer = ath11k_peer_find(ab, vdev_id, mac_addr); + if (!peer) { + peer = kzalloc(sizeof(*peer), GFP_ATOMIC); + if (!peer) + goto exit; + + peer->vdev_id = vdev_id; + peer->peer_id = peer_id; + peer->ast_hash = ast_hash; + ether_addr_copy(peer->addr, mac_addr); + list_add(&peer->list, &ab->peers); + wake_up(&ab->peer_mapping_wq); + } + + ath11k_dbg(ab, ATH11K_DBG_DP_HTT, "htt peer map vdev %d peer %pM id %d\n", + vdev_id, mac_addr, peer_id); + +exit: + spin_unlock_bh(&ab->data_lock); +} + +static int ath11k_wait_for_peer_common(struct ath11k_base *ab, int vdev_id, + const u8 *addr, bool expect_mapped) +{ + int ret; + + ret = wait_event_timeout(ab->peer_mapping_wq, ({ + bool mapped; + + spin_lock_bh(&ab->data_lock); + mapped = !!ath11k_peer_find(ab, vdev_id, addr); + spin_unlock_bh(&ab->data_lock); + + (mapped == expect_mapped || + test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags)); + }), 3 * HZ); + + if (ret <= 0) + return -ETIMEDOUT; + + return 0; +} + +void ath11k_peer_cleanup(struct ath11k *ar, u32 vdev_id) +{ + struct ath11k_peer *peer, *tmp; + struct ath11k_base *ab = ar->ab; + + lockdep_assert_held(&ar->conf_mutex); + + spin_lock_bh(&ab->data_lock); + list_for_each_entry_safe(peer, tmp, &ab->peers, list) { + if (peer->vdev_id != vdev_id) + continue; + + ath11k_warn(ab, "removing stale peer %pM from vdev_id %d\n", + peer->addr, vdev_id); + + list_del(&peer->list); + kfree(peer); + ar->num_peers--; + } + + spin_unlock_bh(&ab->data_lock); +} + +static int ath11k_wait_for_peer_deleted(struct ath11k *ar, int vdev_id, const u8 *addr) +{ + return ath11k_wait_for_peer_common(ar->ab, vdev_id, addr, false); +} + +int ath11k_peer_delete(struct ath11k *ar, u32 vdev_id, u8 *addr) +{ + int ret; + + lockdep_assert_held(&ar->conf_mutex); + + ret = ath11k_wmi_send_peer_delete_cmd(ar, addr, vdev_id); + if (ret) { + ath11k_warn(ar->ab, + "failed to delete peer vdev_id %d addr %pM ret %d\n", + vdev_id, addr, ret); + return ret; + } + + ret = ath11k_wait_for_peer_deleted(ar, vdev_id, addr); + if (ret) + return ret; + + ar->num_peers--; + + return 0; +} + +static int ath11k_wait_for_peer_created(struct ath11k *ar, int vdev_id, const u8 *addr) +{ + return ath11k_wait_for_peer_common(ar->ab, vdev_id, addr, true); +} + +int ath11k_peer_create(struct ath11k *ar, struct ath11k_vif *arvif, + struct ieee80211_sta *sta, struct peer_create_params *param) +{ + struct ath11k_peer *peer; + int ret; + + lockdep_assert_held(&ar->conf_mutex); + + if (ar->num_peers > (ar->max_num_peers - 1)) { + ath11k_warn(ar->ab, + "failed to create peer due to insufficient peer entry resource in firmware\n"); + return -ENOBUFS; + } + + ret = ath11k_wmi_send_peer_create_cmd(ar, param); + if (ret) { + ath11k_warn(ar->ab, + "failed to send peer create vdev_id %d ret %d\n", + param->vdev_id, ret); + return ret; + } + + ret = ath11k_wait_for_peer_created(ar, param->vdev_id, + param->peer_addr); + if (ret) + return ret; + + spin_lock_bh(&ar->ab->data_lock); + + peer = ath11k_peer_find(ar->ab, param->vdev_id, param->peer_addr); + if (!peer) { + spin_unlock_bh(&ar->ab->data_lock); + ath11k_warn(ar->ab, "failed to find peer %pM on vdev %i after creation\n", + param->peer_addr, param->vdev_id); + ath11k_wmi_send_peer_delete_cmd(ar, param->peer_addr, + param->vdev_id); + return -ENOENT; + } + + peer->sta = sta; + arvif->ast_hash = peer->ast_hash; + + ar->num_peers++; + + spin_unlock_bh(&ar->ab->data_lock); + + return 0; +} diff --git a/drivers/net/wireless/ath/ath11k/peer.h b/drivers/net/wireless/ath/ath11k/peer.h new file mode 100644 index 0000000..99e54f1 --- /dev/null +++ b/drivers/net/wireless/ath/ath11k/peer.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: ISC */ +/* + * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. + */ + +#ifndef ATH11K_PEER_H +#define ATH11K_PEER_H + +struct ath11k_peer { + struct list_head list; + struct ieee80211_sta *sta; + int vdev_id; + u8 addr[ETH_ALEN]; + int peer_id; + u16 ast_hash; + + /* protected by ab->data_lock */ + struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1]; + struct dp_rx_tid rx_tid[IEEE80211_NUM_TIDS + 1]; +}; + +void ath11k_peer_unmap_event(struct ath11k_base *ab, u16 peer_id); +void ath11k_peer_map_event(struct ath11k_base *ab, u8 vdev_id, u16 peer_id, + u8 *mac_addr, u16 ast_hash); +struct ath11k_peer *ath11k_peer_find(struct ath11k_base *ab, int vdev_id, + const u8 *addr); +struct ath11k_peer *ath11k_peer_find_by_addr(struct ath11k_base *ab, + const u8 *addr); +struct ath11k_peer *ath11k_peer_find_by_id(struct ath11k_base *ab, int peer_id); +void ath11k_peer_cleanup(struct ath11k *ar, u32 vdev_id); +int ath11k_peer_delete(struct ath11k *ar, u32 vdev_id, u8 *addr); +int ath11k_peer_create(struct ath11k *ar, struct ath11k_vif *arvif, + struct ieee80211_sta *sta, struct peer_create_params *param); + +#endif /* _PEER_H_ */ diff --git a/drivers/net/wireless/ath/ath11k/wmi.c b/drivers/net/wireless/ath/ath11k/wmi.c index 1477247..9778a02 100644 --- a/drivers/net/wireless/ath/ath11k/wmi.c +++ b/drivers/net/wireless/ath/ath11k/wmi.c @@ -17,6 +17,7 @@ #include "debug.h" #include "mac.h" #include "hw.h" +#include "peer.h" struct wmi_tlv_policy { size_t min_len;