Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp572027rdb; Mon, 29 Jan 2024 10:49:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEspgBz+sY84po/NDG4ZnjGKHsd9k2SvSXmEP009ctOW5oduLX89oowxZPPx+j/2gL2NHyS X-Received: by 2002:a17:906:d8da:b0:a31:6a03:d1aa with SMTP id re26-20020a170906d8da00b00a316a03d1aamr8317423ejb.22.1706554162915; Mon, 29 Jan 2024 10:49:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706554162; cv=pass; d=google.com; s=arc-20160816; b=IuiG1WQyt46UVIPUg7zYBo89XwYJGFlLB//wuV9FeCjy6h0Ow3OOZBIWGipix3gN3S bKTIDdaHn7EuvLVfVWH6cfEVRJ4XkpXV2Xs5Az2Z5/E1pe5RwTOIbLxIyoE3mcNe9Vvs fg98qTEnuJCn/7Mv7yDna/3aoP2+BHbgpKblQS/fuJ7/vECsJmZmkkpMdIcpsPeJbCFj hmXCdk2BINqc9JoGYzWa3tNVbD570vbhNFO7UEI9onuIXQrsl5PMEmxrF9+ouQVyVH8e RCQTfLPtpvbkpf6K9/P4S2GfGsFFhMT4HjAuMTqBkA/vpQzw4uztBua/zu7VXK29ZkQV 98Jg== 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=QPretpK49GERcMqUt9zwN7Ok4/lvUI5cZMiChIAtXvo=; fh=GajzDCYrjr0pcItEGhxPdW6vSzUiLsiMniCi45zUYHc=; b=XRRxiRRDxJaQuDd8dAI9o2ZENKCiIBJsOit/kvA5E6PJraRp6fYRCfoUFNF2cnr1wF p81hPX722uwKZ9BxLAwuOSY0MuAfZyYw2jNibrMX3dscbqF68EqYO0x1Jv3pLPaoZL25 QTEikDLTaNamQFtJ+OXY1OBc8S71wfKXicfgrx5PBFPFr0U0z1fu0ImeSnC8PC+aiyFl EtTpJOg1FzUuqEGUfU9bSFXVnfjEZbPiBWihOyPmVplo+S5lFu82yX0JOt5FHoOSKNNM ekrAZcxcRfO98bw8BdWwn/mD7HnObNAzZNN7plNdZU7Lrf2w35AofAlyiNrk719x4FR7 MFdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=v3quiYhO; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-wireless+bounces-2688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-wireless+bounces-2688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net X-Forwarded-Encrypted: i=1; AJvYcCXW+3nxeP4979ulacmaHICs4CrbMk7V5/onZCmd9U2MC8zfM82R60A/N3FhmxMGQH7MVo+i80XBG6TfWddDohB0iZQtP4lmMnxe7uqjKg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gs10-20020a170906f18a00b00a35a018042csi1520971ejb.338.2024.01.29.10.49.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 10:49:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-2688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=v3quiYhO; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-wireless+bounces-2688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-wireless+bounces-2688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5A10D1F23083 for ; Mon, 29 Jan 2024 18:49:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 939A515A489; Mon, 29 Jan 2024 18:41:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="v3quiYhO" X-Original-To: linux-wireless@vger.kernel.org Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (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 A9AEA159574 for ; Mon, 29 Jan 2024 18:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706553685; cv=none; b=Y3608PPO6Or96g36UAVBh6N5ef9LIcTpQcz75ktKJ1Imr/FSG8rHNDzQtGD4/433qULXcAbr+Ja5vvNCLfmqWGX/K75IVtEB2HP6G9mo67PjDqN1yQR+n+/9lrohmgtT2/SVpYGALxJHPsGHwCtOuQ0yBWmzjRzs73B0GTktG6Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706553685; c=relaxed/simple; bh=EKSdNwt19CKH3tIOcT2/1wLoTBi9/zjzWkdRvGk/gHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aMZrt8LAb0QcyVvgcdeKoBIyVxlGs+O97dE5HZa3hYqqROVP4SL+3g/CIAezCSFaqaV7Mx9miwtjbfAqmMV0iNXsGnAWbx7+ehCj6uexczfmThLDRL1jU0yafl3eRVkc7bxcQL/VnDOiW7ZNWIesgwWQFya7tb03ux7sc9Q52Ww= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=v3quiYhO; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=QPretpK49GERcMqUt9zwN7Ok4/lvUI5cZMiChIAtXvo=; t=1706553682; x=1707763282; b=v3quiYhOW+qDAp5tVAexKEDPoaLpuIBkaZrrkG0dU5Sd/F6 eewxoy5fFKMoyxskwQK24bUXuNFo0K9v4qiMm6qzTzwgh4XQU1kcffXvDz84oX6hqTr/c8fO0LaCT RRtLKhepf8d7rOsJ4v9LSOtDf3Y8oSlFxsk6WFW37+JtWEPcns3ULOMkwiPf21p+tOFF6B92FaACR a5RaZloWoDDFxMHoAnlkZV4KLAqNnKCxZpGtCIDJSKu2HWIzJFCZm/c92eegH/jlGQgcHPFNm5LC7 GrMlYd0nuZIxRP+qH7bJqXJlAbWYlXJq/0YJRSLZOrWrByfdAxgIewACnj8GT02w==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1rUWZL-00000004z9N-24QR; Mon, 29 Jan 2024 19:41:19 +0100 From: Johannes Berg To: linux-wireless@vger.kernel.org Cc: Johannes Berg Subject: [PATCH 10/15] wifi: cfg80211: move puncturing validation code Date: Mon, 29 Jan 2024 19:34:44 +0100 Message-ID: <20240129194108.1ca184427c76.I077deb8d52c4648eac145b63f88b6c5a3b920ddc@changeid> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129184108.49639-17-johannes@sipsolutions.net> References: <20240129184108.49639-17-johannes@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Johannes Berg Upcoming patches will move the puncturing bitmap into the chandef, so chandef validation will need to check for correct puncturing. Purely move the code first so later changes are easier to review. Signed-off-by: Johannes Berg --- net/wireless/chan.c | 138 ++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/net/wireless/chan.c b/net/wireless/chan.c index ceb9174c5c3d..71f1bd456d88 100644 --- a/net/wireless/chan.c +++ b/net/wireless/chan.c @@ -56,6 +56,75 @@ void cfg80211_chandef_create(struct cfg80211_chan_def *chandef, } EXPORT_SYMBOL(cfg80211_chandef_create); +struct cfg80211_per_bw_puncturing_values { + u8 len; + const u16 *valid_values; +}; + +static const u16 puncturing_values_80mhz[] = { + 0x8, 0x4, 0x2, 0x1 +}; + +static const u16 puncturing_values_160mhz[] = { + 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1, 0xc0, 0x30, 0xc, 0x3 +}; + +static const u16 puncturing_values_320mhz[] = { + 0xc000, 0x3000, 0xc00, 0x300, 0xc0, 0x30, 0xc, 0x3, 0xf000, 0xf00, + 0xf0, 0xf, 0xfc00, 0xf300, 0xf0c0, 0xf030, 0xf00c, 0xf003, 0xc00f, + 0x300f, 0xc0f, 0x30f, 0xcf, 0x3f +}; + +#define CFG80211_PER_BW_VALID_PUNCTURING_VALUES(_bw) \ + { \ + .len = ARRAY_SIZE(puncturing_values_ ## _bw ## mhz), \ + .valid_values = puncturing_values_ ## _bw ## mhz \ + } + +static const struct cfg80211_per_bw_puncturing_values per_bw_puncturing[] = { + CFG80211_PER_BW_VALID_PUNCTURING_VALUES(80), + CFG80211_PER_BW_VALID_PUNCTURING_VALUES(160), + CFG80211_PER_BW_VALID_PUNCTURING_VALUES(320) +}; + +bool cfg80211_valid_disable_subchannel_bitmap(u16 *bitmap, + const struct cfg80211_chan_def *chandef) +{ + u32 idx, i, start_freq; + + switch (chandef->width) { + case NL80211_CHAN_WIDTH_80: + idx = 0; + start_freq = chandef->center_freq1 - 40; + break; + case NL80211_CHAN_WIDTH_160: + idx = 1; + start_freq = chandef->center_freq1 - 80; + break; + case NL80211_CHAN_WIDTH_320: + idx = 2; + start_freq = chandef->center_freq1 - 160; + break; + default: + *bitmap = 0; + break; + } + + if (!*bitmap) + return true; + + /* check if primary channel is punctured */ + if (*bitmap & (u16)BIT((chandef->chan->center_freq - start_freq) / 20)) + return false; + + for (i = 0; i < per_bw_puncturing[idx].len; i++) + if (per_bw_puncturing[idx].valid_values[i] == *bitmap) + return true; + + return false; +} +EXPORT_SYMBOL(cfg80211_valid_disable_subchannel_bitmap); + static bool cfg80211_edmg_chandef_valid(const struct cfg80211_chan_def *chandef) { int max_contiguous = 0; @@ -1532,72 +1601,3 @@ struct cfg80211_chan_def *wdev_chandef(struct wireless_dev *wdev, } } EXPORT_SYMBOL(wdev_chandef); - -struct cfg80211_per_bw_puncturing_values { - u8 len; - const u16 *valid_values; -}; - -static const u16 puncturing_values_80mhz[] = { - 0x8, 0x4, 0x2, 0x1 -}; - -static const u16 puncturing_values_160mhz[] = { - 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1, 0xc0, 0x30, 0xc, 0x3 -}; - -static const u16 puncturing_values_320mhz[] = { - 0xc000, 0x3000, 0xc00, 0x300, 0xc0, 0x30, 0xc, 0x3, 0xf000, 0xf00, - 0xf0, 0xf, 0xfc00, 0xf300, 0xf0c0, 0xf030, 0xf00c, 0xf003, 0xc00f, - 0x300f, 0xc0f, 0x30f, 0xcf, 0x3f -}; - -#define CFG80211_PER_BW_VALID_PUNCTURING_VALUES(_bw) \ - { \ - .len = ARRAY_SIZE(puncturing_values_ ## _bw ## mhz), \ - .valid_values = puncturing_values_ ## _bw ## mhz \ - } - -static const struct cfg80211_per_bw_puncturing_values per_bw_puncturing[] = { - CFG80211_PER_BW_VALID_PUNCTURING_VALUES(80), - CFG80211_PER_BW_VALID_PUNCTURING_VALUES(160), - CFG80211_PER_BW_VALID_PUNCTURING_VALUES(320) -}; - -bool cfg80211_valid_disable_subchannel_bitmap(u16 *bitmap, - const struct cfg80211_chan_def *chandef) -{ - u32 idx, i, start_freq; - - switch (chandef->width) { - case NL80211_CHAN_WIDTH_80: - idx = 0; - start_freq = chandef->center_freq1 - 40; - break; - case NL80211_CHAN_WIDTH_160: - idx = 1; - start_freq = chandef->center_freq1 - 80; - break; - case NL80211_CHAN_WIDTH_320: - idx = 2; - start_freq = chandef->center_freq1 - 160; - break; - default: - *bitmap = 0; - break; - } - - if (!*bitmap) - return true; - - /* check if primary channel is punctured */ - if (*bitmap & (u16)BIT((chandef->chan->center_freq - start_freq) / 20)) - return false; - - for (i = 0; i < per_bw_puncturing[idx].len; i++) - if (per_bw_puncturing[idx].valid_values[i] == *bitmap) - return true; - - return false; -} -EXPORT_SYMBOL(cfg80211_valid_disable_subchannel_bitmap); -- 2.43.0