Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1142837lqt; Fri, 7 Jun 2024 09:07:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUCo0ncEWBjqRcF5MCp2wF099BWN3pOYtK3C/alZZDJIjF31wcRNPqYOIwOz6Fau2HmVWfh1A1dk6hHAgHBd1aOqBFnP+nQeqGXr04/4Q== X-Google-Smtp-Source: AGHT+IGpfBxgIdb3v4HVMogWpZvjJlQDhWnk+9uLgwTAwvv3cvRc5WBY61R/Qsly7XwUax7/mtsm X-Received: by 2002:a05:6214:5d92:b0:6ae:d9a9:90de with SMTP id 6a1803df08f44-6b059f159f4mr30765756d6.47.1717776472347; Fri, 07 Jun 2024 09:07:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717776472; cv=pass; d=google.com; s=arc-20160816; b=iQIc9xmNgk6CIOllI26jOKnojmoJCkxA6bXJ32yd8KE3f8yVhB+rO0oIo2fg5925qP RiywLeUlz7IGBdt3ojypokaUHghVMAtSK+emKY3EMVbSaXH0hI60xKL5Udt8T2A4ghuQ MXt9vSYJdn9YkV3YhiiVdhXOn0gBbSuwfs17smwFkvT32tOmau76g7bxen1hgA4BERO/ ys0aqS2wLbKUyM02bhw54l/kdTRyiTFAvoCMEkxF7D5aNRfkP3DiD6S+vD9ECnOfNJ3W t5+V5ku2QkhSOgJ2FdfE+qz7QsWhTAVWLEsD/74mqEBhQiG0jR3HlT+sthhl0LfMmfvi QJZw== 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=E5CI0wDHvksxh6jXzTcJcoR/Vkw4nSvBxyZsxzfQIAI=; fh=fUr549cSqKocV7UcRuBHkVs5Q/EFHHdf/SC+m2DGkeo=; b=UvKia474pBWouwVTtLy5jbCaIuoMq1E4SlbAnRrKWR+OA1KNe7GvBd3mn+/kfYJu/v ohkL1F/BUqEnJYoGz7I+eAXaX2Hym8no43UyPO7NyZip3Lbe1hRew1fDDikDHUrBLB2R BcZyMUv1T82hmtltRtSQ8i864JoBLvA4WNd7dhXC+21JLqkcH59ZnA0q4P4f/uILvz8f SoKlsEANTgVWAqzXAMKrXgevqvk5/L1To/Qdu0qyF4PxOguD+29JF5PHWZsvkuZx4cNE cWDR1mu+IEuYtbI8RTnkhSRoT8X4eSXm3Dsl1J3VvEBlR2LZrjhXn83Uyk7CgZOYua0q MnvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b="D/uk2gFA"; arc=pass (i=1 dkim=pass dkdomain=nbd.name dmarc=pass fromdomain=nbd.name); spf=pass (google.com: domain of linux-wireless+bounces-8708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-8708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6b04f963e82si2034786d6.267.2024.06.07.09.07.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 09:07:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless+bounces-8708-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=fail header.i=@nbd.name header.s=20160729 header.b="D/uk2gFA"; arc=pass (i=1 dkim=pass dkdomain=nbd.name dmarc=pass fromdomain=nbd.name); spf=pass (google.com: domain of linux-wireless+bounces-8708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-8708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name 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 045901C2245C for ; Fri, 7 Jun 2024 16:07:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6154A19AA4B; Fri, 7 Jun 2024 16:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=nbd.name header.i=@nbd.name header.b="D/uk2gFA" X-Original-To: linux-wireless@vger.kernel.org Received: from nbd.name (nbd.name [46.4.11.11]) (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 4266119AA4F for ; Fri, 7 Jun 2024 16:05:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.4.11.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776358; cv=none; b=bIiSQ65VE9/03jcdeOJugDWGX0zzqUS3+ZcwW2PpTLH5j81a2FnYiQ1OYr3yaqGL4Jk08CEczUFKZ5Xka74cGYbYZ4QFJPzRg0YvMpoarEGT9W3bqMdUYXhiKK5fRdZ2wuoBMH1rlRci1TF4ERNMXgbG+uovBMHF+F0Ni8qlRUU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776358; c=relaxed/simple; bh=Q+tmcwpANBlkIWAOYG5xvF+QYH9H/ktKdDKijOIuRDI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rHxvP0HWN8G00jb0AhFZQzyvlG9wj3d1rxKiwMqbmZXhOkhQIaiwqwILdGgP1rH1gy/aVuVIv6nDoY6WC+K/oCFyQA7W1DvAUavc9kQa3Lqc6oA072ObrrwI9yULUwhDiXNfU1pKnvMlmoYsumDlHPsIqGi+hzp3yNaqR6cGFko= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nbd.name; spf=none smtp.mailfrom=nbd.name; dkim=pass (1024-bit key) header.d=nbd.name header.i=@nbd.name header.b=D/uk2gFA; arc=none smtp.client-ip=46.4.11.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nbd.name Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=nbd.name DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=E5CI0wDHvksxh6jXzTcJcoR/Vkw4nSvBxyZsxzfQIAI=; b=D/uk2gFACaUhTuT969ZVdX092u 6wdA0JBLwlS+eipurGBtnMtjGxrfFR1YkyKSPpOdbykszLJI8C1Cytg25ZvJ8YVKtxYV2lO04Ei+r UX/Ihw3yxJiz+uM6IcH7WV6leGjppZ/yKGZFyJK22IXPBvf5motB/gjVBfR2lW1TkJwA=; Received: from p4ff13226.dip0.t-ipconnect.de ([79.241.50.38] helo=localhost.localdomain) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.96) (envelope-from ) id 1sFc6C-008xPc-0U; Fri, 07 Jun 2024 18:05:52 +0200 From: Felix Fietkau To: linux-wireless@vger.kernel.org Cc: johannes@sipsolutions.net, quic_adisi@quicinc.com, quic_periyasa@quicinc.com, ath12k@lists.infradead.org Subject: [RFC v4 9/9] wifi: mac80211: add wiphy radio assignment and validation Date: Fri, 7 Jun 2024 18:05:48 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Validate number of channels and interface combinations per radio. Assign each channel context to a radio. Signed-off-by: Felix Fietkau --- net/mac80211/chan.c | 52 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c index ac49c2c71d2b..6cbf314d706f 100644 --- a/net/mac80211/chan.c +++ b/net/mac80211/chan.c @@ -696,14 +696,15 @@ static struct ieee80211_chanctx * ieee80211_new_chanctx(struct ieee80211_local *local, const struct ieee80211_chan_req *chanreq, enum ieee80211_chanctx_mode mode, - bool assign_on_failure) + bool assign_on_failure, + int radio_idx) { struct ieee80211_chanctx *ctx; int err; lockdep_assert_wiphy(local->hw.wiphy); - ctx = ieee80211_alloc_chanctx(local, chanreq, mode, -1); + ctx = ieee80211_alloc_chanctx(local, chanreq, mode, radio_idx); if (!ctx) return ERR_PTR(-ENOMEM); @@ -1067,6 +1068,8 @@ ieee80211_replace_chanctx(struct ieee80211_local *local, struct ieee80211_chanctx *curr_ctx) { struct ieee80211_chanctx *new_ctx, *ctx; + struct wiphy *wiphy = local->hw.wiphy; + const struct wiphy_radio *radio; if (!curr_ctx || (curr_ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) || @@ -1096,6 +1099,12 @@ ieee80211_replace_chanctx(struct ieee80211_local *local, if (!list_empty(&ctx->reserved_links)) continue; + if (ctx->conf.radio_idx >= 0) { + radio = &wiphy->radio[ctx->conf.radio_idx]; + if (!cfg80211_radio_chandef_valid(radio, &chanreq->oper)) + continue; + } + curr_ctx = ctx; break; } @@ -1125,6 +1134,34 @@ ieee80211_replace_chanctx(struct ieee80211_local *local, return new_ctx; } +static bool +ieee80211_find_available_radio(struct ieee80211_local *local, + const struct ieee80211_chan_req *chanreq, + int *radio_idx) +{ + struct wiphy *wiphy = local->hw.wiphy; + const struct wiphy_radio *radio; + int i; + + *radio_idx = -1; + if (!wiphy->n_radio) + return true; + + for (i = 0; i < wiphy->n_radio; i++) { + radio = &wiphy->radio[i]; + if (!cfg80211_radio_chandef_valid(radio, &chanreq->oper)) + continue; + + if (!ieee80211_can_create_new_chanctx(local, i)) + continue; + + *radio_idx = i; + return true; + } + + return false; +} + int ieee80211_link_reserve_chanctx(struct ieee80211_link_data *link, const struct ieee80211_chan_req *chanreq, enum ieee80211_chanctx_mode mode, @@ -1133,6 +1170,7 @@ int ieee80211_link_reserve_chanctx(struct ieee80211_link_data *link, struct ieee80211_sub_if_data *sdata = link->sdata; struct ieee80211_local *local = sdata->local; struct ieee80211_chanctx *new_ctx, *curr_ctx; + int radio_idx; lockdep_assert_wiphy(local->hw.wiphy); @@ -1142,9 +1180,10 @@ int ieee80211_link_reserve_chanctx(struct ieee80211_link_data *link, new_ctx = ieee80211_find_reservation_chanctx(local, chanreq, mode); if (!new_ctx) { - if (ieee80211_can_create_new_chanctx(local, -1)) + if (ieee80211_can_create_new_chanctx(local, -1) && + ieee80211_find_available_radio(local, chanreq, &radio_idx)) new_ctx = ieee80211_new_chanctx(local, chanreq, mode, - false); + false, radio_idx); else new_ctx = ieee80211_replace_chanctx(local, chanreq, mode, curr_ctx); @@ -1755,6 +1794,7 @@ int _ieee80211_link_use_channel(struct ieee80211_link_data *link, struct ieee80211_chanctx *ctx; u8 radar_detect_width = 0; bool reserved = false; + int radio_idx; int ret; lockdep_assert_wiphy(local->hw.wiphy); @@ -1785,9 +1825,11 @@ int _ieee80211_link_use_channel(struct ieee80211_link_data *link, /* Note: context is now reserved */ if (ctx) reserved = true; + else if (!ieee80211_find_available_radio(local, chanreq, &radio_idx)) + ctx = ERR_PTR(-EBUSY); else ctx = ieee80211_new_chanctx(local, chanreq, mode, - assign_on_failure); + assign_on_failure, radio_idx); if (IS_ERR(ctx)) { ret = PTR_ERR(ctx); goto out; -- git-series 0.9.1