Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp245989imn; Wed, 27 Jul 2022 05:14:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vubrb/xC/651/Pu4QEGXQ+JV9kIxP2V0Crxrsf3dPFXXbzAYI43iDvpS3yDBrJUhOXnY23 X-Received: by 2002:a05:6808:238d:b0:33a:8965:3a9d with SMTP id bp13-20020a056808238d00b0033a89653a9dmr1684347oib.167.1658924071885; Wed, 27 Jul 2022 05:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658924071; cv=none; d=google.com; s=arc-20160816; b=fbjZJx8es9nQjvJKIDU1/3JKMxjDaxhYql0kfW663jfqReChdSwPswn+GT9/7t1Obu 27WL8eWNh+3NNLOsPMIib1QlxvETUrSYzn2LfQ0iVdMr1f9kGcFczxfe9dMPGuMacQdS QO4Nk1XZJCXtTIkY8jm32vngjx8JqbyYRB5PP6AKWM73GQsPKAz5UtIO6O74QTXExS3I foJjvB57rMxGl2oyxCaLS/9MOwtxDRn0oGBuftJVbRptL6iDYwTH+MVs/U7Ii3fRdw+q evZ7ahYOe8DaSy5+Qj4bSJmLhRhrPA7csU8slIclKdQk9OOoMfNSkO82UoDb82pvdS5j QJzQ== 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:to:from :dkim-signature; bh=n3uP0n8WEVP/ZpEVjoeqf0ElYkVUtFFVT2Yra7D28lI=; b=JMBuU/LYOn9ecRPR4NgOR1cbWWr2IeK5OT4TdoTZP8IhkaJRYA8O5tOlSQjlZ706FT IWmxYkzzrONMpFzWRHzZcTN6CJCaNAcs3wYdNeE7Ad2hDXHozjTx2eA/yBmeWdHn52R2 as6ujW1HxMWg81wtPpncnwEjfxH0o3Tvt6KSHbC+My4j3pSVxEw+Plkz0AB8bWxbme2X xRxhNa3bfUUzUGygRQKs95Qj/sVkK1gOu+KSKCo6CR3quyHTHTRLBlnFVCyOecg9HYKA MNkQw79Va/z+6fKvyh2tm7xaBNOMvK5Uum+sKETQ3/svTsfCuyrMrjflYkZ3hd2xaeGI LZMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="kqcJLz/9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f27-20020a056870899b00b00101a0a33139si13869898oaq.103.2022.07.27.05.14.18; Wed, 27 Jul 2022 05:14:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="kqcJLz/9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232380AbiG0Lgj (ORCPT + 99 others); Wed, 27 Jul 2022 07:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232249AbiG0LgF (ORCPT ); Wed, 27 Jul 2022 07:36:05 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B26CB4A80B; Wed, 27 Jul 2022 04:35:53 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id oy13so30979846ejb.1; Wed, 27 Jul 2022 04:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=n3uP0n8WEVP/ZpEVjoeqf0ElYkVUtFFVT2Yra7D28lI=; b=kqcJLz/9hF1qtx2ihYL5eO6o9LHFvGgT0acTr+bXc+uZGdhFG2guI60/3CJ8i1Womk OmIz/05W67SCxNjxPF/vAS79GBfQ1/9Is8qeJooxcQj7jrbTcmxwblgh6aoiPdXGM7gt FS4DVk/SIdfFXqKiPcu51Ffv6ncM97uU3LDwq9neR01+Uy8QpHb6P+59bZL4Q0DZ1o6H VfKoqxq/f9JdH7+e5ZHMZIkCoP49P9n2e0MKWcQFd1lw/kcFEs0X9gpJ7SgQ9MYKP1wf 5rKXbc/gQUMNM+EWue7eIP6aR9wngXmlPHjFth8IPn4oCrLg532FAkoiOP7oGdCIfmAf cwEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n3uP0n8WEVP/ZpEVjoeqf0ElYkVUtFFVT2Yra7D28lI=; b=f/vax0LiVPqzq4nrEBjgmGMnXkI0gviGpyBZJ7Cvw/ZBQ/csdvteSbVcXxX/lnRPiZ XCY/NIbMb5+84BGn+6xCIuii+Lon4wh9w5Q4OTgMDZl0EwVabmbWKPfHtEN940+SW+y6 yh7IT886oSTqxVtvG3aEvdseJBWW2KF6Q9IjVpAVzxL/DkfKKYp3XghklW83nUqZUssO evGavSLs1bZX+g1lJ83WcUBd04CnfvfLIAKQcJahGc4vafI0x+Qz6wqH9RaoEuxJf+6I PZlfvFusm7NSmvlCja1KIghQaTL4G2L5jRfUvzGSdNZCD30YPzO6oJyviDfr774FzjPr Th3Q== X-Gm-Message-State: AJIora8ZCAkeHaAPxSAdCeFF3fIRt6CE/Adw2SRj63nBr7j1HRUAFoVG 9P7Bsb/WoyTMRNLrGblPx1k= X-Received: by 2002:a17:907:7394:b0:72b:44ff:5cec with SMTP id er20-20020a170907739400b0072b44ff5cecmr17721686ejc.670.1658921751950; Wed, 27 Jul 2022 04:35:51 -0700 (PDT) Received: from localhost.localdomain (c105-182.i13-27.melita.com. [94.17.105.182]) by smtp.googlemail.com with ESMTPSA id p25-20020aa7cc99000000b0043ca6fb7e7dsm1334056edt.68.2022.07.27.04.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jul 2022 04:35:51 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Greg Kroah-Hartman , Jens Axboe , Christian Marangi , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v5 08/14] net: dsa: qca8k: move bridge functions to common code Date: Wed, 27 Jul 2022 13:35:17 +0200 Message-Id: <20220727113523.19742-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220727113523.19742-1-ansuelsmth@gmail.com> References: <20220727113523.19742-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The same bridge functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers. While at it also drop unnecessary qca8k_priv cast for void pointers. Signed-off-by: Christian Marangi Reviewed-by: Vladimir Oltean --- drivers/net/dsa/qca/qca8k-8xxx.c | 93 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 93 ++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 9 +++ 3 files changed, 102 insertions(+), 93 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index 9729aabbd83d..11d3116733af 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -1898,99 +1898,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data) return ret; } -static void -qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) -{ - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; - u32 stp_state; - - switch (state) { - case BR_STATE_DISABLED: - stp_state = QCA8K_PORT_LOOKUP_STATE_DISABLED; - break; - case BR_STATE_BLOCKING: - stp_state = QCA8K_PORT_LOOKUP_STATE_BLOCKING; - break; - case BR_STATE_LISTENING: - stp_state = QCA8K_PORT_LOOKUP_STATE_LISTENING; - break; - case BR_STATE_LEARNING: - stp_state = QCA8K_PORT_LOOKUP_STATE_LEARNING; - break; - case BR_STATE_FORWARDING: - default: - stp_state = QCA8K_PORT_LOOKUP_STATE_FORWARD; - break; - } - - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port), - QCA8K_PORT_LOOKUP_STATE_MASK, stp_state); -} - -static int qca8k_port_bridge_join(struct dsa_switch *ds, int port, - struct dsa_bridge bridge, - bool *tx_fwd_offload, - struct netlink_ext_ack *extack) -{ - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; - int port_mask, cpu_port; - int i, ret; - - cpu_port = dsa_to_port(ds, port)->cpu_dp->index; - port_mask = BIT(cpu_port); - - for (i = 0; i < QCA8K_NUM_PORTS; i++) { - if (dsa_is_cpu_port(ds, i)) - continue; - if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge)) - continue; - /* Add this port to the portvlan mask of the other ports - * in the bridge - */ - ret = regmap_set_bits(priv->regmap, - QCA8K_PORT_LOOKUP_CTRL(i), - BIT(port)); - if (ret) - return ret; - if (i != port) - port_mask |= BIT(i); - } - - /* Add all other ports to this ports portvlan mask */ - ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port), - QCA8K_PORT_LOOKUP_MEMBER, port_mask); - - return ret; -} - -static void qca8k_port_bridge_leave(struct dsa_switch *ds, int port, - struct dsa_bridge bridge) -{ - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; - int cpu_port, i; - - cpu_port = dsa_to_port(ds, port)->cpu_dp->index; - - for (i = 0; i < QCA8K_NUM_PORTS; i++) { - if (dsa_is_cpu_port(ds, i)) - continue; - if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge)) - continue; - /* Remove this port to the portvlan mask of the other ports - * in the bridge - */ - regmap_clear_bits(priv->regmap, - QCA8K_PORT_LOOKUP_CTRL(i), - BIT(port)); - } - - /* Set the cpu port to be the only one in the portvlan mask of - * this port - */ - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port), - QCA8K_PORT_LOOKUP_MEMBER, BIT(cpu_port)); -} - static void qca8k_port_fast_age(struct dsa_switch *ds, int port) { diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c index c662fdbae51f..13069c9ba3e6 100644 --- a/drivers/net/dsa/qca/qca8k-common.c +++ b/drivers/net/dsa/qca/qca8k-common.c @@ -8,6 +8,7 @@ #include #include +#include #include "qca8k.h" @@ -275,3 +276,95 @@ int qca8k_get_mac_eee(struct dsa_switch *ds, int port, /* Nothing to do on the port's MAC */ return 0; } + +void qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) +{ + struct qca8k_priv *priv = ds->priv; + u32 stp_state; + + switch (state) { + case BR_STATE_DISABLED: + stp_state = QCA8K_PORT_LOOKUP_STATE_DISABLED; + break; + case BR_STATE_BLOCKING: + stp_state = QCA8K_PORT_LOOKUP_STATE_BLOCKING; + break; + case BR_STATE_LISTENING: + stp_state = QCA8K_PORT_LOOKUP_STATE_LISTENING; + break; + case BR_STATE_LEARNING: + stp_state = QCA8K_PORT_LOOKUP_STATE_LEARNING; + break; + case BR_STATE_FORWARDING: + default: + stp_state = QCA8K_PORT_LOOKUP_STATE_FORWARD; + break; + } + + qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port), + QCA8K_PORT_LOOKUP_STATE_MASK, stp_state); +} + +int qca8k_port_bridge_join(struct dsa_switch *ds, int port, + struct dsa_bridge bridge, + bool *tx_fwd_offload, + struct netlink_ext_ack *extack) +{ + struct qca8k_priv *priv = ds->priv; + int port_mask, cpu_port; + int i, ret; + + cpu_port = dsa_to_port(ds, port)->cpu_dp->index; + port_mask = BIT(cpu_port); + + for (i = 0; i < QCA8K_NUM_PORTS; i++) { + if (dsa_is_cpu_port(ds, i)) + continue; + if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge)) + continue; + /* Add this port to the portvlan mask of the other ports + * in the bridge + */ + ret = regmap_set_bits(priv->regmap, + QCA8K_PORT_LOOKUP_CTRL(i), + BIT(port)); + if (ret) + return ret; + if (i != port) + port_mask |= BIT(i); + } + + /* Add all other ports to this ports portvlan mask */ + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port), + QCA8K_PORT_LOOKUP_MEMBER, port_mask); + + return ret; +} + +void qca8k_port_bridge_leave(struct dsa_switch *ds, int port, + struct dsa_bridge bridge) +{ + struct qca8k_priv *priv = ds->priv; + int cpu_port, i; + + cpu_port = dsa_to_port(ds, port)->cpu_dp->index; + + for (i = 0; i < QCA8K_NUM_PORTS; i++) { + if (dsa_is_cpu_port(ds, i)) + continue; + if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge)) + continue; + /* Remove this port to the portvlan mask of the other ports + * in the bridge + */ + regmap_clear_bits(priv->regmap, + QCA8K_PORT_LOOKUP_CTRL(i), + BIT(port)); + } + + /* Set the cpu port to be the only one in the portvlan mask of + * this port + */ + qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port), + QCA8K_PORT_LOOKUP_MEMBER, BIT(cpu_port)); +} diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h index c73cbdfc6ac6..edb2b23a02b9 100644 --- a/drivers/net/dsa/qca/qca8k.h +++ b/drivers/net/dsa/qca/qca8k.h @@ -454,4 +454,13 @@ int qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset); int qca8k_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *eee); int qca8k_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e); +/* Common bridge function */ +void qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state); +int qca8k_port_bridge_join(struct dsa_switch *ds, int port, + struct dsa_bridge bridge, + bool *tx_fwd_offload, + struct netlink_ext_ack *extack); +void qca8k_port_bridge_leave(struct dsa_switch *ds, int port, + struct dsa_bridge bridge); + #endif /* __QCA8K_H */ -- 2.36.1