From patchwork Sat Apr 10 13:34:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 419868 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00, DATE_IN_PAST_24_48, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ADAEC433B4 for ; Sun, 11 Apr 2021 15:04:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E97E610A6 for ; Sun, 11 Apr 2021 15:04:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236268AbhDKPE0 (ORCPT ); Sun, 11 Apr 2021 11:04:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236182AbhDKPEZ (ORCPT ); Sun, 11 Apr 2021 11:04:25 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BADAC061574; Sun, 11 Apr 2021 08:04:09 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id sd23so7413567ejb.12; Sun, 11 Apr 2021 08:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TP//p5Hq9CM2Hfznxk5ShC9ChhuREDW41Rf2hAiWGJA=; b=BgCqO4QD2MZmWZ0fb8HPEh+aRox+eA1s2DYR/aYkwtx9LeOZz1WWHDdgqAZYOEApZ2 cWoZF3LAhNvYwQb8/m6hwa436iFHeue1Jih7ZmJsXpZiJ57gDtxt7wPjon2YkSgu7NmH BxZuRoMgK6i8z1SYAqiibj7wLdTGaw4dLWz7vkOwentg25Q13CWk95BCQioR3b72nn/Y T8YgmlAifEEXDgkcgLJ3MPsPxTN/L76agvFbb/hpC9Qn0zoEPZ89SCC8m50U+wz+mVkI Htegc4kZRoprWoXuAu4A2WYcevIg0/CXQAIE6MTzqDzdxKpuuzspGcGfeK/YYwiMFSpR j6mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TP//p5Hq9CM2Hfznxk5ShC9ChhuREDW41Rf2hAiWGJA=; b=At8MViSnrWzAPwkdcGkpfSNomprcvnN0gXxMXajNFyNHHnXL0RKQ45xyFliTcwIyic 62ZARqdrXAEHteaDs5jc82sfHwKL6TF+PASwfgQW+PZzsHeuRuet8rE0XsJxO+RkWx0+ j0hGWkifTy1qobUzuBQUaUz2ML5vKyu17GHAQoMFI46+JHVrB664e1ygNrbeoBujLr3m QFPHhaCBA9ZA/D5B+TPV33qokMDxcJ/T6kdzblBlIl/vtfQwQ6jenBYUbdi7Z8vNcmaV JBEtadXSTm8w5gT5oMdIh087UnJhlx5f6mPnwNPbUdfm35JzpUeJ+Eil91Va71LIel5g Mblw== X-Gm-Message-State: AOAM531bwqprfxfyudQcDIondtYDrn509c8hwvdq7YB7AoIcHMNI78cu WCO/A8+xc/gRWWvP319YK1umhKJCn6i9dQ== X-Google-Smtp-Source: ABdhPJyr6FTeSN04PU7jiIvYcmU7cl2nWMUaeMYMcBq0zzEilG8lpLyXWo72bNfqyZszvNtXFVEyyQ== X-Received: by 2002:a17:906:a0d4:: with SMTP id bh20mr23722082ejb.348.1618153447836; Sun, 11 Apr 2021 08:04:07 -0700 (PDT) Received: from Ansuel-xps.localdomain (host-95-239-254-7.retail.telecomitalia.it. [95.239.254.7]) by smtp.googlemail.com with ESMTPSA id l15sm4736146edb.48.2021.04.11.08.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Apr 2021 08:04:07 -0700 (PDT) From: Ansuel Smith To: netdev@vger.kernel.org Cc: Ansuel Smith , =?utf-8?q?Marek_Beh=C3=BAn?= , "David S. Miller" , Jakub Kicinski , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eric Dumazet , Wei Wang , Cong Wang , Taehee Yoo , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Francis Laniel , zhang kai , Di Zhu , Roopa Prabhu , linux-kernel@vger.kernel.org Subject: [PATCH RFC net-next 3/3] net: dsa: implement ndo_set_netlink for chaning port's CPU port Date: Sat, 10 Apr 2021 15:34:49 +0200 Message-Id: <20210410133454.4768-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210410133454.4768-1-ansuelsmth@gmail.com> References: <20210410133454.4768-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Implement ndo_set_iflink for DSA slave device. In multi-CPU port setup this should be used to change to which CPU destination port a given port should be connected. On CPU port change, the mac address is updated with the new value, if not set to a custom value. Signed-off-by: Marek BehĂșn Signed-off-by: Ansuel Smith --- net/dsa/slave.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 992fcab4b552..c68dbd3ab21a 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -63,6 +63,36 @@ static int dsa_slave_get_iflink(const struct net_device *dev) return dsa_slave_to_master(dev)->ifindex; } +static int dsa_slave_set_iflink(struct net_device *dev, int iflink) +{ + struct net_device *master = dsa_slave_to_master(dev); + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_slave_priv *p = netdev_priv(dev); + struct net_device *cpu_dev; + struct dsa_port *cpu_dp; + + cpu_dev = dev_get_by_index(dev_net(dev), iflink); + if (!cpu_dev) + return -ENODEV; + + cpu_dp = cpu_dev->dsa_ptr; + if (!cpu_dp) + return -EINVAL; + + /* new CPU port has to be on the same switch tree */ + if (cpu_dp->dst != dp->cpu_dp->dst) + return -EINVAL; + + if (ether_addr_equal(dev->dev_addr, master->dev_addr)) + eth_hw_addr_inherit(dev, cpu_dev); + + /* should this be done atomically? */ + dp->cpu_dp = cpu_dp; + p->xmit = cpu_dp->tag_ops->xmit; + + return 0; +} + static int dsa_slave_open(struct net_device *dev) { struct net_device *master = dsa_slave_to_master(dev); @@ -1666,6 +1696,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = { .ndo_fdb_dump = dsa_slave_fdb_dump, .ndo_do_ioctl = dsa_slave_ioctl, .ndo_get_iflink = dsa_slave_get_iflink, + .ndo_set_iflink = dsa_slave_set_iflink, #ifdef CONFIG_NET_POLL_CONTROLLER .ndo_netpoll_setup = dsa_slave_netpoll_setup, .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup,