From patchwork Tue Jun 11 19:49:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694168 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.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 BA2621534EA; Tue, 11 Jun 2024 19:51:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135463; cv=none; b=Xcw5KNFWAn5sjfWtxft07USxjiZhuDCk8vqk4HxkDMSt7/NEutb7//s7u+Oqueg4xy7YJu9db8olpgeoIJH8i2EKCqvAh7euGPyXqg92YH/qHWbBDevPhiU4pBVHSZTe4y2dQkNRXl/va2YWr2NVyWVe1Pfq9CzRYLnoOr85DDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135463; c=relaxed/simple; bh=MuiG8AjfkDOJYyP8PAX6pDf8PzjRMpV+WgtH4FRb9Hg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XZCMC5tasZLsyRpymKAnpU0Dqz5OA41cW9BnaCvz+2i6/LD5fu25MuA6W2YPtpaV/5oOyQiVEejUqEn7MpAaVR0CdBl5J6mg6iWN3qaSdDEC/2L8FLFuljyLCBIFSG+WLhLGN0CM6PxKI4tsOEv+SzMWnxp4yXXN3cyag/HEpyc= 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=XFgODGf7; arc=none smtp.client-ip=209.85.218.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="XFgODGf7" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a6f1f33486eso158177766b.3; Tue, 11 Jun 2024 12:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135460; x=1718740260; 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=cpHorWpFXkyaD7lGP655nNnlrJvJ0HHxDtEJDmoiKB8=; b=XFgODGf7ER3NnYETT5WmyreYA5A4F9G4hJsMa8RWqvGhYIwRs96ggii6bIM0itZ4gU 4L3FQGkN+ZwZ0ktCI4D6b4xN2C+h5/h9o+4YHfjxeCNMuiWdVgTV/OsRo2HMjz6X4+Q6 /ZX6wVfFf62Hs/3zQXcNUvQ6arfZWfbZsSTbnTcLUAjJGjm4YQODcXXBJtyh2n9sPg3o Qdp12hMfAeaWimy5mDh0gKgiNW6fa/p8z0DqlEyMEaJC8CAPkmiUY7cPVgH7RIetgX4E uClZr+ddGbzJ5wlUDLYiZrvM3Df56lRu6F5kal8YjU1EAF7qA0CuhYPHh9X/4P5tMyQM lSWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135460; x=1718740260; 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=cpHorWpFXkyaD7lGP655nNnlrJvJ0HHxDtEJDmoiKB8=; b=pzz63td9ok28IZa0i5gsmBf4mhu0BrsD7Al2LT6uvl/X5CGvEaUysz/+5jLh7nQDsn zGwCq5bSJW4MjtYiRqmDLYEYClPcm0YBAq/d06MjIvlRX4c+ckq+NKpCzlKsp+B96+4F gRyEHJ+Q2LY1ZaY/7Fvn4P7jW32VOU2u9s+TOSb24pOr20ZKDK7Ah8/zgC/Dxf6d/Fy2 BxRG/3QNcNAKV4UdLn//uYg6ILYNnQQ5m6s8g8ZxbOpafB7ueFF603zXkcByNiO/no8o Bw4OycDWCxh4HCT4NRNZgkgsApPOBbGEVi3pJaWZ96GtcReNNB/fqEH71eXXukpMCWbA tf3Q== X-Forwarded-Encrypted: i=1; AJvYcCV2pIfEE3Pj2C63cSTGXHi2I/hKk2QMVrypz1YgterYrZ2Zs/qpVZ8NBvJcczxKmUwBYXavXDtHfgNbuOKzA4GjZYsDlR5H1VtiYwgy X-Gm-Message-State: AOJu0YzlbXjcKK9OqK3b8bd57gb++D691SZ938gBoB3p8ISE3QOEiVLW SJ/ogO6ia+l5izEPUAvSm4b9P3UVGjJuc/xwoc1wxMjVFdwQErJf5qPxpbOpHcA= X-Google-Smtp-Source: AGHT+IHM+9kcFfX6O+6VrNVJVUu0E1wOP2WB5lGNlNvHmG2ABQPobNr4CJpxqr+191aMPjvlerf4Mw== X-Received: by 2002:a50:bb28:0:b0:57a:4c22:b3 with SMTP id 4fb4d7f45d1cf-57c5085e6ecmr11924082a12.1.1718135459464; Tue, 11 Jun 2024 12:50:59 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:50:59 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Linus Walleij , Florian Fainelli , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 01/12] net: dsa: vsc73xx: add port_stp_state_set function Date: Tue, 11 Jun 2024 21:49:53 +0200 Message-Id: <20240611195007.486919-2-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 Tue Jun 11 19:49:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694169 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 1525215444E; Tue, 11 Jun 2024 19:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135467; cv=none; b=uF8gFhNcLDADQyro5ANl3ZU+PKIGQRvndK6inF9kb7BM7ReaQtHk8ZkohpGv1qMqi8uA1WfPT+bAiSsqclvZ0hYKn+QN4Nm9Mh92F/ms1j+EbjBPy5FTqtcptKh0SqWMVrtNYqtMOq+uCPxfpyRr67lFBAhdzEOI/8gFlCpGXcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135467; c=relaxed/simple; bh=4R7BoyTAwRemnlJ333h9GQ/K/mMNEQTZAecMgbV8Q7A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GXHFX4bKFHAGqy58ctN4yWviwYgkCHJJ2Mu+0BXFmLOq57O+mf4JTxlWcOT3vuul6PqfdeJ254nR2FQfJij8opUYXr/DrtKJr8nd/VeUknOzX37J/+dyT+kJV2hZPU2V2ltVogxBEBiiBZO3h/tpvXQ61WQGQxfZOOO1uHajIRw= 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=XEznIDj1; arc=none smtp.client-ip=209.85.208.47 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="XEznIDj1" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-57864327f6eso392587a12.1; Tue, 11 Jun 2024 12:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135463; x=1718740263; 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=eeGzenQGQ2YijNtvrCD7yeB5tovh9Vx5Z1w6X3Qf/TI=; b=XEznIDj1a0RfKmuKuXuxslSL9Gc0gvk1quIsw1CIyRZtxhSHrvu1yzkWn18bK8Ik3k 43FbTTBn0YqWlONvAzuNLwgBdXlrGrNcZqlu2igq2FLfhHI5sPOaegvwxFoq1vpY8RM6 oar7tsHRaQWqB/3BARqxn5TEhI4N5wzTd7iNBWX3bOsA/PhTD+8kyTie75LoS9nDbRhD 20AdP+X7rj2uIboqH9HCbZtwCrImImIUh/B0kzalb6pQsz/OBitCdK507LmzaLqnO3hJ Z3B98qkTrI/fXRVppQ8yoVm0XNSWJ1ewKvj1V/3Oyg8HCzuStclSH6VGdV2dlG+IM/i/ bNsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135463; x=1718740263; 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=eeGzenQGQ2YijNtvrCD7yeB5tovh9Vx5Z1w6X3Qf/TI=; b=vOnHweM8qOWibv+QRyJiOQzRP4LPjonyIlTJACAy25k8edhByiS6BrQ+ObmwWh1AGI lmz/7x/ENqYaMDmwDJrsvvHu1AhwgXYNW3KqvuN1H/t2znXdlJ3u1ip/W2TJlxv2kfRE 6x1DJfgwsLB9wdC4o7/wcAOjDFn0d6CDkmxq6aNovFDhuCrd4mIPQU9j77vmkPUIJ6Mi Mx6hZecAHutWPWIYwdnLVc3ewBH4DiTdMpU1qMaTcJ4WEObTSthA0CxRauEzlRLR3Ozb Hp1Pe0p3227ioPvgnyVNu0RtpvCYwF6k8kpGCmWLS2bfqhDZ5GzcQSw2OQJ0Pi0Rkw2f QZ1w== X-Forwarded-Encrypted: i=1; AJvYcCVybwOn8IxzajjwyJD1CRDjHyFiZLFLtm/kRiyedM6h9Z7L4dP4/vTV+3THOTu492k1wjUD1HeME+38VA6sAAmVjJ9xX/lhbgkIaHDC X-Gm-Message-State: AOJu0YwCVqkZrINv111mbvz0TY/uKthfJRaOirojdb+B65K6w8Bsm/20 I4QrWLBY7zmUGiC9OdIV7Rm+u/Gr7SE9ebOuvb68Txdnjn2O+IybfThMK6gb6nc= X-Google-Smtp-Source: AGHT+IElRqbMvhspkUhKp1Dpm8qDOG5+nmZiPzQ+nDGpIcyATnCMrWCkMynSVqQMNa/ysuovuLnkrQ== X-Received: by 2002:a05:6402:5147:b0:57c:7cff:6c7e with SMTP id 4fb4d7f45d1cf-57c90d1888emr2329675a12.12.1718135463021; Tue, 11 Jun 2024 12:51:03 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:02 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 02/12] net: dsa: vsc73xx: Add vlan filtering Date: Tue, 11 Jun 2024 21:49:54 +0200 Message-Id: <20240611195007.486919-3-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 | 482 ++++++++++++++++++++++++- drivers/net/dsa/vitesse-vsc73xx.h | 42 +++ 2 files changed, 522 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index ebeea259f019..782eddcb1169 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: @@ -1032,6 +1167,345 @@ 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 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_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 void +vsc73xx_set_vlan_conf(struct vsc73xx *vsc, int port, + enum vsc73xx_port_vlan_conf port_vlan_conf) +{ + u32 val = 0; + + if (port_vlan_conf == VSC73XX_VLAN_IGNORE) + val = VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA | + VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA; + + 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); + + val = (port_vlan_conf == VSC73XX_VLAN_FILTER) ? + VSC73XX_TXUPDCFG_TX_INSERT_TAG : 0; + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_TXUPDCFG, + VSC73XX_TXUPDCFG_TX_INSERT_TAG, val); +} + +static void 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; + } + + 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); +} + +static void vsc73xx_vlan_commit_untagged(struct vsc73xx *vsc, int port) +{ + struct vsc73xx_portinfo *portinfo = &vsc->portinfo[port]; + bool valid = portinfo->untagged_tag_8021q_configured; + struct dsa_port *dp = dsa_to_port(vsc->ds, port); + u16 vid = portinfo->untagged_tag_8021q; + + if (dsa_port_is_vlan_filtering(dp)) { + struct vsc73xx_vlan_summary summary; + + 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; + + valid = (summary.num_untagged == 1); + if (valid) + vid = vsc73xx_find_first_vlan_untagged(vsc, port); + } + + 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); +} + +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_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. + */ + vsc73xx_vlan_commit_untagged(vsc, port); + vsc73xx_vlan_commit_pvid(vsc, port); + vsc73xx_vlan_commit_conf(vsc, port); + + return 0; +} + +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 allow 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; + vsc73xx_vlan->portmask = 0; + vsc73xx_vlan->untagged = 0; + + INIT_LIST_HEAD(&vsc73xx_vlan->list); + list_add_tail(&vsc73xx_vlan->list, &vsc->vlans); + } + + /* CPU port must be always tagged because port separation is based on + * tag_8021q. + */ + if (port == CPU_PORT) + goto update_vlan_table; + + vsc73xx_vlan->portmask |= BIT(port); + + 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) { + vsc73xx_vlan_commit_pvid(vsc, port); + vsc73xx_vlan_commit_untagged(vsc, port); + vsc73xx_vlan_commit_conf(vsc, port); + } + +update_vlan_table: + ret = vsc73xx_update_vlan_table(vsc, port, vlan->vid, true); + if (!ret) + return 0; + + list_del(&vsc73xx_vlan->list); + kfree(vsc73xx_vlan); + 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_vlan->portmask &= ~BIT(port); + + if (vsc73xx_vlan->portmask) + return 0; + + list_del(&vsc73xx_vlan->list); + kfree(vsc73xx_vlan); + } + + commit_to_hardware = !vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + if (commit_to_hardware) { + vsc73xx_vlan_commit_pvid(vsc, port); + vsc73xx_vlan_commit_untagged(vsc, port); + vsc73xx_vlan_commit_conf(vsc, port); + } + + return 0; +} + +static int vsc73xx_port_setup(struct dsa_switch *ds, int port) +{ + struct vsc73xx_portinfo *portinfo; + struct vsc73xx *vsc = ds->priv; + + portinfo = &vsc->portinfo[port]; + + portinfo->pvid_vlan_filtering_configured = false; + portinfo->pvid_tag_8021q_configured = false; + portinfo->untagged_tag_8021q_configured = false; + + vsc73xx_vlan_commit_untagged(vsc, port); + vsc73xx_vlan_commit_pvid(vsc, port); + vsc73xx_vlan_commit_conf(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); @@ -1126,11 +1600,15 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_strings = vsc73xx_get_strings, .get_ethtool_stats = vsc73xx_get_ethtool_stats, .get_sset_count = vsc73xx_get_sset_count, + .port_setup = vsc73xx_port_setup, .port_enable = vsc73xx_port_enable, .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, + .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..fc8b7a73d652 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -14,6 +14,27 @@ */ #define VSC73XX_MAX_NUM_PORTS 8 +/** + * struct vsc73xx_portinfo - port data structure: contains storage data + * @pvid_vlan_filtering_configured: imforms if port have configured pvid in vlan + * fitering mode + * @pvid_vlan_filtering: pvid vlan number used in vlan fitering mode + * @pvid_tag_8021q_configured: imforms if port have configured pvid in tag_8021q + * mode + * @pvid_tag_8021q: pvid vlan number used in tag_8021q mode + * @untagged_tag_8021q_configured: imforms if port have configured untagged vlan + * in tag_8021q mode + * @untagged_tag_8021q: untagged vlan number used in tag_8021q mode + */ +struct vsc73xx_portinfo { + bool pvid_vlan_filtering_configured; + u16 pvid_vlan_filtering; + bool pvid_tag_8021q_configured; + u16 pvid_tag_8021q; + bool untagged_tag_8021q_configured; + u16 untagged_tag_8021q; +}; + /** * struct vsc73xx - VSC73xx state container: main data structure * @dev: The device pointer @@ -25,6 +46,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 +60,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 +76,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 Tue Jun 11 19:49:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694170 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 7FA45155323; Tue, 11 Jun 2024 19:51:08 +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=1718135470; cv=none; b=I+mrRV7UJvntjj2xLKDBv6sXs0P3XLODqTLhjam9ILwKCA7h7juITzkNsUOt4whxAAF70+imNPszPP5ArE5MWjDiHKS/LQVV03fjOw4qB8DM5Zu8NYAz8E9wgdr3jE+ZTcGAY7JG/eKdqPD0kpSZaeNoSiMVBz4sCVosvr0jyMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135470; c=relaxed/simple; bh=EGzLIr8J6g5Pc6ruWwM3htFjv6loaPRNQh8Kypboh6k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tQrgl7Gt1gQqYrq2NhmmSEgFEsX+fsnSeMoolRL0cSCdU97nEjO4Jfx6O1Slm3CgbIdcxOhwRrJKKTBIl7bpC5d3zF7XL1WKXo2n+A87giyBsZ0GWfBbaZPY6FqsC1IIc3fTfAs3yCUJY9Bn8ygfaxKBrUKgcot+2ZYFuINAMzA= 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=Be8b50Xk; 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="Be8b50Xk" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-579fa270e53so2388785a12.3; Tue, 11 Jun 2024 12:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135466; x=1718740266; 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=dmBOyhIK8bj8E+oMmNWfuKWO1MxxTZyTVSN1v/d4NYg=; b=Be8b50XkTUAV4taCda1QRqM20DddGyoIp2qoskBC8Ux+2nZGC7WdHN4o4vKIZFpZPp r9DiBj/FuBjq/KD+0nHoa4mYRYGfsXoy0t8vzxAlH35UXZ0p7Vgws18X42Uit/nHscG7 fV18gJmDJCr1p7j9eedkuBi5EfN/6gUuz9gjSEn1okBtqOKK3qqXPeYhRJ1x78cOTzWI HnqX5WSOEaLgIK2wDPyXknRXTFYqXCLHE12EMOcBuv31TgVtKHcBYcBWdJKtigW09bC+ pdYx8dkax3b86R9OYr/ZfsL8jRLn88RfB5keBY3PqOyIR8RHiYADTYZyyp0q+9chGhue sB1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135466; x=1718740266; 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=dmBOyhIK8bj8E+oMmNWfuKWO1MxxTZyTVSN1v/d4NYg=; b=QOJdxOYzyEfNlThNHkw2MOfCWSNRspVbqREx+KK6XxP14CcwPrPwt3HzbB3Id0me4n GGDe4MWSvAKPO1dupte7EQYfygvMaiJmhWqJ1KbgsqMCt2NNc6iwB7YCjsaky96U2tVd nrK/H57Mpm2yiYfQ1XrEJpWJdULCy7hGsSlhbSiXPby2ZV/4XPPsAZKrt60RK1ECQSv5 e0kKUhm8Vdhig6xeUEnkI5YOytndHK3Af55LHlEb/6Cjk5fQ89lKrlsjpWIatrbe+DIC vLjs+REFt8xnLAaS41dmHzdKJPox4QAKdKPfd8ofw0LLtycKnUctqFS2De2ZOWa+vC/C OoFg== X-Forwarded-Encrypted: i=1; AJvYcCVy+TPlwswXjm6Iqywmb8WfaszO/kyp2AKHXv8GbVKUingHy6o6R2ZmvPDIqf5z5i3CA8rsfZiytBhy5l5PDcY6GAGFVehbVA3oQcNg X-Gm-Message-State: AOJu0Yyxnc0wWZTn8V/fJia1KNsiZ4Z9iuY4wzvPXuY4ZWa3/r0jJ1X6 cHVzUxR/RnmgSH9gWTbWqJFIi+L8sBEtNQ4v+zSQP3//BQhTz8uwbcABsojlO+Q= X-Google-Smtp-Source: AGHT+IHnebIc1CaYifooFoLoGqBbMHHopBtBX0svSF49Bbk+C9xlpxnhWcIF5LENXspq1VVQeHyCPA== X-Received: by 2002:a50:9b03:0:b0:57c:6f67:b173 with SMTP id 4fb4d7f45d1cf-57c6f67b45emr7243745a12.2.1718135466302; Tue, 11 Jun 2024 12:51:06 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:05 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 03/12] net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv() Date: Tue, 11 Jun 2024 21:49:55 +0200 Message-Id: <20240611195007.486919-4-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 Tue Jun 11 19:49:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694171 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 DABFF150993; Tue, 11 Jun 2024 19:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135473; cv=none; b=KAzGGAUdqnEqjlSjXrXqtpxKfOmlBHdYsavX2Uce2xv8PYng23kcrvgfHkhahO49OdM9EfgJbp+kdeUe/CmOkn9WvstfzGd6iRMEU+U+oiVDCZAzhKEZwKBb9KzXHjlticc2x2/wd+3IhBCBFWUKK6o/LCEbWeNq0cxxVd2LwoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135473; c=relaxed/simple; bh=kjYdFUBPAzPkN1UZwpKAOwJLyxC1tiQeE2B7N5YPM4A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g+m8fIrVjlu2q/z5ccmBZiTxUN8w5K7MfvItKb446QxjM01Mo1EZaJe4Ju7A2i+HByuZcJIZpJvOh75gTuauWxIHhCCKJvfdf3KbGrlk0ok5NefaqB0V/+0+oNtpCMMMHHtTjH96nfiMvUqc8IJlB4hHpifCsy6WZnKiXsvnyqs= 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=MAqWpghY; arc=none smtp.client-ip=209.85.208.52 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="MAqWpghY" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-57864327f6eso392799a12.1; Tue, 11 Jun 2024 12:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135470; x=1718740270; 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=8hW1/9QkXf8YuIscopyljOyfTgaaSevIzyohGKSS7YI=; b=MAqWpghYXRjFRjrjPHpgU7HshsSpnW5VhgfbXNzr2puahmlVgA/XPfa0WEzFzgYp/A qZlsqLEdLBTyHGrRLycdq7I+dP/d7MCJlsUDLrLmOb4C2XgqeY8EkrEFsIQSV7ltOzgS TQ7mwWfjzZbQygI3an5GL2MHpo3lRK1vmlp11FW4wMo5dFVRIbHn2XbgcvDeywdYa6md MZ9Fv/Imu96HMdgRCmSvucLWgz0Syc6M/UnEYIQSicndnRhNoklQegGL3/pHuulckEjC g3TIIGE6jk0TNgHJUeS+fcO5gg+QpSU/pz0+K3hGcAmrQzOItisasQu5JA3YYLZHuBja 13/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135470; x=1718740270; 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=8hW1/9QkXf8YuIscopyljOyfTgaaSevIzyohGKSS7YI=; b=HgfeorJbaD3XGYcdPA5KGF+NpNj7BE0ZXcY4CHuNZBaa0imrnaQ+atwKfB2IGmh2vi 8DVJ+lqhuIqk32bL+xf7vGDvtPKr18nQFBIPYiVr0gbHGYoc36vSqblcdeOm08FLVkl1 CYYdEbQDl6XpE+n9A9ceUxwKIrr0g1v1YKztJ0XSFJ6I3bXNmz8hcbY2siUop8CbSYw/ I0hgpNrNqQrerd9br8PFgR3ST9/46auzqmaknJHUvD5Ku3BusNvJDzn36XuThckT4N/7 nUAOWj8rD5BUgZhLGF4oluvD5RCe4bt2gujrZXd3wPCDSOo9lev3wvcJs/h6Mjduyzq3 P8jA== X-Forwarded-Encrypted: i=1; AJvYcCWsLFJTHR5b+r5HqGME9ySbgxnQWHSI32XuDxqC5VFGb2iTKhW6IuuiY0QeY/bOGA+zOmRG0cECw8yG0fZVxmg/OpthpJyVcdlBWPdU X-Gm-Message-State: AOJu0YxUO+5ywym+dy/UiKIhiLzZxeYznJDhp592wYZ/megQ0jKvhUqO AU0mpUg29y5mDsbvTTJDW60eDDQogWTOqyXMhhupr3krBSFWaTRywNqerV2jQZY= X-Google-Smtp-Source: AGHT+IF5eEQjuGX5vw/FmuHzKq5+foeLShGRLaoss1fTB3fgCIhIBhFcHvVP+SoR6y73opQex8exfg== X-Received: by 2002:a05:6402:26d4:b0:57c:93b7:ab36 with SMTP id 4fb4d7f45d1cf-57c93b7ac73mr1911037a12.21.1718135469587; Tue, 11 Jun 2024 12:51:09 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:09 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 04/12] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv() Date: Tue, 11 Jun 2024 21:49:56 +0200 Message-Id: <20240611195007.486919-5-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 Signed-off-by: Pawel Dembicki --- 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..332b0ae02645 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -507,27 +507,39 @@ 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)) + goto not_tag_8021q; - 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 +558,15 @@ 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; + +not_tag_8021q: + if (vid) + *vid = tmp_vid; + if (vbid) + *vbid = -1; + + /* Put the tag back */ + __vlan_hwaccel_put_tag(skb, vlan_proto, tci); } 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 Tue Jun 11 19:49:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694172 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 0809E155A5C; Tue, 11 Jun 2024 19:51:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135476; cv=none; b=EpsaUkSmEGNNPyNafpZussI+d5qiraayu2GxadB3th0CDpNG03nfJxCiyJ6mX3zIcAZn1cpbQPauj1SyNptxe0iNcD+7bdL6krYWh/Vinw6CLXrRgKuAnOaJN87pb/vXxNHKHjHtdhakLnKfA53DjrTwQMHJolPes6G6aYvGcAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135476; c=relaxed/simple; bh=5/D4BQ1WBsT6GU2VLzpbbHXzFCv7BFu7hzKEmRicHmc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M6c3LatqLyfQOSz6V6FQvp3WfTVmJgXHjFiIgVndlZYOMJZsyvr2RbS8F4/bJjucfva3B1y83q1tVWqUsNxTdq7uyi3cEUo/aaMlKmM2YI35q25PsPuTPBtD77NxsUUFFQv4PLOs14+F+47Q0M7ZhlHIta0G5gLZn9Cc2QaXtbM= 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=egf8ggWe; arc=none smtp.client-ip=209.85.208.43 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="egf8ggWe" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-57c83100cb4so3094495a12.1; Tue, 11 Jun 2024 12:51:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135473; x=1718740273; 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=EjWQ6m5e09n9wr/OJFVwEPXmlpK+mE24iUfx3PoRLCk=; b=egf8ggWeEpo4QEyqSAycZU1gpIEU1pwVluQAZAb8IKodVgr97Rjggadr+kn3KPHphq CO+B1KFx4VYIZDGaKO7WwoZjKCl6pTcLUTDhvZssncfRF9V+y00+9HXED3ZkJ9OinzfN njbC3X+zVKyjahuvJw+DAIucn8V2nHeUCHw037EDYm0Yt7gQraEFCCPAB2Gl8iVhumKB n8heP+iUTJ7ZUBiynGFc5+kbsBsDizL3DITX6OP7ICdD/oXc3cqecxAYuO6g05wV/ldW c6yJUKCxNrFDCAwqSP9ut0bxeYEQnWFvegyD3TUMdCc+lw5RXdSEqI+t0wCPDh88Avbo MOKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135473; x=1718740273; 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=EjWQ6m5e09n9wr/OJFVwEPXmlpK+mE24iUfx3PoRLCk=; b=ZKe0BONrzKH+C+R/2N6LLUXjbH2wFYEPGJoIgwmE3gobe8hjUY9XqUhah02FYvjAde smd/kthpowppNBXGtVGO6C7AgPEeDcDC8qBiIeV1Umkckenrb3INsdJ8dhbjbsfkwZLX sjK774QoT1jxOkLxvO/Yp/xWgBuUbisueVt9T/ZwkYYGar0Wvfp3oXdfEpTyVa2d+NN2 4lcFl92BYswp2/oAFMjd3USmPScVlAgQc+oSVxx/F8xR47vBs+8VosH4+8hTUIymfsSu tNprE6UmaLSttK/dLRMopKRLgk0yTNvY1vG/gcJgCt7cidOMmHHpo1lIpTF/fOHFcdoE yiUA== X-Forwarded-Encrypted: i=1; AJvYcCXoiIrGDws1gYBFq1Ay1OR3SnpXNojCvhcAUqLmZydFU/meqXPwLIJZC5Ta7wisTKOGf0JYV4u6yYwaGJfuip0unwPLgXmHIn7rXaRP X-Gm-Message-State: AOJu0YyRDe0hh/SljuYHAB3JWLGNwpKzciUQv4qKsrzuOYOhDEppfYMy vGWbfJBuY2/Q7Tq1YiYxzhWaKBrtpSWQae1bBdMgkM5eIcHgDdvejuEFIhzXMuo= X-Google-Smtp-Source: AGHT+IHkXYq/Ss6+KK9itjakY0DDtOx3bnqmqMYtddtdV59++6y07lw3Ptj7eB645bKi5vd1jRFyBQ== X-Received: by 2002:a50:bb07:0:b0:578:6c19:4801 with SMTP id 4fb4d7f45d1cf-57c81afdca1mr4126722a12.22.1718135472828; Tue, 11 Jun 2024 12:51:12 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:12 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 05/12] net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too Date: Tue, 11 Jun 2024 21:49:57 +0200 Message-Id: <20240611195007.486919-6-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 Tue Jun 11 19:49:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694173 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 4659E155CBE; Tue, 11 Jun 2024 19:51:18 +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=1718135480; cv=none; b=I09buG77XYZHTotB4Q/2CMhGLCxHFgEy7lhFibZbDp3cmFKE+38FDdcIOO/Mw3Ulc/RTmO7kNF+cK+veWdgXgVEwLfP9EBGr3aLdRH6E1cFdIpXWfOXIv7lDUOwoY0WXDYltWYh5+RJCcIHBzFBtXqulZHVkCsrbVOW1Bi0uacE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135480; c=relaxed/simple; bh=Cc6KBm/kcHsJEUO1e/40plBCarP3vyvwxi2sGSDWHYE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cSihMC+2p2X4Bs9bJSTbMYlHXpnpucw/1vd3eKABy4wG9gzWXII64x9Na0NLsZMkn4e7VM1RXTn7xNEm0MX24/K585FVvcrSqBDS5DRsrm2urLtDzVvA8tbmGX6I3greSyE96vEhhMa2KIBnE2BRRFOSlCz6sskxinXeWgahfbQ= 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=dUIJWXaC; 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="dUIJWXaC" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2ebdfe261f9so44902151fa.1; Tue, 11 Jun 2024 12:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135476; x=1718740276; 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=5SOVH07U/QHe0OegKKIrnCZXEuVAF4MtMi5yje9hWAE=; b=dUIJWXaCJ51+vAenWinvHGmSPoQ1SYQvXaQQj6xn33wSjfEBS6D+JEjty5nFy/VQW+ HL9L0kKPFHdKNywxBPZn0pMcgGFgAniva7hW+dLa72/oq3yVSunC+r4OVnUG8I7YAW/X q2thNTR0Af1/ZNJE4Eym8PTMdSLfoyq4iHOYEvJp/xKwPqclUwVYV+QT5hRlMQPEvpwk Y9oSb1plZtErYh5Op7G3BAMn9VmY0LJqfApBoOi+hXLZz7y/SJRacSAyLYzAc+Fxi72I LjzHh4cTWpLd6bqqGCoMn9uhlqzr4WoCbkzwQIWZK7c3drBHKLFl9G/DC3XzZ4CyaIoD I9JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135476; x=1718740276; 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=5SOVH07U/QHe0OegKKIrnCZXEuVAF4MtMi5yje9hWAE=; b=TmC46WjKAVBWmUGWlVJigPCd8xm45xmm7y6cTogZO/+WsuwaCGVXcWLRE8JlT8go+k o9Uix3mq34LTAvrG9ak/BWHxSUfwOV0s7WqZqkvY2rC5b/eORas5ZyYj46o+9dpAQ92d 3ZwrHgp+D+zwDRkivfyCsBKJ3LqKrlFylOQOtrWSwKt9UBNdESC4xCe4dgTn6zS5+PHq nhu459RPlMRlVmB4AH+2EuS6UOw35ekW5wyuONIQjcb1cEAa6m/pmIGXiV/aq5AQX6St PS5iV0croiuvyqzEbhhoxf9TB5cqBaZar7kHhNnBPKEE2qdsVUxsfNn/AlMP8kUfPG2a U8mA== X-Forwarded-Encrypted: i=1; AJvYcCVu1zugyIR6O0tjWd8IHwlM4jnmYPaYZhFeMxubNS2Eghd9q3RQ+6E0k8Za3QqfZBLTP069C4ZoJocI7E599f4DyTO+JG3YCJIicMU0 X-Gm-Message-State: AOJu0YzfHfZwUny+kwFqp6Cp8zG+UqeOE3CLAVpQNUuRaGMxULMkxt47 WZyfBFWCNytoaYh03p+PzrOuujLV6THNS/U0HjLBkCfpjDSFnZAUiT0/YCFSEgc= X-Google-Smtp-Source: AGHT+IFBgiBerS/nAkaVCo7w6S7mqMBVOwrqlDz/iSu8xuMNSPSo1r296Ka5VDNn9rywyOphubqowQ== X-Received: by 2002:a05:651c:c3:b0:2eb:eb82:4112 with SMTP id 38308e7fff4ca-2ebeb824186mr41857121fa.17.1718135476149; Tue, 11 Jun 2024 12:51:16 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:15 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Vladimir Oltean , Pawel Dembicki , Florian Fainelli , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 06/12] net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user() Date: Tue, 11 Jun 2024 21:49:58 +0200 Message-Id: <20240611195007.486919-7-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 332b0ae02645..454d36c84671 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 Tue Jun 11 19:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694174 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.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 C472A156257; Tue, 11 Jun 2024 19:51:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135483; cv=none; b=M15Md2k/UyJP7xbUKcTtpp2BJDrF3zOl95GmamO/zgVoKzA0NsZ3qJmi886u3Ru1cqvy2gO6W5USkd7AMOjGP2zfxBKch2FtWttv4tTb5Wupt1cxRuA6VlbPnyxCZ9eEzsVmTDnpeOnFVcd5vFcBlakOqgax/Ib+GlaRkfd7/J4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135483; c=relaxed/simple; bh=CeZvKfJM6diifXGTJNLHv33j2pa/42CSAk2m9TDYrNs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iRVs4AahipF6fv9o/KpPU7GpnRPjtzhW/MqI3JrOYiXWlcQsdmo0fEoXu8FFwkMT1lHs99KN8yTD9E+r1h50d5yYwKvdZOl+q5VRGNPpnEG8AROL/0INXNG7cn/0fxK5hIFKH9qXGE5vr/AUlrZ06gd5Fg9apgloLn183CO8u9A= 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=XTIo1M8k; arc=none smtp.client-ip=209.85.208.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="XTIo1M8k" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-57864327f6eso393094a12.1; Tue, 11 Jun 2024 12:51:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135480; x=1718740280; 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=O5n9oE0ukmeKOaxWYmzQjz4q7vlmRvhTLb2hwLacImM=; b=XTIo1M8kRmqY3DtgJg4ZYGLlRWHF+2E1dJ9d+WEsYxuqLIgCnlNPTwUXbfTIN7pHoj 0KfzQyBDWOk00alpoGbkfhCIkmvUadkhHAH4JHwgHq76bqJcxdNdjoknfVLUopi5vq4s bmVgMTVZFo9Diu3klzHvvZbgHE5UQ35CCzTwPDuHWguz45TWKAllIlANqQs3ICl4VlWO DS2IQLUja5PsY7nyOrwmmqabc6GTkXNkKSAR7nNnlXaOu9caRFQUVOUJk24KqGGVkHvX th4L6k++jFHj9x9jdTidMkFaNCjujTQn9UjDJ+K5+STNG1pvbO2jowvUnXFSy4G7ah7H hViw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135480; x=1718740280; 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=O5n9oE0ukmeKOaxWYmzQjz4q7vlmRvhTLb2hwLacImM=; b=bA0826Co22DDBvadO9hPAtLKEDtAJ5x8RzanIONb/LWjfBJDjshqEOrKLsymMAtuzT szWspz/CXPgjqecddyoYlgx+MZvNzrSWP4zo/4Gb8h6u6MBqOZAYRgVp7dN0bUtI6EI9 EcFVNbnYeNvkw74HBty7SeLRidA12qzLazJlReCBgPAEgtqqOPDb+v044xQHDfbD44vX oqy6qLp2F81YnkiZuYjpbdECgXyUhNGLWuA+H446fsWpk521GIhCjbAaftNZa3Xpd0U0 xdZiZqrUjKXHeF0Oa9kW71IN5uG7ttU7CNDeTZAT+uSIEYJlcPgjTkH0UzByRO8MdjiS WXoA== X-Forwarded-Encrypted: i=1; AJvYcCVWM3QL1IBN5NY2BtJo9LMPDyMq9IavmMHfGdOak3DJDCNd4i9uYhzxRLKrllzIdC9cpIZrxeNk7x75pG57l1QkmofRn2iar3qiE84N X-Gm-Message-State: AOJu0YyPQhRB83Z9AstOB6ewZN5H9O2BbyjAqGs697jzjWU3dJd4qxYD MYMGQVwu07qH9nSItTSnA8SOAjEN4cpHTpGoDFawUDNry8aRFWO4TBL7xGQZFBY= X-Google-Smtp-Source: AGHT+IFLHXiU4CR5i9G2b51OSC48LHzX9vMrFNtsOUTyTBtcrbp7SZrY0stuUQKoMFeph0YX7TllTA== X-Received: by 2002:a50:8713:0:b0:57c:614c:56e7 with SMTP id 4fb4d7f45d1cf-57c90e53d08mr2108281a12.18.1718135479497; Tue, 11 Jun 2024 12:51:19 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:19 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Florian Fainelli , Vladimir Oltean , Linus Walleij , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 07/12] net: dsa: vsc73xx: introduce tag 8021q for vsc73xx Date: Tue, 11 Jun 2024 21:49:59 +0200 Message-Id: <20240611195007.486919-8-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 8e698bea99a3..e59360071c67 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 Tue Jun 11 19:50:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694175 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 DB395156679; Tue, 11 Jun 2024 19:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135486; cv=none; b=KPkN6bKyJwmJn3l0eTQCWIXZItlMBy6pVmc2mWQauP1HKDIHydDVempTnZ9GcG1cOsVlFooFqFccMx/ugMg8MYHzNvJXwcBSJUpFvTdfBvm0Dj3NCKqoCkRqf6f9jpiRVUNT74KZWRLmJQctfWWPzLy1iuLw82zpSPa08Zivu0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135486; c=relaxed/simple; bh=2x/TeQyPN06DQxpdVXcwuP7TaDQZwqmbyTlMAl16rqU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XKEN908zr1RRePD9fi413yVcpJ4qPzWSJRzPp0QzliV1KFWbfYt/F5+6Pbr1oX/2ostHXbYrLmR4P2edMiYEjbbEtE6FuJDUwgGnH4Ff+k30mTlR1bw/2Ra4Lef/Hh+9zGJdL+vZeTcIhAWOnSfRZqOpn+228QvXNf4ZE96Kls4= 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=SHIYH+fO; arc=none smtp.client-ip=209.85.208.175 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="SHIYH+fO" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2ebed33cbaeso16560441fa.1; Tue, 11 Jun 2024 12:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135483; x=1718740283; 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=7lXnGQzCsTNRuKgirCpeRx91mu5ywCx4lqyrJRq5Um8=; b=SHIYH+fOdZFhl4qr4uZ2e4fE/BZ7SnYYSZzKBWafZXpcUQ/0zQmt4x84M+gWpkBfoH W0VH4pHo77AmmVUBSUnLbBuxhXOrGQP1N4Ce5zncO031NaHptp+RGE6hx7J6k2xnmu5j BrJImRozSVc+z4HJW5J3SL7Jo6zYHaiJNuhhQfd1USbRE8fKY4qbX74bPPh9Nr76Kt6A gD4LAPDk1hCnVFp9h0cHHfb3xVYczNP5gAl81xmkK79fp/Hx7DeFMWmdncqDSNraa+rE mOYHD2RLiUxs6jNoYLKDfNHDVqFLPdhO+A4DqNiSQhyga281mb8ej//4te+G5RPT1ZFE D2ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135483; x=1718740283; 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=7lXnGQzCsTNRuKgirCpeRx91mu5ywCx4lqyrJRq5Um8=; b=TqdXz2CP0TS7eQg6lAq8LYRjnn5tjtFu8gQ/OrUVPd5BxSO7gIOftLFegwD+1wOGP5 bvQdYhHDSChJMIl++R+uYvRPAUUAnYesmZ25w10MxcZpqvAtbWf17nhjNoso6H6fg0mQ Q60ZoiRF055k03mo2fZg9aGZ3Eu/H71VEi1ivsW9mskTKLOUisS1drIhkidYRWwgSJ16 bPwS/dA+3VzNruFEZncDFVq1VvYPgvWZwuLi4gtHk4JHXwx229SMbHenCv5WxKueIFP+ 6g51xi7EaSkbsSu7zezTKEhkNp8eOfEf1p9YWZEpEP6etcfB/LDMsr7N8tcVt6+AogqR L2Pw== X-Forwarded-Encrypted: i=1; AJvYcCVQQw19im7jayQb7+2/dDwaKLd1Er+cjw8VDqdCzE2U7p4gLHYGe3pacTiWw0BUL2JEIfbIIPUshZWpTzzl3xo81DAg8Jli/lISyxfp X-Gm-Message-State: AOJu0YxyhTg2Uiacqr7GWxeIOBV1f43Nb02eqpyJe0bvlPhaDpEvfI8K yZGeENm6JKetUGhZRMqltdzjEeo+4I2bfEXAAJEEQMVwKy6Hhv+SFvNsbWTnQLg= X-Google-Smtp-Source: AGHT+IHATGLqR54VpVvNCv1vH/FBEheSgLlze+LZn3798kA3FcHJN9hUVqMi3mx7lECYgzmF6KKHTw== X-Received: by 2002:a2e:a7c8:0:b0:2eb:e505:ebd5 with SMTP id 38308e7fff4ca-2ebe505ee5emr54597161fa.3.1718135482761; Tue, 11 Jun 2024 12:51:22 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:22 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 08/12] net: dsa: vsc73xx: Implement the tag_8021q VLAN operations Date: Tue, 11 Jun 2024 21:50:00 +0200 Message-Id: <20240611195007.486919-9-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 | 56 ++++++++++++++++++++++++-- 2 files changed, 54 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 782eddcb1169..86b88743890b 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) @@ -1488,6 +1499,42 @@ static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port, return 0; } +static int vsc73xx_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid, + u16 flags) +{ + bool untagged = flags & BRIDGE_VLAN_INFO_UNTAGGED; + bool pvid = flags & BRIDGE_VLAN_INFO_PVID; + struct vsc73xx_portinfo *portinfo; + struct vsc73xx *vsc = ds->priv; + bool commit_to_hardware; + + portinfo = &vsc->portinfo[port]; + + if (untagged) { + portinfo->untagged_tag_8021q_configured = true; + portinfo->untagged_tag_8021q = vid; + } + 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) { + vsc73xx_vlan_commit_untagged(vsc, port); + vsc73xx_vlan_commit_pvid(vsc, port); + } + + 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 *vsc = ds->priv; + + return vsc73xx_update_vlan_table(vsc, port, vid, false); +} + static int vsc73xx_port_setup(struct dsa_switch *ds, int port) { struct vsc73xx_portinfo *portinfo; @@ -1595,6 +1642,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, @@ -1610,6 +1658,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 Tue Jun 11 19:50:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694176 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 21959156C47; Tue, 11 Jun 2024 19:51:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135489; cv=none; b=d4IuZK6WOttaTu/SlNQZ8OZmbz2UWShWP42riIPGniG40BXTrKixXn/mctXpkhyHUFRb4KfKPTNeYAHCmPSyFgWvGG1WI6aPOlHkoIdXEnQVSXdnKqKQ+9yR5zlRlg8G2GAWakrJJu2FREyTPoWYc0eQnBhf8D+QKCgHQ0elisw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135489; c=relaxed/simple; bh=X0ZPmfLloqmpVIb9TshXzGhKrVzZ8CtutBNGM8GN3qM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FJKGyOR7F+TwP1ajWSPvuD8wms48DQRZUKCifO4EcPF6b8cIxLKiKKej9k+k794FlXgHE6sAoiuXHNghVFlqhP49dLhVfU9UvkCDeJ4HvOEInQ1c6IyurwjtDW2wMQhtVlbAEo2w4wTXEiHu2P55leP1Owp9dNXe6sjhVenOwVk= 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=TFq+qx36; arc=none smtp.client-ip=209.85.208.174 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="TFq+qx36" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2eaa89464a3so65982241fa.3; Tue, 11 Jun 2024 12:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135486; x=1718740286; 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=9eANHmQBc3AlTNfbBTeiU+zRfE2tvSTSJjYs0pCCYYY=; b=TFq+qx36VvgQxufz1JVjWGNw/vfNB/IPziUlYeFQosZ7WGuGmQZ0fkZ2E+ATY9Z1Vr jeqiON9y5Bo7+ma6Y3AuzXz5Rx+lEEpQE4SLjTWg+GHLdpHqrGZc4qZZ95roOtBpijzc CxR97mWS1l9USD1pRo36Kl8Xj3co9IBYP+mFCn4lyn/jo52xHNXYLuhyqWDgSyIdqAw/ 7lw2bb8VnJEiy9Bhy/mZOcGILouVY0jl6v1abQIVPxdPsmnEQv5rhFM12tV43Hnw4jt9 pVqzyWkofRWY9DFtoCr29KmL1YWzHGFhwJC9R/mp/oEvHAVIuKK727X1aRuTdk61agJd ztKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135486; x=1718740286; 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=9eANHmQBc3AlTNfbBTeiU+zRfE2tvSTSJjYs0pCCYYY=; b=MDh8we96Va1Vm5XeEiJehntIYnUjVOA7DjNTt5UJjCSvy0urZvsmlY0D2a0QtgCT5s pq+qRJYOfzp9QMdJohOoDi89s9vVE3pcLc6KYQc8S2igr9xjpH1gKl9a2uvLo1w49ZVQ EcYORbakMwkJWT31FyEqqvZy05k/9cQCLemJiAwlyOI6eRNsA8GoYXQ3y/VXsKvNnnG8 nmNZXWWGjpqo15f/TmTTlyxySrYGm2T17+WQ1eS+H3liXC86DhXj30Ye0/ZE62OShJqN HhvWxdP0mC1wTO9ngsu7kCpB1mY4iizyPstfneCEOZYrnQIPszbke4b/z1e+IvAannWl r4NA== X-Forwarded-Encrypted: i=1; AJvYcCVuOnN+arinXu4nQK6qGC5KIt5JLO2nQRfGdL8i7wBCQGNgzSe3UKetXPnZDoGro5wYhjbJQkrztMmWAiDUaX1nfSrA7a2ZwnqVSx3Z X-Gm-Message-State: AOJu0YzNDM189lJ23QBJD9Zkewob0vNVoYid6rPxz1EsciQM4f6yF2TK 6HSJnFpKSlj5DAfPh4a33mKq2VUyzyNBDYVgeZLdyyV13HPQ6nyhIbU4ENcw6Cs= X-Google-Smtp-Source: AGHT+IEESn7w2tsjgocoMjHbgQP//+f5JggTuvmW5T4+G2lwrGenyJaQgwJHHf5X55t123Ry/FWu3w== X-Received: by 2002:a2e:2d01:0:b0:2ea:85f0:9165 with SMTP id 38308e7fff4ca-2eadce35604mr85032271fa.19.1718135486075; Tue, 11 Jun 2024 12:51:26 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:25 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Vladimir Oltean , Florian Fainelli , Linus Walleij , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 09/12] net: dsa: Define max num of bridges in tag8021q implementation Date: Tue, 11 Jun 2024 21:50:01 +0200 Message-Id: <20240611195007.486919-10-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 Tue Jun 11 19:50:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694177 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.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 B7435156F2E; Tue, 11 Jun 2024 19:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135493; cv=none; b=KrQy/KYzzE5RJcXuA5FiG4FTAdFoOivMvX8PvYcQefY6zU0tKoBtE/3i7PWfxHCV0iXmgoG2y5kHKVx8V2VhRpu5JX1zAsn77NwjdaSgUOLugeSjweNHQz09+BNiMuF4bHXhK67BRD9LtOxhwDNHC3QjBCbj5G7bjAPHAQt+JzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135493; c=relaxed/simple; bh=ZlQWRLWgOu2Qi85OCTxl2HybPMlfiOoh6DRNweGKCaI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FEgf8Ij2uEjlxTeve4BLKPZznZWW9bK72PeXXYC6CGxuNCtBiWICIgTApLmlJQBnI9oZRoFS6Jui4iybzQ0V2femm1Pya+QG9Z0v/1qg+yCg5SC9mHkSJB1ndkGJNwq47GDktp6dTDFXNlacqniIsbVKmFBT1RkTPS2mgE/t7p0= 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=LTbU5Wj0; arc=none smtp.client-ip=209.85.208.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="LTbU5Wj0" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-57c61165af6so5370561a12.2; Tue, 11 Jun 2024 12:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135489; x=1718740289; 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=0EcKXTdU/rHpORXQYu7ZrEBF+RV8M26YBMM/XJd4Ec8=; b=LTbU5Wj0aIH9ZCEUGhhaLQM1ZpUv/v4BK4V0UpPxqrUcaqx9BfSb3ETiV88Eg9AGDq m0+AyjmNghsG/bzBOreAJmSz0mJ6QwKY3dyA0lJjWUqP1xISpo4Us05DcNNYHaatYAze iPOEOJRN1M93OJ6SSqeHm8ceNbkHi82PkhtLHBh84L+8k26FDqE95DqJvkyktrl9DXHQ bK62ydyB79V4iJxvhtx0IALwH9n0s7+i5Mk6zBTNnBxY9YKhpa2jBMXnj2hatuLmvfG1 eOiVMQXVVJIuz3VDx0LHfC1D6kC+LLiuF+F3WSu/5ZKw0wxWbtRhhAMqfy9goEJ3+H6J xCkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135489; x=1718740289; 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=0EcKXTdU/rHpORXQYu7ZrEBF+RV8M26YBMM/XJd4Ec8=; b=FuNR2WzeY2iCiC/pMmuu/eiyOcmRyWiBp7yneJqsED0N+1xSQPtTvjsmq3vKPgTrAx s0JkR+LaX7AezngIDirhu4dyZ3jjvRdF/p8BjyrGXbksAX0cFZ0ygh/MP/d88UL4orYJ h+3VoxWqRt0/EiiCOZ8vXRocubi2/Za547aVPkvkTCJyt8wt0q5BeeWGIuinVkx8HOlu RaHPFUiUm5N5kj/ojvXxVoKqLAzBzcm7oCB8/NjF34wEhzozhT8tn+nIbx9T3PNu9K0u uTbp7Emdpt0QCa32zjpqgyfdA+gXwA4/upky8L6VMF8Uke8iWgqOjP4UGvaqgYwWri5V isYA== X-Forwarded-Encrypted: i=1; AJvYcCUu462hwP48nMtQuOHHmdqlmgRvTojawRib0socNrg7b7Sz7UgR05P08HFJIEE4d5rcl3QuIQpAY29D78BFu9mNNT11lq38MX9YjyS2 X-Gm-Message-State: AOJu0YxJ8P5+gjyQ7PzeEgRy1t6xirVJlzFm6ravUH5HK6+awV+hRGMv JDsxJcsGwWZjqeiYU9/AXdz3euyxu1oIaDL8q5oau3b6+KWUmZkLoRcIq+4ClM8= X-Google-Smtp-Source: AGHT+IHnLoZG3nr9h1y2gqPTc1Aib48NLG6kGsDXEg3qeh9Eyft5qg1elJokHGGnaReTIxm3OyMKqQ== X-Received: by 2002:a50:d48f:0:b0:57c:628a:1759 with SMTP id 4fb4d7f45d1cf-57c628a1ab5mr6315378a12.8.1718135489313; Tue, 11 Jun 2024 12:51:29 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:29 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 10/12] net: dsa: prepare 'dsa_tag_8021q_bridge_join' for standalone use Date: Tue, 11 Jun 2024 21:50:02 +0200 Message-Id: <20240611195007.486919-11-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 454d36c84671..81ac14603fb0 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 Tue Jun 11 19:50:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694178 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 AF8C3156F5D; Tue, 11 Jun 2024 19:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135496; cv=none; b=oSyhwsW1YNjq6b1MMx5klGeiF3k2TAVv5JUOz1EG7goo3gCP8ZkvsXMXcVYykhFqKfuD8MAfOW1ImK2jx0plBVNP2f9qFEKhSysQCmVvF2a18FdfwWKx4nd3zDWNpWkCVenJQ6SOB2U0eWBFXhAPy7Ab1qN6DP/Ry1SpKVypado= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135496; c=relaxed/simple; bh=x4lM3sSavOZxrGkFF34xxMmDYW2tZsIScz98YOwR+Gc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Zy/6sTeKlOH4DvVigUwte38hA9B4f3TINVc2v59nw3rCMXeczMCit5UtQrRjYl9ZbgmhwL1+sjccZ9jbxeP5oO16ajwGRBMx+chqq96qV70i4Df/WgukxBQ9oEd0j5MLDt/FKZj/vo9ZrBQ7kAVIfZ0Hf/zWMW4AQoeapKSmv9o= 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=RKLQYjoA; arc=none smtp.client-ip=209.85.208.172 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="RKLQYjoA" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2e95a75a90eso66268511fa.2; Tue, 11 Jun 2024 12:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135492; x=1718740292; 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=VVXbCTkw3GJGcrXuQk5Rjkj3e+1RnM2j78ztInUT5TM=; b=RKLQYjoANCAFfpngL+RHaXHLBr7lHqRu8TCXReWU7xCH2jRqeXHx4w4y04ntBVZD/g 6w+3PjQevr7WqhK2P3t9KOyMxb8yyBHuQ37MfsSadKnqblH1rfjS+h4z+L4cWDPj0MJX Y0JFk+G8bWBmPJzvBF4jBkLjhIiDs8s0sg12GWIQuSFrTfNLuD0VD6GHMxZoLLzwXfee XjxmNZyvxy9SmP39JSTeVT5gORCW5u2Hqhp8vqWXMOyWwL78lg6OGaSmMSRUez3L76TU U5c+YOY/G984YW6simdCyov/LO1+DDzYJLaA4VhqwGRdJVkgtLoEo6HUebXieKrFWW1G b94Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135492; x=1718740292; 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=VVXbCTkw3GJGcrXuQk5Rjkj3e+1RnM2j78ztInUT5TM=; b=sQ8kRIYEguL6UXNTFcGeoAG8JJMsCN5I+7y6SktgxtNKDpQwntmX7OqjwKS+/71zpG hbI5BMdoEplptF2r7rQDNw9uj145XNR4DE5hHfg3itGlBIZy2RkZKnbDxnI2wMmYmi6a /DvLXQVNaz21LQYU++D4MXeLmoSjS+SLn3FfjC6oSLUlrl087mhiINZBsCuES/Sux8IY Wj53uBSqK61+pcBBGeiKxrd0VjbhU0qBsoOSQGDy72RbmcACuz8jJsVyjvMi3uXqy3EC 5SHDVLw/X68khWduDOeFyPeBTGLtN/mJRIDYrNwZ9UGzbJD7M+gPSMIxy8Q11Jhx579U UDsA== X-Forwarded-Encrypted: i=1; AJvYcCX4s2BZuaxc4QAFKZtp9g8sJgqz3CNlzkgZVbRKT6ycYAuW89jdkHgiTIM7feuh8X9lEMpdwUHpgOlfmDwDPDcSli609VQxZiApkR2l X-Gm-Message-State: AOJu0Yxgzok7o5T5epTQ4D5UR9wKaSyRzGh5tf7bd2S+miPeLQ1GSDZg QFX7eHpqIou82cMKUmfpvJVmTGIPXejwhrZOkhzIJZSqV3z/6AiPjDvMABhhAfs= X-Google-Smtp-Source: AGHT+IHXkJkUNKCuiSZ6Q5DQyPFyoC/V/XM2KKxrEac7bSQGwvvp9Ktw+xhF51POMJJA22To3NIrxg== X-Received: by 2002:a2e:9592:0:b0:2eb:fb68:38ce with SMTP id 38308e7fff4ca-2ebfb683928mr1689311fa.28.1718135492575; Tue, 11 Jun 2024 12:51:32 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:32 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 11/12] net: dsa: vsc73xx: Add bridge support Date: Tue, 11 Jun 2024 21:50:03 +0200 Message-Id: <20240611195007.486919-12-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 vsc73xx driver. Vsc73xx require minimal operations and generic dsa_tag_8021q_bridge_* api is sufficient. Signed-off-by: Pawel Dembicki --- 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 86b88743890b..7d5522e146f5 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); @@ -1651,6 +1654,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_setup = vsc73xx_port_setup, .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 Tue Jun 11 19:50:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13694179 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 15C59157492; Tue, 11 Jun 2024 19:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135499; cv=none; b=KhvN5W1pqVqfwgCETta3U4O2RUPdRTnxYGZ8iflx0TjsUMPoYnb3PGQAWnpQ6IzgeQlXKXHOZ6POmPxgCzxu2Ru/uhcIT2byhZlDgWlHB3LNNA95PW3s6cZh12mAYQAj9ZeAtgQGJvYuK1F115VAnZLuzyQxSTqpSzJRty9zMBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718135499; c=relaxed/simple; bh=+RDHrnohSAyhoajZ4SCPPdctIWJd9H2BoT3P/Fcr22U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cLGQKcHHLkeY4mMY2zgiHKn+B+qxuc+IOyuD6jGccl3Iouzo4ubt5YpJ/FbtmqfMuCNjMiJ3BIlqICKGU+NJfvDel8EyRINDTAmt7eXJjKbQhjwKKyEODjXDoEAD9JdVc1y8cjGvcouPDV+baqrcUBCH1GEj+Un6oqXkfIiRYs8= 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=P2EPFSHe; arc=none smtp.client-ip=209.85.208.178 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="P2EPFSHe" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2ebed33cbaeso16562421fa.1; Tue, 11 Jun 2024 12:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718135496; x=1718740296; 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=A340mtEjf+HpqQSbD/fX+pjSP4Osr75EcDU1L1W8Y+8=; b=P2EPFSHeLhTcxe5c3lOpRJoCko5gnXySYtS18ZCx9fWbN5+CLYswxAU0sp8uLHfl45 6NaTnRaQA1aYHupDP9IgKp8tQTkWZZKTY/oCjT2j3YpJbzJLQAo6m6IWISebjBooqgZ4 fWOzSNPXtAQ27utBjOCP2nqU9n9cS/tE3yg3/ze1oFnCFW1B+zVqRLi3lQW0UOuBqb9S X95lTtIFSD6mzcQeG2JNGH8Ih3+kaCcjbkE+cYBvtBYHDjemXR0aabK3kF4XaOLDlh65 fJsNk4GPGjZs3CioXdZRFnqVdxBDTTwBB9Wezy8twnAWd0v856eMJJgQJr39KM5nBvPH IIcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718135496; x=1718740296; 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=A340mtEjf+HpqQSbD/fX+pjSP4Osr75EcDU1L1W8Y+8=; b=vSvwd27XQ2T6SGlfLBP1E/VKihIOD0pTdN9/wkYzGFy/FjB7niRUnCqIazM/rCFMIl nf+uVw1rQhkSNJbWKLQh6oUOLjH48it2mMpVr6QDI5PNHMxOTbD1/019+bRI/8yXYU/L kdDXzaL/XjWTy+r3xywKW/XAyTur2MU3V6nko/lvBSad7SQIS9EEhnIS38DJn76HCBNj 0aEpim54bukJ6hinTi38nKPUT3+6pxcsTAKz9dJLrKcX2b+QaXhUiop2Xmq1GesAejB2 3DctbSgkb5+mxTKgEU0Yk96GNrK45vkEduoym/416Y6bdpjPfuB4GAXScfLwg2vNVhSu gN2w== X-Forwarded-Encrypted: i=1; AJvYcCUC8RmeH4rgrIvK1yLoG4JAIrv+XFMwRrQJuOSqK6CTWaggCMdm0tpfGNmjK0IvDTqXT0ggkQJa6Z+hcfCPN6fSm/f9Y7UNp9kMXnJe X-Gm-Message-State: AOJu0YwccgSMpvLLlch7co5WRwQ/Bh9orNPTnPAoalgFntkELx3h09cU hr2k1VIBg03uqBx1LX7Qtd76bK365SCOyF2O1yM9f+PJhy3wYnUwBtn0vvJxc4Q= X-Google-Smtp-Source: AGHT+IG31zr6oc0gMnKxXF2RWOSy95HFOTS65nReVC6vqQZxdn0Jh4YZBarVwvc6/oJ7elyjcmOCqg== X-Received: by 2002:a2e:a99f:0:b0:2eb:e4b3:2782 with SMTP id 38308e7fff4ca-2ebe4b327bbmr50365901fa.52.1718135495890; Tue, 11 Jun 2024 12:51:35 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c7650b371sm5286737a12.76.2024.06.11.12.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:51:35 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Pawel Dembicki , Linus Walleij , Florian Fainelli , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next 12/12] net: dsa: vsc73xx: start treating the BR_LEARNING flag Date: Tue, 11 Jun 2024 21:50:04 +0200 Message-Id: <20240611195007.486919-13-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240611195007.486919-1-paweldembicki@gmail.com> References: <20240611195007.486919-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 --- 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 7d5522e146f5..e15098a7b75b 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -1538,6 +1538,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 int vsc73xx_port_setup(struct dsa_switch *ds, int port) { struct vsc73xx_portinfo *portinfo; @@ -1616,19 +1641,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. */ @@ -1654,6 +1681,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_setup = vsc73xx_port_setup, .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,