Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp395353rdb; Mon, 29 Jan 2024 05:48:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKQaSAiiQ+l5lkS9B/hHVtD8mc8jdrp5unMCUvugEwc6OO3hm+fQP7o3jfoEMuLllVuue2 X-Received: by 2002:a17:903:1c9:b0:1d7:8541:f914 with SMTP id e9-20020a17090301c900b001d78541f914mr6245119plh.26.1706536081732; Mon, 29 Jan 2024 05:48:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706536081; cv=pass; d=google.com; s=arc-20160816; b=KQMwiISiWjaAjpi4FpK0+wtbsP5xzYawa0Bml09T8MwdRWtlhaDbmbgCMhnLINkOw2 8CCyRXZhPLhGDRFQFg6ZcwbHur1mgsfSjs4tvoo6Hd2b661OWz32Ga9xY8MpYErun5rf 3lzS9I5HKn2fPjCu0hxKKkVLMWOMVkftkqusbfvjCK9y9pI6Riw3yqJWs0F055ESzPFF QB5Sn4DRVOhZ+I9tQufJYgkEf32ZulYCljp0Lh7UMS03WNoZXaQ1QdB8SfsTx2g0nJ5j LU6YXwdFYXMAIebpf0/EuQAcydz+ZL26IdmjG9dt0fuho50Se6xIY+6cvsjPWXy8TR1b 9PRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature :dkim-signature:message-id; bh=MoZo6it93dE2wUUYE3XJlDRneDzNKRP5h/ks8gGsRbM=; fh=d3T9LCqHDOpWDgFN7yaR/kLf3Obje98o5gfDP7oYeyM=; b=yEVqYjuPyNVDCdWWqFsU7ZR7HWjWvdggVF+vWH25q1XnvH3VY6KrNrB3ZcuflpF0mE bPE6D/Yo0UDwHgWjPGwp9HOFD94i7pWjIfn/BAF8ccVPQbyZh8NAUPEigiTKPADCBD9x DHPctyd+1PI9n8rkacjDs8v84GN0Evm/5D5+Z35xI76OXQlb8jNt3BB3PiHaEMgFBnBy BEHyk290mEVTrAUujZ1h8ueUp4fHRAeyjPh8W3lic5CA2MAU51Ea1pcI+CZwOdwv/8pJ LV6APuvmgoPTfyQyONII1WXQyouGDSjjO3P4Ok6M+ip0++iNfINaphqfHekGLKY8lI6/ AmTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sGm8WFmd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-wireless+bounces-2671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-2671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=1; AJvYcCUwTk/nSDdfdo1REO+L+a6pr9UhKJr1moWoCoC/rDP7LOeRtlXPO97xfIqadOdveWhj6sGJz0c/oLCNoM9oIzo3fYrZss7BYWxbwjkEQg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u8-20020a17090341c800b001d8e652bcdasi1492905ple.298.2024.01.29.05.48.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 05:48:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-2671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sGm8WFmd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-wireless+bounces-2671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-2671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AD145292613 for ; Mon, 29 Jan 2024 13:33:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1750E634ED; Mon, 29 Jan 2024 13:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sGm8WFmd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Mo4bKeki" X-Original-To: linux-wireless@vger.kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23A00634F1 for ; Mon, 29 Jan 2024 13:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706535180; cv=none; b=Ckx5ZcGVHUgN3/lcGDbyvB7zWc9OD6G3XLTfBD9BnvHy0kt+OSaw8Mhw4Shzx0WutrbWmHBtWzNbLDuj5GsKPawVqlvVdDMSrEtj2osarYsnUdM+foaQwkpLgHprjWC7cmRD1M38z4yXPm+DTd3XfbRXOCqyzh+eTCC9V62Syac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706535180; c=relaxed/simple; bh=5NRZQpxNE68NfON9OLhzdXa7bflGR5c5OubAIdfK/r4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=WZhT62wQjogVEVIH++k17etxdy3gcDdsYnH4orcFtDrClzfE0EimjS++HRMIRc6xhEus/FFEiaUD2Iz19oPKgAtiyG+Ufk64l12gvTsqevTp9O5dY5p0YeHqlw8raERUMjqjGQ3hvsHeIh/ZBg/iZGucjXpLxdw9VjBAxxZ6bLY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sGm8WFmd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Mo4bKeki; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706535175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MoZo6it93dE2wUUYE3XJlDRneDzNKRP5h/ks8gGsRbM=; b=sGm8WFmdQ/FugqPgiEMmRA5kJlsz3dKuwTHtiYpwv/2kFTDOaUkQIyWCZd14vBK0Tfa1c4 zdPPT14YbTAYEanbyzc+40vgdlYgnrS7LRvlsCfqqO7mPg6Tg282c3kjnNnYDSYYRBYfd6 +GcXwstjZTuqTjVjvA3ipdyfV4TOXiAjb46JXO9ClhaW8tnPeN0/QGsQRl843oRMY9eWdy d+Ssg1g91xs6COV8SnICWgNhrUGhOiuUyJOIewR19uUAjMrcNFwP7TndsVMVUG200jRbJa BCvlUnFAA/BFageOg0pBVQzaQi29RxG5q5JQLpMCn3CAVLTPY/RmRYkwQbk3lA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706535175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MoZo6it93dE2wUUYE3XJlDRneDzNKRP5h/ks8gGsRbM=; b=Mo4bKekiOkRHJf7uVDMsuyGDS/GQq9OsYoHavcKI5s4eN92oAA/ibQhn9DXt8gOUNFg9Jc fzHbX+PuHLqVByDg== Date: Mon, 29 Jan 2024 14:32:55 +0100 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v2] wifi: rtl8xxxu: update rate mask per sta Content-Language: de-DE To: Ping-Ke Shih , "linux-wireless@vger.kernel.org" Cc: Jes Sorensen , Kalle Valo , Bitterblue Smith , Sebastian Andrzej Siewior References: <20240124082705.1098960-1-martin.kaistra@linutronix.de> From: Martin Kaistra In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Am 26.01.24 um 03:41 schrieb Ping-Ke Shih: > > >> -----Original Message----- >> From: Martin Kaistra >> Sent: Wednesday, January 24, 2024 4:27 PM >> To: linux-wireless@vger.kernel.org >> Cc: Jes Sorensen ; Kalle Valo ; Ping-Ke Shih >> ; Bitterblue Smith ; Sebastian Andrzej Siewior >> >> Subject: [PATCH v2] wifi: rtl8xxxu: update rate mask per sta >> >> Until now, rtl8xxxu_watchdog_callback() only fetches RSSI and updates >> the rate mask in station mode. This means, in AP mode only the default >> rate mask is used. >> >> In order to have the rate mask reflect the actual connection quality, >> extend rtl8xxxu_watchdog_callback() to iterate over every sta. Like in >> the rtw88 driver, add a function to collect all currently present stas >> and then iterate over a list of copies to ensure no RCU lock problems >> for register access via USB. Remove the existing RCU lock in >> rtl8xxxu_refresh_rate_mask(). >> >> Since the currently used ieee80211_ave_rssi() is only for 'vif', add >> driver-level tracking of RSSI per sta. >> >> Signed-off-by: Martin Kaistra >> --- >> changes v1->v2: move 'rssi_level' into struct rtl8xxxu_sta_info >> v1: https://lore.kernel.org/linux-wireless/20240117145516.497966-1-martin.kaistra@linutronix.de/ > > [...] > >> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c >> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c >> index 3b954c2fe448f..3820d3c308759 100644 >> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c >> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c >> @@ -4993,8 +4993,8 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, >> struct device *dev = &priv->udev->dev; >> struct ieee80211_sta *sta; >> struct rtl8xxxu_ra_report *rarpt; >> + u8 val8, macid; >> u32 val32; >> - u8 val8; >> >> rarpt = &priv->ra_report; >> >> @@ -5004,6 +5004,7 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, >> rtl8xxxu_set_linktype(priv, vif->type, rtlvif->port_num); >> >> if (vif->cfg.assoc) { >> + struct rtl8xxxu_sta_info *sta_info; > > nit: I remember that declaration at beginning of function is preferred. I will move it to the beginning of the function. > >> u32 ramask; >> int sgi = 0; >> u8 highest_rate; >> @@ -5017,6 +5018,7 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, >> rcu_read_unlock(); >> goto error; >> } >> + macid = rtl8xxxu_get_macid(priv, sta); >> >> if (sta->deflink.ht_cap.ht_supported) >> dev_info(dev, "%s: HT supported\n", __func__); >> @@ -5037,14 +5039,15 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, >> bw = RATE_INFO_BW_40; >> else >> bw = RATE_INFO_BW_20; >> + >> + sta_info = (struct rtl8xxxu_sta_info *)sta->drv_priv; >> + sta_info->rssi_level = RTL8XXXU_RATR_STA_INIT; > > For AP mode, we should do this as well at rtl8xxxu_sta_add() before calling > rtl8xxxu_refresh_rate_mask()? refresh_rate_mask is called from sta_add with force == true, so a new value is set there to sta_info->rssi_level regardless of the previous value, but it can't hurt to have a proper initialisation. > >> rcu_read_unlock(); >> >> rtl8xxxu_update_ra_report(rarpt, highest_rate, sgi, bw); >> >> - priv->rssi_level = RTL8XXXU_RATR_STA_INIT; >> - >> priv->fops->update_rate_mask(priv, ramask, 0, sgi, >> - bw == RATE_INFO_BW_40, 0); >> + bw == RATE_INFO_BW_40, macid); >> >> rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff); >> >> @@ -6317,6 +6320,76 @@ static void rtl8188e_c2hcmd_callback(struct work_struct *work) >> } >> } >> >> +#define rtl8xxxu_iterate_vifs_atomic(priv, iterator, data) \ >> + ieee80211_iterate_active_interfaces_atomic((priv)->hw, \ >> + IEEE80211_IFACE_ITER_NORMAL, iterator, data) >> + >> +struct rtl8xxxu_rx_addr_match_data { >> + struct rtl8xxxu_priv *priv; >> + struct ieee80211_hdr *hdr; >> + struct ieee80211_rx_status *rx_status; >> + u8 *bssid; >> +}; >> + >> +static void rtl8xxxu_rx_addr_match_iter(void *data, u8 *mac, >> + struct ieee80211_vif *vif) >> +{ >> + struct rtl8xxxu_rx_addr_match_data *iter_data = data; >> + struct ieee80211_sta *sta; >> + struct ieee80211_hdr *hdr = iter_data->hdr; >> + struct rtl8xxxu_priv *priv = iter_data->priv; >> + struct rtl8xxxu_sta_info *sta_info; >> + struct ieee80211_rx_status *rx_status = iter_data->rx_status; >> + u8 *bssid = iter_data->bssid; >> + >> + if (!ether_addr_equal(vif->bss_conf.bssid, bssid)) >> + return; >> + >> + if (!(ether_addr_equal(vif->addr, hdr->addr1) || >> + ieee80211_is_beacon(hdr->frame_control))) >> + return; > > nit: Here checks bssid, addr1 and beacon frame. For me, if you want to combine > some of them, would it be reasonable to combine bssid and add1? Ok, I will do that for v3. > >> + >> + sta = ieee80211_find_sta_by_ifaddr(priv->hw, hdr->addr2, >> + vif->addr); >> + if (!sta) >> + return; >> + >> + sta_info = (struct rtl8xxxu_sta_info *)sta->drv_priv; >> + ewma_rssi_add(&sta_info->avg_rssi, -rx_status->signal); >> +} >> + >> +static inline u8 *get_hdr_bssid(struct ieee80211_hdr *hdr) > > Would you like to add a ieee80211_get_BSSID() to ieee80211.h in separated > patch? But I wonder if it is enough to check addr1 only? I just saw that there already is a ieee80211_get_bssid() in net/mac80211/util.c. Only problem is that it needs enum nl80211_iftype type as parameter and I currently do not have that available in rtl8xxxu_parse_rxdesc16().. > >> +{ >> + __le16 fc = hdr->frame_control; >> + u8 *bssid; >> + >> + if (ieee80211_has_tods(fc)) >> + bssid = hdr->addr1; >> + else if (ieee80211_has_fromds(fc)) >> + bssid = hdr->addr2; >> + else >> + bssid = hdr->addr3; >> + >> + return bssid; >> +} >> + >> +static void rtl8xxxu_rx_addr_match(struct rtl8xxxu_priv *priv, >> + struct ieee80211_rx_status *rx_status, >> + struct ieee80211_hdr *hdr) >> +{ >> + struct rtl8xxxu_rx_addr_match_data data = {}; >> + >> + if (ieee80211_is_ctl(hdr->frame_control)) >> + return; >> + >> + data.priv = priv; >> + data.hdr = hdr; >> + data.rx_status = rx_status; >> + data.bssid = get_hdr_bssid(hdr); >> + >> + rtl8xxxu_iterate_vifs_atomic(priv, rtl8xxxu_rx_addr_match_iter, &data); >> +} >> + >> int rtl8xxxu_parse_rxdesc16(struct rtl8xxxu_priv *priv, struct sk_buff *skb) >> { >> struct ieee80211_hw *hw = priv->hw; >> @@ -6376,18 +6449,26 @@ int rtl8xxxu_parse_rxdesc16(struct rtl8xxxu_priv *priv, struct sk_buff *skb) >> skb_queue_tail(&priv->c2hcmd_queue, skb); >> schedule_work(&priv->c2hcmd_work); >> } else { >> + struct ieee80211_hdr *hdr; >> + >> phy_stats = (struct rtl8723au_phy_stats *)skb->data; >> >> skb_pull(skb, drvinfo_sz + desc_shift); >> >> skb_trim(skb, pkt_len); >> >> - if (rx_desc->phy_stats) >> + hdr = (struct ieee80211_hdr *)skb->data; >> + if (rx_desc->phy_stats) { >> priv->fops->parse_phystats( >> priv, rx_status, phy_stats, >> rx_desc->rxmcs, >> - (struct ieee80211_hdr *)skb->data, >> + hdr, >> rx_desc->crc32 || rx_desc->icverr); >> + if (!rx_desc->crc32 && !rx_desc->icverr) >> + rtl8xxxu_rx_addr_match(priv, >> + rx_status, >> + hdr); > > This function name isn't clear, because it doesn't just match rx addr, > but it is to update RSSI by rx_status for corresponding station. Does rtl8xxxu_rx_update_rssi() sound better to you? > >> + } >> >> rx_status->mactime = rx_desc->tsfl; >> rx_status->flag |= RX_FLAG_MACTIME_START; > > [...] >