From patchwork Sat Apr 10 13:34:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12196467 X-Patchwork-Delegate: kuba@kernel.org 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=ham 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 EA704C43460 for ; Sun, 11 Apr 2021 15:03:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0A1A610C7 for ; Sun, 11 Apr 2021 15:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236191AbhDKPEN (ORCPT ); Sun, 11 Apr 2021 11:04:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236182AbhDKPEM (ORCPT ); Sun, 11 Apr 2021 11:04:12 -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 8B6EEC061574; Sun, 11 Apr 2021 08:03:55 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id sd23so7412538ejb.12; Sun, 11 Apr 2021 08:03:55 -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=gpkgEVO/zDb4BQWWCSfcVeMDtwsSzKiUo/BR0+dqhGQ=; b=LB0kznnhRE4HdMxic0cno6S/pXZ9A2m6veo9ugsQYOn1RhXtQJ4Xt7Kceb4J6kFZDn 8GHjlbjK2gCmm/ovmFlasvO4G5HAdtcbdWUKT/iHPKMeXbd6Tq265I54D76/+UW1P/13 fIU2oIu50xNJdLkWB5u1fUTpuoOuJAMqew6th6PsJRBxRZxaGet7JWI5Iov65Bf/h4TU pOcS+kogcKs/4KUzbvHNNFCypqCTomzV0jKG/ZUVT+JBr3/oy7wRMFSojDqARGBePgAZ 1HCRagX2zPQUCggV/mhFs6L0jr/nvv8cV/DpAdzYQDlVoASsSVqPCeUMOURV9GYXGy47 Nq3w== 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=gpkgEVO/zDb4BQWWCSfcVeMDtwsSzKiUo/BR0+dqhGQ=; b=GgkkLJRnKxAeBPj1+t8bMiKLEoFb0IhaFFirgaLZHZ8BSWnzsT/3AUITc7QKzs0BKW jxxwvX6gpfjHDE/9xrIv5Sz2bRV/gjzdNyi4tIV72p3BFZr//72JOniveMES3cQlvp9D Z76BF1ufzXhENUchn+7jisinu5BTELVGU+NCHUFuasAhbPHVfW6SBliQypMhal0pjyUL vTrcbyuTGljUtwD+fMMrwMuOmU/J99iQN8N79CLudSuociJtRXddU0nIFepkEjFYFBwR TFq6T2HDqNM9cOAso5aAstw0ldsov54XL5VUVVsILiULisNpd2a89Ml+YgsqwANDmcxD H7jw== X-Gm-Message-State: AOAM53179Mx8HmoAm2lrCilH+cplx/Gp3X34a5oxrEOHjWPiUiVJcVGZ hURrZbbGn7xLvAnTnPocHdsKNjhbkF8HvA== X-Google-Smtp-Source: ABdhPJy+JvQ0166o8WqSp2IgLWfPP8SzMy2ibsTSzlxr+Q3Xdsj0eDJxPO+h0YbbYq7i3gOGeTfBxg== X-Received: by 2002:a17:906:5855:: with SMTP id h21mr23953848ejs.522.1618153433944; Sun, 11 Apr 2021 08:03:53 -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.03.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Apr 2021 08:03:53 -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==?= , zhang kai , Roopa Prabhu , Di Zhu , Nikolay Aleksandrov , Francis Laniel , linux-kernel@vger.kernel.org Subject: [PATCH RFC net-next 1/3] net: dsa: allow for multiple CPU ports Date: Sat, 10 Apr 2021 15:34:47 +0200 Message-Id: <20210410133454.4768-2-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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Allow for multiple CPU ports in a DSA switch tree. By default the first CPU port is assigned mimic the original assignement logic. A DSA driver can define a function to declare a preferred CPU port based on the provided port. If the function doesn't have a preferred port the CPU port is assigned using a round-robin way starting from the last assigned CPU port. Examples: There are two CPU port but no port_get_preferred_cpu is provided: - The old logic is used. Every port is assigned to the first cpu port. There are two CPU port but the port_get_preferred_cpu return -1: - The port is assigned using a round-robin way since no preference is provided. There are two CPU port and the port_get_preferred_cpu define only one port and the rest with -1: (wan port with CPU1 and the rest no preference) lan1 <-> eth0 lan2 <-> eth1 lan3 <-> eth0 lan4 <-> eth1 wan <-> eth1 There are two CPU port and the port_get_preferred assign a preference for every port: (wan port with CPU1 everything else CPU0) lan1 <-> eth0 lan2 <-> eth0 lan3 <-> eth0 lan4 <-> eth0 wan <-> eth1 Signed-off-by: Marek Behún Signed-off-by: Ansuel Smith --- include/net/dsa.h | 7 +++++ net/dsa/dsa2.c | 66 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index d71b1acd9c3e..3d3e936bda4c 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -523,6 +523,13 @@ struct dsa_switch_ops { void (*teardown)(struct dsa_switch *ds); u32 (*get_phy_flags)(struct dsa_switch *ds, int port); + /* + * Get preferred CPU port for the provided port. + * Return -1 if there isn't a preferred CPU port, a round-robin logic + * is used to chose the CPU port to link to the provided port. + */ + int (*port_get_preferred_cpu)(struct dsa_switch *ds, int port); + /* * Access to the switch's PHY registers. */ diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index d142eb2b288b..d3b92499f006 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -315,10 +315,17 @@ static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst) return complete; } -static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst) +static struct dsa_port *dsa_tree_find_next_cpu_port(struct dsa_switch_tree *dst, + struct dsa_port *cpu_dp) { - struct dsa_port *dp; + struct dsa_port *dp = cpu_dp; + + if (dp) + list_for_each_entry_from(dp, &dst->ports, list) + if (dsa_port_is_cpu(dp)) + return dp; + /* If another CPU port can't be found, try from the start */ list_for_each_entry(dp, &dst->ports, list) if (dsa_port_is_cpu(dp)) return dp; @@ -326,25 +333,40 @@ static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst) return NULL; } -static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst) +static int dsa_tree_setup_default_cpus(struct dsa_switch_tree *dst) { - struct dsa_port *cpu_dp, *dp; + struct dsa_port *dp, *cpu_dp = NULL, *first_cpu_dp; + int cpu_port; - cpu_dp = dsa_tree_find_first_cpu(dst); - if (!cpu_dp) { + first_cpu_dp = dsa_tree_find_next_cpu_port(dst, NULL); + if (!first_cpu_dp) { pr_err("DSA: tree %d has no CPU port\n", dst->index); return -EINVAL; } - /* Assign the default CPU port to all ports of the fabric */ list_for_each_entry(dp, &dst->ports, list) - if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp)) - dp->cpu_dp = cpu_dp; + if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp)) { + /* Check if the driver advice a CPU port for the current port */ + if (dp->ds->ops->port_get_preferred_cpu) { + cpu_port = dp->ds->ops->port_get_preferred_cpu(dp->ds, dp->index); + + /* If the driver doesn't have a preferred port, + * assing in round-robin way. + */ + if (cpu_port < 0) + cpu_dp = dsa_tree_find_next_cpu_port(dst, cpu_dp); + else + cpu_dp = dsa_to_port(dp->ds, cpu_port); + } + + /* If a cpu port is not chosen, assign the first one by default */ + dp->cpu_dp = cpu_dp ? cpu_dp : first_cpu_dp; + } return 0; } -static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst) +static void dsa_tree_teardown_default_cpus(struct dsa_switch_tree *dst) { struct dsa_port *dp; @@ -822,7 +844,7 @@ static void dsa_tree_teardown_switches(struct dsa_switch_tree *dst) dsa_switch_teardown(dp->ds); } -static int dsa_tree_setup_master(struct dsa_switch_tree *dst) +static int dsa_tree_setup_masters(struct dsa_switch_tree *dst) { struct dsa_port *dp; int err; @@ -831,14 +853,20 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst) if (dsa_port_is_cpu(dp)) { err = dsa_master_setup(dp->master, dp); if (err) - return err; + goto teardown; } } return 0; +teardown: + list_for_each_entry_from_reverse(dp, &dst->ports, list) + if (dsa_port_is_cpu(dp)) + dsa_master_teardown(dp->master); + + return err; } -static void dsa_tree_teardown_master(struct dsa_switch_tree *dst) +static void dsa_tree_teardown_masters(struct dsa_switch_tree *dst) { struct dsa_port *dp; @@ -888,7 +916,7 @@ static int dsa_tree_setup(struct dsa_switch_tree *dst) if (!complete) return 0; - err = dsa_tree_setup_default_cpu(dst); + err = dsa_tree_setup_default_cpus(dst); if (err) return err; @@ -896,7 +924,7 @@ static int dsa_tree_setup(struct dsa_switch_tree *dst) if (err) goto teardown_default_cpu; - err = dsa_tree_setup_master(dst); + err = dsa_tree_setup_masters(dst); if (err) goto teardown_switches; @@ -911,11 +939,11 @@ static int dsa_tree_setup(struct dsa_switch_tree *dst) return 0; teardown_master: - dsa_tree_teardown_master(dst); + dsa_tree_teardown_masters(dst); teardown_switches: dsa_tree_teardown_switches(dst); teardown_default_cpu: - dsa_tree_teardown_default_cpu(dst); + dsa_tree_teardown_default_cpus(dst); return err; } @@ -929,11 +957,11 @@ static void dsa_tree_teardown(struct dsa_switch_tree *dst) dsa_tree_teardown_lags(dst); - dsa_tree_teardown_master(dst); + dsa_tree_teardown_masters(dst); dsa_tree_teardown_switches(dst); - dsa_tree_teardown_default_cpu(dst); + dsa_tree_teardown_default_cpus(dst); list_for_each_entry_safe(dl, next, &dst->rtable, list) { list_del(&dl->list); From patchwork Sat Apr 10 13:34:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12196469 X-Patchwork-Delegate: kuba@kernel.org 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=ham 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 2AA58C433ED for ; Sun, 11 Apr 2021 15:04:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 044A6610A6 for ; Sun, 11 Apr 2021 15:04:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236236AbhDKPET (ORCPT ); Sun, 11 Apr 2021 11:04:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236182AbhDKPET (ORCPT ); Sun, 11 Apr 2021 11:04:19 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8668AC061574; Sun, 11 Apr 2021 08:04:02 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id h10so11961221edt.13; Sun, 11 Apr 2021 08:04:02 -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=lgxZt4qmUinPpQwAqhqlCDZULXlHFnKBwRrbCmMUAGA=; b=Kox88v6eK8fD7zmIONpE+adu5p0RZIXQ/Xce7UP+XLsgRdBcVuPCWHTcvBvUXIH6U4 ljvL4f6vQvR/VWfqWY0b8H0PWos5KopMSgVhC5s3N9qtz0Nja0UetGPJYAFecXYgcWqS iNR+izJoY7TfkNnnqd7EMairnUi2S+LVIlPZZ9ZSOxDUaL88fvUsbclcuc6CRYwfSM4Z rlXw9sbV/atoPiYU5jFdLPBbf1msdykvvqMkJMWRNMi1ffbb5dF/tBOSbB5x82n2HfRJ zipQgB9QVT99+k7klOtBLxsqk0YIXkxbq0HWLIDKCg4efr6Luk+vNLkjcXQw2/sVRXRm MqOg== 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=lgxZt4qmUinPpQwAqhqlCDZULXlHFnKBwRrbCmMUAGA=; b=DNTBkPIspLQOXLpKZPwPsln2B1Zh8+1SiCWsnTHW/RgmUc1If+upB0ABwPOIzdc9J8 US6iomvXPxBb3VG4gUWN4h8OU4SNaA9jzAlLx4OupkXRQqXsAZQXBkkkCYpLrmfYzR/r qtM3kpLI33foN2ZBOsxJNzFyUddH5X4V/nbYUPQB8r5ELI80S+Njaez41W7ohWVsTGb7 YPtWAKw7QNiagszpBpLCJi+v87zK2vyrbHamzs00ZYPaeIvLJRoHn3SRWbGnSb/X39cb QdKAwrBu5sIzVk2HofGYqcPDmQ9kgyOFgPocJxenSjqkL22X+UvQRh/aCHXc8Wfx23CC qQGQ== X-Gm-Message-State: AOAM5328AiADS9KhgrdpnohE79ub4Ll4+NBOZ9X0p22jsoOjLjbbNhFp XWZS5B2prQ5K/s4Vf8/jX+c2Px1VNSRpaA== X-Google-Smtp-Source: ABdhPJzpOK3bXAu7N4W0TVcg/QZR71efp6cbARnC6KWGEji++LH34vGZyV3Wdfpkdurxh4hYlI4oZA== X-Received: by 2002:a05:6402:350f:: with SMTP id b15mr25464285edd.6.1618153440843; Sun, 11 Apr 2021 08:04:00 -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.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Apr 2021 08:04:00 -0700 (PDT) From: Ansuel Smith To: netdev@vger.kernel.org Cc: =?utf-8?q?Marek_Beh=C3=BAn?= , "David S. Miller" , Jakub Kicinski , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eric Dumazet , Wei Wang , Cong Wang , Taehee Yoo , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Nikolay Aleksandrov , Roopa Prabhu , Di Zhu , Francis Laniel , linux-kernel@vger.kernel.org Subject: [PATCH RFC net-next 2/3] net: add ndo for setting the iflink property Date: Sat, 10 Apr 2021 15:34:48 +0200 Message-Id: <20210410133454.4768-3-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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Marek Behún In DSA the iflink value is used to report to which CPU port a given switch port is connected to. Since we want to support multi-CPU DSA, we want the user to be able to change this value. Add ndo_set_iflink method into the ndo strucutre to be a pair to ndo_get_iflink. Also create dev_set_iflink and call this from the netlink code, so that userspace can change the iflink value. Signed-off-by: Marek Behún --- include/linux/netdevice.h | 5 +++++ net/core/dev.c | 15 +++++++++++++++ net/core/rtnetlink.c | 7 +++++++ 3 files changed, 27 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 87a5d186faff..76054182c288 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1225,6 +1225,8 @@ struct netdev_net_notifier { * TX queue. * int (*ndo_get_iflink)(const struct net_device *dev); * Called to get the iflink value of this device. + * int (*ndo_set_iflink)(struct net_device *dev, int iflink); + * Called to set the iflink value of this device. * void (*ndo_change_proto_down)(struct net_device *dev, * bool proto_down); * This function is used to pass protocol port error state information @@ -1456,6 +1458,8 @@ struct net_device_ops { int queue_index, u32 maxrate); int (*ndo_get_iflink)(const struct net_device *dev); + int (*ndo_set_iflink)(struct net_device *dev, + int iflink); int (*ndo_change_proto_down)(struct net_device *dev, bool proto_down); int (*ndo_fill_metadata_dst)(struct net_device *dev, @@ -2845,6 +2849,7 @@ void dev_add_offload(struct packet_offload *po); void dev_remove_offload(struct packet_offload *po); int dev_get_iflink(const struct net_device *dev); +int dev_set_iflink(struct net_device *dev, int iflink); int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb); struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags, unsigned short mask); diff --git a/net/core/dev.c b/net/core/dev.c index 0f72ff5d34ba..9e5ddcf6d401 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -822,6 +822,21 @@ int dev_get_iflink(const struct net_device *dev) } EXPORT_SYMBOL(dev_get_iflink); +/** + * dev_set_iflink - set 'iflink' value of an interface + * @dev: target interface + * @iflink: new value + * + * Change the interface to which this interface is linked to. + */ +int dev_set_iflink(struct net_device *dev, int iflink) +{ + if (dev->netdev_ops && dev->netdev_ops->ndo_set_iflink) + return dev->netdev_ops->ndo_set_iflink(dev, iflink); + + return -EOPNOTSUPP; +} + /** * dev_fill_metadata_dst - Retrieve tunnel egress information. * @dev: targeted interface diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 1bdcb33fb561..629b7685f942 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2718,6 +2718,13 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_MODIFIED; } + if (tb[IFLA_LINK]) { + err = dev_set_iflink(dev, nla_get_u32(tb[IFLA_LINK])); + if (err) + goto errout; + status |= DO_SETLINK_MODIFIED; + } + if (tb[IFLA_CARRIER]) { err = dev_change_carrier(dev, nla_get_u8(tb[IFLA_CARRIER])); if (err) 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: 12196471 X-Patchwork-Delegate: kuba@kernel.org 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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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,