From patchwork Fri Dec 14 16:48:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Wunderlich X-Patchwork-Id: 10731445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA2BE112C for ; Fri, 14 Dec 2018 16:50:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B4C52D85A for ; Fri, 14 Dec 2018 16:50:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F27E2D865; Fri, 14 Dec 2018 16:50:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9B09E2D85A for ; Fri, 14 Dec 2018 16:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=B2U2y6yf/HonUDNKdOkRtc6YSg00xNLk8BVkMDHriC4=; b=pLfO1Tqu66MH6rSV60djBeQpBA AGM4D1kAH6MMci+czLmLGWVdwe0uAb3I+6GceVCOnyWOLxQNY8WjjtQN16JJWvfnXJ3GyCdhj+mIh yzC2bZDcAEQnVm66t8/nMdSyPCpQ61WUN0l5JBTyKcQ/8uK1MQD1GU2+2Q/Kaj2muOloRBrQl/lVW yoilxXJ+284VBRmfhVPWsVcH8LCCSI0BCHOrduZaJPVdIXB9SrnTjc0+0z5GIJkW10pX/taoFhvZC yIvSUKGUMA6Mk5h5QsjszGlePPbjMeaK55Bu+EHnpXwwCHr/umaiC4pZv1B7ydLIIe41zu2egJzP5 ZsKm8hPA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gXqfR-0000sM-Nx; Fri, 14 Dec 2018 16:50:25 +0000 Received: from mout.gmx.net ([212.227.15.18]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gXqfM-0008KK-Tq for linux-mediatek@lists.infradead.org; Fri, 14 Dec 2018 16:50:23 +0000 Received: from localhost.localdomain ([91.14.94.237]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0LiDnn-1hAUvr2Chf-00nMYy; Fri, 14 Dec 2018 17:49:12 +0100 From: Frank Wunderlich To: Matthias Brugger , netdev@vger.kernel.org, Sean Wang , Andrew Lunn , linux-mediatek@lists.infradead.org Subject: [PATCH 2/8] net: dsa: add helper functions Date: Fri, 14 Dec 2018 17:48:41 +0100 Message-Id: <20181214164847.4851-3-frank-w@public-files.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181214164847.4851-1-frank-w@public-files.de> References: <20181214164847.4851-1-frank-w@public-files.de> X-Provags-ID: V03:K1:8Y/ysQdttt6vSxa2xsYkPMW3601sKcRiBd9NtuKZEK+iwZfpbBd F3uz3d40RnfxDRhC7wFHBONNxLPk0H2YByh9cGbgfrpyP9MBgDXyQW+m4HRMHOtHW+s0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DKNKdaYzEvPJUCNkC7WbAzo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181214_085021_258943_8F449D50 X-CRM114-Status: UNSURE ( 9.51 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Frank Wunderlich MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP for using mutliple cpu-Ports 3 additional functions are defined to read dts-option (dsa_user_parse) and check if current port is a upstream-port (dsa_port_upstream_port, dsa_is_upstream_port) based on https://github.com/openwrt/openwrt/blob/master/target/linux/mediatek/patches-4.14/0033-dsa-multi-cpu.patch Signed-off-by: Frank Wunderlich --- include/net/dsa.h | 18 ++++++++++++++++++ net/dsa/dsa2.c | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index 3efa81e08993..612942ac56de 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -319,6 +319,12 @@ static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, return ds->rtable[device]; } + +static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int p) +{ + return dsa_is_cpu_port(ds, p) || dsa_is_dsa_port(ds, p); +} + /* Return the local port used to reach the dedicated CPU port */ static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) { @@ -331,6 +337,18 @@ static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); } +static inline u8 dsa_port_upstream_port(struct dsa_switch *ds, int port) +{ + /* + * If this port has a specific upstream cpu port, use it, + * otherwise use the switch default. + */ + if (ds->ports[port].upstream) + return ds->ports[port].upstream; + else + return dsa_upstream_port(ds, port); +} + typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, bool is_static, void *data); struct dsa_switch_ops { diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index a1917025e155..b7c6da2f1f08 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -255,6 +255,24 @@ static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst) dst->cpu_dp = NULL; } +static int dsa_user_parse(struct dsa_port *port, u32 index, + struct dsa_switch *ds) +{ + struct device_node *cpu_port; + const unsigned int *cpu_port_reg; + int cpu_port_index; + + cpu_port = of_parse_phandle(port->dn, "default_cpu", 0); + if (cpu_port) { + cpu_port_reg = of_get_property(cpu_port, "reg", NULL); + if (!cpu_port_reg) + return -EINVAL; + cpu_port_index = be32_to_cpup(cpu_port_reg); + ds->ports[index].upstream = cpu_port_index; + } + return 0; +} + static int dsa_port_setup(struct dsa_port *dp) { struct dsa_switch *ds = dp->ds;