Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2373961lqp; Sun, 24 Mar 2024 16:27:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXxSkoMhKJkpFxqiPy1Q076jnoMzKkgptjy2VI6LmNMYZs1SCLrHNGDMQg2ee7AgZaPwoGuluXXOpo80Ye4e7MpdvKL0Pnc9Da8psjjQw== X-Google-Smtp-Source: AGHT+IH8RWsrUCqMQrTmrUEVvaIzyPiYELCgizaz1SGawW2lERXrVlFReQT42BtqoRua/50hdzWh X-Received: by 2002:ac8:5815:0:b0:431:5152:b41c with SMTP id g21-20020ac85815000000b004315152b41cmr3539882qtg.21.1711322870191; Sun, 24 Mar 2024 16:27:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711322870; cv=pass; d=google.com; s=arc-20160816; b=y/CcLl9bgXEyuLDtW7trlx5Qv29gBNbyfXF71DfnPFbUXditY4RnmM/CnQn7DB9ANo caFwXSwAiY9VqBQQUdv4oVF/zUvo0uz1clEGiMsFscH/EOfb9VN+CbgD4AIpzeJLrrZo wqZ1LBqIW/FnzmuvZgGGYShST7oCEcB2KcEkUqHSfANqnENLz2yrwVrwUXMPafKNoORA bMQzWZ48Q0x9yfOhaCjP3cvp5v7RXM+tPbErKBOWbscXuvmvGepmaq9Iuj+Qcr/US2Ce x7uYUvReTZQfuf73U1eMr83dj67THNco7FWM6aLjycvL8gi/A5SGIrIeINpH7iHf/5SR Z+WA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dYvsEA28XVwo1GKoJsm3V0lru9dtP81ZYhAYm9etHdI=; fh=75dLTr36I5W9FBN+Z3weG/mVZD8GM7lGUnkhMFCKvJc=; b=W+vz3j6qnGAEaMmynpL8q0DU6OelR3AJALb3G8BuAMDE9o4F9cVnnLUt5SOhXItkj+ RKo8AQubQQvsqMvAlO//sTVkiYPbgyPAqZJXGCfbzBhPo+6EOoKpmDcTQUWG/pru1Nyp tRrKopKvxBaeKhEanotuYk71GwR/PmOxJXYlf3hbBpeI4UJXBVyMtG0Ip9leC2v5PIWu 4dyjjubNtUuap2hV5Fv4oWKz6mKNXHl5BXMEttzzfpYIFdprT4Lwk5GH2EVsttVsjwHu VCWBwktPsmoPuwxmXy/ryFArkf8k78qYDV7D10z/QdLdvCAzrssL86rpfi1YUNM7VajM Lmow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V8rKjwBl; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id cc10-20020a05622a410a00b00430a675f9b8si4763167qtb.422.2024.03.24.16.27.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:27:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V8rKjwBl; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E2D5F1C21D03 for ; Sun, 24 Mar 2024 23:27:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B76D1649CD; Sun, 24 Mar 2024 22:39:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="V8rKjwBl" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 853AF161B56; Sun, 24 Mar 2024 22:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319939; cv=none; b=KCJAssfF1odxtxmY0H6NDO+WfQmxqKpCu6LnuDvNGtHMA4oeKr1dViK7QEGUyF6EXydtH/o1wppFb6oCjp/nywYCOYpyEJLsecnFauQO4/0sRZ73rFjTa70es4UDaKsvmGyj8+iCxf78vhwQaxs8xS8DrfCfEmU+4cCDA5sdNwc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319939; c=relaxed/simple; bh=z2iUOQCdt0N2rh0v6Bua7z3hbJ7d+N7jjIvJfVpe/jY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TYn2gbWTF/ai005VX+fbTO+CwekO+SkCVtKXTzoeUcUN717bzao4iZy0DuafQmvdb0ymbWnV48dbgQMIvY5ExDMPQvasK0YphwrP1783pXNOyq2S6soZjFwVCFxejpnvffvgZiqGv4JGR4peVW/3mXrIfrTNgNEqCO+tXRpVRVg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V8rKjwBl; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAC7CC43394; Sun, 24 Mar 2024 22:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319939; bh=z2iUOQCdt0N2rh0v6Bua7z3hbJ7d+N7jjIvJfVpe/jY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V8rKjwBlzxUFR1lVNLldeAGOX8ZqV4JjhTRWNUqVttk4TfWh/v+gA1KBjyWXMt0Fo mdEDsOyXc/Y72aZE86rSeZs+AxsfB6+MGRw3iuGvHrR2OskTrqm+6opJhLAoFhcvZ9 vuHABEBhsT7P8RCsl4fBuzYpSgkA0r8G4UYivqGiJ4KsFayOvAHEUFYmrxE5842C/U lXStJDe512r7h2l57a19JhwWaNN9fddMRWerPf+8PFatyw0A7k0O7eEl64Iw2c6/Qg bZA7ADZ0H+MrNPQYMbUYELLRhMkupnluW4SO9HY+8jkbDtqvTuhsxbnpF0AxDAfavz 0Sa52Cz3k223A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peter Chiu , Shayne Chen , Felix Fietkau , Sasha Levin Subject: [PATCH 6.8 245/715] wifi: mt76: mt7996: fix TWT issues Date: Sun, 24 Mar 2024 18:27:04 -0400 Message-ID: <20240324223455.1342824-246-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Peter Chiu [ Upstream commit 5c832c228f6a7ba7e900c5296ce0fb3844bafec5 ] This patch fixes the following TWT issues: - Change table_mask to u16 to support up to 16 TWT stations - Reject TWT flows for duplicated establishment - Fix possible unaligned pointer - Remove unsupported TWT_CONTROL_WAKE_DUR_UNIT flag - The minimum TWT duration supported by mt7996 chipsets is 64. Reply with TWT_SETUP_CMD_DICTATE if the min_twt_dur is smaller than 64 Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Signed-off-by: Peter Chiu Signed-off-by: Shayne Chen Signed-off-by: Felix Fietkau Signed-off-by: Sasha Levin --- .../net/wireless/mediatek/mt76/mt7996/mac.c | 53 ++++++++++++++++--- .../wireless/mediatek/mt76/mt7996/mt7996.h | 3 +- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c index a8414fbb07c82..63d34844c1223 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c @@ -2530,6 +2530,34 @@ static int mt7996_mac_check_twt_req(struct ieee80211_twt_setup *twt) return 0; } +static bool +mt7996_mac_twt_param_equal(struct mt7996_sta *msta, + struct ieee80211_twt_params *twt_agrt) +{ + u16 type = le16_to_cpu(twt_agrt->req_type); + u8 exp; + int i; + + exp = FIELD_GET(IEEE80211_TWT_REQTYPE_WAKE_INT_EXP, type); + for (i = 0; i < MT7996_MAX_STA_TWT_AGRT; i++) { + struct mt7996_twt_flow *f; + + if (!(msta->twt.flowid_mask & BIT(i))) + continue; + + f = &msta->twt.flow[i]; + if (f->duration == twt_agrt->min_twt_dur && + f->mantissa == twt_agrt->mantissa && + f->exp == exp && + f->protection == !!(type & IEEE80211_TWT_REQTYPE_PROTECTION) && + f->flowtype == !!(type & IEEE80211_TWT_REQTYPE_FLOWTYPE) && + f->trigger == !!(type & IEEE80211_TWT_REQTYPE_TRIGGER)) + return true; + } + + return false; +} + void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw, struct ieee80211_sta *sta, struct ieee80211_twt_setup *twt) @@ -2541,8 +2569,7 @@ void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw, enum ieee80211_twt_setup_cmd sta_setup_cmd; struct mt7996_dev *dev = mt7996_hw_dev(hw); struct mt7996_twt_flow *flow; - int flowid, table_id; - u8 exp; + u8 flowid, table_id, exp; if (mt7996_mac_check_twt_req(twt)) goto out; @@ -2555,9 +2582,19 @@ void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw, if (hweight8(msta->twt.flowid_mask) == ARRAY_SIZE(msta->twt.flow)) goto unlock; + if (twt_agrt->min_twt_dur < MT7996_MIN_TWT_DUR) { + setup_cmd = TWT_SETUP_CMD_DICTATE; + twt_agrt->min_twt_dur = MT7996_MIN_TWT_DUR; + goto unlock; + } + + if (mt7996_mac_twt_param_equal(msta, twt_agrt)) + goto unlock; + flowid = ffs(~msta->twt.flowid_mask) - 1; - le16p_replace_bits(&twt_agrt->req_type, flowid, - IEEE80211_TWT_REQTYPE_FLOWID); + twt_agrt->req_type &= ~cpu_to_le16(IEEE80211_TWT_REQTYPE_FLOWID); + twt_agrt->req_type |= le16_encode_bits(flowid, + IEEE80211_TWT_REQTYPE_FLOWID); table_id = ffs(~dev->twt.table_mask) - 1; exp = FIELD_GET(IEEE80211_TWT_REQTYPE_WAKE_INT_EXP, req_type); @@ -2604,10 +2641,10 @@ void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw, unlock: mutex_unlock(&dev->mt76.mutex); out: - le16p_replace_bits(&twt_agrt->req_type, setup_cmd, - IEEE80211_TWT_REQTYPE_SETUP_CMD); - twt->control = (twt->control & IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT) | - (twt->control & IEEE80211_TWT_CONTROL_RX_DISABLED); + twt_agrt->req_type &= ~cpu_to_le16(IEEE80211_TWT_REQTYPE_SETUP_CMD); + twt_agrt->req_type |= + le16_encode_bits(setup_cmd, IEEE80211_TWT_REQTYPE_SETUP_CMD); + twt->control = twt->control & IEEE80211_TWT_CONTROL_RX_DISABLED; } void mt7996_mac_twt_teardown_flow(struct mt7996_dev *dev, diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index bc73bcb47bf02..8154ad37827f0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -53,6 +53,7 @@ #define MT7996_MAX_TWT_AGRT 16 #define MT7996_MAX_STA_TWT_AGRT 8 +#define MT7996_MIN_TWT_DUR 64 #define MT7996_MAX_QUEUE (__MT_RXQ_MAX + __MT_MCUQ_MAX + 3) /* NOTE: used to map mt76_rates. idx may change if firmware expands table */ @@ -320,7 +321,7 @@ struct mt7996_dev { struct rchan *relay_fwlog; struct { - u8 table_mask; + u16 table_mask; u8 n_agrt; } twt; -- 2.43.0