From patchwork Wed Sep 29 21:03:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 514866 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:4087:0:0:0:0 with SMTP id m7csp418729jam; Wed, 29 Sep 2021 14:07:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMBdOr3WJMQ+kQhuX9pJKGX2RBc4ARh1LanHffLA9DkGHtMeAgCleqlYJyFFYz4vCRuvOJ X-Received: by 2002:aa7:c78f:: with SMTP id n15mr2604946eds.338.1632949627887; Wed, 29 Sep 2021 14:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632949627; cv=none; d=google.com; s=arc-20160816; b=sQB6gASFX8YnE3bMqaksm0NJcC+E5LizQhL4exWqb4FCIkvGlDkxD1v7+suEuC8Z+l OO7FIlZUVqI1cDkBhQm5JPULWUcm/Nuj/0d38mwIPNd+D7xF9swDgX+ho/Cew/bE0k0R 8hETA+s9P1n1L8TiJzifBeQPZ6+mhIqZezsROCHBD0orLh2UacqNuzc0uDfBTfTvaMm/ d1lxwLIKMUdaXukoG9sH+7IKtOheX/BEd+0RFCAF7zOMuMguAMlwXToJGcFeVVmFfFhM N8RsdrkGxEutdX66JGIufqIM5C2YCSobNU3DHqTRf217bZe1Lkjs06Q5ITi6P7EVATpl zdag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3KZeQ1UL+Qr6VrGAkVMnUDxIrRV+iTWbafHkEPoCs9g=; b=N6XuLjts0Ph+2dZnwifkX0QIeWh00A5PfTjMjUBACF/7E4sIFrvutXANDTRD6tWNMY KF1S0y+5/IN3N7Te/BI2G4224S5l8DvAFMN849VOsJjQIlez6TddGqQ+FC8Hrz8rMz98 AO0fUfO3HVE9ASepuorAAM492csG7ihPJFZtznhTvsfwEdJToJ/CWL8OjJoWhOm5zLXH fHx8/jaN7Isj26/cxiF66ndLCbbdnBb8Ja/BHVXYDK3a37CdQap7OZfiqAtP+IkH3x3V iXIxtcbgcdk0eRmFfRzfWXUQd06rTz45TORfie6h5ubomVcCJbwc0I4n1F7+MEO3Hora 9w1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M58hkh9S; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si1714686ejo.634.2021.09.29.14.07.07; Wed, 29 Sep 2021 14:07:07 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M58hkh9S; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346550AbhI2VIq (ORCPT + 8 others); Wed, 29 Sep 2021 17:08:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345622AbhI2VIo (ORCPT ); Wed, 29 Sep 2021 17:08:44 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 354EFC06161C for ; Wed, 29 Sep 2021 14:07:02 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id x27so16328799lfu.5 for ; Wed, 29 Sep 2021 14:07:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3KZeQ1UL+Qr6VrGAkVMnUDxIrRV+iTWbafHkEPoCs9g=; b=M58hkh9SpiSFF7g28cyy/3kzGz+I4WM2ImAvKHGPlvAQpoXgjzo5WLGWVFb2XS+DjO aGc3YjZu4CVVsc+LGQFH5P3tMSUwNuYH5Gt2Y19W330VfK1P3wVoEiCeCqy1U4FGiksp kZLs/GfxDAICvCJToEk9tOHXIlCwuhhqk8ypq/CnIuuYxCJEPSKV8BZutt4hop+Jylrc MpjwotUmbKWHWGCRS5nNPCzcyCkL5GL6ZdQRzn4frd7le3ceCt0x1/f0djx/2nZ15JOY jdKWAvJdW/yvUoZq7h8w1svZxIIA6KiLyB/MSPLYlasCwC8ztIL0eMPCqFykGw6rzp3M 8xVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3KZeQ1UL+Qr6VrGAkVMnUDxIrRV+iTWbafHkEPoCs9g=; b=6j50UzYQHskyFTNJ8zSjfaKVXFX52bLfHrgC3NDHEslxRtM6bR16os3MzB/dPYMrwd k0LhQrlAvo982zUDuMfcHLZbUl7gpvjRdWZSIggAJNsyS3xMTnpkAFooSLw3yhNTCWzl zNcts6FuU0LhPqCXbbooAUb9sVD1Mm8JvfUKamtUuTadALDDBZjYQj1Zmlk83GxDOsQW RYmUYIBejDASJkpaXtUTye7+6kXKQoo+Kpm6RPbvS+9VscM5RkGnric2nfVaytXoUZFL cbSrqiqANOBM1HAaK3jWwL/fIUUCPJHP5dbn9xR6jAHPys5WLshgvOQTeHNRxHCewbkw YJGw== X-Gm-Message-State: AOAM531vvBF4NpnVFu7ifgceTUCwMY49IjJ70GvupeB0yz32nLSNG27H 5wUQ1LcI6JrWqlAEN/43YT18Gw== X-Received: by 2002:ac2:5e24:: with SMTP id o4mr1731035lfg.522.1632949620530; Wed, 29 Sep 2021 14:07:00 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id s9sm112613lfp.291.2021.09.29.14.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 14:07:00 -0700 (PDT) From: Linus Walleij To: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Mauri Sandberg , DENG Qingfang Subject: [PATCH net-next 4/4 v4] net: dsa: rtl8366rb: Support setting STP state Date: Wed, 29 Sep 2021 23:03:49 +0200 Message-Id: <20210929210349.130099-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210929210349.130099-1-linus.walleij@linaro.org> References: <20210929210349.130099-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This adds support for setting the STP state to the RTL8366RB DSA switch. This rids the following message from the kernel on e.g. OpenWrt: DSA: failed to set STP state 3 (-95) Since the RTL8366RB has one STP state register per FID with two bit per port in each, we simply loop over all the FIDs and set the state on all of them. Cc: Vladimir Oltean Cc: Alvin Šipraga Cc: Mauri Sandberg Cc: DENG Qingfang Signed-off-by: Linus Walleij --- ChangeLog v1->v4: - New patch after discovering that we can do really nice bridge offloading with these bits. --- drivers/net/dsa/rtl8366rb.c | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) -- 2.31.1 diff --git a/drivers/net/dsa/rtl8366rb.c b/drivers/net/dsa/rtl8366rb.c index 748f22ab9130..c143fdab4802 100644 --- a/drivers/net/dsa/rtl8366rb.c +++ b/drivers/net/dsa/rtl8366rb.c @@ -110,6 +110,14 @@ #define RTL8366RB_POWER_SAVING_REG 0x0021 +/* Spanning tree status (STP) control, two bits per port per FID */ +#define RTL8368S_SPT_STATE_BASE 0x0050 /* 0x0050..0x0057 */ +#define RTL8368S_SPT_STATE_MSK 0x3 +#define RTL8368S_SPT_STATE_DISABLED 0x0 +#define RTL8368S_SPT_STATE_BLOCKING 0x1 +#define RTL8368S_SPT_STATE_LEARNING 0x2 +#define RTL8368S_SPT_STATE_FORWARDING 0x3 + /* CPU port control reg */ #define RTL8368RB_CPU_CTRL_REG 0x0061 #define RTL8368RB_CPU_PORTS_MSK 0x00FF @@ -254,6 +262,7 @@ #define RTL8366RB_NUM_LEDGROUPS 4 #define RTL8366RB_NUM_VIDS 4096 #define RTL8366RB_PRIORITYMAX 7 +#define RTL8366RB_NUM_FIDS 8 #define RTL8366RB_FIDMAX 7 #define RTL8366RB_PORT_1 BIT(0) /* In userspace port 0 */ @@ -1359,6 +1368,43 @@ rtl8366rb_port_bridge_flags(struct dsa_switch *ds, int port, return 0; } +static void +rtl8366rb_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) +{ + struct realtek_smi *smi = ds->priv; + u16 mask; + u32 val; + int i; + + switch (state) { + case BR_STATE_DISABLED: + val = RTL8368S_SPT_STATE_DISABLED; + break; + case BR_STATE_BLOCKING: + case BR_STATE_LISTENING: + val = RTL8368S_SPT_STATE_BLOCKING; + break; + case BR_STATE_LEARNING: + val = RTL8368S_SPT_STATE_LEARNING; + break; + case BR_STATE_FORWARDING: + val = RTL8368S_SPT_STATE_FORWARDING; + break; + default: + dev_err(smi->dev, "unknown bridge state requested\n"); + return; + }; + + mask = (RTL8368S_SPT_STATE_MSK << (port * 2)); + val <<= (port * 2); + + /* Set the same status for the port on all the FIDs */ + for (i = 0; i < RTL8366RB_NUM_FIDS; i++) { + regmap_update_bits(smi->map, RTL8368S_SPT_STATE_BASE + i, + mask, val); + } +} + static void rtl8366rb_port_fast_age(struct dsa_switch *ds, int port) { @@ -1784,6 +1830,7 @@ static const struct dsa_switch_ops rtl8366rb_switch_ops = { .port_disable = rtl8366rb_port_disable, .port_pre_bridge_flags = rtl8366rb_port_pre_bridge_flags, .port_bridge_flags = rtl8366rb_port_bridge_flags, + .port_stp_state_set = rtl8366rb_port_stp_state_set, .port_fast_age = rtl8366rb_port_fast_age, .port_change_mtu = rtl8366rb_change_mtu, .port_max_mtu = rtl8366rb_max_mtu,