From patchwork Thu Oct 12 22:10:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivien Didelot X-Patchwork-Id: 825132 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yClQy0GHXz9sNw for ; Fri, 13 Oct 2017 09:10:33 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753200AbdJLWKU (ORCPT ); Thu, 12 Oct 2017 18:10:20 -0400 Received: from mail.savoirfairelinux.com ([208.88.110.44]:48536 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751541AbdJLWKT (ORCPT ); Thu, 12 Oct 2017 18:10:19 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 352C59C1A0C; Thu, 12 Oct 2017 18:10:19 -0400 (EDT) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id R0z1ShJdBYcM; Thu, 12 Oct 2017 18:10:18 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 93BC99C1B5E; Thu, 12 Oct 2017 18:10:18 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Rto09-Q6YDDV; Thu, 12 Oct 2017 18:10:18 -0400 (EDT) Received: from weeman.mtl.sfl (unknown [192.168.49.104]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 67B809C1A0C; Thu, 12 Oct 2017 18:10:18 -0400 (EDT) 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] net: dsa: set random switch address Date: Thu, 12 Oct 2017 18:10:09 -0400 Message-Id: <20171012221009.14615-1-vivien.didelot@savoirfairelinux.com> X-Mailer: git-send-email 2.14.2 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org An Ethernet switch may support having a MAC address, which can be used as the switch's source address in transmitted full-duplex Pause frames. If a DSA switch supports the related .set_addr operation, the DSA core sets the master's MAC address on the switch. This won't make sense anymore in a multi-CPU ports system, because there won't be a unique master device assigned to a switch tree. To fix this, assign a random MAC address to the switch chip instead. Signed-off-by: Vivien Didelot --- net/dsa/dsa2.c | 8 +++----- net/dsa/dsa_priv.h | 1 + net/dsa/legacy.c | 8 +++----- net/dsa/switch.c | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 54ed054777bd..8e5780ddd7f9 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -336,11 +336,9 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) if (err) return err; - if (ds->ops->set_addr) { - err = ds->ops->set_addr(ds, dst->cpu_dp->netdev->dev_addr); - if (err < 0) - return err; - } + err = dsa_switch_set_addr(ds); + if (err) + return err; if (!ds->slave_mii_bus && ds->ops->phy_read) { ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev); diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 2850077cc9cc..9c4c17a4bd6b 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -172,6 +172,7 @@ void dsa_slave_unregister_notifier(void); /* switch.c */ int dsa_switch_register_notifier(struct dsa_switch *ds); void dsa_switch_unregister_notifier(struct dsa_switch *ds); +int dsa_switch_set_addr(struct dsa_switch *ds); /* tag_brcm.c */ extern const struct dsa_device_ops brcm_netdev_ops; diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c index 19ff6e0a21dc..340ca7997271 100644 --- a/net/dsa/legacy.c +++ b/net/dsa/legacy.c @@ -172,11 +172,9 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, if (ret) return ret; - if (ops->set_addr) { - ret = ops->set_addr(ds, master->dev_addr); - if (ret < 0) - return ret; - } + ret = dsa_switch_set_addr(ds); + if (ret) + return ret; if (!ds->slave_mii_bus && ops->phy_read) { ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev); diff --git a/net/dsa/switch.c b/net/dsa/switch.c index e6c06aa349a6..b45a26b006af 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c @@ -10,6 +10,7 @@ * (at your option) any later version. */ +#include #include #include #include @@ -267,3 +268,19 @@ void dsa_switch_unregister_notifier(struct dsa_switch *ds) if (err) dev_err(ds->dev, "failed to unregister notifier (%d)\n", err); } + +int dsa_switch_set_addr(struct dsa_switch *ds) +{ + u8 addr[6]; + int err; + + if (ds->ops->set_addr) { + eth_random_addr(addr); + + err = ds->ops->set_addr(ds, addr); + if (err) + return err; + } + + return 0; +}