Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752727AbdLDRfy (ORCPT ); Mon, 4 Dec 2017 12:35:54 -0500 Received: from mail.savoirfairelinux.com ([208.88.110.44]:45210 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752061AbdLDRfp (ORCPT ); Mon, 4 Dec 2017 12:35:45 -0500 From: Vivien Didelot To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com, "David S. Miller" , Florian Fainelli , Andrew Lunn , Vivien Didelot Subject: [PATCH net-next 5/5] net: dsa: return per-port upstream port Date: Mon, 4 Dec 2017 12:34:57 -0500 Message-Id: <20171204173457.14873-6-vivien.didelot@savoirfairelinux.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171204173457.14873-1-vivien.didelot@savoirfairelinux.com> References: <20171204173457.14873-1-vivien.didelot@savoirfairelinux.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2070 Lines: 53 The current dsa_upstream_port() helper still assumes a unique CPU port in the whole switch fabric. This is becoming wrong, as every port in the fabric has its dedicated CPU port, thus every port has an upstream port. Add a port argument to the dsa_upstream_port() helper and fetch its CPU port instead of the deprecated unique fabric CPU port. A CPU or unused port has no dedicated CPU port, so return itself in this case. At the same time, change the return value from u8 to unsigned int since there is no need to limit the size here. Signed-off-by: Vivien Didelot --- drivers/net/dsa/mv88e6xxx/chip.c | 2 +- include/net/dsa.h | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 5de8596b01ad..fe4881795906 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1746,7 +1746,7 @@ static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port, static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port) { struct dsa_switch *ds = chip->ds; - int upstream_port = dsa_upstream_port(ds); + int upstream_port = dsa_upstream_port(ds, port); int err; if (chip->info->ops->port_set_upstream_port) { diff --git a/include/net/dsa.h b/include/net/dsa.h index 8198efcc8ced..d29feccaefab 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -307,10 +307,13 @@ static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, } /* Return the local port used to reach the dedicated CPU port */ -static inline u8 dsa_upstream_port(struct dsa_switch *ds) +static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) { - struct dsa_switch_tree *dst = ds->dst; - struct dsa_port *cpu_dp = dst->cpu_dp; + const struct dsa_port *dp = dsa_to_port(ds, port); + const struct dsa_port *cpu_dp = dp->cpu_dp; + + if (!cpu_dp) + return port; return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); } -- 2.15.1