From patchwork Mon Mar 25 20:43:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602933 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 B489F5C901; Mon, 25 Mar 2024 20:44:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399479; cv=none; b=F/ADb6NDFN1P45jX2qSDECaLXsOQBzh9T9zHS/8+aNWAY7b3NaBFEOXFc7D2HIsk/yEVGVWL5Y7tE3XJnLEeNqM4enyDehvGTE7zaKF1ccyjVW1k6RI2dIMutmx+mKlAYTWpcKR2VeentmDOkREwMa7snhGzQWbOeS0wNFNp7Lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399479; c=relaxed/simple; bh=GlSUQz1tJAfco/7YWHdhANQ0v28uxyKkDF7xpgAQN8I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RrN7nzhKk08SWEoTiRqASkXBQ/18s/ljkMP4JVETDQvH6uy0dDPqsZPoepW1dyR1ESBkZTKr0Kye9DfpE7V8Jj+NGUXXTAHxL48pu6hA3wpciJ21g3oWk3hksQ8skdf/LOGekiQqytrLVIKejefqO0xFMaYUEO8QGzsUnbZKpoc= 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=LdEggiPn; arc=none smtp.client-ip=209.85.208.50 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="LdEggiPn" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-56c147205b9so1998145a12.0; Mon, 25 Mar 2024 13:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399476; x=1712004276; 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=C0F/8H7Tcr8axVcQTcIq59S1STUD5wziimqr+zfEnTo=; b=LdEggiPn9o7OWcWAVgupPuORmSLz5BJJQUOwb87LBDTf8r7n/xPA/TZGTPaLXADaiR PWUlxok1LWjkdamOcxzjzaNQ5OEowzoS3/V3L+CbhcuxYWElviLjHJQrKPjJxURFQsWq JUlCgIiK/MHLmoWx5usmMeCImiHa1hEo37wngsk44KeKskplt29NM4lPt/R7d6zr/OsS Gc0xDNCGnuiBM7Omu78JChkruMC2tz9TGPvTwfT2lxp8wol9NdHDvpTOwXSqibqmrd/j ASDnnl54HsYTA/H/kpUazbORffcooEFi0s0lWs5rZPohm74sIOlkac3j8Q6lvqD+F4q4 0DDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399476; x=1712004276; 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=C0F/8H7Tcr8axVcQTcIq59S1STUD5wziimqr+zfEnTo=; b=CAorOGcuFtSFusEu/UwlkemVxNBMbygHqdxLL5HVYTR+/zgVNoP+8TUzkDIC0tuvgi 6JgRmi1pKIX4hXBM0anPWRUkJkCoFgwdhjv/hX+8r6oc/IB3kkydFCm8K0ghFwDB96eo QHMcPEC6xC7k7prLK26y4ebH+AVPFmWPpkeX6VVtXaA9K21O2h08UnQ675vRUHH0tGcL dP2p/kZpPNGbLE3Xdop8fu6O7r6tGa8QiuJ8VCeKl7+jsc6NQ49iqciqF+0ReFoiJgKp Y2aVE/rzPs5LOwkLc7ajLcYi2inW9fqu7ZeRz+E9g8ylHzXn6lcBynat0cBw1EuJENzN Xsow== X-Forwarded-Encrypted: i=1; AJvYcCXMj9MLrfDigk9SxWpSQeVYUuZx9nOR4CWhClj8mwrMPGGyPlZH0TyZtHvjT96N3tuW5ZTmy9sHcdmMSKFzk4IYu0rsl39MQ5wTmiX5 X-Gm-Message-State: AOJu0YzQfAu/uiHw7j04fsO+dWJvE/y/tOw5NsoXFYDnPs/93ekRDo9Z eLtsFe2L5emfewW9HTE+nAM6hxr9Eh2GSEiR78YXP4sC9C0gL+1ivFo/57y5c5c= X-Google-Smtp-Source: AGHT+IHb5+Qn0KLelSHb8PUgxEYczvwlI6xU3Y3Hw/P2M8dBYpBG9wNQG2avYKguJXaA39V4eMkPKg== X-Received: by 2002:a50:8753:0:b0:568:aced:e5a0 with SMTP id 19-20020a508753000000b00568acede5a0mr7058709edv.14.1711399475594; Mon, 25 Mar 2024 13:44:35 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:44:34 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , Russell King , Andrew Lunn , Florian Fainelli , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, linux-kernel@vger.kernel.org Subject: [PATCH net-next v7 01/16] net: dsa: vsc73xx: use read_poll_timeout instead delay loop Date: Mon, 25 Mar 2024 21:43:26 +0100 Message-Id: <20240325204344.2298241-2-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 Switch the delay loop during the Arbiter empty check from vsc73xx_adjust_link() to use read_poll_timeout(). Functionally, one msleep() call is eliminated at the end of the loop in the timeout case. As Russell King suggested: "This [change] avoids the issue that on the last iteration, the code reads the register, tests it, finds the condition that's being waiting for is false, _then_ waits and end up printing the error message - that last wait is rather useless, and as the arbiter state isn't checked after waiting, it could be that we had success during the last wait." Suggested-by: Russell King Reviewed-by: Andrew Lunn Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli Signed-off-by: Pawel Dembicki --- v7,v6: - resend only v5: - improved commit description - added two defines instead magic numbers - added include with iopoll.h v4: - resend patch v3: - added "Reviewed-by" to commit message only v2: - introduced patch drivers/net/dsa/vitesse-vsc73xx-core.c | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index ae70eac3be28..ab5771d4d828 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -268,6 +269,9 @@ #define IS_7398(a) ((a)->chipid == VSC73XX_CHIPID_ID_7398) #define IS_739X(a) (IS_7395(a) || IS_7398(a)) +#define VSC73XX_POLL_SLEEP_US 1000 +#define VSC73XX_POLL_TIMEOUT_US 10000 + struct vsc73xx_counter { u8 counter; const char *name; @@ -779,7 +783,7 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, * after a PHY or the CPU port comes up or down. */ if (!phydev->link) { - int maxloop = 10; + int ret, err; dev_dbg(vsc->dev, "port %d: went down\n", port); @@ -794,19 +798,17 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, VSC73XX_ARBDISC, BIT(port), BIT(port)); /* Wait until queue is empty */ - vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBEMPTY, &val); - while (!(val & BIT(port))) { - msleep(1); - vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBEMPTY, &val); - if (--maxloop == 0) { - dev_err(vsc->dev, - "timeout waiting for block arbiter\n"); - /* Continue anyway */ - break; - } - } + ret = read_poll_timeout(vsc73xx_read, err, + err < 0 || (val & BIT(port)), + VSC73XX_POLL_SLEEP_US, + VSC73XX_POLL_TIMEOUT_US, false, + vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_ARBEMPTY, &val); + if (ret) + dev_err(vsc->dev, + "timeout waiting for block arbiter\n"); + else if (err < 0) + dev_err(vsc->dev, "error reading arbiter\n"); /* Put this port into reset */ vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, From patchwork Mon Mar 25 20:43:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602934 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 B99F266B56; Mon, 25 Mar 2024 20:44:41 +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=1711399483; cv=none; b=iaPOAxwZcXjPfs4GwKh75pahlk1PqyXLIIqmGym21WI9dfa7NGOz+l/yjDgevYh7AtcMjUgD8VXOzV0jy/vedpnMXf3fqItM8e4oG7ZCN/AT1Th4BDvK5dTgqr4oAccc8V8PlGKCNjaeXQY+ki2YOCiwCwyfvWis0JM3/P88nZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399483; c=relaxed/simple; bh=NN3Q6fEUpQFPJwyI/sF2V4GUMiIqPWv8LHfRQaeaVwY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kIktXxTa/SN8TKh/amNAAIWuBLahrwgsmCr7RqxjM8wCgacCqdkVHFeLJ4cdSiINo3mzs7V3dZCmHPg8Fgh4WMKSOLQuXxAqOu/YJnpV2M32CPi3Yw2qUjeTzeDVm2O07RSD+4ACcmJZ/7FDXWH/6rT8cSGEnSLMjvOO5t55poE= 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=UArTmgyY; 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="UArTmgyY" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-56c1a520659so1204533a12.1; Mon, 25 Mar 2024 13:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399480; x=1712004280; 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=D3F3o0xYdA9ZOv6apMVbgo/NjnscMLmWpdUFxEQ0wug=; b=UArTmgyYYx77BXNHvgCDHYOFKmKv15J6D2YPsMmGkcGw/L4r+5GyA/I8Gfwio2qThk M3/yuTqWraaj3/ssjISlNzT8HY/bWbE7sIoljpR78Dx1j47Cj99zkgfu03kTT5fjm2NF g3j7ipfkVyBgTGWucXd65S0+e9lssEwxlQkGvp6p1Xr6aXEazHjaBYc1/5b3Nu5VQvPf JhOKAWcGRt5Tc8WUPmF52nwYxLx168+2rpJMjatjiV4Dttj+pOxiDMKCrF3SK94cLLtK S21eSalrDuzLyDV23/uFiDwamGNgDwc2QE0nWO3b+DzgPV1RjS13tKxs5WvxwA1+da3I xEiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399480; x=1712004280; 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=D3F3o0xYdA9ZOv6apMVbgo/NjnscMLmWpdUFxEQ0wug=; b=vorI8DoLK/pJiUCe9691IyLbvpivObzQJjOKJ9VGpnjbLOvxvk3Te3RwDrazjkeXnd aPCjCb1Y7FrYNeeZxxb6As5isALrU/LWpHV23IkKfR7L6BldyCbHq79QFa0FWiKt9GAe c2cldPRwqHEMoMgBs6BxRm21I0jWhE/Jq68HJ5CXBJHNdfss5A/W+An5k8qXoGvRQ+RM qTTESpPDQQYWSL2bo83kawRqWQaCTrHPwVwMV8FIlvDu1f9hfGGNRKxJ+yADkDS47Agl RVrWvtresE/sArkrqyQt3lmTan9u35NFdkUbkEwYUljVql480hv4w1+1nR+0njuglV1c 6YXg== X-Forwarded-Encrypted: i=1; AJvYcCXt32wBwWSOrp09bkdRumKbJhtNqi5uAbCPHHHk8mXJYbsxLz81sA82BMJWwHljZipyynoMAf7lrvdEDUrbV0TU6HKChccaPWgFqJpd X-Gm-Message-State: AOJu0Yzv9a51S1V/6ZLPLV98U0GDMqLutwQU4lScxJ3Oo7WRtp/9fscr unqNwhbqioHj8IxR8DG7UqhHFalzxL4OWIPwcepWq/jVe2f2h/jaS59MDiQMyqM= X-Google-Smtp-Source: AGHT+IHqVJnpocOEDgV7jAIbVWN1L28cHyk2FlXMCpKmLd1ERX4vUxh7TjhW8IhPvOaBczs7RNvfYg== X-Received: by 2002:a50:cd4c:0:b0:568:b851:f718 with SMTP id d12-20020a50cd4c000000b00568b851f718mr542540edj.40.1711399479801; Mon, 25 Mar 2024 13:44:39 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:44:39 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , Florian Fainelli , Russell King , 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 v7 02/16] net: dsa: vsc73xx: convert to PHYLINK Date: Mon, 25 Mar 2024 21:43:27 +0100 Message-Id: <20240325204344.2298241-3-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 replaces the adjust_link api with the phylink apis that provide equivalent functionality. The remaining functionality from the adjust_link is now covered in the phylink_mac_link_* and phylink_mac_config. Removes: .adjust_link Adds: .phylink_mac_config .phylink_mac_link_up .phylink_mac_link_down Signed-off-by: Pawel Dembicki Reviewed-by: Florian Fainelli Reviewed-by: Linus Walleij Reviewed-by: Russell King (Oracle) --- v7: - added 'Reviewed-by' to commit message only v6: - resend only v5: - introduce MAC reset function with procedure described in datasheet - reorganise routines - move 'Accept packets again' routine to 'phylink_mac_link_up' - fix one FIXME v4: - update commit descripion - remove phylink_get_caps after rebase to current net-next/main v3: - remove legacy_pre_march2020 after rebase v2: - replace switch to if and get rid of macros in vsc73xx_phylink_mac_link_up function drivers/net/dsa/vitesse-vsc73xx-core.c | 235 ++++++++++++------------- 1 file changed, 109 insertions(+), 126 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index ab5771d4d828..cb2e7e256279 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -717,52 +717,43 @@ static void vsc73xx_init_port(struct vsc73xx *vsc, int port) port, VSC73XX_C_RX0, 0); } -static void vsc73xx_adjust_enable_port(struct vsc73xx *vsc, - int port, struct phy_device *phydev, - u32 initval) +static void vsc73xx_reset_port(struct vsc73xx *vsc, int port, u32 initval) { - u32 val = initval; - u8 seed; - - /* Reset this port FIXME: break out subroutine */ - val |= VSC73XX_MAC_CFG_RESET; - vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, val); - - /* Seed the port randomness with randomness */ - get_random_bytes(&seed, 1); - val |= seed << VSC73XX_MAC_CFG_SEED_OFFSET; - val |= VSC73XX_MAC_CFG_SEED_LOAD; - val |= VSC73XX_MAC_CFG_WEXC_DIS; - vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, val); + int ret, err; + u32 val; - /* Flow control for the PHY facing ports: - * Use a zero delay pause frame when pause condition is left - * Obey pause control frames - * When generating pause frames, use 0xff as pause value - */ - vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_FCCONF, - VSC73XX_FCCONF_ZERO_PAUSE_EN | - VSC73XX_FCCONF_FLOW_CTRL_OBEY | - 0xff); + /* Disable RX on this port */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_MAC_CFG, + VSC73XX_MAC_CFG_RX_EN, 0); - /* Disallow backward dropping of frames from this port */ + /* Discard packets */ vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_SBACKWDROP, BIT(port), 0); + VSC73XX_ARBDISC, BIT(port), BIT(port)); + + /* Wait until queue is empty */ + ret = read_poll_timeout(vsc73xx_read, err, + err < 0 || (val & BIT(port)), + VSC73XX_POLL_SLEEP_US, + VSC73XX_POLL_TIMEOUT_US, false, + vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_ARBEMPTY, &val); + if (ret) + dev_err(vsc->dev, + "timeout waiting for block arbiter\n"); + else if (err < 0) + dev_err(vsc->dev, "error reading arbiter\n"); - /* Enable TX, RX, deassert reset, stop loading seed */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, - VSC73XX_MAC_CFG, - VSC73XX_MAC_CFG_RESET | VSC73XX_MAC_CFG_SEED_LOAD | - VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN, - VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN); + /* Put this port into reset */ + vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, + VSC73XX_MAC_CFG_RESET | initval); } -static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, - struct phy_device *phydev) +static void vsc73xx_phylink_mac_config(struct dsa_switch *ds, int port, + unsigned int mode, + const struct phylink_link_state *state) { struct vsc73xx *vsc = ds->priv; - u32 val; - /* Special handling of the CPU-facing port */ if (port == CPU_PORT) { /* Other ports are already initialized but not this one */ @@ -778,102 +769,92 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, VSC73XX_ADVPORTM_ENA_GTX | VSC73XX_ADVPORTM_DDR_MODE); } +} + +static void vsc73xx_phylink_mac_link_down(struct dsa_switch *ds, int port, + unsigned int mode, + phy_interface_t interface) +{ + struct vsc73xx *vsc = ds->priv; - /* This is the MAC confiuration that always need to happen - * after a PHY or the CPU port comes up or down. + /* This routine is described in the datasheet (below ARBDISC register + * description) */ - if (!phydev->link) { - int ret, err; - - dev_dbg(vsc->dev, "port %d: went down\n", - port); - - /* Disable RX on this port */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, - VSC73XX_MAC_CFG, - VSC73XX_MAC_CFG_RX_EN, 0); - - /* Discard packets */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBDISC, BIT(port), BIT(port)); - - /* Wait until queue is empty */ - ret = read_poll_timeout(vsc73xx_read, err, - err < 0 || (val & BIT(port)), - VSC73XX_POLL_SLEEP_US, - VSC73XX_POLL_TIMEOUT_US, false, - vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBEMPTY, &val); - if (ret) - dev_err(vsc->dev, - "timeout waiting for block arbiter\n"); - else if (err < 0) - dev_err(vsc->dev, "error reading arbiter\n"); - - /* Put this port into reset */ - vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, - VSC73XX_MAC_CFG_RESET); - - /* Accept packets again */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBDISC, BIT(port), 0); - - /* 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); + vsc73xx_reset_port(vsc, port, 0); - return; - } + /* Allow backward dropping of frames from this port */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_SBACKWDROP, BIT(port), BIT(port)); - /* Figure out what speed was negotiated */ - if (phydev->speed == SPEED_1000) { - dev_dbg(vsc->dev, "port %d: 1000 Mbit mode full duplex\n", - port); - - /* Set up default for internal port or external RGMII */ - if (phydev->interface == PHY_INTERFACE_MODE_RGMII) - val = VSC73XX_MAC_CFG_1000M_F_RGMII; - else - val = VSC73XX_MAC_CFG_1000M_F_PHY; - vsc73xx_adjust_enable_port(vsc, port, phydev, val); - } else if (phydev->speed == SPEED_100) { - if (phydev->duplex == DUPLEX_FULL) { - val = VSC73XX_MAC_CFG_100_10M_F_PHY; - dev_dbg(vsc->dev, - "port %d: 100 Mbit full duplex mode\n", - port); - } else { - val = VSC73XX_MAC_CFG_100_10M_H_PHY; - dev_dbg(vsc->dev, - "port %d: 100 Mbit half duplex mode\n", - port); - } - vsc73xx_adjust_enable_port(vsc, port, phydev, val); - } else if (phydev->speed == SPEED_10) { - if (phydev->duplex == DUPLEX_FULL) { - val = VSC73XX_MAC_CFG_100_10M_F_PHY; - dev_dbg(vsc->dev, - "port %d: 10 Mbit full duplex mode\n", - port); - } else { - val = VSC73XX_MAC_CFG_100_10M_H_PHY; - dev_dbg(vsc->dev, - "port %d: 10 Mbit half duplex mode\n", - port); - } - vsc73xx_adjust_enable_port(vsc, port, phydev, val); - } else { - dev_err(vsc->dev, - "could not adjust link: unknown speed\n"); - } + /* Receive mask (disable forwarding) */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_RECVMASK, BIT(port), 0); +} + +static void vsc73xx_phylink_mac_link_up(struct dsa_switch *ds, int port, + unsigned int mode, + phy_interface_t interface, + struct phy_device *phydev, + int speed, int duplex, + bool tx_pause, bool rx_pause) +{ + struct vsc73xx *vsc = ds->priv; + u32 val; + u8 seed; + + if (speed == SPEED_1000) + val = VSC73XX_MAC_CFG_GIGA_MODE | VSC73XX_MAC_CFG_TX_IPG_1000M; + else + val = VSC73XX_MAC_CFG_TX_IPG_100_10M; + + if (interface == PHY_INTERFACE_MODE_RGMII) + val |= VSC73XX_MAC_CFG_CLK_SEL_1000M; + else + val |= VSC73XX_MAC_CFG_CLK_SEL_EXT; + + if (duplex == DUPLEX_FULL) + val |= VSC73XX_MAC_CFG_FDX; + + /* This routine is described in the datasheet (below ARBDISC register + * description) + */ + vsc73xx_reset_port(vsc, port, val); + + /* Seed the port randomness with randomness */ + get_random_bytes(&seed, 1); + val |= seed << VSC73XX_MAC_CFG_SEED_OFFSET; + val |= VSC73XX_MAC_CFG_SEED_LOAD; + val |= VSC73XX_MAC_CFG_WEXC_DIS; + vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, val); + + /* Flow control for the PHY facing ports: + * Use a zero delay pause frame when pause condition is left + * Obey pause control frames + * When generating pause frames, use 0xff as pause value + */ + vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_FCCONF, + VSC73XX_FCCONF_ZERO_PAUSE_EN | + VSC73XX_FCCONF_FLOW_CTRL_OBEY | + 0xff); + + /* Accept packets again */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_ARBDISC, BIT(port), 0); /* Enable port (forwarding) in the receieve 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); + + /* Enable TX, RX, deassert reset, stop loading seed */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_MAC_CFG, + VSC73XX_MAC_CFG_RESET | VSC73XX_MAC_CFG_SEED_LOAD | + VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN, + VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN); } static int vsc73xx_port_enable(struct dsa_switch *ds, int port, @@ -1060,7 +1041,9 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .setup = vsc73xx_setup, .phy_read = vsc73xx_phy_read, .phy_write = vsc73xx_phy_write, - .adjust_link = vsc73xx_adjust_link, + .phylink_mac_config = vsc73xx_phylink_mac_config, + .phylink_mac_link_down = vsc73xx_phylink_mac_link_down, + .phylink_mac_link_up = vsc73xx_phylink_mac_link_up, .get_strings = vsc73xx_get_strings, .get_ethtool_stats = vsc73xx_get_ethtool_stats, .get_sset_count = vsc73xx_get_sset_count, From patchwork Mon Mar 25 20:43:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602935 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FB6A5B669; Mon, 25 Mar 2024 20:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399488; cv=none; b=uw39/Jj33xx0Mt5s/jPGxDl6XpOgJsvX0vAvikEEIRMfKfQBRN4NmxwMlCx69hOyVOG4GGql6A7uIPCm8OoY5ViZdqxdMSQ9aj1cayvijdWJVfDT1dPhs+GM2FefFE94nFG2DR2Y4nqug/8Xa+LxRzm0alrelFPtENX/BYXjYYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399488; c=relaxed/simple; bh=V1fxWWUvpUniIImiS9q5KVpT11WA5yQQPruCDPMUSws=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dha0aAb2KISMsFXuBNfi4VpWHRJya7KTEEL9WVetOYwvrQ7T+XpqAGp5gVbzSpBe8pi7NOQyUZE6TpKwq3HJyt/4cDkBrFxhrk63+f1+PCls5jSUdx4/CkrbK0ByKnNQBmgG30FNGIQB3JI639b7A9RoJAsSUNANlGAet2dKXbA= 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=N3z0KRCq; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N3z0KRCq" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-513e10a4083so5380057e87.1; Mon, 25 Mar 2024 13:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399484; x=1712004284; 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=upMc+uew/Oz20hh4qPvr2Qm02HG3vgIg6J6Sq4FrSK4=; b=N3z0KRCqqUgPkwWsdzQ0F0ljSs48VgqoPkcTX+yC3ZzWHJbkBsDY4BesAosAGjpkzQ P8hHFX6902mP8V58dry+yuMJWLi6xoD9MzJK9mFT/eUyvLNHohyLn17iLqFw/6XGp+Up M8BhYOb/+3loJqoMlkTGXrL0qbV9b+dMAo+IBzUiixUzwnjHN77AmResyqXdHV8c9RgY eMG6HByOHjA8XNJE5eGCXwYpqDzwzNk8v3WMjiEIZRcGVhjFUOBWLvXeqBUrnVP2NuMc bhGot+iF4lEhvRLe8BX2eaUw6vOCLpqugrGr8AykRqiNe6gDhKNm3FxbiO0PghrIYP6o lqhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399484; x=1712004284; 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=upMc+uew/Oz20hh4qPvr2Qm02HG3vgIg6J6Sq4FrSK4=; b=wKxFU6Zl35oLPHAK5hfAXqnIt6bOJtgYU+27KXv1s7xVETk8EMCDF6Bdoe1d8SAjUA 4N/PM86qVLTOSG/Weogqer5kRBxMTlCFHJVojSwVwmP4RDAWwGLfH77tR/WXBulhk/zQ u0h36Q6eGpGP70uoGlU4Fo9kxHUiyzLLcUi0CDk/mi4TEKaxtVpREkunSiEwWHOTHx5X Znh5bEPWMkgvJhgVVl8mByFP7FYZAhqXMZg82alado8ZSCO9huSjHNgCdHA7nrFQT+e8 FZyLXXGOWOI+53DbsT/s35aal4Uru9X0VFT/ynv4gAnZhoLtailnziUukzvzPYm2uuD7 +4Jg== X-Forwarded-Encrypted: i=1; AJvYcCV8b4HL77rZBHxfNmF6tVYjLXADBhBjRN5sQnT+xz+Mse3Ao/w4NeCJDlEtcrseBbPceYClP+UCClFwqebfvdwbP8TPyT3MrmIfe4WO X-Gm-Message-State: AOJu0YyrxhVVLbHFP/6p7jRK2rjncNfRXjJNCZhRJksfXAj4w5RKX+WR /9IwFoAX09utAdZXjThmzyuKJ+n6KLNZ9ViBipwt6MNKYt4xLrHvPbEzv2rwo/0= X-Google-Smtp-Source: AGHT+IERwi+xu4sSKlMiTteICjWVfDnpA1BVajpzCdkiAiB6C+cBH4pfnY4wxHtaOzFnd4bVmw9S5g== X-Received: by 2002:a19:5f08:0:b0:513:bea3:7f60 with SMTP id t8-20020a195f08000000b00513bea37f60mr4938304lfb.44.1711399483925; Mon, 25 Mar 2024 13:44:43 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:44:43 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , Russell King , 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 v7 03/16] net: dsa: vsc73xx: use macros for rgmii recognition Date: Mon, 25 Mar 2024 21:43:28 +0100 Message-Id: <20240325204344.2298241-4-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 It's preparation for future use. At this moment, the RGMII port is used only for a connection to the MAC interface, but in the future, someone could connect a PHY to it. Using the "phy_interface_mode_is_rgmii" macro allows for the proper recognition of all RGMII modes. Suggested-by: Russell King (Oracle) Signed-off-by: Pawel Dembicki Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli Reviewed-by: Vladimir Oltean Reviewed-by: Russell King (Oracle) --- v7: - added 'Reviewed-by' and fix 'Suggested-by' in commit message v6: - resend only v5: - added 'Reviewed-by' only v4: - introduced patch drivers/net/dsa/vitesse-vsc73xx-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index cb2e7e256279..8ed8fc997d6d 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -807,7 +807,7 @@ static void vsc73xx_phylink_mac_link_up(struct dsa_switch *ds, int port, else val = VSC73XX_MAC_CFG_TX_IPG_100_10M; - if (interface == PHY_INTERFACE_MODE_RGMII) + if (phy_interface_mode_is_rgmii(interface)) val |= VSC73XX_MAC_CFG_CLK_SEL_1000M; else val |= VSC73XX_MAC_CFG_CLK_SEL_EXT; From patchwork Mon Mar 25 20:43:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602936 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2D406E610; Mon, 25 Mar 2024 20:44:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399491; cv=none; b=BH0c9btCu8bPoPdmd6L4Gp5KIp0XiWJI4j2F9VFCFirjWqp6lzaNRM2WW4371Ww0D6lpG1SzEf44LEVhD7pboN/o4ZsaJe5wLWvDI13p9zTCjAIjxKnO33hhRik5hYxRzg+dJmqYnkVcrfvkf39qb4ca8sgaIUeVcOzp8G9iOaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399491; c=relaxed/simple; bh=mD1M3LVfb5RknNH730RDEoVVN+tgv1mN6PW++COOwB4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wf28x0xUddsYvbsTwVXFzVVpSylOyPPqu9/lysNaRnGOlBXG/SG0XtPYzFtFthqH1bvamVI/TpF9ZNzBDn/Y28aaUbsxEVTO6Xhh2Gy6oR6xR/yhictJMhsERv1P14jZDT2meqn6aaZ8VHUt/NXzTeswqespdQIUNg08F9jD944= 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=MOpa/Ooo; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MOpa/Ooo" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a46de423039so275348966b.0; Mon, 25 Mar 2024 13:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399488; x=1712004288; 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=cRdG6NQnSKMzq/RbCCRDnlTZbYIKa3h23JrZEJ03gXg=; b=MOpa/OoocJ2O9CEFM4Sb4N7+B/HG8DdtHavQpUl4Eq+UFsor8eV5Ofnq+BsIDR5Ew/ Sn0WxE7Im2t0y8CyvtEEX9X/XH2YgB/9n6D+CwvQIr/63EmcjB4i36cMfPVfNvVx0BcA gjTLTsic7PmjVFMYbF8yosVQbKCrSJXwvZMawp0BxX1QP3kbozc+sbvW4Mjc+knADLTj NcPEmHdD7x+b/XlqSS3h84RvzhykZc3KWN8PeP/tNp2QTB7M2JYGKMeym29gZ6s+UagV u/ERFhJ6DZxqnyCvdWye74Nsp6gh41JMfMGf8uoXuHXxOXubTan9oErkIjdus7RnlTCZ dtlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399488; x=1712004288; 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=cRdG6NQnSKMzq/RbCCRDnlTZbYIKa3h23JrZEJ03gXg=; b=OIZFae6fIHbDZDlPKvwRcKF2jnVTtlAziAaOezE++YGAxgimZ3DpdVOk5qNsPqaOaw 2+2BRUdzR+HkobBxLqKtFdUxICq+kfat3fqByQ1poh07MnQaRCrjZ0kOxW9TcnG1GeLR SWme59ZKd42RfShv+LfOp0h1R0o1sf0huEgRz4CIN2QtVF0tE+nTpR/4D9UZM4CPn9/o 7WSxtvwH52m1FAMDVW4S4zaNRPPOyjlPbCcxTxJSSfu/YdWF0S4YzqjvGL+mm1lZSPTl P2nBeIhwFvcAwfPFE7xOkxyXS3znE14ByvDEHJtEjnT47k5YoxzfHQga4I3ezKJ+sYg2 foUQ== X-Forwarded-Encrypted: i=1; AJvYcCUcl/eGGLnzE5Oc/rGGwaEtKA0rhBplC7bj5mmICzIKfars1Ny59kwxWynasDI589RY3a7fXyRhgmt/X6lHjqWAJPn0nYe60sXlCmBE X-Gm-Message-State: AOJu0Yx19h5ofQcpb8dBN3SR01ROjj15EJSCl6B+AuODCobtor5ZMdld z1BzNIzEvB2bLdNINA0zvYmph8oABqGvitO4t6bJBsk0wrTyof1YWKPxsVVLmt8= X-Google-Smtp-Source: AGHT+IEK+CPromJgklE4wCB81BT8DIB+yArFcjEsyESiitoBU+L4dC/FDbRDBZJpBJmzba2X7u6oFA== X-Received: by 2002:a50:d4d9:0:b0:566:43ab:8b78 with SMTP id e25-20020a50d4d9000000b0056643ab8b78mr7237870edj.30.1711399487998; Mon, 25 Mar 2024 13:44:47 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:44:47 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , Vladimir Oltean , Florian Fainelli , 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 v7 04/16] net: dsa: vsc73xx: Add define for max num of ports Date: Mon, 25 Mar 2024 21:43:29 +0100 Message-Id: <20240325204344.2298241-5-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 introduces a new define: VSC73XX_MAX_NUM_PORTS, which can be used in the future instead of a hardcoded value. Currently, the only hardcoded value is vsc->ds->num_ports. It is being replaced with the new define. Suggested-by: Vladimir Oltean Signed-off-by: Pawel Dembicki Reviewed-by: Vladimir Oltean Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli --- v7: - added 'Reviewed-by' only v6: - resend only v5: - added 'Reviewed-by' only v4: - Resend patch v3: - Introduce patch drivers/net/dsa/vitesse-vsc73xx-core.c | 13 +------------ drivers/net/dsa/vitesse-vsc73xx.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 8ed8fc997d6d..425999d7bf41 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -1180,23 +1180,12 @@ int vsc73xx_probe(struct vsc73xx *vsc) vsc->addr[0], vsc->addr[1], vsc->addr[2], vsc->addr[3], vsc->addr[4], vsc->addr[5]); - /* The VSC7395 switch chips have 5+1 ports which means 5 - * ordinary ports and a sixth CPU port facing the processor - * with an RGMII interface. These ports are numbered 0..4 - * and 6, so they leave a "hole" in the port map for port 5, - * which is invalid. - * - * The VSC7398 has 8 ports, port 7 is again the CPU port. - * - * We allocate 8 ports and avoid access to the nonexistant - * ports. - */ vsc->ds = devm_kzalloc(dev, sizeof(*vsc->ds), GFP_KERNEL); if (!vsc->ds) return -ENOMEM; vsc->ds->dev = dev; - vsc->ds->num_ports = 8; + vsc->ds->num_ports = VSC73XX_MAX_NUM_PORTS; vsc->ds->priv = vsc; vsc->ds->ops = &vsc73xx_ds_ops; diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vsc73xx.h index 30b1f0a36566..fee1378508b5 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -3,6 +3,17 @@ #include #include +/* The VSC7395 switch chips have 5+1 ports which means 5 ordinary ports and + * a sixth CPU port facing the processor with an RGMII interface. These ports + * are numbered 0..4 and 6, so they leave a "hole" in the port map for port 5, + * which is invalid. + * + * The VSC7398 has 8 ports, port 7 is again the CPU port. + * + * We allocate 8 ports and avoid access to the nonexistent ports. + */ +#define VSC73XX_MAX_NUM_PORTS 8 + /** * struct vsc73xx - VSC73xx state container */ From patchwork Mon Mar 25 20:43:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602937 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 579AE6F51D; Mon, 25 Mar 2024 20:44:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399496; cv=none; b=GIQAAh7FJ9/yXzi0fwsI8X3R4Xf1nSKmJZ0rBbvVvWHEVNNJPLtV+agxs5KersnbE9bJ1h2+q6LXm/xLhg5XfFze4E6Sv+k1PSTmedrEJAVefRmqUTp2pe0dZrVfAgA5911sEOv+xCmC33tOAcLxPCW5/JIhXyUOzgdOWaenN6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399496; c=relaxed/simple; bh=LN4dT4d7P8qQBwedPyFT2jT5dVKTs6A7A2F7zwpITOc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k05N8UxtkdGy5sxOsq/Rj0gCetrZZiMae1F6G4zDYTeWnQWFKY7F9g5S+pENvvi16+YC4wFrMxPm0jKIqbsVOrDFy6iOX9+FANoasINM6GoOuZUQyMZdjl65DM97tJ/T3aRQxpU7W01DTA27HYUxzIZ30oJzc201e91sDnplz3E= 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=KVk5gxma; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KVk5gxma" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-515a86daf09so2438341e87.3; Mon, 25 Mar 2024 13:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399492; x=1712004292; 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=kdX7GSsZnXTSylOv9Y3Ibi+HXBYjvkvffIzYw5Muc/4=; b=KVk5gxmaOVB/NIwEAAcFSgfbxyXza7T6cOeCiNR6fMVCg57F5+Onh5vLv/77ZAUXi9 BzS2tRSGpFyOUtCdMwzS2eB6WzYYk1wB2FQhSaakI1Kp6th1Inu+Op8AY9vn7P2HYRhV /UZ9EY6wwUqp8xnQCpbgnTMCu0lmQGfUdvhEFdHSvSIcvcT3fTtaRltOVPCK9/1UmVaI QEf1eSPWsKsKarahnxx6WkwED6mccvdwzGK0P6j+wTy/ZXKrLqXDfGy4iDjO2rMDUK6E vaSHkMiTD7+4eF50KLgIoQXCSkFffuBnJ4nGZK07mkF9xLNx6dHPvdfvf0xn6SdyM7Qm BB6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399492; x=1712004292; 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=kdX7GSsZnXTSylOv9Y3Ibi+HXBYjvkvffIzYw5Muc/4=; b=AQDKu0Aj/Zk2Ak3hpCsLHGw9FK2An2bzRlvunwHoKRnaMIO+5CNLxy27TC88ZBMARA AbWId058r/y3kt1VM1z9NqBFQRL11WSoBla4Zq0WpPSXn9mzyijKNZhckPcDmF5CykwU Ty13TZhUtPzurFcKDZJkAXVCwzcUnheBgMWFfRRQAfw8STQVUv8Dqf+XNh6NTazlM0iJ K3WgcYSQYf9GuALwSrOQaTc+DWwQYpN2MxBAaehT38h2FVTCJxYSIdgiaZoxKHSJ9KLB X69Py+yYsVzlCIz8iECLshD8MN1zi2O4b/qG6kxtz/N7GuFUc3Hp4eRk6zm1Xy92VkVM m0qg== X-Forwarded-Encrypted: i=1; AJvYcCXtdVzpe2kaPAfNC1NP7nTWOGz8CaPNgjUmE/U5uGEb6R9AvaZ5gkpkI/SUurBeIG8iLHkIkKhGmIQeBN9DacXFibYXi9YA/5x7Yk69 X-Gm-Message-State: AOJu0YwmE1HOXW7vCHf6+PzFXkailr9dsBaaHdz1pjF/D1mRFZHOQKRq n5H2wkm0vxIQV1/Ps97hwofpYFrsbZOYff9Entk+1Fkx2wZ0ICbITqyEHN5VLko= X-Google-Smtp-Source: AGHT+IGR99AwEcs60I5LaFb36uz4ABm53DTgzPKYSJ5bOBquRnnhOw0ax9pVqsAi3sbZ2H26EjFTGA== X-Received: by 2002:a05:6512:535:b0:515:a58e:82e with SMTP id o21-20020a056512053500b00515a58e082emr5233083lfc.62.1711399492034; Mon, 25 Mar 2024 13:44:52 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:44:51 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , 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 v7 05/16] net: dsa: vsc73xx: add structure descriptions Date: Mon, 25 Mar 2024 21:43:30 +0100 Message-Id: <20240325204344.2298241-6-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 adds updates to the documentation describing the structures used in vsc73xx. This will help prevent kdoc-related issues in the future. Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli Signed-off-by: Pawel Dembicki --- v7,v6: - resend only v5: - improved description and stick to 80 characters per line v4: - introduced patch drivers/net/dsa/vitesse-vsc73xx.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vsc73xx.h index fee1378508b5..e7b08599a625 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -15,7 +15,16 @@ #define VSC73XX_MAX_NUM_PORTS 8 /** - * struct vsc73xx - VSC73xx state container + * struct vsc73xx - VSC73xx state container: main data structure + * @dev: The device pointer + * @reset: The descriptor for the GPIO line tied to the reset pin + * @ds: Pointer to the DSA core structure + * @gc: Main structure of the GPIO controller + * @chipid: Storage for the Chip ID value read from the CHIPID register of the + * sswitch + * @addr: MAC address used in flow control frames + * @ops: Structure with hardware-dependent operations + * @priv: Pointer to the configuration interface structure */ struct vsc73xx { struct device *dev; @@ -28,6 +37,11 @@ struct vsc73xx { void *priv; }; +/** + * struct vsc73xx_ops - VSC73xx methods container + * @read: Method for register reading over the hardware-dependent interface + * @write: Method for register writing over the hardware-dependent interface + */ struct vsc73xx_ops { int (*read)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg, u32 *val); From patchwork Mon Mar 25 20:43:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602938 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 2304B6EB52; Mon, 25 Mar 2024 20:44:58 +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=1711399499; cv=none; b=DvonoDHM1ZGfe6x/+P5Juk10oxLS+TXLTW5ZX/bdPbDnVrFYGyf9dcXqq6qUhcjFbN2ZzHikjh2JozXqivLLQJMaf/V2rN41Osi9ndoxKZURRWZviVlqzi3O/yP+OazuFwTfwPSD9Z+xwBXLquFinCyM1AsGIJb0IvJmjgdx1xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399499; c=relaxed/simple; bh=MNy4a9LrRLFB9UFbrtc1jj60lgKwWYTXEKysX0ELC+U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uKYwdKTmaABhVQCpwGsPnXkj99Et2eLdcBbAzp3zHtdSiaTCYDI+mgDWxihb8+PtEKMpg3e6cyeR0ZjQiMb5LT5OsWaRZSXfEWXIKHQb7SdTpfFgRy7UbmrFfrB8M/fIYIkl/PjziOe5zZkfdeLJJBfdXVZqiUyeMC10lN50scg= 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=IQHE09Uv; 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="IQHE09Uv" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-56c1a520659so1204813a12.1; Mon, 25 Mar 2024 13:44:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399496; x=1712004296; 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=nJOhT/NhfBRNemKHQ4KsvY/IdcyTqEthLWerBC7um4A=; b=IQHE09UvMtYS/4bgybSW88yoXmivpvAm7SnMObYPvZdAkJKxvMvGdwGZGLrQt1DURi iirLh6pvvHvOr+T7ZD0ZfRu7KpC+qi3i1cH7kxFY7wGYK072zCJxXRwMezEh0P3nQ8L/ JN/FuindBVgToUt6xhDOrCBkRAS7MTpFCapzORE45hsUeKca4y8tsRqwgK/YMo1yqHlZ glRVeRZdBbnJ/vozb6gaI5fpYUTbS5rFeCdommw0lv8QvYFabd05CT47uALkx0k4XsE6 2rVCJ4Xb4yR8Ls2JFVtOQXT3+QE0k0iXaEsp0bkK8wmGm+xC5F1SR+ao/7Ce6Qh3/qua qBvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399496; x=1712004296; 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=nJOhT/NhfBRNemKHQ4KsvY/IdcyTqEthLWerBC7um4A=; b=GeTkQBixSMGY4sDFI+e9kmtzccZOJ4rwQcV/q2f+04rC8Zf1USMiaoQnKtZeZtI0cc tDob8+qqtYrsmiQVrC3MFM52NJjbLi0asCCxFWLvkOTgvVu/g500BeSKEJWt5YkWO6hX bKK7oFb+Lm70K6bdzqfyDRcDfWzQK1q4Ib340gNvwW8luGU1CDC4C7Mp6bo4d6LUj4Gj Ayw3bBoG8zDnsOnaXS71CSuCvKwO0CXhLJN6Qi1i0/cA0sOvrBy83qfZQCyJJCQcFPEv CKBuZRP9nKl4oRALK89RDAgzhcIBqXhx5ZtfywR53fXy4I0Hd+2JYYIKsAUbEYrwjDnO DU6Q== X-Forwarded-Encrypted: i=1; AJvYcCUUuZRnLDYUHcjLHo6LAmUz/3am/tueUpEauJn00sci3Tl+iOuvFa+lmXEJUGyPCKSFdxfuM8wcBT2GOamHq0iLZlJsj6T0cV8dna8E X-Gm-Message-State: AOJu0YyiPahc7bvw4Vh3nKC2suj+kZE3jA1lz7TPRFahhEOu0Q+dAU5T T0gd1z4ktcrqYByE5izmpcOhgllbG1AoE2WhgAPcSpHBJEfZfioX1baz85u6JAk= X-Google-Smtp-Source: AGHT+IF4lQcHa60qMNikZp1uI7bqrjqUR285+MuN34xZ5raHk3YF2hJBkuhX5/FosFIJ/JWubDlfrg== X-Received: by 2002:a50:9eea:0:b0:56b:dcdc:6fad with SMTP id a97-20020a509eea000000b0056bdcdc6fadmr625842edf.13.1711399496230; Mon, 25 Mar 2024 13:44:56 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:44:55 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , 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 v7 06/16] net: dsa: vsc73xx: add port_stp_state_set function Date: Mon, 25 Mar 2024 21:43:31 +0100 Message-Id: <20240325204344.2298241-7-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 425999d7bf41..07f982cf62dd 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); @@ -785,10 +786,6 @@ static void vsc73xx_phylink_mac_link_down(struct dsa_switch *ds, int port, /* 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_phylink_mac_link_up(struct dsa_switch *ds, int port, @@ -841,10 +838,6 @@ static void vsc73xx_phylink_mac_link_up(struct dsa_switch *ds, int port, vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, VSC73XX_ARBDISC, BIT(port), 0); - /* Enable port (forwarding) in the receieve 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); @@ -1036,6 +1029,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 dsa_switch_ops vsc73xx_ds_ops = { .get_tag_protocol = vsc73xx_get_tag_protocol, .setup = vsc73xx_setup, @@ -1051,6 +1124,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 Mon Mar 25 20:43:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602939 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 BB09A7640A; Mon, 25 Mar 2024 20:45:02 +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=1711399505; cv=none; b=n12KluIwr3dxhK/qNtZSUdNpGk7JMCMD/73BtnhXXqhpCQ34z+y3kIkZ4rYYVI2mIF2qBdhECgGIBwljzysF0uzFWxDlRci6emuUzO7MnHXpILP8zXZEJfZhJq5rY9Qa0zsX6MCJ2gyuh+8qLFQm2ziWyp2uGfPV8UqdP6HuuYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399505; c=relaxed/simple; bh=zl8+Tt+zqZgTrdpPd+JhlRmKvRKhX3x+Nk8KWGT2/oc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KtMV25VXWPSk9I2mY0fjmRkjx3yabG2MGOud8skX8024Mm3WZ5he3YWgp4ZhsvjPGlANJ0tXl2R93zi+GyTiSg9yZ2/+KQcBrQopCUImYGVxkTkGxxeGhR11ILqtCpSBDClepeKF9w5Puxli6MjSzu8RdKSmeh+sn0ovVoD6L2g= 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=P7NqY+np; 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="P7NqY+np" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-56bf6418434so2951393a12.0; Mon, 25 Mar 2024 13:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399501; x=1712004301; 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=t8ypWzVoCNkkwXGrqyDauyDRfAmVUJXPwBCH62qc9ks=; b=P7NqY+np+Qo9QJbAeW8ciyPZH9pxZO/wcPtUx373nqZjlxSrgMGC8HdsMjEUYeGHZs Uk4qZC85Rey4xgsY96qL7gJ0vODBenZ9scNNzbfMOB/EGO8ZbXW2sBYzClX60bKtjEae dZuLpf3ru3yna1aCs3uJjZneC542kVYdqdDEHog1usIsXAY7QKMTNRmK12lXueh8Q4vL jMdrn9B2XbGfeJGsha7SISKXcWGu7TijEoN+Ht3h7lQiKgme0wuRmLGKgate8ILAw9i4 6SAH5rT9/VEs+rghypNBcpL/yEDmAJlYYp6XGWnGWUgdrGKANcPCc9IN99IA6XKLMXpk LCow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399501; x=1712004301; 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=t8ypWzVoCNkkwXGrqyDauyDRfAmVUJXPwBCH62qc9ks=; b=b4jdm1LWrnJVzQJwlKhZQs/1XBvu9MzvEygnupEGwJC2nf+tBhmeQDyyrvge+laX0r G3OHeB/RTdT/P1A2O/wiu+E6nPd95sc1H81kVO6WYydyRm2VjtvrV4oiQqEBJf1SJn+D fVDJ3Y2cqkVp12qsr/a+mgoV+X+ph5SGBtu4ULXh1ONTeqTdFh7rlfOMO3SdTHb1LmrR Ud3XLZ4b+CM+zoZfAv/sEoAJvdEShNMnCrs7g+kbYZf2D2o8sz0nl/it7IG6u7fc1njD MCS+veQP4D6ubMS+pCQuObZO65VRE1HXsHucPV1sdq+om9Kuv7S7As8HJBCQM3maiqit IT1Q== X-Forwarded-Encrypted: i=1; AJvYcCWoD/albqwR5wu4y8sMPDOHr9b80UPEcXmsELBhlZwb3OaqxGxnevOjPGpbrsfPjYK0DbJ5RMMftv++X/6ytYhTHd4Pfr17p/Iw02xF X-Gm-Message-State: AOJu0YxgnsHdS/2qaVLtld7gN2w1yf2S6bvkUkazTIIM5y/0u8Cz8fsu vv8GN4flVuBT4CzrfJLEpQrHc0YWHPnNAp+VHEyTkIBMTDR4EBrKR7noCpxlnSs= X-Google-Smtp-Source: AGHT+IHOQk1UiMl+h+HfJJmluL2hBZU6m28dbALdRRPQ0DWlCNJP9R2XJz5MC34vRim6I5jH4vCj3Q== X-Received: by 2002:a50:c312:0:b0:56c:17ef:9ab1 with SMTP id a18-20020a50c312000000b0056c17ef9ab1mr1919660edb.2.1711399500655; Mon, 25 Mar 2024 13:45:00 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:00 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , 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 v7 07/16] net: dsa: vsc73xx: Add vlan filtering Date: Mon, 25 Mar 2024 21:43:32 +0100 Message-Id: <20240325204344.2298241-8-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 | 545 ++++++++++++++++++++++++- drivers/net/dsa/vitesse-vsc73xx.h | 42 ++ 2 files changed, 585 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 07f982cf62dd..833e4e50e737 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; } @@ -822,6 +951,12 @@ static void vsc73xx_phylink_mac_link_up(struct dsa_switch *ds, int port, 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: @@ -1029,6 +1164,408 @@ 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 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 int vsc73xx_vlan_change_untagged_hw(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 int vsc73xx_vlan_set_untagged_hw(struct vsc73xx *vsc, int port, u16 vid) +{ + return vsc73xx_vlan_change_untagged_hw(vsc, port, vid, true); +} + +static int +vsc73xx_vlan_change_pvid_hw(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_change_pvid(struct vsc73xx *vsc, int port, u16 vid, + bool valid, bool operate_on_storage, + bool tag_8021q_mode) +{ + struct vsc73xx_portinfo *portinfo = &vsc->portinfo[port]; + + if (tag_8021q_mode) { + portinfo->pvid_tag_8021q_configured = valid; + portinfo->pvid_tag_8021q = vid; + } else { + portinfo->pvid_vlan_filtering_configured = valid; + portinfo->pvid_vlan_filtering = vid; + } + + if (operate_on_storage) + return 0; + + return vsc73xx_vlan_change_pvid_hw(vsc, port, vid, valid); +} + +static int vsc73xx_vlan_clear_pvid(struct vsc73xx *vsc, int port, + bool operate_on_storage, bool tag_8021q_mode) +{ + return vsc73xx_vlan_change_pvid(vsc, port, 0, false, + operate_on_storage, tag_8021q_mode); +} + +static int vsc73xx_vlan_set_pvid(struct vsc73xx *vsc, int port, u16 vid, + bool operate_on_storage, bool tag_8021q_mode) +{ + return vsc73xx_vlan_change_pvid(vsc, port, vid, true, + operate_on_storage, tag_8021q_mode); +} + +static bool vsc73xx_port_get_pvid(struct vsc73xx *vsc, int port, u16 *vid, + bool tag_8021q_mode) +{ + struct vsc73xx_portinfo *portinfo = &vsc->portinfo[port]; + + if (tag_8021q_mode) { + if (portinfo->pvid_tag_8021q_configured) + *vid = portinfo->pvid_tag_8021q; + return portinfo->pvid_tag_8021q_configured; + } + + if (portinfo->pvid_vlan_filtering_configured) + *vid = portinfo->pvid_vlan_filtering; + return portinfo->pvid_vlan_filtering_configured; +} + +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 int +vsc73xx_port_vlan_filtering(struct dsa_switch *ds, int port, + bool vlan_filtering, struct netlink_ext_ack *extack) +{ + enum vsc73xx_port_vlan_conf port_vlan_conf = VSC73XX_VLAN_IGNORE; + u16 vid_pvid = 0, vid_untagged = 0; + struct vsc73xx_portinfo *portinfo; + struct vsc73xx *vsc = ds->priv; + bool set_untagged = false; + bool set_pvid = false; + + portinfo = &vsc->portinfo[port]; + + /* The swap 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. Analogic routine is processed when vlan_filtering + * is disabled, but values used for tag_8021q are restored. + */ + if (vlan_filtering) { + struct vsc73xx_vlan_summary summary; + + /* Use VLAN_N_VID to count all vlans */ + vsc73xx_bridge_vlan_summary(vsc, port, &summary, VLAN_N_VID); + + port_vlan_conf = (summary.num_untagged > 1) ? + VSC73XX_VLAN_FILTER_UNTAG_ALL : + VSC73XX_VLAN_FILTER; + + if (summary.num_untagged == 1) { + vid_untagged = vsc73xx_find_first_vlan_untagged(vsc, + port); + set_untagged = true; + } + + vid_pvid = portinfo->pvid_vlan_filtering; + set_pvid = portinfo->pvid_vlan_filtering_configured; + } else { + vid_untagged = portinfo->untagged_tag_8021q; + set_untagged = portinfo->untagged_tag_8021q_configured; + vid_pvid = portinfo->pvid_tag_8021q; + set_pvid = portinfo->pvid_tag_8021q_configured; + } + + vsc73xx_vlan_change_untagged_hw(vsc, port, vid_untagged, set_untagged); + vsc73xx_vlan_change_pvid_hw(vsc, port, vid_pvid, set_pvid); + vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf); + + 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); + enum vsc73xx_port_vlan_conf port_vlan_conf; + struct vsc73xx_bridge_vlan *vsc73xx_vlan; + struct vsc73xx_vlan_summary summary; + struct vsc73xx *vsc = ds->priv; + bool operate_on_storage; + int ret; + u16 vid; + + /* 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); + } + + vsc73xx_vlan->portmask |= BIT(port); + + if (untagged) + vsc73xx_vlan->untagged |= BIT(port); + else + vsc73xx_vlan->untagged &= ~BIT(port); + + /* CPU port must be always tagged because port separation is based on + * tag_8021q. + */ + if (port == CPU_PORT) + goto update_vlan_table; + + operate_on_storage = vsc73xx_tag_8021q_active(dp); + + if (pvid) + ret = vsc73xx_vlan_set_pvid(vsc, port, vlan->vid, + operate_on_storage, false); + else if (vsc73xx_port_get_pvid(vsc, port, &vid, false) && + vid == vlan->vid) + ret = vsc73xx_vlan_clear_pvid(vsc, port, operate_on_storage, + false); + if (ret) + goto err; + + if (operate_on_storage) + goto update_vlan_table; + + port_vlan_conf = VSC73XX_VLAN_FILTER; + + if (summary.num_tagged == 0 && untagged) + port_vlan_conf = VSC73XX_VLAN_FILTER_UNTAG_ALL; + vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf); + + if (port_vlan_conf == VSC73XX_VLAN_FILTER_UNTAG_ALL) + goto update_vlan_table; + + if (untagged) { + ret = vsc73xx_vlan_set_untagged_hw(vsc, port, vlan->vid); + } else if (summary.num_untagged == 1) { + vid = vsc73xx_find_first_vlan_untagged(vsc, port); + ret = vsc73xx_vlan_set_untagged_hw(vsc, port, vid); + } + if (ret) + goto err; + +update_vlan_table: + ret = vsc73xx_update_vlan_table(vsc, port, vlan->vid, true); + if (!ret) + return 0; +err: + 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_vlan_summary summary; + struct vsc73xx *vsc = ds->priv; + bool operate_on_storage; + int ret; + u16 vid; + + vsc73xx_bridge_vlan_summary(vsc, port, &summary, vlan->vid); + + ret = vsc73xx_update_vlan_table(vsc, port, vlan->vid, false); + if (ret) + return ret; + + operate_on_storage = vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + + if (!operate_on_storage) { + enum vsc73xx_port_vlan_conf port_vlan_conf = + VSC73XX_VLAN_FILTER; + + if (summary.num_tagged == 0) + port_vlan_conf = VSC73XX_VLAN_FILTER_UNTAG_ALL; + vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf); + + if (summary.num_untagged <= 1) { + vid = vsc73xx_find_first_vlan_untagged(vsc, port); + vsc73xx_vlan_change_untagged_hw(vsc, port, vid, + summary.num_untagged); + } + } + + if (vsc73xx_port_get_pvid(vsc, port, &vid, false) && vid == vlan->vid) + vsc73xx_vlan_clear_pvid(vsc, port, operate_on_storage, 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); + } + + 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]; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_DROP, + VSC73XX_CAT_DROP_TAGGED_ENA | + VSC73XX_CAT_DROP_UNTAGGED_ENA, + VSC73XX_CAT_DROP_UNTAGGED_ENA); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_TXUPDCFG, + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA | + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID, 0); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_PORT_VLAN, + VSC73XX_CAT_PORT_VLAN_VLAN_VID, 0); + + if (port == CPU_PORT) + vsc73xx_set_vlan_conf(vsc, port, VSC73XX_VLAN_FILTER); + else + vsc73xx_set_vlan_conf(vsc, port, VSC73XX_VLAN_IGNORE); + + portinfo->pvid_vlan_filtering_configured = false; + portinfo->pvid_tag_8021q_configured = false; + portinfo->untagged_tag_8021q_configured = false; + + 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); @@ -1120,11 +1657,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 e7b08599a625..ce007273eafe 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 Mon Mar 25 20:43:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602940 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 245D07F477; Mon, 25 Mar 2024 20:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399509; cv=none; b=Y359ynkc4HbUTCRiwchbldsAMhO5RiWlJM/z+LeUYNdxyNHWgYjAS8yMYObo/V0sPkRDOx3IWG2bSrESuG4BkurtJpFYETvjJypc1Ui1NKbgXTo0xyfo44iN9WOCd2z+1T5lKAv6tXFLDxaxb8hNdGTGZLXc46LNIj7Z9OJhlYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399509; c=relaxed/simple; bh=CzhSfwM+D0WsxonCK8YnLO+vv0g995LbiCsceBJorV0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ll/sfjDEabpm+ZVrjjj2rdE2CpDc3koy8eEsOG0cGjeGcIsgYwAgam4zOYFU03EksJ4olUp/c/SNRqNWfPRaYF/X2CFc/eOZTxgkwJ8wS0q73i5dCN6bg/2XBblvJYJZuJnM8vqAmh+onH+tQVjcaw8JLZ/NGDTERiNw17cTm34= 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=i7QcUdBj; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i7QcUdBj" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d6a1af9c07so69148761fa.3; Mon, 25 Mar 2024 13:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399505; x=1712004305; 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=EgbZCr1mQfvbcSKQLR8Uuga1LyHUh7mtUpXZJxBAGbw=; b=i7QcUdBjzYaaKCyVvx03tqvDJO5KUA3f9AM4zN8f+DuXCLMlJr/U3JS+ZVcMZq1BDi ulfqcHwKz3bF4F2cJYv2oE4iGLWFwZd7BkmmlmRiXIDrpkphQCmzLEV7WFGQCVcbTAgw 6Lrw8N7lENUCQJf2aZkyO/naSBlkAE4jdyYBMlLbLIG8z4HTJhLqcebd6QOW6OgRNVo6 SYihBBTejipIC4rprxz/0HncUP3a/CNRKCnEms8wLS3K2nuDvEvRMjoEcm2iC7L2qGrZ WuS7bVPdqJX0y53K9sxuKU+t+4tWaxZCeyhpNLl5tEeIVq2coBoeBQQkNLPRWIeoof7O Hgmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399505; x=1712004305; 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=EgbZCr1mQfvbcSKQLR8Uuga1LyHUh7mtUpXZJxBAGbw=; b=wijEL2zpgZY7DcVjJuEs1Nzl36um8JaEPFwJznMSPqKxgaj3kW4aNLYmhqfd783H5D WA9vNF+YioGgIYA+eI8SDO0UktmvK/PkicV7q9l+Z7qoRSf2m2KduD6p5Qp8i0UVGhGD 1L51Eqeh/tU9+XNukwvm60TIg5L9jZhqlREumlNFlSwi8sp4rFLFcc9FfV+a2b2veDha KgciYU6azYJSqqeOROTgaTFn7anniUbgPbMFYTDOoSo/R0DKMv8p3udHol/8dt3Bo5XN uoSnbcAPeMEXegeukA0i5Jb6jihre8mbNlgiJAfMJesiT1ooAl5FQXqI/ULL3/3psJRK Wwpw== X-Forwarded-Encrypted: i=1; AJvYcCX8kFfgRfK+W1RhUUFERDZ0awZCJSxh97zulF3Npc0P1CQvz9RDYhDQFyEPliy2E+1oJrd9OZhDtc7Px6eXmFC4T6Zcgur/CQM15L/C X-Gm-Message-State: AOJu0YxKb0CRnyOJ0sopbBeazXkXl9VeBd7OfcdzXwtzlkaUPEgmji9W FDGBvlUWPxp5THAloiKVYHopn2ltSupJOf4L94ukigQP4hdUqQ5l7pauEOJKUDs= X-Google-Smtp-Source: AGHT+IHPLDbb1xiPdMlLKbLxm72JC1Us9Tzj69+k4BbcCuLV6jxvi4hgKO3PFoyNac0BIK85ny1kSQ== X-Received: by 2002:a19:5f53:0:b0:513:a88b:3296 with SMTP id a19-20020a195f53000000b00513a88b3296mr4885575lfj.9.1711399504747; Mon, 25 Mar 2024 13:45:04 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:04 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , 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 v7 08/16] net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv() Date: Mon, 25 Mar 2024 21:43:33 +0100 Message-Id: <20240325204344.2298241-9-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 Mon Mar 25 20:43:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602941 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 0386F80033; Mon, 25 Mar 2024 20:45:10 +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=1711399512; cv=none; b=XV7r/AvY2qTuPi49DfE1Kg1/mVPwz6kKWxE6kR8YKxdpWaZFZBoE5DgbYQNOqi35S4vtLNkZAMiNp6yZPabnrvNR9gl7KXUUc9rqatsByTmzKNUGVj0o0pu08LVptbZAWBjO07iOEX2fVsV5QFmERnK6a+OiFDTWLaPua/smIDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399512; c=relaxed/simple; bh=EWKoIDVF8fm0QYl3FNRQ3+x62OTfQHW818wFLTOSGtc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B8ug2JhdJuy1iQ4iXIv9Eu31ZbCnWk2ag3KodllAVXVGG2LtfbuhFbimJJu0rw8VK5ZcXqja9/I0vNqEEQRCqTbaNwKbqA/dkUqPyIUyEf+dCOWERM5HPFvOGFtab58l5l9vd+y9+rMLn6s8Uq0Oa7ZwR8ZUlVPfY8EREfB2l68= 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=LTkne9bF; 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="LTkne9bF" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-56899d9bf52so6072581a12.2; Mon, 25 Mar 2024 13:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399509; x=1712004309; 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=6tG75z9PFe35m2y550RzYH/uskT5uLKYmRA0ol34i+U=; b=LTkne9bFzs6Mxdpmm+FpKwjFaPfnZSsydogFLtlNeZ2n9GSmPNAKkGIXh4H7ScrbNq FWfshaxffIXFieKF0JDmyKiXryxVmj8KWUWi+VlLbxSS50Cyp2G9Os8txcA4DphRRwy9 F8f96bbzcE+Vz5Re/kIkB/rSJWun7Zjwpdji8bLbKBUWPsoed47h6+bH0XiTUNXskmwE PF1MwQPj3yCKElnzYtj4JPrCL5vFNmsqzkkM0HPwkDwLGQ60JYa/pytJswHsenm9QaCT dPyoSkMpIUAAVfmhkBbpytmTEnCVt019jdNQqoU3j2z0a4sg8hCvchxjRqLRFpfvmMUA QS1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399509; x=1712004309; 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=6tG75z9PFe35m2y550RzYH/uskT5uLKYmRA0ol34i+U=; b=rAt/RZ1vcjb2C66J0qZ9VZFFMB7kkuQbZU6LW/f5TrL9GWEQchMCSV6lGm0zHOfI9Q TrSwchF8fjy3SBfp6uFRxju4Zhm2Z7rbJT2Rd6mts50DSmIMAHnAnjRukCPLKWX9Afiu jfFo6Nsp2blq9SuCwIqE4jRnH1j/nfHIqjJD/muNqRJjTepEhBYPwgZr70k70W0HJ2sc RkTaDz1/iw9Km9M72n5Ms73r0MDMl7iGiZV7QJG662e+QuSFbA4OOgE3MAjRHrt+BTyM M4P2ULpG7aNWslInr+5/pCCG9TOGenKeJIbp8G3Az46rIVQN6ojSktFxRDvP4KudvXYr v/Yg== X-Forwarded-Encrypted: i=1; AJvYcCXJX+5XWm6GFiLxQ2jSCidGKY7/H9qukfnJbjW8jKCIgt9BsTFdVMomMnP/sFmEwJaQHO8MNp42xPO8HIOg3O94FAhMHI/x45UmwWQp X-Gm-Message-State: AOJu0Yxfimw9dzRX6Y1LY6oFfXYkf3Iqj2pEhVkW4XB4gUbf3zYZtU82 8a+YaKhv+bZZqQdyg7KbEMEKoaXikg54T68pmI7sPWQyZ92cKaENKvhPcG/O3lA= X-Google-Smtp-Source: AGHT+IFpcjAmn2B7uk42LQV++Wyh0sJ6FIuqPVge98TTrCYFvR2OVaJbUUpatYT2aYeT5tMi4R1npQ== X-Received: by 2002:a50:ab4d:0:b0:56b:cf40:f6fb with SMTP id t13-20020a50ab4d000000b0056bcf40f6fbmr6015029edc.6.1711399508899; Mon, 25 Mar 2024 13:45:08 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:08 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , 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 v7 09/16] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv() Date: Mon, 25 Mar 2024 21:43:34 +0100 Message-Id: <20240325204344.2298241-10-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 Mon Mar 25 20:43:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602942 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 C5AC26BFCC; Mon, 25 Mar 2024 20:45:14 +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=1711399516; cv=none; b=S5/90m4ZQHCo8m88JpZZmIRTCNkhnnr1+kWRNe8Zxx558e2PHrLkjhY00OhVs+Qj9OT1C81WLZsiiTVsJxd0nhOK5UQvmcLNBLYrvqUZR/x7chOGIyPV83GNO3b1CTEb4OvcZQ5Z8iX57yCAPfUsw0fghgyOX6t4KDWYvJ3e5LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399516; c=relaxed/simple; bh=9j8ww96xZAA5t61iUhYjOuJc3n9ckfgsgyCrBkegL5k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SzuEpzPAAvUBzrbDyP9kxZgUlfq5fx0PvTG1DJI6zXfgvW82jHXXtc6Jo7mUUNjYbXN8MIwc81kbw0Pw+MHRk+SOpBWzZrvhlmTeF3361ey+pDznGcuLyNUOk+DELz5qlG0g4YDRkX8ZCd1cKYAibv9PRnqEVv8bjGzigI13FGI= 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=bzz8tOQg; 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="bzz8tOQg" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-56829f41f81so5953662a12.2; Mon, 25 Mar 2024 13:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399513; x=1712004313; 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=xmYDYlHI8ubyZLeGylt14fi0GeBgKPGuFj2fUHhgPug=; b=bzz8tOQgbFcPqF8XrHBCmLVxLlDknG+p8R2DFP2upmdGpa1yoX4NOW609IjCGlNwue pCJ5Fc8fiskXkWRi4Ixn9PTsPJGaX6ST4xTpwQYmyDYs2fdvn0c/duqMk2WaTxFRlhqd qdAmZhrDtzIIHhqKLrnYtiip9AIFTD3zZNRMMv4H8oWw8O3aJM8Q+6gBns0paXeHMqSF NmgUR79W6WFmz4nDl2oy0ijtDs6YQXj4+qqAqE8J8Psn1gw9lKcnzyb7TfKLA8zd9dBY f74n+iLQd9zDRMk0dp8wvd8ONu9m+UXkS8QK6u2W60Kx3gC7SUTOILhG7DYoXLftIKRg FsdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399513; x=1712004313; 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=xmYDYlHI8ubyZLeGylt14fi0GeBgKPGuFj2fUHhgPug=; b=uHEgnXG5KvcX31SoCDRStWDuZdgsYdXC4yiP/E0X5WC6uLH8IFAZ+YwkJtR353cnKI FaUS7X+co+2qSbpdtc5slzbl9ipioJOb8mFSImlMCneECYANdvs82Y3QIkCk8+7OyqOI /pYZwxg3/j75eYnWvfFVPPhFTwDPIlCA9OrCOkaJJLveESfKJm6F57mPK/n7KmLbaooy OfTpj5FskfrTgWicZZBa9m+lWWE7S9A03ipqShEDnbu5kARDSXsKnEq27M9lHIYbI+OC mFVgFqeca1cOoEnRT+k+auoR8G9W3IcFQYQr79UUAab0rT74+pYdXThDIpqeL4LLZtld CXIA== X-Forwarded-Encrypted: i=1; AJvYcCWr/r0+MxC9tp9QsddcJ6xHhWJboz5u562gi5ewcD5WKqWOkW9nCg+KVRhpDuq+XnEAXMHIm+P76SvgmKI1sc1PQOL1RlWLJuLR5YmD X-Gm-Message-State: AOJu0YwRs4+9nazjgw8CaMMVx4jMtaeFY7ccwxK9hmP4hS67VTlvFsk8 lynQm+2/ANr2CSXaL5Pi86+KAe4TtmGBsTDTcs4GfyVAadnvF7S0wFnKW3lzlR4= X-Google-Smtp-Source: AGHT+IGpSBRJGdEtwVg2BGsj6lCELQXGqhgg6sM7D+rniqQ5qW7RIVrx4u71WsaPgyE5xoHwd3zGiQ== X-Received: by 2002:aa7:d8d8:0:b0:56c:26f4:bfe9 with SMTP id k24-20020aa7d8d8000000b0056c26f4bfe9mr297540eds.27.1711399512922; Mon, 25 Mar 2024 13:45:12 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:12 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , 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 v7 10/16] net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too Date: Mon, 25 Mar 2024 21:43:35 +0100 Message-Id: <20240325204344.2298241-11-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 Mon Mar 25 20:43:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602943 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06DE482D9A; Mon, 25 Mar 2024 20:45:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399520; cv=none; b=TCXR+GMW91/WqjJmrY97NbWRlM1Cxk8p8Skg5v40QiPsXH5vc3prE7r9DVUj/VuT7R3WigvnIBi61MfJm/vn+7yxIqiHUkbjbJbUBNbQP9tJziK9+VKw2h8z5njSIxtcPCuyv5TQGtAJD0IxPENls2/m5vZqUE+IuJOX5e0mmw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399520; c=relaxed/simple; bh=DDE/rUmOMNE04KTgH51pZZVtXb9QkzU4zP3jG4SK+6M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EgWrwaxS2/OzyK+vsRQX7GcHGuVRGW7ATbec5BXjraW9NPkb/bkRh7+69Q1t+Yxac7g7yygyYeEJ5nBGrwaMXBdFGXJaOFYubebiJrE7At2ICzCjEKH3Ao7G33JEB+mLlfxKWyUmcoMlJsFGRRCpFVf1FumDSon6TQrWYlLokRw= 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=Ml2qq5G5; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ml2qq5G5" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-56a2bb1d84eso8507670a12.1; Mon, 25 Mar 2024 13:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399517; x=1712004317; 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=VwxiH5lx/9RYIz3hxmE1liFC9ih5JE9dAbG25/LF7X4=; b=Ml2qq5G5lthLobtLP7auQ3nfVVfexDAxpfro1HstXyaIXAE5bD2ZxAIsBTUUafmLSU thzno4knsqqPP/xPMLR6NmAyDcNH5SGsaTaVNo0ic98ktDhhlY9vOEVDmsv6YSwDXzbj +QDsZWvPZv/EJvIhoRyiCv5Ic0Q/yNrB9QBVN6nzcUXRTLzbQ686KLIExrU5vZtxBffz nC0BZ/cd/gnrkGn0m6JOWVFbbd4xkAEqkpsAwTEfFS/NOux05SEiG9g8inuaRL3ehAID xrF3qCJh/CTTDUnhmj/vpOvIwRGTkxn1I0gwCeOjsR4uvfFU17PYoFDaiKpaNdIP9T1b AxQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399517; x=1712004317; 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=VwxiH5lx/9RYIz3hxmE1liFC9ih5JE9dAbG25/LF7X4=; b=Im7CF1bIhFC8kSXEvcqoMzIY0Vz1kiUofEsadI4GMD1eJIPRJuXQJjBS361nbDvw5q TeC9yjd3t9X/bY1Z4QzAqgDC7TavDpNWhdM5DBYQkk+B5xoNXmhvzELqpomjDiYhqm2l aJlM8ch8Bsg4ta9s9TzJ8iD+IRQqHvA8N0IdzvC2d2bbJRzayoO3049/YGJodMR5l4hm dyVnd5VikKaDB13o8ujswBC0DAizP4GBNLuxyKw4U4ECv6bW8eFVTAzmqaFhhRCkWarA CeV/a9YKsXWf83QFFH1qBJYGBp1TAkH1t+/kEjUExXXISyJWfu0GkAsIPQMiBxavt877 cy6w== X-Forwarded-Encrypted: i=1; AJvYcCWoZCyG3XGtKbgazsOd1oXR5Avv8OR92sd8iRyuQ8iKPpMis4dz3AGVXxXwvfCnLADgyuO+fEQg6YcuZqtY/A6J2AVug7TvtczXDxeZ X-Gm-Message-State: AOJu0YzPoNjTqtAxyw7j/fQeLp6VsLWpIb+sUOsg/NUlpFFBDuzmp5j6 L4X23jvbai/XBpoM0zWtWltTedSAa2z39pphi956zdFxSu29xRz0xd3LuJuu3To= X-Google-Smtp-Source: AGHT+IEOyXmmLJ+2J9G9+2hc82emBh9qRqtI0xxLgMGVpLHaah44v69/KJ43kgxuOjD/Jze4eg103g== X-Received: by 2002:a50:8e1c:0:b0:567:800c:f6c6 with SMTP id 28-20020a508e1c000000b00567800cf6c6mr6352731edw.15.1711399517099; Mon, 25 Mar 2024 13:45:17 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:16 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , 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 v7 11/16] net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user() Date: Mon, 25 Mar 2024 21:43:36 +0100 Message-Id: <20240325204344.2298241-12-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 Mon Mar 25 20:43:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602944 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 C3D006CDDB; Mon, 25 Mar 2024 20:45:22 +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=1711399524; cv=none; b=jyOQ0ywWXqewBsj+cM+gkR6w12DOB36g4azqGeaXnpEXN3ENS8dYiqnznjUZxi0HjTlqcGJ3bZCCqVYGvhoKLabCHFZkqqXZTGoljHhlIcwcVVhu9UNVlcVLQJb0o5Oo/jNFallWJb6+h/ipwLdCC0b5FWuLMuygJMkM532vmhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399524; c=relaxed/simple; bh=3Fh9/szZaGY/QRjbESlj6Atfhm3pzShy88grtilyhi8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SCXUiMK5hY/lyEfDLIVRGNWY6yTS63bv9QNej1Rg0qxdMHVmrxgyiFvQla0SjqFOn0V+0XriF7ZLAqwvZuxbsqdmhMy7IP1iqkofOUbU96ViJoX8d/9vuss7rEdqWjrZS1+bULedss8N2rnRC3XBDR4oMTyiYu+sF90Tg2Orh1s= 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=LS473dpv; 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="LS473dpv" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-566e869f631so5143989a12.0; Mon, 25 Mar 2024 13:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399521; x=1712004321; 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=u5ygUCJTE280Q0jyVNdLwABcw296Un0BHN6laP6hkL0=; b=LS473dpvNTUHuzafn41U7/jP5VyDRbyT8Qw6IEcUWoVh6XGwTS3nshi9LFBhkKV0Zt BcXhANiKuxmx2ZMUdXQCAr69/96Ec6f13/B4xBnQhD9D0AcPdACaFP7qz9qo0t5oLltA EK+KAk3rr6/Xjg8HZsE/HZMJD8fEIM/RGKvGnHLboIK23pm8InxFPGP45q17UtgLC4so dk/AQ09kXJCLxSU6iSuge3FL4qRoHlPIIlXeBE9XirJQPZW2TyNJvd5K9CKKWllXt5X2 HoxqSWAUZ0LNukY6Wsm/jHu+SYStjwDXdlfOQ+AMJgIAvTJ/3jo/xIM91+KpESWJoO09 MCCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399521; x=1712004321; 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=u5ygUCJTE280Q0jyVNdLwABcw296Un0BHN6laP6hkL0=; b=V6ApvFnJpwkVwTF/EB0uoOLVDdmheJr0TWs3mp864mbqMBNRjN8iLi5I129K+zytgJ TEH9I9G0o96deIKbKy8Rf7KJpSPjTF8eBj2v0pjhp179ZiGSVbDbgugcKUQPaO0FkmLl vjl2RZg9KVePxmaeF/dinwEej/+qaICFwPLnCbi57rYOCbsK34ZW0lFFM7m3OWP56HMt YXyzIYQt5G88UIc5H8bCaUK+jKpOxxoXcrgBasu7j4BYImS4aMhHB8wvLib+D817dIVy Pp9DgPvYIpUrzWr6CUFo2XbOjEolMBiFgremeiuuNH0UCLdjsm0pbNr9R0kQRZeUYcMR ksjw== X-Forwarded-Encrypted: i=1; AJvYcCX2rFt9TjHCV9ljfF/MD1Uo67aMFuV70jtKI4suV5wcpmvpaz9sGnib12lemG6LAbxuVzKW9WhAlQCXILOZbWlq8TJofSaxxhmkryiZ X-Gm-Message-State: AOJu0YzrzX7qSP/BEtG369bAJ8anEAUfR9rd2SW3loQ+wUQG6qUMbzsQ jdk6yscl41wDnN8LUX5/n9seP0Bz8y/rIueE4NcW7Ay856Ysn3U2NLcH/us1Xxs= X-Google-Smtp-Source: AGHT+IEiCF4cyRSybGOjT3TE1zij1G7XxONjgXRCWhfmXwEzzKNGWo8UGxFxPMW7N+db2WpY9qEvcg== X-Received: by 2002:a50:8e41:0:b0:56b:a03c:4eb with SMTP id 1-20020a508e41000000b0056ba03c04ebmr6554817edx.31.1711399521127; Mon, 25 Mar 2024 13:45:21 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:20 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , 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 v7 12/16] net: dsa: vsc73xx: introduce tag 8021q for vsc73xx Date: Mon, 25 Mar 2024 21:43:37 +0100 Message-Id: <20240325204344.2298241-13-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 7c0da9effe4e..b79e136e4c41 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -56,6 +56,7 @@ struct phylink_link_state; #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, @@ -86,6 +87,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 Mon Mar 25 20:43:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602945 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 1D62484A31; Mon, 25 Mar 2024 20:45:26 +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=1711399528; cv=none; b=GnDdoxTn/zCZSFWhsuznGNctW5Hi0gC11swdJH+DX1NicolB4gunYCV3H6l9jD13W1qz5dbipyQNjsEY6bmaKHwZoZEt5y7GPAC7RvjoUVBIAOLc0uBrkMGCeNIBx/+p84CfBBGa5jJlPu/svaMvbLGr1zoh2YvGtUobdV38ta0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399528; c=relaxed/simple; bh=rgoixMAwGv72yjDjsqhIZ3P7MKK154c00Eqetsmo3dA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eRyQY+hNX1nZEuJIExAe6fjOQD0bgq3mrrouCtdi16NQ/J1Z/bgkXg6TSU+5ZYv1I53XhhOOqFAICs3HCOwu+HMbeEjN7LgN1O9BECNt3R5e+1GjEFmU6FUPbee+KDlieHECLfISqRpRhid5uOno+CdIqtqdX836Ru5wSYdSlpI= 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=UlRsSQTf; 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="UlRsSQTf" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5684db9147dso5569511a12.2; Mon, 25 Mar 2024 13:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399525; x=1712004325; 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=1Ln71Alhu87Jqe+kyFPpkWr0ICct1vn7MAEQLlK4m0s=; b=UlRsSQTfO7GtdfDmUoBhQ/c4j66KK6hAFhpbIE+AXMB+11BY9yi2xyIRYaGzZx0n9s tFYp/O689yK3lnR6Q6L414jigiMU/TA4CHbYxUQHNimx9TFDo/BnUYzblOz9J3TmQshP OxMwtV/Pmnq9svZ+D5WBc4QaxN4sBHhCvw/TcOClLrXsCKFwifh1A4qTUeHPCFQ7uMos NrcJ0QZYzs9NqltmZ3IF8ZbfcsTanwIvCjfNs+isUCQIVDveERiuakJpUMwP0tNXf1PH TrYJh8kClCLPUW9pYkuTSCSDLzJ9JZ6fWnj3XNikRG3/xMhV0a+WqOXV0TZL/PCDm8gb 8n8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399525; x=1712004325; 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=1Ln71Alhu87Jqe+kyFPpkWr0ICct1vn7MAEQLlK4m0s=; b=PtXCVrUuNCEVKFmstAYNwuus7EKJS59G4HCst+RfkTRLUXl+OZ1iNlLKuKO5QmRnWj TSR1TKykkJ9SMt7p2XB58GdL5z8Lalq93s9GmRW+ulIL51Y0eV+XC4ktjuvxHnozVZJV M0wl8gcpxb/2K3NBE4hDJrFzCu1waZW5Grh7TA/rzVFd1q5ACcwMsI/QoUfkxSPIW58T O44Vsz0nBeOOz1JZUjy5Qx/pF2sNAdz3Hlq6gpiu6iWwNQuUyDERQ+PEwQt/5MuojcKz Z4qc9h2cxQNJIDhGQj7CQ9cGnlEc1m/MSF61WBJMduaiKcOjWI6AkgUYrVYLZ5NGdtOB axtw== X-Forwarded-Encrypted: i=1; AJvYcCUdxl3+s8iJ/kz32ZWgtn+b8yX2jn0LTUuoFYo2zybznqX+rjnCw5NX8f7FFeVQsIND6DHHhvZtaiCr2KHlY/oxVyyHYWxwE4DzykFW X-Gm-Message-State: AOJu0YxD7TrgienyOgSmJyBS/LF3N9YABhlJa+27cmKwWHEJsuJQiDAs 7mL7CyeJCLGi6anZJJAvvKPw7MU6VeC5QIS4CIBFQyjZw7mJYasfSue7auRnVC8= X-Google-Smtp-Source: AGHT+IFXMlXExNMnpgypW6EAl6Kz6e98neRXoVSfBxSKu1ouwdZ3ATgnzFtu6nkEkMbVDxhR0L/COg== X-Received: by 2002:a50:bb6d:0:b0:566:4aa9:7143 with SMTP id y100-20020a50bb6d000000b005664aa97143mr5814927ede.14.1711399525225; Mon, 25 Mar 2024 13:45:25 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:24 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , 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 v7 13/16] net: dsa: vsc73xx: Implement the tag_8021q VLAN operations Date: Mon, 25 Mar 2024 21:43:38 +0100 Message-Id: <20240325204344.2298241-14-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 | 54 +++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index 3092b391031a..22a04636d09e 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -126,7 +126,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 833e4e50e737..9d678414f3ca 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"); @@ -756,6 +756,12 @@ static int vsc73xx_setup(struct dsa_switch *ds) mdelay(50); + rtnl_lock(); + ret = dsa_tag_8021q_register(ds, htons(ETH_P_8021Q)); + rtnl_unlock(); + if (ret) + return ret; + /* Release reset from the internal PHYs */ vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GLORESET, VSC73XX_GLORESET_PHY_RESET); @@ -1210,6 +1216,21 @@ static int vsc73xx_vlan_set_untagged_hw(struct vsc73xx *vsc, int port, u16 vid) return vsc73xx_vlan_change_untagged_hw(vsc, port, vid, true); } +static int vsc73xx_vlan_change_untagged_tag_8021q(struct vsc73xx *vsc, int port, + u16 vid, bool valid, + bool operate_on_storage) +{ + struct vsc73xx_portinfo *portinfo = &vsc->portinfo[port]; + + portinfo->untagged_tag_8021q_configured = valid; + portinfo->untagged_tag_8021q = vid; + + if (operate_on_storage) + return 0; + + return vsc73xx_vlan_change_untagged_hw(vsc, port, vid, valid); +} + static int vsc73xx_vlan_change_pvid_hw(struct vsc73xx *vsc, int port, u16 vid, bool set) { @@ -1537,6 +1558,33 @@ 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 *vsc = ds->priv; + bool operate_on_storage; + + operate_on_storage = !vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + + if (untagged) + vsc73xx_vlan_change_untagged_tag_8021q(vsc, port, vid, true, + operate_on_storage); + if (pvid) + vsc73xx_vlan_change_pvid(vsc, port, vid, true, + operate_on_storage, true); + + 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; @@ -1667,6 +1715,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 Mon Mar 25 20:43:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602946 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (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 4E7F86D1BB; Mon, 25 Mar 2024 20:45:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399533; cv=none; b=UOzjXDU0Kqtt2A+89lcbkm4KGftJCl/Hg4XglqvT8I9ECUGL4RBrCdguvlIknV27CKUBUQIhLIrICLTlnYPnVRlMayK45EvReEvGEV9JTAEq1IATIrF79pHKqPkh10/BXw50Ll1alI+RvEeKvMs0IWF0AnbBWsNHH8ta7MW7C6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399533; c=relaxed/simple; bh=bqJJx/zrSTCy5XUk4jROLUayidTR0avivuWUquHNNB8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JCZHxB2OPCkjO34R5pva9svsNfMYw7IxtTUCWJWLdIDD+TnjUBplD+CwUV+jwNCJpN+c9bMtzqpAXoyOORc0Vxj0nZR4OTmjOUgmF02rIIR5rUpPPaNbQImf7q4a7kLQzKfsJg43qMD+XyTWsxQqzwO+JrGJ7D2q1Ucmzm+sCnY= 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=hU3X7MZi; arc=none smtp.client-ip=209.85.208.171 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="hU3X7MZi" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2d49f7e5c2cso64584351fa.2; Mon, 25 Mar 2024 13:45:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399529; x=1712004329; 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=dNp1OGI/1SWamqfMcRFzMSU1aNElG2nHb7wTH+ue4Ik=; b=hU3X7MZis/uscoPLJYF1Io0OOvGZP3M8+ixVoijoWxk80ipP24J9HAlHGrAJqSvKGC gPMsYvI6VzynQb3FlTUM/CWxtBnqRScoBFTD1u8qgePNgjz14LRlMreFOIki6sbcZ/qz 4FnSNacBEJl1YNsAvm6wwJsvtGyuXxOJwIQfH0SAQLqGzldh2L9mlCe0Mt+JCEO7FVHK h9YtxJpj/O4P44wDpGMmHqs/QLGsaGjfysSlTZSv7trY/lW1pNxsaSCXFZ0LfRxu7vWn NGWns/GmoL0GHHanAkX2RfC8AUiiMDb+eKgaEmhFsRZzKUC9SdL4NNuwPkTxUjOkh3aH jklQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399529; x=1712004329; 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=dNp1OGI/1SWamqfMcRFzMSU1aNElG2nHb7wTH+ue4Ik=; b=B5hdPS0VXt6qSZ0fPB/cIQZlVAYKE5Gt9yot/waiI28qVhwjVzpLku10tSPamJow3J l2RXSm94okdU9OWlQgCUB72CcaKdd9d7kMiWpwelT1LeH/QsRbsoqX7lIaYpuIQssNmt cwhL8NMQgtX3TuLVTHkCyYzdzF2aT9YPOksxJ7DuW4ozG4yAEepc1eElFMJUYjEMLSCt ZxuQBCabqiJHUIYZErTJ0eIV8tzfAsmecv7GhNx6vZn1RWvDz+Zdd7mm8INMrbUKwwrn zw+S/Tvkc2vgPddMafGXZAZHaRgIV3kVe+4qobnuvJpVhYVukYLOgQzX5VTvoWzHbtLD 4bmA== X-Forwarded-Encrypted: i=1; AJvYcCUrkS+VAqpOYijB4R0p+DQEMlxcXNamrY38jkvwhzNb2gwyxbkUMvyyG4miAVbXHw/Jy5hhwwDEit78GWXGQPc4eKaHd/SKK8NrgXgz X-Gm-Message-State: AOJu0Yz4WYSN8qpXwlM4K925l5WOnkUI8KTbQWf/XjeRhRrHTawD6NOc 2OOIIuO1cspbGrFFEIpgXwCeNV5xDrsbycKn1CebNymeAmeqYNrixTBDGiRzBI0= X-Google-Smtp-Source: AGHT+IGChCtBunqe0A4RfA7EI03c4cmaad9++riRDdXdL8CT7wP9awJANdmhHntZkEH9tW0Uy+fUTA== X-Received: by 2002:a2e:8014:0:b0:2d6:a699:4bae with SMTP id j20-20020a2e8014000000b002d6a6994baemr5340908ljg.6.1711399529268; Mon, 25 Mar 2024 13:45:29 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:28 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , Vladimir Oltean , Florian Fainelli , 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 v7 14/16] net: dsa: Define max num of bridges in tag8021q implementation Date: Mon, 25 Mar 2024 21:43:39 +0100 Message-Id: <20240325204344.2298241-15-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 6646f7fb0f90..6e22d7a6bfa3 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3156,8 +3156,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 Mon Mar 25 20:43:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602947 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 4D0CC86279; Mon, 25 Mar 2024 20:45:35 +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=1711399537; cv=none; b=Noy8INhpWV5KCZEx9B5q3uk8pYi+zpNmGyTOPRZIVIP9JaoFPA7tYpdGsBNo03TuP9Y6fH+OX8TTJpSCSbyVjbeqnY6hg8aYlXWgd7oOagls+MNval5uUBfLi/606wnE+2MdYuDr0m3WjpxMRAy1unJ9dvcUnG1yUhp0VUZ4z2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399537; c=relaxed/simple; bh=S51/LPCB5EdTpEZfibpDIYuyrDG10p2ILcElzdF65t0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XXG5TXZQtY6tJmSPOr0T98Ed1+5p6aCaWKvzxbMmBlS5tNFMaUWnTZdcQGRaQYFOCzhgJb6BVJPnL1qgyNzkhWMSpLXDab/ldl1tYEjfR8flFaG58D2ZQSJmB9nPRfR/AYyLYGPDi8icRCN7+n8XJGLRF+ldwC3H339qFc3G5sI= 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=g4c56MXF; 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="g4c56MXF" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-56c2818e977so138961a12.0; Mon, 25 Mar 2024 13:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399533; x=1712004333; 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=QE1BA5ViLMATtt4YKzjKBWlb/e+klcdW1qAoMPTU4A4=; b=g4c56MXFpHYH0a/gWc+DyEeFKNbljJYRlHo/8kocW/BFZYH61ZKTNhXyCuX1ekGIZ6 REVXuMb40grXyHmj7aYlqDMfT17H+TAX6rTb/gtHnDlIXd/DS3GaR+WDKDCrNsG/JVcN BhZQR1jxkdeQpgSv3ua+ny9g/OdldBXr9XGwGSqPvNYWLQ+sLa8oT8jnYaYufRV7SPH6 81UrErjbPIUJ9IHut5zSXu8kO0dAyn4zGahRrXjv+8pPYR3ISxv5xhP5gyWpYMQuZZOX h4apWx6aduXdrUpjOIh+L6Bkww7tlcxhzDHFfm+gbGrjZMS1Ov13jTbCyy9hHBqNrOrh QXuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399533; x=1712004333; 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=QE1BA5ViLMATtt4YKzjKBWlb/e+klcdW1qAoMPTU4A4=; b=NpBfuz+kT0K2k7e5cpJ9Ap3uOIYNb3KDicFtsU4WjGgEmZmxS3cNXWpuvdmHREHpdl j3tHKD6R95IoJ6M0FcFji72P7esmajLrT9DOmBCGZUDLoMOSVZ+wpIAiUXdW/4dmZfmS MqACCX7PV2wI3r1mxYJ0gDBwWzg7x0RD4Qwq475f/oHPkXDN/K4k7FRtNucKKrd9P1m1 8gwaC0okFmqUobCmwZKTU1bDi/8nnkVtH5TiH753QXs2ZX6B8HMzM30RcwYrooyf/CU7 42odKe5ix4UfGJC8kLVN3uD7y3Q59PzhjB7VMo9QIfB99+LykhXCNwP40kQRhIE3+5u7 gMSw== X-Forwarded-Encrypted: i=1; AJvYcCXkQmafZnshX+yhSOMIN5sQCCqOJrylqY1T3hyHcHY4YaP0RHSa2n0j8wqYY5msGobbEPJeu1Oe8118FS3RJIvU2v1aewFuZN9MEgO6 X-Gm-Message-State: AOJu0Ywu8IHqAwy5H/4xmc2IemTtEG1YNnOxR3nmTmwbfA44Rry/ioXF +fQW8F7ZKKTauRK79ZaL729vW1YNtbJ7uCWRE1eW/ni/6SABmqCA8wQGOHRorPc= X-Google-Smtp-Source: AGHT+IEMu3/aehjdG/+D5Th8XKPTWx4YIxNxfkzwGWAMFbqK51uCSEMK3xQk34IQS25GgcbOud2Llg== X-Received: by 2002:a50:a456:0:b0:56c:d20:22df with SMTP id v22-20020a50a456000000b0056c0d2022dfmr609112edb.20.1711399533304; Mon, 25 Mar 2024 13:45:33 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:33 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , Vladimir Oltean , Florian Fainelli , 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 v7 15/16] net: dsa: vsc73xx: Add bridge support Date: Mon, 25 Mar 2024 21:43:40 +0100 Message-Id: <20240325204344.2298241-16-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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. It introduce two functions for port_bridge_join and vsc73xx_port_bridge_leave handling. Those functions implement forwarding adjust and use dsa_tag_8021q_bridge_* api for adjust VLAN configuration. Reviewed-by: Linus Walleij Signed-off-by: Pawel Dembicki Reviewed-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 9d678414f3ca..5bfb8aba7428 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); @@ -1585,6 +1588,22 @@ 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_bridge_join(struct dsa_switch *ds, int port, + struct dsa_bridge bridge, + bool *tx_fwd_offload, + struct netlink_ext_ack *extack) +{ + *tx_fwd_offload = true; + + return dsa_tag_8021q_bridge_join(ds, port, bridge); +} + +static void vsc73xx_port_bridge_leave(struct dsa_switch *ds, int port, + struct dsa_bridge bridge) +{ + dsa_tag_8021q_bridge_leave(ds, port, bridge); +} + static int vsc73xx_port_setup(struct dsa_switch *ds, int port) { struct vsc73xx_portinfo *portinfo; @@ -1708,6 +1727,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 = vsc73xx_port_bridge_join, + .port_bridge_leave = vsc73xx_port_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 Mon Mar 25 20:43:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13602948 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 5E84C126F05; Mon, 25 Mar 2024 20:45:39 +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=1711399541; cv=none; b=OjPDVGbfSdPr2I3HS06V1IT82MPLP15A9z+U23MJm9QCUrHW5eXJr80/6bok8xxN6hlD0Y6rJtn9/y4jHADbj8MpLkAXeQFsvNBdSlqQbGFI1HiKube5p140x6Xi774wn1MxGVDr5BhV1CEkINYDTYK3S0/LfFyWTmZ1S46wEZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711399541; c=relaxed/simple; bh=msFwLUgoInL49KijPQT3psq55laeDSaMjfTc1uVOExQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QmafQ2lHcLpr4bIFCm1TGWlUzv69AOe2pU6wxcO6V9+954DM2nr5GyGWpbxKdda3lT/8Z3QPmDKN+4zpH1gDPYhwv0O+m1CjeObyhxYVrX7EhoH9NF/nvJOcPpo2L93QAPQIuZfTY+nelGCGIGV/brRVij2+rikE9NKPHt0Sw7U= 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=YZKCIos0; 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="YZKCIos0" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-56829f41f81so5954206a12.2; Mon, 25 Mar 2024 13:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711399537; x=1712004337; 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=es8X5rKWvUhOVlQ7heJvrLyXvex4sJ4OBGyiyZz9Njc=; b=YZKCIos0TEMt3OHDb7PWzSNVYzGk2s+uTxr/fJpBsGp7e7wsOBCmVHUwj16q0xTefS egCR5Jv1bKhAre6HKc458/IKxvr7LpGTtOUbHT/f1hWdvlh5t/vKJKlZyAK4y7KQFRWa bjAYoaeON4x4riOK3kBvLcD7cE+gXl6yyRKddHVG+VyPHPGULT4ggBoFpE2beezzxMef BcZ68pL8hxtMFDwCSCvbnKA044sURb741TuNr6dHzwFPk7mr0/8+Ml5r1X1vsegGjueM FND2l5E1B7bhDv5T+3pcQlvIMXkYPuXQ03tujye3Cwp5LKqDoX2XI8gCLfnEnOXNfUM0 bwig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711399537; x=1712004337; 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=es8X5rKWvUhOVlQ7heJvrLyXvex4sJ4OBGyiyZz9Njc=; b=ZzyKKeiNNTB2oGT17NVSy2LfTJ9SxUv244+oFKBrRrF5rlwu5EgiyOaWsJ7uT59PUv Ms5uledj7HpxGfNXx3hEwRj02UDtioClZNtfjlb6cdyOoC53BZ5IL3slgM9FgxugAQE7 9wB38k/wixxDIuLlhn8IR5Q5afHW9rYSXk2jGAjqn3AvqxLFHJhPQsNm0Xfx2tOQogJB rEOOVKdDWDINPWtxxK3ZdPGUua0Bi8cdcdOQDDb1xmybsWOG4Qyke8Q9nvsowkCjFHS7 qsdHGL868sdaID+lgWE4EaOW+kgMZGEmr6j3s44KFBQk/rJrgdklJNwAHLBMKVkswCqG f/Yg== X-Forwarded-Encrypted: i=1; AJvYcCUvt5i2ljoCv82jnqD9HbWMzCIa5t4PeCkNuswDwVjRiCasDa4rzzgM2oW/xxaxX+oQmZHaFXlkE4woTNxkyy7+VmWpXBGzpCzAy0M/ X-Gm-Message-State: AOJu0YwZaIy8sRwZg+FFMp8RNyaS9JoaedCu9+/bkSuorxHQqYM6W4sH 9qBKeBrfojQijzGEV0G7Yfov/dgu2uI9IvUPgpNpN3PSHw4r8rSrt0q2wPuhYNM= X-Google-Smtp-Source: AGHT+IGAMnjq3J0/O7f3rW1mKQF1cazGi150PHih2hz7HvEBnpeqOORATCMj5xfrL8v2v42qwrabYQ== X-Received: by 2002:a50:9352:0:b0:56c:274a:31df with SMTP id n18-20020a509352000000b0056c274a31dfmr277188eda.5.1711399537360; Mon, 25 Mar 2024 13:45:37 -0700 (PDT) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id k18-20020a056402049200b0056c1cba8480sm591751edv.25.2024.03.25.13.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:45:37 -0700 (PDT) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: Linus Walleij , Simon Horman , Pawel Dembicki , 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 v7 16/16] net: dsa: vsc73xx: start treating the BR_LEARNING flag Date: Mon, 25 Mar 2024 21:43:41 +0100 Message-Id: <20240325204344.2298241-17-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325204344.2298241-1-paweldembicki@gmail.com> References: <20240325204344.2298241-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 --- 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 5bfb8aba7428..8408f86d0936 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -1588,6 +1588,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_bridge_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge, bool *tx_fwd_offload, @@ -1693,19 +1718,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. */ @@ -1727,6 +1754,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 = vsc73xx_port_bridge_join, .port_bridge_leave = vsc73xx_port_bridge_leave, .port_change_mtu = vsc73xx_change_mtu,