Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp442330lqc; Fri, 8 Mar 2024 01:55:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWWO1gayV5mcgwGQFh94XnOOOqL7i7q1I0cZ7X7oK/SDHao9fRdDnDswZXGWMOv01XNCyy2S9JdSGhEhsFB5klaH4ARQGym8efyLJyS8A== X-Google-Smtp-Source: AGHT+IHmVvg/2YwSzPAaqtT4NfVNFtQFqX832ElFNa3bulimBS/QMcQZIRmSO0jchNQapEMgsim0 X-Received: by 2002:a05:620a:2053:b0:788:1f98:14b8 with SMTP id d19-20020a05620a205300b007881f9814b8mr10608947qka.39.1709891718730; Fri, 08 Mar 2024 01:55:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709891718; cv=pass; d=google.com; s=arc-20160816; b=FhTgrnC7gLL9fqG96jATBku4LKH64zaowKtOa0NC4ol+Qg4fuQnMBxNFvoyZ+sD+Yp Lk6oFJgQPJCPuEpu7rFYkf6rGJaeBlAqszGSeEi7B5XmI7bvfpxq8F7eqJfu4Rz1Bw1K wcExC3ReTZwV8aSaRzIE2gtxAxTiSX4siRRHvSSa/CFkV4vtTIpjq7d5FfaO+fRIzzVQ XoExGpDoezXRVRu07FnSSzeV+NkHYdQPACOMSEls4JkFN6QLgIHepkyZudduqkkSofwh Q/IFaGARjKHe9w1hktzQ6HIi4OWhLEwqGKInhz03L1kexjVD7mC+cs13cIOgEUwGE2Qg EDJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lx3npHykkw1gOdQqXLW5o/F+B78jLU3tilBWulRgUu0=; fh=e41HssbKEyeFFKh8Unka8lLK3t84XrA4bDVmHQBgSfY=; b=WgcaVWZ5ROK7Y3i/BAXRLhzTbAaKID4EbE+TBOBxU2DG2alx/iGhSVQyB+y/K0dB5P sDxStI7eKbHVkLy/s1Gyvj363H1fbXUNdZxQjht1xery9E+LQ595SxcweMXH4LQmR/aD UNXiW0GqCsAgM8Wua+MMflYFo2cUl9X1FsPSwlgR2MvtTBfhD6ZJfI7Wk6OqmCVYnCSQ Zjn5WbwZ/NeuKta+zT+c8PMWX16N7yYC9gYfC8uqFQI6TOnwf/crFbMyOS+AWRagRONY Jz60Zm+ShRzaaa21hKCCPPbxfSm1eKlmfO00UcXZgKF9AvrHfr5lrWxJS8mqbxfYDZUE XZXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="eCh/g4jq"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-96782-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96782-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u6-20020a05620a120600b0078826f168c1si10918721qkj.737.2024.03.08.01.55.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 01:55:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96782-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="eCh/g4jq"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-96782-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96782-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 45B2A1C22802 for ; Fri, 8 Mar 2024 09:55:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 107F453E25; Fri, 8 Mar 2024 09:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eCh/g4jq" Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69137535A3; Fri, 8 Mar 2024 09:54:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709891689; cv=none; b=Wvszyko43yUQqi5+rFQ+NYwx4Yr345zUPa8QGxXESvYUS8aB/rSRpXMLq981F/YGUtd5YIcRAb3S6epYFy5Th7tU+nKnFFs3eZnQwHXK3YuMZoFv+sABwNtBGVNIOE1BjmdMPZFFXO6s+9v8g2yvd2OU4QSvboekHXz21d3H27s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709891689; c=relaxed/simple; bh=9+F2N1xirgPO1B/K5OKBxAdcA6ZxVjinMYU43eppFog=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MtvT7YfW4n5PqNcUqyrvsxC5qQzcetkAE1crvukdsnBysTBr2/wxUidlzBbcDPO9ksTcvQ1XFDdqla0nEhXvq2hWwTy22wDcfLia7MpFKtxjJajJTeSOjFwqe+yre6tIEFsHfD9PPA0SxqK1GT2JfJC4R98bdpU/XBNPBef1jC8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eCh/g4jq; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a28a6cef709so97677466b.1; Fri, 08 Mar 2024 01:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709891686; x=1710496486; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=lx3npHykkw1gOdQqXLW5o/F+B78jLU3tilBWulRgUu0=; b=eCh/g4jqDMU+DIb1Xuo1g8UFa5GVdj/eOurzpE/mpP1FGEPS3sUsGP4obd4q3jv0ot Ynuj/+oUSaGg/8tnJx9tpbMj6k+McA5J9dUiuu8DcNz5hGiltVHHO+ekneafIo2ibRVi n9Lugq8Bl+Ylthl0D0tTCTDiGNd5GsvC0Id2y2i/CK9eEH72RkUoNZ1MMVbqNBUgc/0I bkQhNx8GxFynienzKMMQ6ZoEdzniNdzY4Ib39m8zgfkT5TAZnKcvllhhEQbwSa9oC/D4 GTqUICVsz1b2cfLAk2DOpHsp2JhEbLL43/y/VCTNyO3/KQR87q6vzLZzopl3SLsOHqZF M9VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709891686; x=1710496486; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lx3npHykkw1gOdQqXLW5o/F+B78jLU3tilBWulRgUu0=; b=Bz4UJb4PISRHtTtyfKhH/3uHeNNsZOeYH62EYfphS7QiE6sXOsRaeAr//rDFdi+42B Pg1sSRRaEG1wOFr+juEINd5SFuMmewExqZoeLnMMid2OJndF/+57MVB3/V1IygZnCIZb 5k/wa3uCRYms4nVovBs0snaOTORPIlMMZnqYGVq/jswzTpKvIvnhRLS3zKaMo2LB3Lag PQwoCAF6Pz8DfgISSCqzrZr+ylZZh7O3iFPZDMLb0UknBzbxTVEeZNaSeuDy5NuzFCuf OnfV61gARZpVqGHyQgp38IYwJbnyrXBwxtL/ATAiC2MOqHcJxKv50nZdCAVj2QRK2QUM FZtA== X-Forwarded-Encrypted: i=1; AJvYcCXOdGh1bgpA2CX7qwRB3VcORWFEU28VUPR4Ikpi1drSPejaOK+90I/g0slGPNjDFAzrURmY9rOpdm47oACZT59A7R7MM+Zms7IbZPIo X-Gm-Message-State: AOJu0YzF/ULrOdMRgXUuwm6K+yPGBK7OrjxKRHBnPMdmCrsmei8oIaIw DAupka6vS/JM9FevwAm0c7PqA0EUrL0xAbaqmoqLpGvK4V8b1Lq2 X-Received: by 2002:a17:906:f850:b0:a45:bdc0:7f00 with SMTP id ks16-20020a170906f85000b00a45bdc07f00mr4849698ejb.46.1709891685642; Fri, 08 Mar 2024 01:54:45 -0800 (PST) Received: from skbuf ([2a02:2f04:d207:f600::b2c]) by smtp.gmail.com with ESMTPSA id cm26-20020a170906f59a00b00a3ca56e9bcfsm9199309ejd.187.2024.03.08.01.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 01:54:45 -0800 (PST) Date: Fri, 8 Mar 2024 11:54:42 +0200 From: Vladimir Oltean To: Pawel Dembicki Cc: netdev@vger.kernel.org, Linus Walleij , Simon Horman , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v6 06/16] net: dsa: vsc73xx: add port_stp_state_set function Message-ID: <20240308095442.ug4pmh4entgah5l3@skbuf> References: <20240301221641.159542-1-paweldembicki@gmail.com> <20240301221641.159542-1-paweldembicki@gmail.com> <20240301221641.159542-7-paweldembicki@gmail.com> <20240301221641.159542-7-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240301221641.159542-7-paweldembicki@gmail.com> <20240301221641.159542-7-paweldembicki@gmail.com> On Fri, Mar 01, 2024 at 11:16:28PM +0100, Pawel Dembicki wrote: > This isn't a fully functional implementation of 802.1D, but > port_stp_state_set is required for a future tag8021q operations. > > This implementation handles properly all states, but vsc73xx doesn't > forward STP packets. > > Signed-off-by: Pawel Dembicki > --- > v6: > - fix inconsistent indenting > v5: > - remove unneeded 'RECVMASK' operations > - reorganise vsc73xx_refresh_fwd_map function > v4: > - fully reworked port_stp_state_set > v3: > - use 'VSC73XX_MAX_NUM_PORTS' define > - add 'state == BR_STATE_DISABLED' condition > - fix style issues > v2: > - fix kdoc > > drivers/net/dsa/vitesse-vsc73xx-core.c | 99 +++++++++++++++++++++++--- > 1 file changed, 88 insertions(+), 11 deletions(-) > > diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c > index 425999d7bf41..d1e84a9a83d1 100644 > --- a/drivers/net/dsa/vitesse-vsc73xx-core.c > +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c > @@ -1036,6 +1029,89 @@ static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, > config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000; > } > > +static void vsc73xx_refresh_fwd_map(struct dsa_switch *ds, int port, u8 state) > +{ > + struct dsa_port *other_dp, *dp = dsa_to_port(ds, port); > + struct vsc73xx *vsc = ds->priv; > + u16 mask; > + > + if (state != BR_STATE_FORWARDING) { > + /* Ports that aren't in the forwarding state must not > + * forward packets anywhere. > + */ > + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, > + VSC73XX_SRCMASKS + port, > + VSC73XX_SRCMASKS_PORTS_MASK, 0); > + > + dsa_switch_for_each_available_port(other_dp, ds) { > + if (other_dp == dp) > + continue; > + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, > + VSC73XX_SRCMASKS + other_dp->index, > + BIT(port), 0); > + } > + > + return; > + } > + > + /* Forwarding ports must forward to the CPU and to other ports > + * in the same bridge > + */ > + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, > + VSC73XX_SRCMASKS + CPU_PORT, BIT(port), BIT(port)); > + > + mask = BIT(CPU_PORT); > + > + if (dp->bridge) { > + dsa_switch_for_each_user_port(other_dp, ds) { > + if (other_dp->bridge == dp->bridge && You could use dsa_port_bridge_same(dp, other_dp) and that could eliminate the extra "if (dp->bridge)" condition, because it explicitly makes standalone ports isolated from other standalone ports. > + other_dp->index != port && You could move the "int other_port" definition to dsa_switch_for_each_user_port() scope, and thus reuse it here. > + other_dp->stp_state == BR_STATE_FORWARDING) { You could "continue" on the negated condition, and reduce the indentation one level further. > + int other_port = other_dp->index; > + > + mask |= BIT(other_port); > + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, > + 0, > + VSC73XX_SRCMASKS + > + other_port, > + BIT(port), BIT(port)); > + } > + } > + } All in all, I would have written this as: dsa_switch_for_each_user_port(other_dp, ds) { int other_port = other_dp->index; if (port == other_port || !dsa_port_bridge_same(dp, other_dp) || other_dp->stp_state != BR_STATE_FORWARDING) continue; mask |= BIT(other_port); vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_SRCMASKS + other_port, BIT(port), BIT(port)); } Anyway this does not affect functionality, and it is up to you if you integrate these suggestions or not. Reviewed-by: Vladimir Oltean > + > + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, > + VSC73XX_SRCMASKS + port, > + VSC73XX_SRCMASKS_PORTS_MASK, mask); > +}