From patchwork Sat Jul 13 05:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732309 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 7DC8028689; Sat, 13 Jul 2024 05:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850098; cv=none; b=Yhc226NH+GOw4cf4P4WYzyKvO9mMkbC/sUiA1EgMPueYRBw4W0sUB8DC2aDtCI577me6rzDq3b7duzHix98m0BCXYLZKPEQdI11EMsAVYA5avSHP9gOZ5ZHlUsJVu4YSjELmpSbEki75EEs7qMu+K2z12h1Ov7bymRfmPBEiimI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850098; c=relaxed/simple; bh=ciKXY3w0l37EQqP4vMf+BolN4hHfiiZLJVh+t8wqZ8s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=usfDzfFoPJ8g8NJZmGnSbSyEoS3usOEKUfPwG+RoKBuRAazYOVuHccLwtYFMPNubhyisOED388jUEUQ67Fi1bRu9t/rnH6m3RYaGeK0WyzYZf+7hyn/Wye7mm7EB58N/q6rq+ZOIA1ffkxhJ5LxCUmk3K4KvAwiRO6BjbBPtDfs= 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=cRR6ofUQ; arc=none smtp.client-ip=209.85.167.54 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cRR6ofUQ" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-52ea79e689eso3783114e87.1; Fri, 12 Jul 2024 22:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850094; x=1721454894; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/2+5DQMVD0/GEw7pjfq2huiSdFh+Bq9HPXGf/oU8NU4=; b=cRR6ofUQ9NASccqdltUNO6bbNcLrFXGHb+8APdAgs+wywQN0ddh5OOYvClDplsqY+M TigfA1Ub+eds43O/78qaDhMPvufZWELp5zt5md1xdssvFG+L8+FErz+p94IeDeINBIcf mjX4iOIuE5wFbpyxt4x8GjLlnWH10ov1zY4i0uZMIxEqAs1WyRKUgygJ9eaizxJQwUeV LcomS1pllyKd3u1Aq2Yle0LTtJjkQhdTqXn2wI7uM/P3WWqLjL3IKPNdAdJ/qNI0DJOf YJ4DEVD/y2bxAMKE8s+ZnfhMuFvr0GFFU5e2KT0PI7axKNYaTstUtnl1ZNenHXt8SKNb +jWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850094; x=1721454894; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/2+5DQMVD0/GEw7pjfq2huiSdFh+Bq9HPXGf/oU8NU4=; b=LHKkv4yjDdVD/QKzhIKDU/NoMSlsWJ+4N36OBmHyncfSvTNRN1hugEOcVGVhut+4Sm 8OaapiyNrtW/7bftoaWQzkxj3dU0ArLbPknO00XSnF0ywTAAC7YlyY/czz0oPTcDNva8 6HF9DRUmrEOSqpEuwCFF33VJkQJUtUCOE7bXUuhimTus6+2Ov/N+HCB32vmnN9892xVk QyuXsYSSbbb5wemaRE0D02BTEbR4cBp8c0RHbjWrv6jmesdbWkXxwooBMbutYrAPG+O8 5d7xtWsEMcaevgO4FVE+XT7NfRibhEUQSAPFeE1iYqmiHBzPl+wlc1172EoW8XjV8oBk sy6g== X-Forwarded-Encrypted: i=1; AJvYcCVqWZWrVTTmGyhrmrKz3v7m+jbvoZEvJnXSpP0NUgFcWkBnWW62iqVyKVwTQkJm2GG4txC42G3SKQVJPoM97eeYl4JAu5VDr1VkVlaT X-Gm-Message-State: AOJu0YxjyOKrMUNcVuVYSU5GsmXc0oMxE2ru10FTHPtCGKaz69+KEN83 HFqQN4jk4pxQ1HyLKRMSNHJQNYCe4xyQXUlQ+rY0FpepEqTe8TCOLjeUO867 X-Google-Smtp-Source: AGHT+IEww7OeiVhAWHuJgiO+70NnoRorIlMCULoyeiiqigSbBbD+Kd/mZ/dmDizPftTzh8CiqxtpoQ== X-Received: by 2002:a05:6512:4016:b0:52e:d0f8:2d43 with SMTP id 2adb3069b0e04-52ed0f82f09mr1143455e87.17.1720850093856; Fri, 12 Jul 2024 22:54:53 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:54:53 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Pawel Dembicki , Linus Walleij , Florian Fainelli , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 01/12] net: dsa: vsc73xx: add port_stp_state_set function Date: Sat, 13 Jul 2024 07:54:29 +0200 Message-Id: <20240713055443.1112925-2-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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. Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli Reviewed-by: Vladimir Oltean Signed-off-by: Pawel Dembicki --- v3,v2,v1: - resend only --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v7: - implement 'vsc73xx_refresh_fwd_map' simplification 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 | 96 +++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 11 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 4b031fefcec6..ebeea259f019 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -164,6 +164,10 @@ #define VSC73XX_AGENCTRL 0xf0 #define VSC73XX_CAPRST 0xff +#define VSC73XX_SRCMASKS_CPU_COPY BIT(27) +#define VSC73XX_SRCMASKS_MIRROR BIT(26) +#define VSC73XX_SRCMASKS_PORTS_MASK GENMASK(7, 0) + #define VSC73XX_MACACCESS_CPU_COPY BIT(14) #define VSC73XX_MACACCESS_FWD_KILL BIT(13) #define VSC73XX_MACACCESS_IGNORE_VLAN BIT(12) @@ -623,9 +627,6 @@ static int vsc73xx_setup(struct dsa_switch *ds) vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GMIIDELAY, VSC73XX_GMIIDELAY_GMII0_GTXDELAY_2_0_NS | VSC73XX_GMIIDELAY_GMII0_RXDELAY_2_0_NS); - /* Enable reception of frames on all ports */ - vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_RECVMASK, - 0x5f); /* IP multicast flood mask (table 144) */ vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_IFLODMSK, 0xff); @@ -788,10 +789,6 @@ static void vsc73xx_mac_link_down(struct phylink_config *config, /* Allow backward dropping of frames from this port */ vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, VSC73XX_SBACKWDROP, BIT(port), BIT(port)); - - /* Receive mask (disable forwarding) */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, - VSC73XX_RECVMASK, BIT(port), 0); } static void vsc73xx_mac_link_up(struct phylink_config *config, @@ -844,10 +841,6 @@ static void vsc73xx_mac_link_up(struct phylink_config *config, vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, VSC73XX_ARBDISC, BIT(port), 0); - /* Enable port (forwarding) in the receive mask */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, - VSC73XX_RECVMASK, BIT(port), BIT(port)); - /* Disallow backward dropping of frames from this port */ vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, VSC73XX_SBACKWDROP, BIT(port), 0); @@ -1039,6 +1032,86 @@ 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); + + 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)); + } + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_SRCMASKS + port, + VSC73XX_SRCMASKS_PORTS_MASK, mask); +} + +/* FIXME: STP frames aren't forwarded at this moment. BPDU frames are + * forwarded only from and to PI/SI interface. For more info see chapter + * 2.7.1 (CPU Forwarding) in datasheet. + * This function is required for tag_8021q operations. + */ +static void vsc73xx_port_stp_state_set(struct dsa_switch *ds, int port, + u8 state) +{ + struct vsc73xx *vsc = ds->priv; + u32 val; + + val = (state == BR_STATE_BLOCKING || state == BR_STATE_DISABLED) ? + 0 : BIT(port); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_RECVMASK, BIT(port), val); + + val = (state == BR_STATE_LEARNING || state == BR_STATE_FORWARDING) ? + BIT(port) : 0; + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_LEARNMASK, BIT(port), val); + + /* CPU Port should always forward packets when user ports are forwarding + * so let's configure it from other ports only. + */ + if (port != CPU_PORT) + vsc73xx_refresh_fwd_map(ds, port, state); +} + static const struct phylink_mac_ops vsc73xx_phylink_mac_ops = { .mac_config = vsc73xx_mac_config, .mac_link_down = vsc73xx_mac_link_down, @@ -1057,6 +1130,7 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_disable = vsc73xx_port_disable, .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, + .port_stp_state_set = vsc73xx_port_stp_state_set, .phylink_get_caps = vsc73xx_phylink_get_caps, }; From patchwork Sat Jul 13 05:54:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732310 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 9C49939FC1; Sat, 13 Jul 2024 05:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850102; cv=none; b=ZigGSBTRlm9u+mbLiuqWT+lyFnP5kR7dLsKRXO7AMvk/nmeQMpdlBptWmVD7/V5u20md+XaKgI3dyo1aF8IxkJbQnDw9U5/c+NrHVKG3WixW+o/wVM3Cvn8b40HY3TooJea5VrsWuvTFHaryJP8+pKA4T6rkRddTrRroNwOfx48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850102; c=relaxed/simple; bh=U7YGs1qbGrXvM+vRPMcObJwPPLFxWim1DRgCZHnsDIM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kehWNFF0Qs+b0ILLoSyMuAwg6hH0J1t2Mooofdj3yZIihjzbhIGcxO6pwZITLnMc+kUfzrUKhpDeFGls59lyI+oT8nOw1rWOzGld5NA7n5DYRpzJlSxmoh7/337r8j1ZVE4Nk/KnW1PeChYbWsFeglgQrMMfZ+SAbkB8OXxNIdA= 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=HEKNAjns; arc=none smtp.client-ip=209.85.218.46 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HEKNAjns" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a728f74c23dso378155966b.1; Fri, 12 Jul 2024 22:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850098; x=1721454898; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NoWaoH8/bqshrbpUaCo/UUmjcwP47ofx9dWBzTyeYfA=; b=HEKNAjns6NQxSuUq6Vcmq9WA/wUjK0b4FcwZcsNCLb2HYF24W4JE7Lkyb3bx6OYsIO 9ykyRXLYDLY8c5WbX8WBYTzXKgCFqnfe4hPEd1S+pftwaLxJKppyp9D2zLxzya3v76Hx pGJbcqq2Np01pcB+oxDzCdqh+KIe6+z/4fC09LZ/GfNzlKADmXJkB0WcS3dVIiYV/eOt gRXJlqJPSAEBgbErqBMlAZ760TMYxm8AUnHdH2pU0OHVx7sgTxKxuVlkT/8fNgKRJ8Cu PLmrjGc3KAITRLUw8mGP2gMzJIP6+dDkiXI7JizkyqamfUs3U+Rpc/lyxQusm5fUdQL6 RqKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850098; x=1721454898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NoWaoH8/bqshrbpUaCo/UUmjcwP47ofx9dWBzTyeYfA=; b=vI4pwOZE4uL9nJgSmRPfU6DQ0r2kLdl61YizluOgxrXPeQHUz1flDzG0AYEdFawMcA Dqh6kSr6vpIAGcPgRxdaQN2XcRP/Qrll2qlg7WHNLPTLcXB+mR9VXVlFkYTqInxxdnFm NRVp+BlPWklA+8CtT5apL/mD34SwJ8F0Urnuf4VX4MiDhrMJz0VECN6hKdx8B/4G6d5H PUDdvS7Hh7YgQHqHXGeiFB4USF3r0V3u1sIQOZPo/p1+vq6boSIZE5avJ0uWuJj5gpG5 5lk1EJoyYwxXFw93dHRiHRURolfw0JNLqR8eIA6whFQGKCOMRPQiPrUisFHitjgj2MAF h7hw== X-Forwarded-Encrypted: i=1; AJvYcCVLMM+aD8vrJurzSKZcCoihC6q6kV03y4l3B9zyWaTMY4dGyPX38bWjUX7jFRezsZWzFb5gaGnrt/QAnlUysW8C7zQSTAtNLegpnpRA X-Gm-Message-State: AOJu0YyoLuuFwAN4ecOxZWIVUzmYRNnBVQahGi97E/QGzs70nfZPCfX9 UZ2UYF2s51ehARZGm/A6erVNWRXKb3mvIAbF7k3LyEFcmBU7yucYXW3uQV67 X-Google-Smtp-Source: AGHT+IFiMzStl0jxFXAastZQR6UgYN00Fsd7ykwFzTlmCsvh5N6ApK1sN26Ln3Jgb/llCvFwAZ5nYw== X-Received: by 2002:a17:907:720c:b0:a77:d880:2c91 with SMTP id a640c23a62f3a-a780b68873amr1181913266b.16.1720850097573; Fri, 12 Jul 2024 22:54:57 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:54:57 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 02/12] net: dsa: vsc73xx: Add vlan filtering Date: Sat, 13 Jul 2024 07:54:30 +0200 Message-Id: <20240713055443.1112925-3-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This patch implements VLAN filtering for the vsc73xx driver. After starting VLAN filtering, the switch is reconfigured from QinQ to a simple VLAN aware mode. This is required because VSC73XX chips do not support inner VLAN tag filtering. Signed-off-by: Pawel Dembicki --- v3: - added kdoc descriptions of some functions - fixed typos - modified 'vsc73xx_vlan_commit_untagged' implementation - introduce 'vsc73xx_vlan_commit_settings' - removed unnescessary 'portinfo' value initialization - CPU_PORT is now addded to VLAN map - removed 'untagged_tag_8021q' from 'portinfo' - removed unnescessary 'port_setup' implementation v2: - removed not needed INIT_LIST_HEAD - fix vsc73xx_vlan removing procedure - fix code spell - handle return codes from 'vsc73xx_vlan_commit*' functions - move 'vsc73xx_vlan_commit*' call from port_setup to port_enable to avoid unused port configuration v1: - refactored pvid, untagged and vlan filter configuration - fix typo - simplification --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8: - set init value of 'ret' in 'vsc73xx_port_vlan_add' v7: - rework pvid and untagged configuration routines - introduce portinfo structure which should make pvid/untagged procedures simpler - introduce 'vsc73xx_vlan_summary' structure - replace tagged/untagged count functions with 'vsc73xx_bridge_vlan_summary' - fix VSC73XX_VLANMASK configuration. It was copy from existing code. - stop configuring pvid/untagged registers whed pvid/untagged is disabled v6: - resend only v5: - fix possible leak in 'vsc73xx_port_vlan_add' - use proper variable in statement from 'vsc73xx_port_vlan_filtering' - change 'vlan_no' name to 'vid' - codding style improvements - comment improvements - handle return of 'vsc73xx_update_bits' - reduce I/O operations - use 'size_t' for counting variables v4: - reworked most of conditional register configs - simplified port_vlan function - move vlan table clearing from port_setup to setup - pvid configuration simplified (now kernel take care about no of pvids per port) - port vlans are stored in list now - introduce implementation of all untagged vlans state - many minor changes v3: - reworked all vlan commits - added storage variables for pvid and untagged vlans - move length extender settings to port setup - remove vlan table cleaning in wrong places v2: - no changes done --- drivers/net/dsa/vitesse-vsc73xx-core.c | 526 ++++++++++++++++++++++++- drivers/net/dsa/vitesse-vsc73xx.h | 37 ++ 2 files changed, 560 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index ebeea259f019..57a6f34805bd 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -22,9 +22,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -62,6 +64,8 @@ #define VSC73XX_CAT_DROP 0x6e #define VSC73XX_CAT_PR_MISC_L2 0x6f #define VSC73XX_CAT_PR_USR_PRIO 0x75 +#define VSC73XX_CAT_VLAN_MISC 0x79 +#define VSC73XX_CAT_PORT_VLAN 0x7a #define VSC73XX_Q_MISC_CONF 0xdf /* MAC_CFG register bits */ @@ -122,6 +126,17 @@ #define VSC73XX_ADVPORTM_IO_LOOPBACK BIT(1) #define VSC73XX_ADVPORTM_HOST_LOOPBACK BIT(0) +/* TXUPDCFG transmit modify setup bits */ +#define VSC73XX_TXUPDCFG_DSCP_REWR_MODE GENMASK(20, 19) +#define VSC73XX_TXUPDCFG_DSCP_REWR_ENA BIT(18) +#define VSC73XX_TXUPDCFG_TX_INT_TO_USRPRIO_ENA BIT(17) +#define VSC73XX_TXUPDCFG_TX_UNTAGGED_VID GENMASK(15, 4) +#define VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA BIT(3) +#define VSC73XX_TXUPDCFG_TX_UPDATE_CRC_CPU_ENA BIT(1) +#define VSC73XX_TXUPDCFG_TX_INSERT_TAG BIT(0) + +#define VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_SHIFT 4 + /* CAT_DROP categorizer frame dropping register bits */ #define VSC73XX_CAT_DROP_DROP_MC_SMAC_ENA BIT(6) #define VSC73XX_CAT_DROP_FWD_CTRL_ENA BIT(4) @@ -135,6 +150,15 @@ #define VSC73XX_Q_MISC_CONF_EARLY_TX_512 (1 << 1) #define VSC73XX_Q_MISC_CONF_MAC_PAUSE_MODE BIT(0) +/* CAT_VLAN_MISC categorizer VLAN miscellaneous bits */ +#define VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA BIT(8) +#define VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA BIT(7) + +/* CAT_PORT_VLAN categorizer port VLAN */ +#define VSC73XX_CAT_PORT_VLAN_VLAN_CFI BIT(15) +#define VSC73XX_CAT_PORT_VLAN_VLAN_USR_PRIO GENMASK(14, 12) +#define VSC73XX_CAT_PORT_VLAN_VLAN_VID GENMASK(11, 0) + /* Frame analyzer block 2 registers */ #define VSC73XX_STORMLIMIT 0x02 #define VSC73XX_ADVLEARN 0x03 @@ -189,7 +213,8 @@ #define VSC73XX_VLANACCESS_VLAN_MIRROR BIT(29) #define VSC73XX_VLANACCESS_VLAN_SRC_CHECK BIT(28) #define VSC73XX_VLANACCESS_VLAN_PORT_MASK GENMASK(9, 2) -#define VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK GENMASK(2, 0) +#define VSC73XX_VLANACCESS_VLAN_PORT_MASK_SHIFT 2 +#define VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK GENMASK(1, 0) #define VSC73XX_VLANACCESS_VLAN_TBL_CMD_IDLE 0 #define VSC73XX_VLANACCESS_VLAN_TBL_CMD_READ_ENTRY 1 #define VSC73XX_VLANACCESS_VLAN_TBL_CMD_WRITE_ENTRY 2 @@ -347,6 +372,17 @@ static const struct vsc73xx_counter vsc73xx_tx_counters[] = { { 29, "TxQoSClass3" }, /* non-standard counter */ }; +struct vsc73xx_vlan_summary { + size_t num_tagged; + size_t num_untagged; +}; + +enum vsc73xx_port_vlan_conf { + VSC73XX_VLAN_FILTER, + VSC73XX_VLAN_FILTER_UNTAG_ALL, + VSC73XX_VLAN_IGNORE, +}; + int vsc73xx_is_addr_valid(u8 block, u8 subblock) { switch (block) { @@ -564,6 +600,90 @@ static enum dsa_tag_protocol vsc73xx_get_tag_protocol(struct dsa_switch *ds, return DSA_TAG_PROTO_NONE; } +static int vsc73xx_wait_for_vlan_table_cmd(struct vsc73xx *vsc) +{ + int ret, err; + u32 val; + + ret = read_poll_timeout(vsc73xx_read, err, + err < 0 || + ((val & VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK) == + VSC73XX_VLANACCESS_VLAN_TBL_CMD_IDLE), + VSC73XX_POLL_SLEEP_US, VSC73XX_POLL_TIMEOUT_US, + false, vsc, VSC73XX_BLOCK_ANALYZER, + 0, VSC73XX_VLANACCESS, &val); + if (ret) + return ret; + return err; +} + +static int +vsc73xx_read_vlan_table_entry(struct vsc73xx *vsc, u16 vid, u8 *portmap) +{ + u32 val; + int ret; + + vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANTIDX, vid); + + ret = vsc73xx_wait_for_vlan_table_cmd(vsc); + if (ret) + return ret; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANACCESS, + VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK, + VSC73XX_VLANACCESS_VLAN_TBL_CMD_READ_ENTRY); + + ret = vsc73xx_wait_for_vlan_table_cmd(vsc); + if (ret) + return ret; + + vsc73xx_read(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANACCESS, &val); + *portmap = (val & VSC73XX_VLANACCESS_VLAN_PORT_MASK) >> + VSC73XX_VLANACCESS_VLAN_PORT_MASK_SHIFT; + + return 0; +} + +static int +vsc73xx_write_vlan_table_entry(struct vsc73xx *vsc, u16 vid, u8 portmap) +{ + int ret; + + vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANTIDX, vid); + + ret = vsc73xx_wait_for_vlan_table_cmd(vsc); + if (ret) + return ret; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANACCESS, + VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK | + VSC73XX_VLANACCESS_VLAN_SRC_CHECK | + VSC73XX_VLANACCESS_VLAN_PORT_MASK, + VSC73XX_VLANACCESS_VLAN_TBL_CMD_WRITE_ENTRY | + VSC73XX_VLANACCESS_VLAN_SRC_CHECK | + (portmap << VSC73XX_VLANACCESS_VLAN_PORT_MASK_SHIFT)); + + return vsc73xx_wait_for_vlan_table_cmd(vsc); +} + +static int +vsc73xx_update_vlan_table(struct vsc73xx *vsc, int port, u16 vid, bool set) +{ + u8 portmap; + int ret; + + ret = vsc73xx_read_vlan_table_entry(vsc, vid, &portmap); + if (ret) + return ret; + + if (set) + portmap |= BIT(port); + else + portmap &= ~BIT(port); + + return vsc73xx_write_vlan_table_entry(vsc, vid, portmap); +} + static int vsc73xx_setup(struct dsa_switch *ds) { struct vsc73xx *vsc = ds->priv; @@ -598,7 +718,7 @@ static int vsc73xx_setup(struct dsa_switch *ds) VSC73XX_MACACCESS, VSC73XX_MACACCESS_CMD_CLEAR_TABLE); - /* Clear VLAN table */ + /* Set VLAN table to default values */ vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANACCESS, VSC73XX_VLANACCESS_VLAN_TBL_CMD_CLEAR_TABLE); @@ -627,6 +747,9 @@ static int vsc73xx_setup(struct dsa_switch *ds) vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GMIIDELAY, VSC73XX_GMIIDELAY_GMII0_GTXDELAY_2_0_NS | VSC73XX_GMIIDELAY_GMII0_RXDELAY_2_0_NS); + /* Ingess VLAN reception mask (table 145) */ + vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANMASK, + 0xff); /* IP multicast flood mask (table 144) */ vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_IFLODMSK, 0xff); @@ -639,6 +762,12 @@ static int vsc73xx_setup(struct dsa_switch *ds) udelay(4); + /* Clear VLAN table */ + for (i = 0; i < VLAN_N_VID; i++) + vsc73xx_write_vlan_table_entry(vsc, i, 0); + + INIT_LIST_HEAD(&vsc->vlans); + return 0; } @@ -825,6 +954,12 @@ static void vsc73xx_mac_link_up(struct phylink_config *config, val |= seed << VSC73XX_MAC_CFG_SEED_OFFSET; val |= VSC73XX_MAC_CFG_SEED_LOAD; val |= VSC73XX_MAC_CFG_WEXC_DIS; + + /* Those bits are responsible for MTU only. Kernel takes care about MTU, + * let's enable +8 bytes frame length unconditionally. + */ + val |= VSC73XX_MAC_CFG_VLAN_AWR | VSC73XX_MAC_CFG_VLAN_DBLAWR; + vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, val); /* Flow control for the PHY facing ports: @@ -853,6 +988,251 @@ static void vsc73xx_mac_link_up(struct phylink_config *config, VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN); } +static bool vsc73xx_tag_8021q_active(struct dsa_port *dp) +{ + return !dsa_port_is_vlan_filtering(dp); +} + +static struct vsc73xx_bridge_vlan * +vsc73xx_bridge_vlan_find(struct vsc73xx *vsc, u16 vid) +{ + struct vsc73xx_bridge_vlan *vlan; + + list_for_each_entry(vlan, &vsc->vlans, list) + if (vlan->vid == vid) + return vlan; + + return NULL; +} + +static void +vsc73xx_bridge_vlan_remove_port(struct vsc73xx_bridge_vlan *vsc73xx_vlan, + int port) +{ + vsc73xx_vlan->portmask &= ~BIT(port); + + if (vsc73xx_vlan->portmask) + return; + + list_del(&vsc73xx_vlan->list); + kfree(vsc73xx_vlan); +} + +static void vsc73xx_bridge_vlan_summary(struct vsc73xx *vsc, int port, + struct vsc73xx_vlan_summary *summary, + u16 ignored_vid) +{ + size_t num_tagged = 0, num_untagged = 0; + struct vsc73xx_bridge_vlan *vlan; + + list_for_each_entry(vlan, &vsc->vlans, list) { + if (!(vlan->portmask & BIT(port)) || vlan->vid == ignored_vid) + continue; + + if (vlan->untagged & BIT(port)) + num_untagged++; + else + num_tagged++; + } + + summary->num_untagged = num_untagged; + summary->num_tagged = num_tagged; +} + +static u16 vsc73xx_find_first_vlan_untagged(struct vsc73xx *vsc, int port) +{ + struct vsc73xx_bridge_vlan *vlan; + + list_for_each_entry(vlan, &vsc->vlans, list) + if ((vlan->portmask & BIT(port)) && + (vlan->untagged & BIT(port))) + return vlan->vid; + + return VLAN_N_VID; +} + +static int vsc73xx_set_vlan_conf(struct vsc73xx *vsc, int port, + enum vsc73xx_port_vlan_conf port_vlan_conf) +{ + u32 val = 0; + int ret; + + if (port_vlan_conf == VSC73XX_VLAN_IGNORE) + val = VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA | + VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA; + + ret = vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_CAT_VLAN_MISC, + VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA | + VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA, val); + if (ret) + return ret; + + val = (port_vlan_conf == VSC73XX_VLAN_FILTER) ? + VSC73XX_TXUPDCFG_TX_INSERT_TAG : 0; + + return vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_TXUPDCFG, + VSC73XX_TXUPDCFG_TX_INSERT_TAG, val); +} + +/** + * vsc73xx_vlan_commit_conf - Update VLAN configuration of a port + * @vsc: Switch private data structure + * @port: Port index on which to operate + * + * Update the VLAN behavior of a port to make sure that when it is under + * a VLAN filtering bridge, the port is either filtering with tag + * preservation, or filtering with all VLANs egress-untagged. Otherwise, + * the port ignores VLAN tags from packets and applies the port-based + * VID. + * + * Must be called when changes are made to: + * - the bridge VLAN filtering state of the port + * - the number or attributes of VLANs from the bridge VLAN table, + * while the port is currently VLAN-aware + */ +static int vsc73xx_vlan_commit_conf(struct vsc73xx *vsc, int port) +{ + enum vsc73xx_port_vlan_conf port_vlan_conf = VSC73XX_VLAN_IGNORE; + struct dsa_port *dp = dsa_to_port(vsc->ds, port); + + if (port == CPU_PORT) { + port_vlan_conf = VSC73XX_VLAN_FILTER; + } else if (dsa_port_is_vlan_filtering(dp)) { + struct vsc73xx_vlan_summary summary; + + port_vlan_conf = VSC73XX_VLAN_FILTER; + + vsc73xx_bridge_vlan_summary(vsc, port, &summary, VLAN_N_VID); + if (summary.num_tagged == 0) + port_vlan_conf = VSC73XX_VLAN_FILTER_UNTAG_ALL; + } + + return vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf); +} + +static int +vsc73xx_vlan_change_untagged(struct vsc73xx *vsc, int port, u16 vid, bool set) +{ + u32 val = 0; + + if (set) + val = VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA | + ((vid << VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_SHIFT) & + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID); + + return vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_TXUPDCFG, + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA | + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID, val); +} + +/** + * vsc73xx_vlan_commit_untagged - Update native VLAN of a port + * @vsc: Switch private data structure + * @port: Port index on which to operate + * + * Update the native VLAN of a port (the one VLAN which is transmitted + * as egress-tagged on a trunk port) when port is in VLAN filtering mode and + * only one untagged vid is configured. + * In other cases no need to configure it because switch can untag all vlans on + * the port. + */ +static int vsc73xx_vlan_commit_untagged(struct vsc73xx *vsc, int port) +{ + struct dsa_port *dp = dsa_to_port(vsc->ds, port); + struct vsc73xx_vlan_summary summary; + u16 vid = 0; + bool valid; + + if (!dsa_port_is_vlan_filtering(dp)) + /* Port is configured to untag all vlans in that case. + * No need to commit untagged config change. + */ + return 0; + + vsc73xx_bridge_vlan_summary(vsc, port, &summary, VLAN_N_VID); + + if (summary.num_untagged > 1) + /* Port must untag all vlans in that case. + * No need to commit untagged config change. + */ + return 0; + + valid = (summary.num_untagged == 1); + if (valid) + vid = vsc73xx_find_first_vlan_untagged(vsc, port); + + return vsc73xx_vlan_change_untagged(vsc, port, vid, valid); +} + +static int +vsc73xx_vlan_change_pvid(struct vsc73xx *vsc, int port, u16 vid, bool set) +{ + u32 val = 0; + int ret; + + val = set ? 0 : VSC73XX_CAT_DROP_UNTAGGED_ENA; + + ret = vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_CAT_DROP, + VSC73XX_CAT_DROP_UNTAGGED_ENA, val); + if (!set || ret) + return ret; + + return vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_CAT_PORT_VLAN, + VSC73XX_CAT_PORT_VLAN_VLAN_VID, + vid & VSC73XX_CAT_PORT_VLAN_VLAN_VID); +} + +/** + * vsc73xx_vlan_commit_pvid - Update port-based default VLAN of a port + * @vsc: Switch private data structure + * @port: Port index on which to operate + * + * Update the PVID of a port so that it follows either the bridge PVID + * configuration, when the bridge is currently VLAN-aware, or the PVID + * from tag_8021q, when the port is standalone or under a VLAN-unaware + * bridge. A port with no PVID drops all untagged and VID 0 tagged + * traffic. + * + * Must be called when changes are made to: + * - the bridge VLAN filtering state of the port + * - the number or attributes of VLANs from the bridge VLAN table, + * while the port is currently VLAN-aware + */ +static int vsc73xx_vlan_commit_pvid(struct vsc73xx *vsc, int port) +{ + struct vsc73xx_portinfo *portinfo = &vsc->portinfo[port]; + bool valid = portinfo->pvid_tag_8021q_configured; + struct dsa_port *dp = dsa_to_port(vsc->ds, port); + u16 vid = portinfo->pvid_tag_8021q; + + if (dsa_port_is_vlan_filtering(dp)) { + vid = portinfo->pvid_vlan_filtering; + valid = portinfo->pvid_vlan_filtering_configured; + } + + return vsc73xx_vlan_change_pvid(vsc, port, vid, valid); +} + +static int vsc73xx_vlan_commit_settings(struct vsc73xx *vsc, int port) +{ + int ret; + + ret = vsc73xx_vlan_commit_untagged(vsc, port); + if (ret) + return ret; + + ret = vsc73xx_vlan_commit_pvid(vsc, port); + if (ret) + return ret; + + return vsc73xx_vlan_commit_conf(vsc, port); +} + static int vsc73xx_port_enable(struct dsa_switch *ds, int port, struct phy_device *phy) { @@ -861,7 +1241,7 @@ static int vsc73xx_port_enable(struct dsa_switch *ds, int port, dev_info(vsc->dev, "enable port %d\n", port); vsc73xx_init_port(vsc, port); - return 0; + return vsc73xx_vlan_commit_settings(vsc, port); } static void vsc73xx_port_disable(struct dsa_switch *ds, int port) @@ -1032,6 +1412,143 @@ 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 int +vsc73xx_port_vlan_filtering(struct dsa_switch *ds, int port, + bool vlan_filtering, struct netlink_ext_ack *extack) +{ + struct vsc73xx *vsc = ds->priv; + + /* The commit to hardware processed below is required because vsc73xx + * is using tag_8021q. When vlan_filtering is disabled, tag_8021q uses + * pvid/untagged vlans for port recognition. The values configured for + * vlans and pvid/untagged states are stored in portinfo structure. + * When vlan_filtering is enabled, we need to restore pvid/untagged from + * portinfo structure. Analogous routine is processed when + * vlan_filtering is disabled, but values used for tag_8021q are + * restored. + */ + + return vsc73xx_vlan_commit_settings(vsc, port); +} + +static int vsc73xx_port_vlan_add(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack) +{ + bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; + bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; + struct dsa_port *dp = dsa_to_port(ds, port); + struct vsc73xx_bridge_vlan *vsc73xx_vlan; + struct vsc73xx_vlan_summary summary; + struct vsc73xx_portinfo *portinfo; + struct vsc73xx *vsc = ds->priv; + bool commit_to_hardware; + int ret = 0; + + /* Be sure to deny alterations to the configuration done by tag_8021q. + */ + if (vid_is_dsa_8021q(vlan->vid)) { + NL_SET_ERR_MSG_MOD(extack, + "Range 3072-4095 reserved for dsa_8021q operation"); + return -EBUSY; + } + + /* The processed vlan->vid is excluded from the search because the VLAN + * can be re-added with a different set of flags, so it's easiest to + * ignore its old flags from the VLAN database software copy. + */ + vsc73xx_bridge_vlan_summary(vsc, port, &summary, vlan->vid); + + /* VSC73XX allows only three untagged states: none, one or all */ + if ((untagged && summary.num_tagged > 0 && summary.num_untagged > 0) || + (!untagged && summary.num_untagged > 1)) { + NL_SET_ERR_MSG_MOD(extack, + "Port can have only none, one or all untagged vlan"); + return -EBUSY; + } + + vsc73xx_vlan = vsc73xx_bridge_vlan_find(vsc, vlan->vid); + + if (!vsc73xx_vlan) { + vsc73xx_vlan = kzalloc(sizeof(*vsc73xx_vlan), GFP_KERNEL); + if (!vsc73xx_vlan) + return -ENOMEM; + + vsc73xx_vlan->vid = vlan->vid; + + list_add_tail(&vsc73xx_vlan->list, &vsc->vlans); + } + + vsc73xx_vlan->portmask |= BIT(port); + + /* CPU port must be always tagged because source port identification is + * based on tag_8021q. + */ + if (port == CPU_PORT) + goto update_vlan_table; + + if (untagged) + vsc73xx_vlan->untagged |= BIT(port); + else + vsc73xx_vlan->untagged &= ~BIT(port); + + portinfo = &vsc->portinfo[port]; + + if (pvid) { + portinfo->pvid_vlan_filtering_configured = true; + portinfo->pvid_vlan_filtering = vlan->vid; + } else if (portinfo->pvid_vlan_filtering_configured && + portinfo->pvid_vlan_filtering == vlan->vid) { + portinfo->pvid_vlan_filtering_configured = false; + } + + commit_to_hardware = !vsc73xx_tag_8021q_active(dp); + if (commit_to_hardware) { + ret = vsc73xx_vlan_commit_settings(vsc, port); + if (ret) + goto err; + } + +update_vlan_table: + ret = vsc73xx_update_vlan_table(vsc, port, vlan->vid, true); + if (!ret) + return 0; +err: + vsc73xx_bridge_vlan_remove_port(vsc73xx_vlan, port); + return ret; +} + +static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan) +{ + struct vsc73xx_bridge_vlan *vsc73xx_vlan; + struct vsc73xx_portinfo *portinfo; + struct vsc73xx *vsc = ds->priv; + bool commit_to_hardware; + int ret; + + ret = vsc73xx_update_vlan_table(vsc, port, vlan->vid, false); + if (ret) + return ret; + + portinfo = &vsc->portinfo[port]; + + if (portinfo->pvid_vlan_filtering_configured && + portinfo->pvid_vlan_filtering == vlan->vid) + portinfo->pvid_vlan_filtering_configured = false; + + vsc73xx_vlan = vsc73xx_bridge_vlan_find(vsc, vlan->vid); + + if (vsc73xx_vlan) + vsc73xx_bridge_vlan_remove_port(vsc73xx_vlan, port); + + commit_to_hardware = !vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + if (commit_to_hardware) + return vsc73xx_vlan_commit_settings(vsc, port); + + return 0; +} + 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); @@ -1131,6 +1648,9 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, .port_stp_state_set = vsc73xx_port_stp_state_set, + .port_vlan_filtering = vsc73xx_port_vlan_filtering, + .port_vlan_add = vsc73xx_port_vlan_add, + .port_vlan_del = vsc73xx_port_vlan_del, .phylink_get_caps = vsc73xx_phylink_get_caps, }; diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vsc73xx.h index 2997f7e108b1..3ca579acc798 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -14,6 +14,22 @@ */ #define VSC73XX_MAX_NUM_PORTS 8 +/** + * struct vsc73xx_portinfo - port data structure: contains storage data + * @pvid_vlan_filtering: pvid vlan number used in vlan filtering mode + * @pvid_tag_8021q: pvid vlan number used in tag_8021q mode + * @pvid_vlan_filtering_configured: informs if port has configured pvid in vlan + * filtering mode + * @pvid_tag_8021q_configured: imforms if port have configured pvid in tag_8021q + * mode + */ +struct vsc73xx_portinfo { + u16 pvid_vlan_filtering; + u16 pvid_tag_8021q; + bool pvid_vlan_filtering_configured; + bool pvid_tag_8021q_configured; +}; + /** * struct vsc73xx - VSC73xx state container: main data structure * @dev: The device pointer @@ -25,6 +41,10 @@ * @addr: MAC address used in flow control frames * @ops: Structure with hardware-dependent operations * @priv: Pointer to the configuration interface structure + * @portinfo: Storage table portinfo structructures + * @vlans: List of configured vlans. Contains port mask and untagged status of + * every vlan configured in port vlan operation. It doesn't cover tag_8021q + * vlans. */ struct vsc73xx { struct device *dev; @@ -35,6 +55,8 @@ struct vsc73xx { u8 addr[ETH_ALEN]; const struct vsc73xx_ops *ops; void *priv; + struct vsc73xx_portinfo portinfo[VSC73XX_MAX_NUM_PORTS]; + struct list_head vlans; }; /** @@ -49,6 +71,21 @@ struct vsc73xx_ops { u32 val); }; +/** + * struct vsc73xx_bridge_vlan - VSC73xx driver structure which keeps vlan + * database copy + * @vid: VLAN number + * @portmask: each bit represents one port + * @untagged: each bit represents one port configured with @vid untagged + * @list: list structure + */ +struct vsc73xx_bridge_vlan { + u16 vid; + u8 portmask; + u8 untagged; + struct list_head list; +}; + int vsc73xx_is_addr_valid(u8 block, u8 subblock); int vsc73xx_probe(struct vsc73xx *vsc); void vsc73xx_remove(struct vsc73xx *vsc); From patchwork Sat Jul 13 05:54:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732311 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 D0C4B3FBAD; Sat, 13 Jul 2024 05:55:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850104; cv=none; b=uSo7/Oujsc+U7/4WCR5AhL/p5ZFJpXXaNoYhON4YgGkPoysB9rwomrMjPUVdGNNoPb7nRYAuKZVMG5UW2kJvWA2eMPMO6wK3225VkxvrTyxYAnMlM7GdWEw099dndSITApQSmS+W/f0tKZxfnIoDYwAJWq79+BVPnPedavdefFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850104; c=relaxed/simple; bh=ariWw2l84P29D94SojqfympP1B3XCadDNE9P7jTomAg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pROcxgnqJ8bqK9fOyJ0XmLQl8KXPwzSCQjI0PNTYJUG2WtixXQpkq5j8nkgssnVVn/6kZWtV4HyCRlS978K9XnSCRjbXvHfkC70LlU8gWluzZuETHF6LWCQh+4uz2K7qvN672JXOFs+TKjO/fmJDqFsfRvV2CBaGExft7cBDxA0= 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=jlideKmo; arc=none smtp.client-ip=209.85.218.45 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jlideKmo" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a6265d3ba8fso316050466b.0; Fri, 12 Jul 2024 22:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850101; x=1721454901; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SQdD+s1FwQwaalZl72MnE8jZWCMAmoOaR5QJrxBTOeA=; b=jlideKmovPGYclMU7EGAJuXXxDS962MgRAFDBdmp+jhwbCNN7RY27GPP2uVUKSdu7/ boZktfTv3bOpGz1RbOzg+PUAdU0EsR6sGpGcK/EXwshjetg1hFti8ibeIJ6BbgT5Fqsl 1zQQBw3VfNb2DilndX392ui0HYhWiaF/tfQj98q00xFVShuQ6Zxwui7HqHPkMfmBv2wU qabpFE2FqMz7cvxF2FbWy1zy2ml7SOzYl826tY1RtH+rJ58tUq5PlcPlKjbkReTs3gox vMCc+0Z0bndBNGuSRuNmuq6fjQ0Wzn1ZQP5AI2Wn3S7JT7KJkLsU6lWqJu7HRDgalIle /ksA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850101; x=1721454901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SQdD+s1FwQwaalZl72MnE8jZWCMAmoOaR5QJrxBTOeA=; b=USbTpOdN7RjdsowrAnmEycex/t40ek2rVhOq3dSERbi2DHeMsDRBK3FUyMODFAnZSp /Hq+AwAsCaSmbyi+5wfGe+97GtGHl6pMgPgOjhZMdvB6xpxnnxn5BhXVSBV0CKfsbd7q IKFOEUP5zqU3WdYfP7FgRLq4FcVTm0x9jk2C05GJiDyFfxqT1PoYeWUq35qXvqatRQcP l4cj9ciIFYFywZYcTI8YbDimVzdtrLN8f76BrQnWfPnC33odn7VNWVyxo7Jjw7CUhGgY NueRfOj0tCfZPPlhD/vQSe9641gCglYJyvxZLiegPNC5K6Ol0Nyk0GDmHMP8mHbb1MN2 q2Yw== X-Forwarded-Encrypted: i=1; AJvYcCWqcolRSy6oHiXCJCdMX9TUEYkZH2WQIF7M28YNgpefJzfXYYw7tHXqD5PlPobnbH8R7cA8lr/sdmycVBKcPp6a4Uws8EWdoDA3sKjd X-Gm-Message-State: AOJu0YwSJDOx5db97/L8RRJ69rBv0TVetxT+ZY2a15o/3SkZjYTX4QGr smPG2tO/rH2uFFxXhI31vUWGV17Eh9mTWbx6Xw8O3N89nmNw4j2j0/CbZaRm X-Google-Smtp-Source: AGHT+IHxGBwr+twjHZpCLXUXnM8+WuFTEy+KNR+kTuMbFy6TED7x/7gUlR5Hs5p1OUZu1NiOkSk6zA== X-Received: by 2002:a17:906:50c:b0:a77:c5e4:eebb with SMTP id a640c23a62f3a-a780b6882b2mr887303666b.1.1720850100945; Fri, 12 Jul 2024 22:55:00 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:00 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Vladimir Oltean , Pawel Dembicki , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 03/12] net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv() Date: Sat, 13 Jul 2024 07:54:31 +0200 Message-Id: <20240713055443.1112925-4-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean In both sja1105_rcv() and sja1110_rcv(), we may have precise source port information coming from parallel hardware mechanisms, in addition to the tag_8021q header. Only sja1105_rcv() has extra logic to not overwrite that precise info with what's present in the VLAN tag. This is because sja1110_rcv() gets by, by having a reversed set of checks when assigning skb->dev. When the source port is imprecise (vbid >=1), source_port and switch_id will be set to zeroes by dsa_8021q_rcv(), which might be problematic. But by checking for vbid >= 1 first, sja1110_rcv() fends that off. We would like to make more code common between sja1105_rcv() and sja1110_rcv(), and for that, we need to make sure that sja1110_rcv() also goes through the precise source port preservation logic. Signed-off-by: Vladimir Oltean Signed-off-by: Pawel Dembicki Reviewed-by: Vladimir Oltean Tested-by: Vladimir Oltean --- v3: - added 'Reviewed-by' and 'Tested-by' only v2,v1: - resend only --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8, v7, v6: - resend only v5: - add missing SoB v4: - introduced patch --- net/dsa/tag_8021q.c | 32 +++++++++++++++++++++++++++++--- net/dsa/tag_sja1105.c | 23 +++-------------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 71b26ae6db39..3cb0293793a5 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -497,9 +497,21 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, } EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); +/** + * dsa_8021q_rcv - Decode source information from tag_8021q header + * @skb: RX socket buffer + * @source_port: pointer to storage for precise source port information. + * If this is known already from outside tag_8021q, the pre-initialized + * value is preserved. If not known, pass -1. + * @switch_id: similar to source_port. + * @vbid: pointer to storage for imprecise bridge ID. Must be pre-initialized + * with -1. If a positive value is returned, the source_port and switch_id + * are invalid. + */ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, int *vbid) { + int tmp_source_port, tmp_switch_id, tmp_vbid; u16 vid, tci; if (skb_vlan_tag_present(skb)) { @@ -513,11 +525,25 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, vid = tci & VLAN_VID_MASK; - *source_port = dsa_8021q_rx_source_port(vid); - *switch_id = dsa_8021q_rx_switch_id(vid); + tmp_source_port = dsa_8021q_rx_source_port(vid); + tmp_switch_id = dsa_8021q_rx_switch_id(vid); + tmp_vbid = dsa_tag_8021q_rx_vbid(vid); + + /* Precise source port information is unknown when receiving from a + * VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id + * are zeroes in this case. + * + * Preserve the source information from hardware-specific mechanisms, + * if available. This allows us to not overwrite a valid source port + * and switch ID with less precise values. + */ + if (tmp_vbid == 0 && *source_port == -1) + *source_port = tmp_source_port; + if (tmp_vbid == 0 && *switch_id == -1) + *switch_id = tmp_switch_id; if (vbid) - *vbid = dsa_tag_8021q_rx_vbid(vid); + *vbid = tmp_vbid; skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; } diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 1aba1d05c27a..48886d4b7e3e 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -524,30 +524,13 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, /* Normal data plane traffic and link-local frames are tagged with * a tag_8021q VLAN which we have to strip */ - if (sja1105_skb_has_tag_8021q(skb)) { - int tmp_source_port = -1, tmp_switch_id = -1; - - sja1105_vlan_rcv(skb, &tmp_source_port, &tmp_switch_id, &vbid, - &vid); - /* Preserve the source information from the INCL_SRCPT option, - * if available. This allows us to not overwrite a valid source - * port and switch ID with zeroes when receiving link-local - * frames from a VLAN-unaware bridged port (non-zero vbid) or a - * VLAN-aware bridged port (non-zero vid). Furthermore, the - * tag_8021q source port information is only of trust when the - * vbid is 0 (precise port). Otherwise, tmp_source_port and - * tmp_switch_id will be zeroes. - */ - if (vbid == 0 && source_port == -1) - source_port = tmp_source_port; - if (vbid == 0 && switch_id == -1) - switch_id = tmp_switch_id; - } else if (source_port == -1 && switch_id == -1) { + if (sja1105_skb_has_tag_8021q(skb)) + sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + else if (source_port == -1 && switch_id == -1) /* Packets with no source information have no chance of * getting accepted, drop them straight away. */ return NULL; - } if (source_port != -1 && switch_id != -1) skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); From patchwork Sat Jul 13 05:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732312 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 CEF7F4879B; Sat, 13 Jul 2024 05:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850108; cv=none; b=kRKSaZRmn3xeeeQXiMtt4kXSs9s+0V+5ijCxAkkmaxBRvfQE78B8JF2m27oNxUow/FKlGAj09YYfKVM2yNgvpqnw/QR35wOspbyr4siNrCguubojldqtI8N7OJylnj0RzxMQxMB9hZAlZ1ySdJD7W2KdEu0EcLuRBOT869rwJes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850108; c=relaxed/simple; bh=w75m7vuwDkdVv0GXOnFDcJZrp8g04zWV6N/XXtB4B0o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f7ZMImgl7ffjjqYZLF9lOG7ZmB1YI4IPh5k2tkrsNlWHjENlMOZPBNtSXTVzVbfuM+m97+VAR38ZPkG3SWmLYtghlQ9F1OAoFWmyAbKYdG3w5uqhbscNJOEa9W9prlFgi9zARu941aWyVZxp+9VD2fgPBGd9Mef5TK0P/U2g4sI= 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=VBRI0XZy; arc=none smtp.client-ip=209.85.208.173 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VBRI0XZy" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2eecd2c6432so35958971fa.3; Fri, 12 Jul 2024 22:55:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850105; x=1721454905; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I8t4/IOXLQvVBBq5agGXjavJDG6OcHVPOXjOJapQ9v0=; b=VBRI0XZy9pTkganyvWRSllA3QLO0xbADOjy73BBV/Opd1A91/N///fz4hspVbVTlEw Gmhaa5ELiubGYJYBntOVLa1k21qMZGX7ZjNthHb64ptnqvU2ZJIBskumck4eW3nUNNpo Ku0lCP+X7o0gh6BAPYvNoie8nMbdOnWdEKmHyNo+/aRSGwAxxK4xM0ZzoJerqKE1m9FJ Y9cdInKL2PYUcw0H8rShAaqKcEMMDQcgJmpJORoX3CVCmMGCa2ZA5tOMXhUB6saM6iZ7 THt5asKwOGPwMNMfmRd4Wz3Edaa1fs7Iy4Z1AU6V9hsrL/cMSJNIzSNOgJuS4pwVZ1zH YI0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850105; x=1721454905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I8t4/IOXLQvVBBq5agGXjavJDG6OcHVPOXjOJapQ9v0=; b=b90xv1B7K2kYg97XvPVFjq/03EvuRWo6U81ydbfpiYukz6Bm3vAmtoEixu9IvX4P6z Cv2zX+dqTPT0iE2BcowJ9PYt9N+XUXGlJitNRKIKUcKJ2VkxmZTHTpv5Ry9P05HD2x+j pCoxrPCQqDfYjv8gsllPo6o6DwJKIV2Shqp6AbfkVp8OT11RtJYkdSYJDm/dsIxBliYq 9LpHlKkYAjjxOcWi8KyqdEaJt/8AeUxxMuYCr4tsoUrsr35gKNRlwq1tJt/VwQNp+Wro Ol8AfSjJLiocWneoZftNPv1G+5wBT1XsY9I5J+WQnMhY7ta5BPU56O45jh1luvfER7ED mD1A== X-Forwarded-Encrypted: i=1; AJvYcCVT6jiS2ofk0yDu0VQLdd+oWlU9iR6LZ1oVvBVQYMtuomx5MNkH2FuLUfcf7KEfzurgTELyvBdBkfeo1/7qGv+oktCOwRpqlHrwR5Ex X-Gm-Message-State: AOJu0YypqKAkKBU9tHG/EXJ2QQ0OAMlxtn74Cl6ZkGpndwbCqeYQJVk2 so4YWUKjv92T0r9uC/RGKyQnJBxDCDHczi9qw56sho3Xr5SJ6wiDkJG0EM7K X-Google-Smtp-Source: AGHT+IGLSB22KV8LlPAx9KdxiKPodRgpyRXCxfmjIFjnUKR5NoG00MRGTDQGsNLNbJHbdfBWeF/KVQ== X-Received: by 2002:a2e:9b0f:0:b0:2ee:8dce:2f92 with SMTP id 38308e7fff4ca-2eeb30ba7acmr108068451fa.1.1720850104502; Fri, 12 Jul 2024 22:55:04 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:04 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Vladimir Oltean , Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 04/12] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv() Date: Sat, 13 Jul 2024 07:54:32 +0200 Message-Id: <20240713055443.1112925-5-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean tag_sja1105 has a wrapper over dsa_8021q_rcv(): sja1105_vlan_rcv(), which determines whether the packet came from a bridge with vlan_filtering=1 (the case resolved via dsa_find_designated_bridge_port_by_vid()), or if it contains a tag_8021q header. Looking at a new tagger implementation for vsc73xx, based also on tag_8021q, it is becoming clear that the logic is needed there as well. So instead of forcing each tagger to wrap around dsa_8021q_rcv(), let's merge the logic into the core. Signed-off-by: Vladimir Oltean Reviewed-by: Vladimir Oltean Tested-by: Vladimir Oltean Signed-off-by: Pawel Dembicki --- v3: - removed goto - removed unnecessary vbid assignment - added 'Tested-by' and 'Reviewed-by' fields v2,v1: - resend only --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8, v7, v6: - resend only v5: - add missing SoB v4: - introduced patch --- net/dsa/tag_8021q.c | 34 ++++++++++++++++++++++++++++------ net/dsa/tag_8021q.h | 2 +- net/dsa/tag_ocelot_8021q.c | 2 +- net/dsa/tag_sja1105.c | 32 ++++---------------------------- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 3cb0293793a5..2d1c554a63ff 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -507,27 +507,48 @@ EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); * @vbid: pointer to storage for imprecise bridge ID. Must be pre-initialized * with -1. If a positive value is returned, the source_port and switch_id * are invalid. + * @vid: pointer to storage for original VID, in case tag_8021q decoding failed. + * + * If the packet has a tag_8021q header, decode it and set @source_port, + * @switch_id and @vbid, and strip the header. Otherwise set @vid and keep the + * header in the hwaccel area of the packet. */ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, - int *vbid) + int *vbid, int *vid) { int tmp_source_port, tmp_switch_id, tmp_vbid; - u16 vid, tci; + __be16 vlan_proto; + u16 tmp_vid, tci; if (skb_vlan_tag_present(skb)) { + vlan_proto = skb->vlan_proto; tci = skb_vlan_tag_get(skb); __vlan_hwaccel_clear_tag(skb); } else { + struct vlan_ethhdr *hdr = vlan_eth_hdr(skb); + + vlan_proto = hdr->h_vlan_proto; skb_push_rcsum(skb, ETH_HLEN); __skb_vlan_pop(skb, &tci); skb_pull_rcsum(skb, ETH_HLEN); } - vid = tci & VLAN_VID_MASK; + tmp_vid = tci & VLAN_VID_MASK; + if (!vid_is_dsa_8021q(tmp_vid)) { + /* Not a tag_8021q frame, so return the VID to the + * caller for further processing, and put the tag back + */ + if (vid) + *vid = tmp_vid; + + __vlan_hwaccel_put_tag(skb, vlan_proto, tci); + + return; + } - tmp_source_port = dsa_8021q_rx_source_port(vid); - tmp_switch_id = dsa_8021q_rx_switch_id(vid); - tmp_vbid = dsa_tag_8021q_rx_vbid(vid); + tmp_source_port = dsa_8021q_rx_source_port(tmp_vid); + tmp_switch_id = dsa_8021q_rx_switch_id(tmp_vid); + tmp_vbid = dsa_tag_8021q_rx_vbid(tmp_vid); /* Precise source port information is unknown when receiving from a * VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id @@ -546,5 +567,6 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, *vbid = tmp_vbid; skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; + return; } EXPORT_SYMBOL_GPL(dsa_8021q_rcv); diff --git a/net/dsa/tag_8021q.h b/net/dsa/tag_8021q.h index 41f7167ac520..0c6671d7c1c2 100644 --- a/net/dsa/tag_8021q.h +++ b/net/dsa/tag_8021q.h @@ -14,7 +14,7 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, u16 tpid, u16 tci); void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, - int *vbid); + int *vbid, int *vid); struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid); diff --git a/net/dsa/tag_ocelot_8021q.c b/net/dsa/tag_ocelot_8021q.c index b059381310fe..8e8b1bef6af6 100644 --- a/net/dsa/tag_ocelot_8021q.c +++ b/net/dsa/tag_ocelot_8021q.c @@ -81,7 +81,7 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb, { int src_port, switch_id; - dsa_8021q_rcv(skb, &src_port, &switch_id, NULL); + dsa_8021q_rcv(skb, &src_port, &switch_id, NULL, NULL); skb->dev = dsa_conduit_find_user(netdev, switch_id, src_port); if (!skb->dev) diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 48886d4b7e3e..7639ccb94d35 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -472,37 +472,14 @@ static bool sja1110_skb_has_inband_control_extension(const struct sk_buff *skb) return ntohs(eth_hdr(skb)->h_proto) == ETH_P_SJA1110; } -/* If the VLAN in the packet is a tag_8021q one, set @source_port and - * @switch_id and strip the header. Otherwise set @vid and keep it in the - * packet. - */ -static void sja1105_vlan_rcv(struct sk_buff *skb, int *source_port, - int *switch_id, int *vbid, u16 *vid) -{ - struct vlan_ethhdr *hdr = vlan_eth_hdr(skb); - u16 vlan_tci; - - if (skb_vlan_tag_present(skb)) - vlan_tci = skb_vlan_tag_get(skb); - else - vlan_tci = ntohs(hdr->h_vlan_TCI); - - if (vid_is_dsa_8021q(vlan_tci & VLAN_VID_MASK)) - return dsa_8021q_rcv(skb, source_port, switch_id, vbid); - - /* Try our best with imprecise RX */ - *vid = vlan_tci & VLAN_VID_MASK; -} - static struct sk_buff *sja1105_rcv(struct sk_buff *skb, struct net_device *netdev) { - int source_port = -1, switch_id = -1, vbid = -1; + int source_port = -1, switch_id = -1, vbid = -1, vid = -1; struct sja1105_meta meta = {0}; struct ethhdr *hdr; bool is_link_local; bool is_meta; - u16 vid; hdr = eth_hdr(skb); is_link_local = sja1105_is_link_local(skb); @@ -525,7 +502,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, * a tag_8021q VLAN which we have to strip */ if (sja1105_skb_has_tag_8021q(skb)) - sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); else if (source_port == -1 && switch_id == -1) /* Packets with no source information have no chance of * getting accepted, drop them straight away. @@ -660,9 +637,8 @@ static struct sk_buff *sja1110_rcv_inband_control_extension(struct sk_buff *skb, static struct sk_buff *sja1110_rcv(struct sk_buff *skb, struct net_device *netdev) { - int source_port = -1, switch_id = -1, vbid = -1; + int source_port = -1, switch_id = -1, vbid = -1, vid = -1; bool host_only = false; - u16 vid = 0; if (sja1110_skb_has_inband_control_extension(skb)) { skb = sja1110_rcv_inband_control_extension(skb, &source_port, @@ -674,7 +650,7 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb, /* Packets with in-band control extensions might still have RX VLANs */ if (likely(sja1105_skb_has_tag_8021q(skb))) - sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); if (vbid >= 1) skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); From patchwork Sat Jul 13 05:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732313 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 09A0E4EB38; Sat, 13 Jul 2024 05:55:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850111; cv=none; b=ASTYfgi5M75upPbkshb7Ffrr5H1+kUSzjjSXxvc8FsCWAbtGRtDFSSKt7HGq7y7talppK9Snwndv42cIIK7jk2Ta0QxjSWXI1uJzkXkH3hUtsXz12ptZfffEYDBxnU+wkgAxuEwyZDdQx0+AtEw6gB5u82WTd/74rawuKJRpAnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850111; c=relaxed/simple; bh=qUDf5bzJIRpuGG58MPCP71MO5E3Wp+3Z/HtiGO427us=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tOYDzTh0N9+2npWtfQSP8LhDNfYWQO4DvwnoMIFXRDmNoML0//uwDoV0E4TZcEcmmlImpm1hEsFvbllPc4FYd5UK5Wq4TXVNYCRoQgZmjguw+9/o8w+jHU3hAMhfSMrNlcXXTdXqWYH2mXXZmOGy/jxU2matJOmawE8QHRHgsac= 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=CV+HAv3o; arc=none smtp.client-ip=209.85.218.54 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CV+HAv3o" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a77dc08db60so337047866b.1; Fri, 12 Jul 2024 22:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850108; x=1721454908; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rEox4l3skoYQyvZFS9at+xzCRoM9sUiX6FsbRszzTic=; b=CV+HAv3of8cflRwNBnEN+l6fKbGve8La2zKM+bxkBzQBlOB79iou4EMKVN23fLHKd6 HMflaYe9Eu1+yAM5SinZs5Z19zIt68QyQwRD4rVs2nRy4kpLuLf87/U2aBtwJEAc44gB +4dRp0SkqzhaCRqM9uEIdl3Pq322XQoqJ2O7CdPDyZ0HT3lQZpui06KTSiFoKob0B/dw GOmxPS+jPhf71Vwn32cb9nz9QpguBJDolZ4Oum2ifQlVj/SOjDR4+T+bWSfNY4NcWXG4 Ff5r1ESPQ0kS4h6XWJ+tLOmC3MWFMD9+QBhcQlUpQrGIHpz5MKYdTl1/wj9z8yvU2Un5 1Jyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850108; x=1721454908; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rEox4l3skoYQyvZFS9at+xzCRoM9sUiX6FsbRszzTic=; b=oog7YEqMr37xdy59wa0Gfqgg9X/K7anyXIaCYF4TGX/uyhnOBIOfcUgvRZyWVLBa6U CjjxEPkESe2WycXdOqW4OfpLSHxw0gwUm2CUdYf/KMHPSRTn0AtENHC7KDa/TYVRKciR TbNVNlM9/ykz8deqqW2sE1h31aPO9c2wMyaWtSFWzQQsLYts2MHV2UBJ9CLAMkIegeHj jEUMdWANJ8ieW8iVdoomPZYNqn35IUalCTpudwGdYsUcoZ6q7BsyNlPz8W6P4qv92PlM BHmzx9cRNSHa0WTYfUKr/2UVV1PoBCwfKcEqHvpLBWdOGKEusV8O9y8atNMycAEVXVty R2Tw== X-Forwarded-Encrypted: i=1; AJvYcCXjapYdl3NQO3YOgxcYlec3L3u23XgYVZ3V/fkX8FCVb/QRSC1+Yqojrsht4s8kRc4DWcNfSRRYNCHecS9SoKfjtSVHR0Y5adRdvENB X-Gm-Message-State: AOJu0YxEZKuaiZ3L9mmi5W3AAaaKpQIX+6FaUbxZLtLUe858BzRek3Sc i7rfuyxxkNP1mYjG/3dwHRGO8nggQ/QrPHOEzjOizYhnq2C5bpsQn35ZP0qy X-Google-Smtp-Source: AGHT+IG052Q8Ca32OmqKtpHUVymPLfBthlM0z6cmL1v2dMev1y7817YFthT1g5Fhi4EWZ/QYTzaBZA== X-Received: by 2002:a17:907:d93:b0:a75:20f7:2c71 with SMTP id a640c23a62f3a-a780b6ff667mr1338557766b.38.1720850107892; Fri, 12 Jul 2024 22:55:07 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:07 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Vladimir Oltean , Pawel Dembicki , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 05/12] net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too Date: Sat, 13 Jul 2024 07:54:33 +0200 Message-Id: <20240713055443.1112925-6-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean Now that dsa_8021q_rcv() handles better the case where we don't overwrite the precise source information if it comes from an external (non-tag_8021q) source, we can now unify the call sequence between sja1105_rcv() and sja1110_rcv(). This is a preparatory change for creating a higher-level wrapper for the entire sequence which will live in tag_8021q. Signed-off-by: Vladimir Oltean Signed-off-by: Pawel Dembicki Reviewed-by: Vladimir Oltean --- v3: - added 'Reviewed-by' only v2, v1: - resend only --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8,v7,v6,v5: - resend only v4: - introduce patch and replace 'slave' with 'conduit' after rebase --- net/dsa/tag_sja1105.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 7639ccb94d35..35a6346549f2 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -652,12 +652,12 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb, if (likely(sja1105_skb_has_tag_8021q(skb))) dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); - if (vbid >= 1) + if (source_port != -1 && switch_id != -1) + skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); + else if (vbid >= 1) skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else if (source_port == -1 || switch_id == -1) - skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); else - skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); + skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); if (!skb->dev) { netdev_warn(netdev, "Couldn't decode source port\n"); return NULL; From patchwork Sat Jul 13 05:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732314 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 66ECB7316E; Sat, 13 Jul 2024 05:55:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850115; cv=none; b=eLeN6idmbb49LSBNAyq6Iv+A4y4L03ijJediuSBY2nf/tfk32ZDaVhVBQMuhYNBSNCrSEOsblU+MVLrzIesjDgtoRTKUk6FUObRjzAJumO2epsKulJl4lQke0TNaxFN33GB44VVfrwif8M3DVOo4heBSJOxhlMam5XxCqkPaI4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850115; c=relaxed/simple; bh=dsvAEFFYi4cEp7LshOu0kyHfHtkr8SJfr3gpVgJwMGA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lmvuvGTvYepeBs3hiqh5cjjTFy+PBcao2X/vrcRW08VP0S4/aA+9Q1kaKtTC/6Av5xrKbymX1fTu233EtO3S8qv9A84DTZm3rQXTUG4Cgqh8qpPwS9zEArkW9uFKaAZNf7BXmYKQU9yJoFw4YaRY/MLIJILJ+iZCd9nJNnhhYMc= 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=FTgRE4S5; arc=none smtp.client-ip=209.85.208.45 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FTgRE4S5" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-59559ea9cfdso3297237a12.0; Fri, 12 Jul 2024 22:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850111; x=1721454911; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K0fP5T7J9roHoO7jnqM3i5JEtOTM2w+2+LRIgaQhPxk=; b=FTgRE4S5j3ScnQp1ubRlvu4WVcZE0rAcykiDGeGRYVMv4KlNBp0y0bR8RQ22vlcKLZ QeC1Msbxqb4jHfhtXsisM/xVlX7OwRBPyA/QK8092i4InjHSlamZRpcXWikPvNavd/Bd n5WGUOtEJEwNxV5lcdNGFFQvNuousUxAPXYE+Rm0tiXLL06JI1/pnkT6xTWO9ZiT37Eo ER3wg2399SS6HB8X8XhGy24qmgu8C4XkTyWj24+ll7NrQcwvDdFaeVnksbCGAZDLGrWr ABcPQEba0iymfErsEXrkRIhEDzTRlbPM6V9DIzdXoma8Z/M2lZcNgjrgb/54MKU+jDH5 LOSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850111; x=1721454911; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K0fP5T7J9roHoO7jnqM3i5JEtOTM2w+2+LRIgaQhPxk=; b=VElVRu0RXvn4UlvHEdvjMBdLvwHfGAE0761XnUvDjTzwgUQ1FED9kGvr2fj6go7szO rHuuHn8b5tszcrafxmOcGAbD3sd25wFjYV94Whu8wdm3HSAoAYR48HDo/zun/+NBoG7b 1nyFnUxRIZ4b8+xSOlSdD7aSIDF+qHzbMmZ9YtAKbX1TmTcWyuc7LD2TEh7Vi8eM7sbD YJx0ewNnxDwU+5QRlG6plGWuiJvUEXft5Wer1cOLZ04xT48H0PqaRP8cO7ZqeslIqAh7 ZrbejK0/qxSEC1NUE9CfFgHUPWZuZWQHsDrcqgPVoIAMjlmnhpPzx2Trs7QvJ3d+iCSw aSgw== X-Forwarded-Encrypted: i=1; AJvYcCVPvCnlIzZs5Y6Vebijr2soRPGmBJBGZXi9JAZolNzASqd8Y11Der5hK12IBD08uANlCseJzyblCOi67AGAabjUesNIL9ya0ZL9/sjN X-Gm-Message-State: AOJu0YzI572E4B51K2csX8278teXAOOcT9IFEUim2KEHJ2gN8KIdiLba wEIrFNn9fQc/g8rgOLgpPQ8DPry10AQZoQgXU/L4g3kd3I0T/bDUDZSS0tea X-Google-Smtp-Source: AGHT+IExeSH6eS2an84RtlZj0FIKftwPt9gNRnPN6TsktjvL9SujFT5r+sF6QapXFOSH+UWkWLsufQ== X-Received: by 2002:a17:906:27d6:b0:a72:74d5:8a9a with SMTP id a640c23a62f3a-a780b89cc52mr903691666b.65.1720850111356; Fri, 12 Jul 2024 22:55:11 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:10 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Vladimir Oltean , Pawel Dembicki , Florian Fainelli , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 06/12] net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user() Date: Sat, 13 Jul 2024 07:54:34 +0200 Message-Id: <20240713055443.1112925-7-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean A new tagging protocol implementation based on tag_8021q is on the horizon, and it appears that it also has to open-code the complicated logic of finding a source port based on a VLAN header. Create a single dsa_tag_8021q_find_user() and make sja1105 call it. Signed-off-by: Vladimir Oltean Signed-off-by: Pawel Dembicki Reviewed-by: Florian Fainelli --- v3,v2,v1: - resend only --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8: - resend only v7: - added 'Reviewed-by' only v6, v5: - resend only v4: - introduce patch and change from master to conduit and slave to user --- net/dsa/tag_8021q.c | 19 ++++++++++++++++--- net/dsa/tag_8021q.h | 5 +++-- net/dsa/tag_sja1105.c | 17 +++++------------ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 2d1c554a63ff..c0eee113a2b9 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -468,8 +468,8 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, } EXPORT_SYMBOL_GPL(dsa_8021q_xmit); -struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, - int vbid) +static struct net_device * +dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid) { struct dsa_port *cpu_dp = conduit->dsa_ptr; struct dsa_switch_tree *dst = cpu_dp->dst; @@ -495,7 +495,20 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, return NULL; } -EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); + +struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit, + int source_port, int switch_id, + int vid, int vbid) +{ + /* Always prefer precise source port information, if available */ + if (source_port != -1 && switch_id != -1) + return dsa_conduit_find_user(conduit, switch_id, source_port); + else if (vbid >= 1) + return dsa_tag_8021q_find_port_by_vbid(conduit, vbid); + + return dsa_find_designated_bridge_port_by_vid(conduit, vid); +} +EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_user); /** * dsa_8021q_rcv - Decode source information from tag_8021q header diff --git a/net/dsa/tag_8021q.h b/net/dsa/tag_8021q.h index 0c6671d7c1c2..27b8906f99ec 100644 --- a/net/dsa/tag_8021q.h +++ b/net/dsa/tag_8021q.h @@ -16,8 +16,9 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, int *vbid, int *vid); -struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, - int vbid); +struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit, + int source_port, int switch_id, + int vid, int vbid); int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds, struct dsa_notifier_tag_8021q_vlan_info *info); diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 35a6346549f2..3e902af7eea6 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -509,12 +509,8 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, */ return NULL; - if (source_port != -1 && switch_id != -1) - skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); - else if (vbid >= 1) - skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else - skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); + skb->dev = dsa_tag_8021q_find_user(netdev, source_port, switch_id, + vid, vbid); if (!skb->dev) { netdev_warn(netdev, "Couldn't decode source port\n"); return NULL; @@ -652,12 +648,9 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb, if (likely(sja1105_skb_has_tag_8021q(skb))) dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); - if (source_port != -1 && switch_id != -1) - skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); - else if (vbid >= 1) - skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else - skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); + skb->dev = dsa_tag_8021q_find_user(netdev, source_port, switch_id, + vid, vbid); + if (!skb->dev) { netdev_warn(netdev, "Couldn't decode source port\n"); return NULL; From patchwork Sat Jul 13 05:54:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732315 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 B740E12FB2A; Sat, 13 Jul 2024 05:55:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850118; cv=none; b=rs/rqFcz7aqjNnSJQ7lf5ISRaZ/YZf0UeXS1+cfq6V70xcPUtwaHSDZuBVAUTeu9bw0/dZYO7+7hXQZctWIfgdj/BjNPsSdgihPfr5BguNe4Mtn7y4gfAM0NtpLaxSNNwg/dyroWSEzIL4P3YipoRhG6gfrhszFlFKTacw4XM4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850118; c=relaxed/simple; bh=tU1MDBxqtdAEFD/eSWaF3yY5Of+8VsCSB5Xj+ZcGBes=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PekQU4Y1IMXDVngVbjAtv3FZrR2M7AqSurItLwulcYHyg2LPvBXqrQZH/Z6++Vc54+IiqLnCLLXJPBS+XrGria9AMC63xS38Hap8Y3oz5U5kVXuwYC/8yxusqmwTAUmfBn29nHjyRUZ2ujXJA3CKkinzdTlwgha83WFHSAeb+ek= 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=gua/YZr9; arc=none smtp.client-ip=209.85.218.51 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gua/YZr9" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a77b60cafecso337985566b.1; Fri, 12 Jul 2024 22:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850115; x=1721454915; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PRK65MuRL/dqpPYwR3ct1ceNTNZOhW71q5D8BZ5w9KI=; b=gua/YZr9FUyMJ51at8qvKB2FXGVoKxQSkSFc3FyhdUdV77gfN4/YD8727x5JVfJQ/F xkUUWBoA/ECKI9NVUooMtgD3cQTcNOgNMEeLB3oh4N4Hwc974fVxjfl3RKG1gcRkY/S1 rQE5PYFSh04y5hlhCa/4m8Z2ww280I6xIM7mUmiNUWS5WBCKaZQ+LWtUNpAwbXWKRUce GTQPSD1wyQ79YOQaOaR+683AAx74u/Rywh/GDqHzX+qYwQzErZwc7edKkZ6MwXodXUgY Wb3y388VGjGazFc8wL8kxYclVZCGi8gNMb5iyLMFJChg4IreMnH++MPwCYdum09I8Urj xxoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850115; x=1721454915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PRK65MuRL/dqpPYwR3ct1ceNTNZOhW71q5D8BZ5w9KI=; b=F05G7nmR72IiWYF6evw1Q3xuzx0eJ+SmSTNCo9DbH+OiBWlYuPd6NFRbxPWaz8yxDa p/EN6cC5ZqrovjV2Uyrm1JHXvew4TgGtvk66Kd2oZ8sBI0T7JwSkfIyRL6zm14cy3PZs cNKowiOo1yz5kcn11HKGJ2sNkeXJW7x6MGUEmyOWvIlooqwlpWkulqxEdmjlN3eD8ZPS SqHtAVT0d8XpOMaQ8Sn/0Kok7Q1f/ad1xFfbIOcgv//svEz6h8Jz05uYKl3TCV40Lee2 HjCh4YXmpjRFGFhKyR4GIDU7cu9JD0RJexWl/cMqmrGTsqG00Jsz+f6bPYc9RGmj3tNJ tTjQ== X-Forwarded-Encrypted: i=1; AJvYcCWqh+e5Sn3yMXNjs1q++7JLvnSJYlO8sQBjsiKmJORaIpuoI6KGeaW3ls2F7y7SeedXcfHco+v3PRDpPh3c5nj7kemX69GlaNaWHpMi X-Gm-Message-State: AOJu0Yx7hwcVRK5RqQfolINMUXtGv22P36552rdjoaq4oNftIK4P7tfH Ia6kLgCnW5TGzogp8MatDEiB6aEdzePFPI6bu4bfpQxDOYd+MpvUoqN5ewKA X-Google-Smtp-Source: AGHT+IHS4G3bbpFhL6gADmSVDcC8WGI8bRKY8Si/1OK0kN6ZOzefz2MmNiMyoTa4/x6fqZEuemN/3A== X-Received: by 2002:a17:906:48b:b0:a72:8fc7:ef7f with SMTP id a640c23a62f3a-a780b89a12fmr846818566b.65.1720850114790; Fri, 12 Jul 2024 22:55:14 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:14 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Pawel Dembicki , Florian Fainelli , Vladimir Oltean , Linus Walleij , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 07/12] net: dsa: vsc73xx: introduce tag 8021q for vsc73xx Date: Sat, 13 Jul 2024 07:54:35 +0200 Message-Id: <20240713055443.1112925-8-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This commit introduces a new tagger based on 802.1q tagging. It's designed for the vsc73xx driver. The VSC73xx family doesn't have any tag support for the RGMII port, but it could be based on VLANs. Reviewed-by: Florian Fainelli Reviewed-by: Vladimir Oltean Signed-off-by: Pawel Dembicki Reviewed-by: Linus Walleij --- v3,v2,v1: - resend only --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8: - added 'Reviewed-by' only v7: - replace netdev_warn by dev_warn_ratelimited v6: - added missing MODULE_DESCRIPTION() v5: - removed skb_vlan_tag_present(skb) checking - use 80 characters per line limit v4: - rebase to net-next/main v3: - Introduce a patch after the tagging patch split --- include/net/dsa.h | 2 ++ net/dsa/Kconfig | 6 ++++ net/dsa/Makefile | 1 + net/dsa/tag_vsc73xx_8021q.c | 68 +++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 net/dsa/tag_vsc73xx_8021q.c diff --git a/include/net/dsa.h b/include/net/dsa.h index f9ae3ca66b6f..5a5a03a7b4c3 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -53,6 +53,7 @@ struct tc_action; #define DSA_TAG_PROTO_RTL8_4T_VALUE 25 #define DSA_TAG_PROTO_RZN1_A5PSW_VALUE 26 #define DSA_TAG_PROTO_LAN937X_VALUE 27 +#define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE 28 enum dsa_tag_protocol { DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, @@ -83,6 +84,7 @@ enum dsa_tag_protocol { DSA_TAG_PROTO_RTL8_4T = DSA_TAG_PROTO_RTL8_4T_VALUE, DSA_TAG_PROTO_RZN1_A5PSW = DSA_TAG_PROTO_RZN1_A5PSW_VALUE, DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_VALUE, + DSA_TAG_PROTO_VSC73XX_8021Q = DSA_TAG_PROTO_VSC73XX_8021Q_VALUE, }; struct dsa_switch; diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig index 8d5bf869eb14..2dfe9063613f 100644 --- a/net/dsa/Kconfig +++ b/net/dsa/Kconfig @@ -166,6 +166,12 @@ config NET_DSA_TAG_TRAILER Say Y or M if you want to enable support for tagging frames at with a trailed. e.g. Marvell 88E6060. +config NET_DSA_TAG_VSC73XX_8021Q + tristate "Tag driver for Microchip/Vitesse VSC73xx family of switches, using VLAN" + help + Say Y or M if you want to enable support for tagging frames with a + custom VLAN-based header. + config NET_DSA_TAG_XRS700X tristate "Tag driver for XRS700x switches" help diff --git a/net/dsa/Makefile b/net/dsa/Makefile index 8a1894a42552..555c07cfeb71 100644 --- a/net/dsa/Makefile +++ b/net/dsa/Makefile @@ -37,6 +37,7 @@ obj-$(CONFIG_NET_DSA_TAG_RTL8_4) += tag_rtl8_4.o obj-$(CONFIG_NET_DSA_TAG_RZN1_A5PSW) += tag_rzn1_a5psw.o obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o +obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o # for tracing framework to find trace.h diff --git a/net/dsa/tag_vsc73xx_8021q.c b/net/dsa/tag_vsc73xx_8021q.c new file mode 100644 index 000000000000..af121a9aff7f --- /dev/null +++ b/net/dsa/tag_vsc73xx_8021q.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT +/* Copyright (C) 2024 Pawel Dembicki + */ +#include + +#include "tag.h" +#include "tag_8021q.h" + +#define VSC73XX_8021Q_NAME "vsc73xx-8021q" + +static struct sk_buff * +vsc73xx_xmit(struct sk_buff *skb, struct net_device *netdev) +{ + struct dsa_port *dp = dsa_user_to_port(netdev); + u16 queue_mapping = skb_get_queue_mapping(skb); + u16 tx_vid = dsa_tag_8021q_standalone_vid(dp); + u8 pcp; + + if (skb->offload_fwd_mark) { + unsigned int bridge_num = dsa_port_bridge_num_get(dp); + struct net_device *br = dsa_port_bridge_dev_get(dp); + + if (br_vlan_enabled(br)) + return skb; + + tx_vid = dsa_tag_8021q_bridge_vid(bridge_num); + } + + pcp = netdev_txq_to_tc(netdev, queue_mapping); + + return dsa_8021q_xmit(skb, netdev, ETH_P_8021Q, + ((pcp << VLAN_PRIO_SHIFT) | tx_vid)); +} + +static struct sk_buff * +vsc73xx_rcv(struct sk_buff *skb, struct net_device *netdev) +{ + int src_port = -1, switch_id = -1, vbid = -1, vid = -1; + + dsa_8021q_rcv(skb, &src_port, &switch_id, &vbid, &vid); + + skb->dev = dsa_tag_8021q_find_user(netdev, src_port, switch_id, + vid, vbid); + if (!skb->dev) { + dev_warn_ratelimited(&netdev->dev, + "Couldn't decode source port\n"); + return NULL; + } + + dsa_default_offload_fwd_mark(skb); + + return skb; +} + +static const struct dsa_device_ops vsc73xx_8021q_netdev_ops = { + .name = VSC73XX_8021Q_NAME, + .proto = DSA_TAG_PROTO_VSC73XX_8021Q, + .xmit = vsc73xx_xmit, + .rcv = vsc73xx_rcv, + .needed_headroom = VLAN_HLEN, + .promisc_on_conduit = true, +}; + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("DSA tag driver for VSC73XX family of switches, using VLAN"); +MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_VSC73XX_8021Q, VSC73XX_8021Q_NAME); + +module_dsa_tag_driver(vsc73xx_8021q_netdev_ops); From patchwork Sat Jul 13 05:54:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732316 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 E5EDC13213B; Sat, 13 Jul 2024 05:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850122; cv=none; b=pbf7BpLUz/V1gHTvLCRgf38IWhojTgHUOzokfNDEk4pcKNq8/nLW101g5uBAnQ4xwYnT8PNWRbwo0qNtpRYOHlZNVoGRRqWZ10syPeumjzC8CWnE40tZF1A6OizgGDaXTDbGRXq9P/U9FYEfz8y2Vp5b/0AoMKvLEB+4GKtbH1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850122; c=relaxed/simple; bh=o/rCHzh3TsTzS58J1nVqrbuxucT8W6zofidoHk39b/k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GeAA0uFSJkOEyApeQToSCyYz6D6AWqLHvIiFwk+/EgTpsAIwAoogJ34OEEBjT7Ki5D6o03ZKIB19mXIZBuJcKaqC09z9sq7xOYKkqePI+2pr4FJZ1WwdunedoQFLj3rcLomyRbIlOUcpAHvTV8bN+xlCqITOTVZ/zucY4P9+164= 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=Oen9mT7Z; arc=none smtp.client-ip=209.85.208.44 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Oen9mT7Z" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-58ba3e38028so3490561a12.0; Fri, 12 Jul 2024 22:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850118; x=1721454918; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Smj8J5s5NHO9oAwsf7t0gw+QE3FJUlLdGOJ8zQu72pA=; b=Oen9mT7Z14HAsEgvzyzL6j3WRic6pHC72IR4LZxSlaGy0XFCqtU6Avy11g70cxp01l 6rSBa7yEg9qe72HA2g2mhH3HMKxnBKGdfl8HtG6RJT59nkxacZZvnV4ZeR7wTEqyQcdg qbYb7GGak/pvvgzKNrKugGFTc3YUj5Zug2P2860fd2R1QMmbOPXA+OZwwJmHGepwpuUB CzASob/OFBhuGTF/RgEC18QrMEGZ8KhUJOGmZ2e9JyQolzxoJ3A9bWqKmKhqSzyEl7am 9w5mVhX/pyl3gkbL8q5td1dp1gjhEZNPDG3aBUI5stUQWpkfi77Aw4eEFZ0skjaaFC/5 xLCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850118; x=1721454918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Smj8J5s5NHO9oAwsf7t0gw+QE3FJUlLdGOJ8zQu72pA=; b=H0BVSbKb4QoC3LxxrmarOe66cHpY6Tgj3DtRldkYJ4TL1uG21g22q67/99Z1nwSO0s +SlvoYjtzzDma5SD6OTTgbcCSbNU4AVJyCiuPRrPD6UEWbRIXFo0DBQP/FWvKemvwtFH D6vEgPRtzbOYTBtBJj2D7aU/S7Tc93KDi1hCDrrFjvn6s0vMmXvUoxwygMDCAjIz5LYg BjUQXJxq6NVbsTEJyhyWE9ldhYAdDko7HmMIJ3bc5NZPue4rrEkNkqsORHe/C2RoYWk2 hTVLuaa/VEXIlufUv5fRchpbgeL1JiGh9ejCvxVNznsZ969ojdyrhvlz+UxXB0g5gLY0 drNQ== X-Forwarded-Encrypted: i=1; AJvYcCVTUeTbaVu6qUcDslJL0mzKofFYvsvFQ6GaHxVonAv73qSQVq9R3dT1VjktXWKvfnyWL2ELr+Kl+49iVm2koWzjNuR/MTILfUVx3mt6 X-Gm-Message-State: AOJu0Yx9fzHGlVroYDVxalqj2DIs65m4cZwDcylixwORbRPN+Ezt3vL2 fTHS+jTmSYMm2sxFxmLDGRbKofSMqw136YJcQEgV1X7qUCTHMme5WPRv8J5G X-Google-Smtp-Source: AGHT+IF+2rT9s61GDiwbfXXXulSczYSCLc6RBnbOgDV0Vxh7atrS8pjs8zEZXlvp6mdEaymCBDK1Gw== X-Received: by 2002:a17:907:d8a:b0:a72:7c0d:8fdc with SMTP id a640c23a62f3a-a780b68a311mr1099772066b.14.1720850118221; Fri, 12 Jul 2024 22:55:18 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:17 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 08/12] net: dsa: vsc73xx: Implement the tag_8021q VLAN operations Date: Sat, 13 Jul 2024 07:54:36 +0200 Message-Id: <20240713055443.1112925-9-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This patch is a simple implementation of 802.1q tagging in the vsc73xx driver. Currently, devices with DSA_TAG_PROTO_NONE are not functional. The VSC73XX family doesn't provide any tag support for external Ethernet ports. The only option available is VLAN-based tagging, which requires constant hardware VLAN filtering. While the VSC73XX family supports provider bridging, it only supports QinQ without full implementation of 802.1AD. This means it only allows the doubled 0x8100 TPID. In the simple port mode, QinQ is enabled to preserve forwarding of VLAN-tagged frames. Signed-off-by: Pawel Dembicki --- v3: - added the pvid remove routine to 'vsc73xx_tag_8021q_vlan_del' - used 'vsc73xx_vlan_commit_settings' in 'commit_to_hardware' routine v2: - handle raturn values of 'vsc73xx_vlan_commit*' functions v1: - added dsa_tag_8021q_unregister in teardown function - moved dsa_tag_8021q_register after vlan database clean operation --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8: - resend only v7: - adjust tag8021q implementation for vlan filtering implementation changes v6: - resend only v5: - improve commit message v4: - adjust tag8021q implementation for changed untagged vlan storage - minor fixes v3: - Split tagger and tag implementation into separate commits --- drivers/net/dsa/Kconfig | 2 +- drivers/net/dsa/vitesse-vsc73xx-core.c | 70 ++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index 8508b5145bc1..2d10b4d6cfbb 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -127,7 +127,7 @@ config NET_DSA_SMSC_LAN9303_MDIO config NET_DSA_VITESSE_VSC73XX tristate - select NET_DSA_TAG_NONE + select NET_DSA_TAG_VSC73XX_8021Q select FIXED_PHY select VITESSE_PHY select GPIOLIB diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 57a6f34805bd..71be5acb291b 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -597,7 +597,7 @@ static enum dsa_tag_protocol vsc73xx_get_tag_protocol(struct dsa_switch *ds, * cannot access the tag. (See "Internal frame header" section * 3.9.1 in the manual.) */ - return DSA_TAG_PROTO_NONE; + return DSA_TAG_PROTO_VSC73XX_8021Q; } static int vsc73xx_wait_for_vlan_table_cmd(struct vsc73xx *vsc) @@ -687,7 +687,7 @@ vsc73xx_update_vlan_table(struct vsc73xx *vsc, int port, u16 vid, bool set) static int vsc73xx_setup(struct dsa_switch *ds) { struct vsc73xx *vsc = ds->priv; - int i; + int i, ret; dev_info(vsc->dev, "set up the switch\n"); @@ -768,7 +768,18 @@ static int vsc73xx_setup(struct dsa_switch *ds) INIT_LIST_HEAD(&vsc->vlans); - return 0; + rtnl_lock(); + ret = dsa_tag_8021q_register(ds, htons(ETH_P_8021Q)); + rtnl_unlock(); + + return ret; +} + +static void vsc73xx_teardown(struct dsa_switch *ds) +{ + rtnl_lock(); + dsa_tag_8021q_unregister(ds); + rtnl_unlock(); } static void vsc73xx_init_port(struct vsc73xx *vsc, int port) @@ -1543,12 +1554,62 @@ static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port, vsc73xx_bridge_vlan_remove_port(vsc73xx_vlan, port); commit_to_hardware = !vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + if (commit_to_hardware) return vsc73xx_vlan_commit_settings(vsc, port); return 0; } +static int vsc73xx_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid, + u16 flags) +{ + bool pvid = flags & BRIDGE_VLAN_INFO_PVID; + struct vsc73xx_portinfo *portinfo; + struct vsc73xx *vsc = ds->priv; + bool commit_to_hardware; + int ret; + + portinfo = &vsc->portinfo[port]; + + if (pvid) { + portinfo->pvid_tag_8021q_configured = true; + portinfo->pvid_tag_8021q = vid; + } + + commit_to_hardware = vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + if (commit_to_hardware) { + ret = vsc73xx_vlan_commit_settings(vsc, port); + if (ret) + return ret; + } + + return vsc73xx_update_vlan_table(vsc, port, vid, true); +} + +static int vsc73xx_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) +{ + struct vsc73xx_portinfo *portinfo; + struct vsc73xx *vsc = ds->priv; + bool commit_to_hardware; + int err; + + portinfo = &vsc->portinfo[port]; + + if (portinfo->pvid_tag_8021q_configured && + portinfo->pvid_tag_8021q == vid) { + portinfo->pvid_tag_8021q_configured = false; + + if (commit_to_hardware) { + err = vsc73xx_vlan_commit_settings(vsc, port); + if (err) + return err; + } + } + + return vsc73xx_update_vlan_table(vsc, port, vid, false); +} + 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); @@ -1638,6 +1699,7 @@ static const struct phylink_mac_ops vsc73xx_phylink_mac_ops = { static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_tag_protocol = vsc73xx_get_tag_protocol, .setup = vsc73xx_setup, + .teardown = vsc73xx_teardown, .phy_read = vsc73xx_phy_read, .phy_write = vsc73xx_phy_write, .get_strings = vsc73xx_get_strings, @@ -1652,6 +1714,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_vlan_add = vsc73xx_port_vlan_add, .port_vlan_del = vsc73xx_port_vlan_del, .phylink_get_caps = vsc73xx_phylink_get_caps, + .tag_8021q_vlan_add = vsc73xx_tag_8021q_vlan_add, + .tag_8021q_vlan_del = vsc73xx_tag_8021q_vlan_del, }; static int vsc73xx_gpio_get(struct gpio_chip *chip, unsigned int offset) From patchwork Sat Jul 13 05:54:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732317 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 E42CC135A71; Sat, 13 Jul 2024 05:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850125; cv=none; b=C4OnblJ7vEaLRHaydmHUqnW4qbHLKLAzWwjRZ6JqjBOZT3lA/23JWB1tX40uvgeYTutr8UF5Tmi21wQsIEJz8xEIQTM1dp8UR0tDc2dsGvFz5q93TuNkC573ePD/TnXT2ydLlspCsTU+vbQarM7w6QCd9uGdNR/emK3lfsYBXx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850125; c=relaxed/simple; bh=W6438tmc00tM5rZzTKV48k4lj4pUeTKMALkVUuK8H5Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mLp45S4b+X9Fa/qCbtSPadrTuJQX/w5J2/SCLD5c7YObWA4Sf3VAnpiLTvAPoch40OEHcwTO/zGwfI/jqphkuIv6k7nAcF4BxHh3ktuIjNvNn9gtp/AAeDRXcLVRDrFatNpZViyv0RGgidvY2KOhyLmL/7foh6hUg7hgIWXG8Yc= 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=gkA1TDy3; arc=none smtp.client-ip=209.85.167.41 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gkA1TDy3" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-52ea5dc3c79so3798732e87.1; Fri, 12 Jul 2024 22:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850122; x=1721454922; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vSd94frQfpSyqALtcOez4IcP/dqnZZ/I23MmP19uB0I=; b=gkA1TDy3aVqD5TKH5pbWrFYcKBwxjooZhSpvcpbCxvOgnTWM/Vgxjk3sg4d3SZpEbg /2FNoca8QXAcIh7eKjqf+2WMsL7srRqw5BmIhVWVDp8R7CS1k223nSiLcd+I4AmNRWDZ 3AI/30DZO3ou7fuXRP+lQmQR4OxeOcpGjSL3PvM2vDGyFGbmceli2rd9V6JSUuFNb7nL sgCVEIkMMZVcD2qVjTg7g5oX+xo92CFo3fm7z34xyNrZ0qwyv7asVQh3gPbJHcoBfVyx ol4xmL3HqGmddsHMBEfiAkwg+SXTbYcyMjGO2pncH8cSkFzMFLVLDA9uuLuOUM/D0Ob5 GMPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850122; x=1721454922; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vSd94frQfpSyqALtcOez4IcP/dqnZZ/I23MmP19uB0I=; b=E+xTJFGQjq8pn2bc73X2IsfmmotziCn37DRYliQAimgqtytQ+xUN/OQMidMxzYlHLc V4r5rRlpAr/XL8NzFOP+OnM6M9Q5Um3r0MVY48NdvyZ4WwpcUR27MX87w8tSlf+XIPTz 4VWdBypYIRn8n+rCKRK90Q7FWKexbmXbERDVtiPDKU7myqlI0lp7k9moIMhyugPnIzJk KY0rzpHjtJEJtR7QAIZYezKWy+opNDGOaOx0FSxhrf0Zj4Sg/k/gzXJBBR/62kRyO7H8 vHTAjiy/Mc2drk7g3PLYKzUri+syyxkpLm5FPzj3qSajmiwEmvr5A4scSuYIEPh7qrqn cjOA== X-Forwarded-Encrypted: i=1; AJvYcCWyloOIuESLofZCrPaoIS96QbF+uIXcb5m5ZoE/ntBRj0P9zQvKZ0qV4fl7TH7kTRb9Rwch2qSp1RdJSwmMnNpTmZf8gyngN0ZwjhK6 X-Gm-Message-State: AOJu0YzWy+p+GQMfeOKj+5g8Yt0G/UnrGbJs4Gp9K1K+KpEbTNg69166 BGBvmDUxw3rsodr4kf6rChuUFP+PEiOJDYHx0e4a/5gHieUZ56iN/Znfmkjw X-Google-Smtp-Source: AGHT+IHE16dv8de+TUg4jmElVVbPBPngNEooDM8KZRyC9jUUDe79XjDmsdjSMCCLjh+IxCoxdBtxYg== X-Received: by 2002:a05:6512:239d:b0:52e:7542:f471 with SMTP id 2adb3069b0e04-52eb99a317fmr9393180e87.29.1720850121683; Fri, 12 Jul 2024 22:55:21 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:21 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Pawel Dembicki , Vladimir Oltean , Florian Fainelli , Linus Walleij , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 09/12] net: dsa: Define max num of bridges in tag8021q implementation Date: Sat, 13 Jul 2024 07:54:37 +0200 Message-Id: <20240713055443.1112925-10-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Max number of bridges in tag8021q implementation is strictly limited by VBID size: 3 bits. But zero is reserved and only 7 values can be used. This patch adds define which describe maximum possible value. Suggested-by: Vladimir Oltean Signed-off-by: Pawel Dembicki Reviewed-by: Florian Fainelli Reviewed-by: Linus Walleij Reviewed-by: Vladimir Oltean --- v3: - added 'Reviewed-by' only v2, v1: - resend only --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8: - resend only v7: - added 'Reviewed-by' only v6: - resend only v5: - added 'Reviewed-by' only v4: - introduce patch --- drivers/net/dsa/sja1105/sja1105_main.c | 3 +-- include/linux/dsa/8021q.h | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index ee0fb1c343f1..0c55a29d7dd3 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3167,8 +3167,7 @@ static int sja1105_setup(struct dsa_switch *ds) ds->vlan_filtering_is_global = true; ds->untag_bridge_pvid = true; ds->fdb_isolation = true; - /* tag_8021q has 3 bits for the VBID, and the value 0 is reserved */ - ds->max_num_bridges = 7; + ds->max_num_bridges = DSA_TAG_8021Q_MAX_NUM_BRIDGES; /* Advertise the 8 egress queues */ ds->num_tx_queues = SJA1105_NUM_TC; diff --git a/include/linux/dsa/8021q.h b/include/linux/dsa/8021q.h index f3664ee12170..1dda2a13b832 100644 --- a/include/linux/dsa/8021q.h +++ b/include/linux/dsa/8021q.h @@ -8,6 +8,11 @@ #include #include +/* VBID is limited to three bits only and zero is reserved. + * Only 7 bridges can be enumerated. + */ +#define DSA_TAG_8021Q_MAX_NUM_BRIDGES 7 + int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto); void dsa_tag_8021q_unregister(struct dsa_switch *ds); From patchwork Sat Jul 13 05:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732318 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 3FE89136E05; Sat, 13 Jul 2024 05:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850128; cv=none; b=fGtdvkuU6x64MCix/Bj/Bwp9Bm1B7U4XfK6zMmcCi6Ax3+X+3S1YATbr8l02erAn6MAlsnOQMbkIOPdJUdOKiwqGF6bqXxCxdBkFqwYVsEmpw3OljUFV1SmzushHPOuHufYdjZ/dZCbj6E5OxBM1f3ROkc2xTuUozj1rP3j+nNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850128; c=relaxed/simple; bh=7bCGbcfx70RiP+ql8fDb8kYzlGutv+0imJcDQfZHDD8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QGpzpu99SWqJBq+H1BOFl4izhPzNbsz2g9TmUnwj+pieiwg/ha8PpJaOY7L+gVLp6bIrpmCeJnRgPc/uCP5eIr7XRaMFTGczJZlZ34iCVx3aKsrKLE+C80lQ5yEIMuMUBTzdnz93a6qmsDEzOQ/3qb9ZF40BX1BPZYYes09nuuY= 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=W4wXu5l7; arc=none smtp.client-ip=209.85.208.181 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W4wXu5l7" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2eec7e43229so30331841fa.3; Fri, 12 Jul 2024 22:55:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850125; x=1721454925; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZqgCsXPgQR+KBVmH4O95ngJb1/Pd+9E/rt28mJ6/gDY=; b=W4wXu5l7OrxhPQ8jFU85tBurxNmEUrTQEcwR9LLK21bHN880WyPh84A5V2Lws0C15v EDvCEanx/G62/mjVouE2+vNjIZfpgPadQTBhWfy9NFHlTkqBFK9vGib0xEgDMSNaYO45 ymL/hpJ8V4WPfC/qSES0kNI+fDZT+AaROW6Y1cCd/S0fgilf3wJ8eKUD5JFnGIMkQyX+ eBr4PYXzDRCb3cL+bQl56AimdBEa0pmE9ZyYddoL6lap1z2Hp50tpNYfbjJq2n+qj3Zp ttn9r3YHCkv3bhijM1ZjlGju7wEHHcTTpUUCpqEEg+capYYIJUbJFVo7IVzmoQI7XtEd VOSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850125; x=1721454925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZqgCsXPgQR+KBVmH4O95ngJb1/Pd+9E/rt28mJ6/gDY=; b=DL6cXFmN1xwW967Wu2+pwDkBVNuYAPB64p+50baXUL45CYXdHH6hl6JR1yxkcZ2gYD fdBC0cQ9MMIcPwI9yxO8VHoBuWLmDLjKEWHCjDExK5ifVfJBZikwpBQyAqb7FSiniVdS o8L1wBJZtvmA8ZmfTRbVYYTFBi5my9QWeAO5z2fn0smXjYpDsGZKPPRUld66AKlLiqpq nVTHEuAS5LpxLwtBOIMiz7m73hBx5wcOajPWjmAgefPn8VnUZaJyziGNtDtbY1UyVQim owAKCXC+eK+henVzhZjGE5xqipFudzeDAce5jh/vywWSxPdiyK6qkp9Rm9aCCauIuPqp 8UDQ== X-Forwarded-Encrypted: i=1; AJvYcCVsfGrVcUJZW3fZTBIb18WGQHQoVNHZzIZraOy7boJPjiarBeLoOQuzy5Cw31S4EpidcafI4kdHWUff2Vq6MpjIA0HGK4loCDY3ByAw X-Gm-Message-State: AOJu0YwejmekAh2oGedV7rtCXf5gFh+fhrg88KhNhD3CyMuMRpTvsX9q VxNY0sYHYkVHpONcf/Ss1poMVykVs0MhPCgCyBltO4ZveUYv1Rm0T6o/SndI X-Google-Smtp-Source: AGHT+IG4dyKsYWVBIJfpxRz9Ahh3gKhRKYiru9t9DmQ7gsgdp63tOB0yOojwPnccQT7zpOJg74hnVQ== X-Received: by 2002:a05:6512:3d08:b0:52e:9382:a36 with SMTP id 2adb3069b0e04-52eb99a318cmr9862230e87.30.1720850125073; Fri, 12 Jul 2024 22:55:25 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.55.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:24 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Pawel Dembicki , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 10/12] net: dsa: prepare 'dsa_tag_8021q_bridge_join' for standalone use Date: Sat, 13 Jul 2024 07:54:38 +0200 Message-Id: <20240713055443.1112925-11-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The 'dsa_tag_8021q_bridge_join' could be used as a generic implementation of the 'ds->ops->port_bridge_join()' function. However, it is necessary to synchronize their arguments. This patch also moves the 'tx_fwd_offload' flag configuration line into 'dsa_tag_8021q_bridge_join' body. Currently, every (sja1105) driver sets it, and the future vsc73xx implementation will also need it for simplification. Suggested-by: Vladimir Oltean Signed-off-by: Pawel Dembicki Reviewed-by: Vladimir Oltean --- v3: - added 'Reviewed-by' only v2: - resend only v1: - introduce patch --- drivers/net/dsa/sja1105/sja1105_main.c | 5 ++--- include/linux/dsa/8021q.h | 3 ++- net/dsa/tag_8021q.c | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 0c55a29d7dd3..c7282ce3d11c 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2133,14 +2133,13 @@ static int sja1105_bridge_join(struct dsa_switch *ds, int port, if (rc) return rc; - rc = dsa_tag_8021q_bridge_join(ds, port, bridge); + rc = dsa_tag_8021q_bridge_join(ds, port, bridge, tx_fwd_offload, + extack); if (rc) { sja1105_bridge_member(ds, port, bridge, false); return rc; } - *tx_fwd_offload = true; - return 0; } diff --git a/include/linux/dsa/8021q.h b/include/linux/dsa/8021q.h index 1dda2a13b832..d13aabdeb4b2 100644 --- a/include/linux/dsa/8021q.h +++ b/include/linux/dsa/8021q.h @@ -18,7 +18,8 @@ int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto); void dsa_tag_8021q_unregister(struct dsa_switch *ds); int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int port, - struct dsa_bridge bridge); + struct dsa_bridge bridge, bool *tx_fwd_offload, + struct netlink_ext_ack *extack); void dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge); diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index c0eee113a2b9..3ee53e28ec2e 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -286,7 +286,8 @@ int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds, * be used for VLAN-unaware bridging. */ int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int port, - struct dsa_bridge bridge) + struct dsa_bridge bridge, bool *tx_fwd_offload, + struct netlink_ext_ack *extack) { struct dsa_port *dp = dsa_to_port(ds, port); u16 standalone_vid, bridge_vid; @@ -304,6 +305,8 @@ int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int port, dsa_port_tag_8021q_vlan_del(dp, standalone_vid, false); + *tx_fwd_offload = true; + return 0; } EXPORT_SYMBOL_GPL(dsa_tag_8021q_bridge_join); From patchwork Sat Jul 13 05:54:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732319 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 4E9D313774C; Sat, 13 Jul 2024 05:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850131; cv=none; b=e2gc15sX1aMVSUt3df4J2k8bloVPimCCkMFqHnIKpDo2+sj4FZGBCH6g7lT0pPT1vX/Q44Otvyjct65UtKByKaiuK4a5cqkOLXzpJtUJo3EQrJ/r+TUUkDM5JRdocBIY3cK464xYl3M/dHwqUh+1HDKofz1CYJBlMg1kn4L2dU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850131; c=relaxed/simple; bh=Tn5iSYglhZtXTG+V7gPq7wzrm75FHFu4BGHykn1Yk0s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eF68O/y7+5+0RKcy6kR2GB2YEXljOpSsRo9Qv8PDCpQMH19JO7mT5M5ba5cKYFkLfo54pRjQv0J1hzDOVHg4m3hNUANo/DCWiwO0F2FaFxhz/GHlc5WvEcnDUBG5MnN9HOmthsMG0b3Cj19L2yMvYmkJLzapEPyQp0wcdQ1+uMM= 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=GeZlbaIv; arc=none smtp.client-ip=209.85.208.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GeZlbaIv" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-58b447c519eso3536675a12.3; Fri, 12 Jul 2024 22:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850128; x=1721454928; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=89QJeNVLQDkmc2B+6tcM2WBPPc8pRRTlrLPa+MuYhlQ=; b=GeZlbaIvQg2YvXcNw0zBx1R/NgJO1IhLUfDqpEeL2HfRnUTkctRj4k6eLEyu8Mp6QM 5xrfV241/HzCzuaU94cZS14UWKZu12g2axs+Lvtwdzf4NbCJILNuIBmHt90dHmVuXW0x AdRtfc6XiX52Lihzx96v+TvecuTXVCg/DjbVUFiENRbxP03UOm6Iv9c67vMp1mFxuo+O Ah7mizSvsAeSCjJhMCvYBTyLFQm9HLHoXNTmFxCdotmQZce+plJifi3SOJXSsdMoVVyv +6WWKR6aJgWI4GwKRPfraRL6DLI3ryhQ9I4dptzVAPXlIUIRO9dmkAlkqstNcJmqTa4y wjGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850128; x=1721454928; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=89QJeNVLQDkmc2B+6tcM2WBPPc8pRRTlrLPa+MuYhlQ=; b=nTPBuMEZSCwoFtL8gkM8HR4M5Z0aSfzh2WZLz0W+Vo+PElV1/RLH7gT7BlS/+poXSk zROitdqrp3M7WLcsJRpBg4CniS3fhSWPA0/Ft8e9WAdmsWI1J1hartE0bJDWsWaWzoc4 KkH5LDNH9dQxjF34i9aj96mcahYID5qami+VtE3jW3/234jAMwuHs6/TSRr0TPAhA3ox dyjcpMpsFdLAIt4s0JCkJLUv01mDmPVmyShDRTlV89nGf9uuQEljFGoAKQzuzAyP1RzF LMjytuJic4100/LYyWFov1osUbTDXEWknazDUetYhmhOUEq3HB6jPuPBDoj7AVUKn1AK dckg== X-Forwarded-Encrypted: i=1; AJvYcCW1YXjcExzXkwTHJA7WHOfppSWe9NVAHhhermblPF8wlMNpD72g7YLGOLPN+8XLlJfNe3Y0QkA+G6JlTCStCnEk7xkVv0nWlhGDSOWK X-Gm-Message-State: AOJu0YxnQF9BlrE6F+CuC9HYUU1kBqN0Hpam1SScCd7sz2NM4pNsHV3l ruvhgeh+LDtapnTyOldCqGTpTDtfCWGRY9TM95TMGfu00mB0WSt/DHoNcJnJ X-Google-Smtp-Source: AGHT+IFGgnA+t54HANbyOXm/4GGjfvzmO+co5MVkRKRDiZcbLGgpHvO4ZWtcbYZ7NP2H5lOlkUzcNA== X-Received: by 2002:a17:906:2401:b0:a6f:5815:f5e6 with SMTP id a640c23a62f3a-a780b68a736mr856655766b.8.1720850128449; Fri, 12 Jul 2024 22:55:28 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:28 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Pawel Dembicki , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 11/12] net: dsa: vsc73xx: Add bridge support Date: Sat, 13 Jul 2024 07:54:39 +0200 Message-Id: <20240713055443.1112925-12-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This patch adds bridge support for the vsc73xx driver. The vsc73xx requires minimal operations and ithe generic dsa_tag_8021q_bridge_* API is sufficient. The forwarding matrix is managed by vsc73xx_port_stp_state_set() -> vsc73xx_refresh_fwd_map()i routine, which is called immediately after .port_bridge_join() and .port_bridge_leave(). Reviewed-by: Vladimir Oltean Signed-off-by: Pawel Dembicki --- v3: - improved commit description - added 'Reviewed-by' v2, v1: - Use generic functions instead unnecessary intermediary shims --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8: - resend only v7: - added 'Reviewed-by' only v6: - resend only v5: - added 'Reviewed-by' only v4: - remove forward configuration after stp patch refactoring - implement new define with max num of bridges for tag8021q devices v3: - All vlan commits was reworked - move VLAN_AWR and VLAN_DBLAWR to port setup in other commit - drop vlan table upgrade v2: - no changes done --- drivers/net/dsa/vitesse-vsc73xx-core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 71be5acb291b..07115a9d1869 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -691,6 +691,9 @@ static int vsc73xx_setup(struct dsa_switch *ds) dev_info(vsc->dev, "set up the switch\n"); + ds->untag_bridge_pvid = true; + ds->max_num_bridges = DSA_TAG_8021Q_MAX_NUM_BRIDGES; + /* Issue RESET */ vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GLORESET, VSC73XX_GLORESET_MASTER_RESET); @@ -1707,6 +1710,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_sset_count = vsc73xx_get_sset_count, .port_enable = vsc73xx_port_enable, .port_disable = vsc73xx_port_disable, + .port_bridge_join = dsa_tag_8021q_bridge_join, + .port_bridge_leave = dsa_tag_8021q_bridge_leave, .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, .port_stp_state_set = vsc73xx_port_stp_state_set, From patchwork Sat Jul 13 05:54:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13732320 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 1B817137928; Sat, 13 Jul 2024 05:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850135; cv=none; b=PR5SevKflYV6lwhy35dMWKTKe4oJorS5dR+7p2JaAaShxHWsvDYVLjC0KfVwKM9gQwja2aIBiCuBZhpJXgF6LZPG+rWf8w7v2rLQLq4vb0WyCPi/dNXsHaRM/19l78T1rf17kqiOBbVe2u7bFfCNYQKlfZVf9R7W7P1ZGVEY2Hs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850135; c=relaxed/simple; bh=m61yrLiCo/6Coqan3yroa8I4c7Fp0BM+pnhcB9oQZzk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qloy+OGXieUmx1z8E+vdOVOIznipWbb3yzAe/Cf+GlnR0lx2Gp8SLxiHdUzoetgQeySUeadhp1Kjo6hYf2W5Sgy8A43HlcyO2vZWJJ+pV+pANNHy83ccq+mgZOasBBMk7bL5lGwg1Ue9dxcPkePtxtY0TakghlxGKesF3iQ/vU0= 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=hq90AX6H; arc=none smtp.client-ip=209.85.208.169 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hq90AX6H" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2eea8ea8bb0so51043771fa.1; Fri, 12 Jul 2024 22:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720850132; x=1721454932; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TJ8lt0WIPJML/L+Gu3zpYCM/DKICydm3DLZEC2BtLFY=; b=hq90AX6HgCNflw1ytD/c4xBC+jF411ILS1ST7lNKX2Nd7Dgi0A4EqR+UotmFN5p25A /SoOFePMEx/dTO15kxXjVCeMMq7Ta8vLCj6jrefbKPcaCB0bHWC9CLMZsPwg2nwhJWEW Le0ACv+e9NEEtTZ60XPc6S/singZya3CgCnuRHx+7dtdJ+WHeF7ZloO+tUl6nyeJIaAd YCA4IN+NB8q9gUip63k+ru+Sug8RmnaTVur5cnWkohSuwK92Coz11kzBVi0gGB3dDRvo vnb1q9DiwWJqZ0JLDhO5JnyoYOaj66nOs/QuCCXWsQzT6SQdDGafXb6nOPaLvp9WFbd5 95zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720850132; x=1721454932; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TJ8lt0WIPJML/L+Gu3zpYCM/DKICydm3DLZEC2BtLFY=; b=FmP8aReP8LCN74cd9YqPgUIgVfFHE3n8aGwLLOqWVK5GwS9/MfKqkSPxwbIrhLjERg 4/ZrHISK5ybRKoaU4WIq7krZ0bRE4f0oMr3CmbxcdEYnXtQVqDQamLad++6rzBZUbtt3 k76QL2yemmK9uNj8ZfLglc5+rvZP2pBTMQoLCwXj5V1m3hlt/dJ+MWyv96c+iz2wSElk rL8xtpOtchaSPobBuWt562PV4R4pdkhl+hQNeUK1sxBeceI3J7EEuQz9MIHpToP74HcB qJvh3tbj19HEejuRJ4CpZHyoXEfftmYjK5WktB+pgYzOsKfQB3LFp6MokHnRDEDZha5X 8Y5A== X-Forwarded-Encrypted: i=1; AJvYcCVUuHdRIYZGwu0jZeMpk0/qdneUoJonm8PH6NxES/w45cM3uc3HvsptQDD7S3QQyBALYVPvLtoOu8MYj63gakpVqUHPmXW2Y+hrnBwc X-Gm-Message-State: AOJu0Yw0g9N5P9cR/RMdO/PKd57woWW685oSPf4mPfdJ7S9pAG+Gev9h 6Pm7/vJ71jnjr2r2WI9sU8bui4zK19ntEbkVS1PNEbZTCMh4CHg6EnJv62vC X-Google-Smtp-Source: AGHT+IHIGpOuMZbLh4SlGsMLM9NGHFZ017JxrUCmTRcLTgrAKIfbXnMlZNIOjvU18F8Znrn6y84uUQ== X-Received: by 2002:a2e:3306:0:b0:2ee:8454:1c25 with SMTP id 38308e7fff4ca-2eeb316b020mr105005701fa.34.1720850131922; Fri, 12 Jul 2024 22:55:31 -0700 (PDT) Received: from WBEC325.dom.lan ([2001:470:608f:0:b4ea:33f8:5eca:e7fc]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1ceesm20515666b.126.2024.07.12.22.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 22:55:31 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Paolo Abeni , Pawel Dembicki , Linus Walleij , Florian Fainelli , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 12/12] net: dsa: vsc73xx: start treating the BR_LEARNING flag Date: Sat, 13 Jul 2024 07:54:40 +0200 Message-Id: <20240713055443.1112925-13-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713055443.1112925-1-paweldembicki@gmail.com> References: <20240713055443.1112925-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This patch implements .port_pre_bridge_flags() and .port_bridge_flags(), which are required for properly treating the BR_LEARNING flag. Also, .port_stp_state_set() is tweaked and now disables learning for standalone ports. Disabling learning for standalone ports is required to avoid situations where one port sees traffic originating from another, which could cause packet drops. Signed-off-by: Pawel Dembicki Acked-by: Linus Walleij Reviewed-by: Florian Fainelli Reviewed-by: Vladimir Oltean --- v3,v2,v1: - resend only --- Before patch series split: https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both v8: - resend only v7: - added 'Acked-by' and 'Reviewed-by' and improve commit message v6: - fix arranging local variables in reverse xmas tree order v5: - introduce patch --- drivers/net/dsa/vitesse-vsc73xx-core.c | 41 ++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 07115a9d1869..193752194b66 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -1613,6 +1613,31 @@ static int vsc73xx_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) return vsc73xx_update_vlan_table(vsc, port, vid, false); } +static int vsc73xx_port_pre_bridge_flags(struct dsa_switch *ds, int port, + struct switchdev_brport_flags flags, + struct netlink_ext_ack *extack) +{ + if (flags.mask & ~BR_LEARNING) + return -EINVAL; + + return 0; +} + +static int vsc73xx_port_bridge_flags(struct dsa_switch *ds, int port, + struct switchdev_brport_flags flags, + struct netlink_ext_ack *extack) +{ + if (flags.mask & BR_LEARNING) { + u32 val = flags.val & BR_LEARNING ? BIT(port) : 0; + struct vsc73xx *vsc = ds->priv; + + return vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_LEARNMASK, BIT(port), val); + } + + return 0; +} + 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); @@ -1673,19 +1698,21 @@ static void vsc73xx_refresh_fwd_map(struct dsa_switch *ds, int port, u8 state) static void vsc73xx_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) { + struct dsa_port *dp = dsa_to_port(ds, port); struct vsc73xx *vsc = ds->priv; - u32 val; + u32 val = 0; + + if (state == BR_STATE_LEARNING || state == BR_STATE_FORWARDING) + val = dp->learning ? BIT(port) : 0; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_LEARNMASK, BIT(port), val); val = (state == BR_STATE_BLOCKING || state == BR_STATE_DISABLED) ? 0 : BIT(port); vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_RECVMASK, BIT(port), val); - val = (state == BR_STATE_LEARNING || state == BR_STATE_FORWARDING) ? - BIT(port) : 0; - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, - VSC73XX_LEARNMASK, BIT(port), val); - /* CPU Port should always forward packets when user ports are forwarding * so let's configure it from other ports only. */ @@ -1710,6 +1737,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_sset_count = vsc73xx_get_sset_count, .port_enable = vsc73xx_port_enable, .port_disable = vsc73xx_port_disable, + .port_pre_bridge_flags = vsc73xx_port_pre_bridge_flags, + .port_bridge_flags = vsc73xx_port_bridge_flags, .port_bridge_join = dsa_tag_8021q_bridge_join, .port_bridge_leave = dsa_tag_8021q_bridge_leave, .port_change_mtu = vsc73xx_change_mtu,