Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp699030rdb; Fri, 22 Dec 2023 02:16:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGk7Mbw2cVKeTS7icqAUyvImeT2xXSADqQD/wvG0rKpul5ymy/0Y7kvw81MEPBGKsJwH798 X-Received: by 2002:a05:622a:1046:b0:427:8cb2:2570 with SMTP id f6-20020a05622a104600b004278cb22570mr1463010qte.102.1703240162970; Fri, 22 Dec 2023 02:16:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703240162; cv=none; d=google.com; s=arc-20160816; b=ssLKPE1lEgKiW3DpClsogAX1RDWWOjq7PYlnHW/7MzYNMj+HdoMc68Z0M0p94oBIkn 0SfqJ0lHRTsVvK8G1FuLAIDFr3qPI/RfBr4/tktHdzjCppLhbq154GawPDD9g2rQcOEO 8vi1krNHhNfu/LDFDJFQ3D+YgFGQ79D8tuVcjeSC0PauPuy2GF9178Aj7b9+VKVsgSMz FOUHWmKq7RaDlJmVKKR0bO6tOrErPjorhH844Yaa2jpodrBRwUhsN1ebvEDolZlGqDnP SbP2DwI/2MEKM5fEUWBU7y4kcyimCdtb1+xlvsNpbOeyLnrecjAkFHn/v1LpYbYk0cUc w8bQ== ARC-Message-Signature: i=1; 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:dkim-signature:dkim-signature:from; bh=96i3GuOW6QoWwLdot5afBuLFDdBJeRlGRO5Mb9e9ZO8=; fh=KsoNWtazjfstHns8t6UZ1pulwZL69aEO39vRs0LPvyo=; b=NW0RmXN3Ya8n3hLdxztgaYQ+74XoAwXJNGCMDneOktjx+I/lW8QIneSSOPkwLBr5pt 0yLxTGERf1+VitenxXCxeBGRFDYRQrAFMbpA+TlmPfZSaN4e/TUjF/UQsfxG4Ehfbym0 our4YB62ztAuIc9u3Zv0dUvVUzzrqXrvfjK/+cOqMhHTZIV1gbFLRMPkM5zuckgzwMlj XrhXlAhSdXbsLZmVFzFjA631Dls8NYgii/CdgxxHMgXowVj96nkL5MQFeI5cxE8PHRsl EjNm5OCeyytjGERgheI3Oh+nqaq8OdCUERIDshdWL53MY++Gd9yiUtC8R/+PMAupCdtd oM1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=m3SK2CVe; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-wireless+bounces-1242-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-1242-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a11-20020a05622a064b00b00425826acab8si3998024qtb.469.2023.12.22.02.16.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 02:16:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-1242-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=@linutronix.de header.s=2020 header.b=m3SK2CVe; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-wireless+bounces-1242-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-1242-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B84371C2514F for ; Fri, 22 Dec 2023 10:16:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3D541CA9C; Fri, 22 Dec 2023 10:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="m3SK2CVe"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gs6ZbGF+" 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 6F9321864D for ; Fri, 22 Dec 2023 10:14:54 +0000 (UTC) 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 From: Martin Kaistra DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1703240090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=96i3GuOW6QoWwLdot5afBuLFDdBJeRlGRO5Mb9e9ZO8=; b=m3SK2CVe0SL2OO1T8xPUF4eRo+WmNP3gbknJynPiVukCKLNoRdlVIeVLiAwSjx0xhrUTCq bC4W7h+TabzDpvDa2080QZCtOpXsPKvfUgklyGZAMTUl/FphCp5DSxAsCMrCmM0H7WukHi DmSaw57oLfg9iZkbPiqDy4bPyS1JGi9gAlkGot6gHM97cG6W8MYub14XTZgOMFVHDKUHKJ VncMbxqaS6FPTwR9YkIAlQF6En9QOX5uiA9sPUU/fKqUmQ6L+eu/dBNWCjum9Hy6c4FT0v nZKWkrbthuIh8WBcY8nR/xVT7FTfAT3ipKtGWFPiYUPvUPE0TFQ7w89S80nv0w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1703240090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=96i3GuOW6QoWwLdot5afBuLFDdBJeRlGRO5Mb9e9ZO8=; b=gs6ZbGF+IU7Oc3SjJdxhYiN5HXzF+Zw5TkFyqF4P15pUJGEQS8+3uaeyP9sPxNn4H2pyFa M1qW0Sq13u1DNgAg== To: linux-wireless@vger.kernel.org Cc: Jes Sorensen , Kalle Valo , Ping-Ke Shih , Bitterblue Smith , Sebastian Andrzej Siewior Subject: [PATCH v3 20/21] wifi: rtl8xxxu: make supporting AP mode only on port 0 transparent Date: Fri, 22 Dec 2023 11:14:41 +0100 Message-Id: <20231222101442.626837-21-martin.kaistra@linutronix.de> In-Reply-To: <20231222101442.626837-1-martin.kaistra@linutronix.de> References: <20231222101442.626837-1-martin.kaistra@linutronix.de> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When the driver is used for concurrent mode, both virtual interfaces can be set to station or AP mode, though only one can be in AP mode at the same time. In order to keep the code simple, use only hw port 0 for AP mode. When an interface is added in AP mode which would be assigned to port 1, use a switch_port function to transparently swap the mapping between virtual interface and hw port. Signed-off-by: Martin Kaistra Reviewed-by: Ping-Ke Shih --- .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 91 ++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c index 7aafae9fe76b8..0178b441dce53 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -6624,6 +6624,91 @@ static int rtl8xxxu_submit_int_urb(struct ieee80211_hw *hw) return ret; } +static void rtl8xxxu_switch_ports(struct rtl8xxxu_priv *priv) +{ + u8 macid[ETH_ALEN], bssid[ETH_ALEN], macid_1[ETH_ALEN], bssid_1[ETH_ALEN]; + u8 msr, bcn_ctrl, bcn_ctrl_1, atimwnd[2], atimwnd_1[2]; + struct rtl8xxxu_vif *rtlvif; + struct ieee80211_vif *vif; + u8 tsftr[8], tsftr_1[8]; + int i; + + msr = rtl8xxxu_read8(priv, REG_MSR); + bcn_ctrl = rtl8xxxu_read8(priv, REG_BEACON_CTRL); + bcn_ctrl_1 = rtl8xxxu_read8(priv, REG_BEACON_CTRL_1); + + for (i = 0; i < ARRAY_SIZE(atimwnd); i++) + atimwnd[i] = rtl8xxxu_read8(priv, REG_ATIMWND + i); + for (i = 0; i < ARRAY_SIZE(atimwnd_1); i++) + atimwnd_1[i] = rtl8xxxu_read8(priv, REG_ATIMWND_1 + i); + + for (i = 0; i < ARRAY_SIZE(tsftr); i++) + tsftr[i] = rtl8xxxu_read8(priv, REG_TSFTR + i); + for (i = 0; i < ARRAY_SIZE(tsftr); i++) + tsftr_1[i] = rtl8xxxu_read8(priv, REG_TSFTR1 + i); + + for (i = 0; i < ARRAY_SIZE(macid); i++) + macid[i] = rtl8xxxu_read8(priv, REG_MACID + i); + + for (i = 0; i < ARRAY_SIZE(bssid); i++) + bssid[i] = rtl8xxxu_read8(priv, REG_BSSID + i); + + for (i = 0; i < ARRAY_SIZE(macid_1); i++) + macid_1[i] = rtl8xxxu_read8(priv, REG_MACID1 + i); + + for (i = 0; i < ARRAY_SIZE(bssid_1); i++) + bssid_1[i] = rtl8xxxu_read8(priv, REG_BSSID1 + i); + + /* disable bcn function, disable update TSF */ + rtl8xxxu_write8(priv, REG_BEACON_CTRL, (bcn_ctrl & + (~BEACON_FUNCTION_ENABLE)) | BEACON_DISABLE_TSF_UPDATE); + rtl8xxxu_write8(priv, REG_BEACON_CTRL_1, (bcn_ctrl_1 & + (~BEACON_FUNCTION_ENABLE)) | BEACON_DISABLE_TSF_UPDATE); + + /* switch msr */ + msr = (msr & 0xf0) | ((msr & 0x03) << 2) | ((msr & 0x0c) >> 2); + rtl8xxxu_write8(priv, REG_MSR, msr); + + /* write port0 */ + rtl8xxxu_write8(priv, REG_BEACON_CTRL, bcn_ctrl_1 & ~BEACON_FUNCTION_ENABLE); + for (i = 0; i < ARRAY_SIZE(atimwnd_1); i++) + rtl8xxxu_write8(priv, REG_ATIMWND + i, atimwnd_1[i]); + for (i = 0; i < ARRAY_SIZE(tsftr_1); i++) + rtl8xxxu_write8(priv, REG_TSFTR + i, tsftr_1[i]); + for (i = 0; i < ARRAY_SIZE(macid_1); i++) + rtl8xxxu_write8(priv, REG_MACID + i, macid_1[i]); + for (i = 0; i < ARRAY_SIZE(bssid_1); i++) + rtl8xxxu_write8(priv, REG_BSSID + i, bssid_1[i]); + + /* write port1 */ + rtl8xxxu_write8(priv, REG_BEACON_CTRL_1, bcn_ctrl & ~BEACON_FUNCTION_ENABLE); + for (i = 0; i < ARRAY_SIZE(atimwnd); i++) + rtl8xxxu_write8(priv, REG_ATIMWND_1 + i, atimwnd[i]); + for (i = 0; i < ARRAY_SIZE(tsftr); i++) + rtl8xxxu_write8(priv, REG_TSFTR1 + i, tsftr[i]); + for (i = 0; i < ARRAY_SIZE(macid); i++) + rtl8xxxu_write8(priv, REG_MACID1 + i, macid[i]); + for (i = 0; i < ARRAY_SIZE(bssid); i++) + rtl8xxxu_write8(priv, REG_BSSID1 + i, bssid[i]); + + /* write bcn ctl */ + rtl8xxxu_write8(priv, REG_BEACON_CTRL, bcn_ctrl_1); + rtl8xxxu_write8(priv, REG_BEACON_CTRL_1, bcn_ctrl); + + vif = priv->vifs[0]; + priv->vifs[0] = priv->vifs[1]; + priv->vifs[1] = vif; + + /* priv->vifs[0] is NULL here, based on how this function is currently + * called from rtl8xxxu_add_interface(). + * When this function will be used in the future for a different + * scenario, please check whether vifs[0] or vifs[1] can be NULL and if + * necessary add code to set port_num = 1. + */ + rtlvif = (struct rtl8xxxu_vif *)priv->vifs[1]->drv_priv; + rtlvif->port_num = 1; +} + static int rtl8xxxu_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) { @@ -6651,8 +6736,10 @@ static int rtl8xxxu_add_interface(struct ieee80211_hw *hw, } break; case NL80211_IFTYPE_AP: - if (port_num == 1) - return -EOPNOTSUPP; + if (port_num == 1) { + rtl8xxxu_switch_ports(priv); + port_num = 0; + } rtl8xxxu_write8(priv, REG_BEACON_CTRL, BEACON_DISABLE_TSF_UPDATE | BEACON_CTRL_MBSSID); -- 2.39.2