From patchwork Sat Jan 16 00:59:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 365434 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=-15.7 required=3.0 tests=BAYES_00,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 01AAEC433DB for ; Sat, 16 Jan 2021 01:01:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB28223A34 for ; Sat, 16 Jan 2021 01:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728302AbhAPBBR (ORCPT ); Fri, 15 Jan 2021 20:01:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbhAPBBQ (ORCPT ); Fri, 15 Jan 2021 20:01:16 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD0FBC061793 for ; Fri, 15 Jan 2021 17:00:35 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id ga15so15864508ejb.4 for ; Fri, 15 Jan 2021 17:00:35 -0800 (PST) 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=VDJdCaP9sF8SGzmcmkXisXBOlBt0JGJJnYJZHRk+qDQ=; b=sTCU/x6Vibr0eMpUT+6XD6hRyGxcYlD+nPCRGMuzkwa1VOh9q1zJpcH2bWZ53BlTPc mwz+VxbRKMFh5NJJ4ptj95cYFztdI4ZY+ra290TS0r87G7tTDKOUZWXpzDlBFhUWkpC6 KRZPF6plQdhU/lgt9YjdAQ3/pIeDB43sRsd2SXpOyJE+D4RYaJBGP0+YM45cEcQ1ThfZ RQ+SJd+HrzC27Bl+bWHStaw50ICtv18YA2eHBAlyltlSQg72ciXfPUaHOENlrJwgoekq GwJqX72nqRkEdqsF1+M3E1cdrVSXq2tatVpJx9KFu6EPf5cZLMmRJVpYUTvEfZJV/bSg qpYA== 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=VDJdCaP9sF8SGzmcmkXisXBOlBt0JGJJnYJZHRk+qDQ=; b=HEl8+WbuapV0/DmZsqC2jwVn1ghD3/X0sX9PTiYdwEbCAS3VLDqYZqwQOWb3eqFc7Z 7ghvlD/iErEHrW9py1mQkTOpFzaNjEfab7ZObQUILyx5+41z45vlDMKzTTNpRLTv4nNp kD7DC5H9t3/ncZl7CTF4D1JnOh8bgeBbgPecnIvgrEwNq2vJvkDY5NOl9lGhUOgLXb1R Qo1TwT10grHFZxUjRvMfTqbpMnYV3LPvHkJu+ddMlqaMmIraQrDclzIlVa0LjBkhT1gf u9ZW5k6xcfD3tP5hrQPSzhgqcYo6yVwxonxjD0euhWjwGci+PsY12epqaIAoQZzPv/k3 i0eA== X-Gm-Message-State: AOAM530yb85L6cHxHf4Sp/9SvF7XZDpO0hZVTPUsufnXLcxMWNcCMaF9 uZ0hqZ0lDJGzwmSINp6nexo= X-Google-Smtp-Source: ABdhPJw5vkgr5RazOUUirJGU+ucLiBQR2ZvZKUTJXDw4iwcUV5LZGzA7rGR/oYjcv7TU1apq36J8DQ== X-Received: by 2002:a17:906:6a92:: with SMTP id p18mr10231103ejr.308.1610758834555; Fri, 15 Jan 2021 17:00:34 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:34 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 01/14] net: mscc: ocelot: allow offloading of bridge on top of LAG Date: Sat, 16 Jan 2021 02:59:30 +0200 Message-Id: <20210116005943.219479-2-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Commit 7afb3e575e5a ("net: mscc: ocelot: don't handle netdev events for other netdevs") was too aggressive, and it made ocelot_netdevice_event react only to network interface events emitted for the ocelot switch ports. In fact, only the PRECHANGEUPPER should have had that check. When we ignore all events that are not for us, we miss the fact that the upper of the LAG changes, and the bonding interface gets enslaved to a bridge. This is an operation we could offload under certain conditions. Signed-off-by: Vladimir Oltean Reviewed-by: Alexandre Belloni --- Changes in v2: None. drivers/net/ethernet/mscc/ocelot_net.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index a520fd485912..467170363ab2 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -1153,10 +1153,8 @@ static int ocelot_netdevice_event(struct notifier_block *unused, struct net_device *dev = netdev_notifier_info_to_dev(ptr); int ret = 0; - if (!ocelot_netdevice_dev_check(dev)) - return 0; - if (event == NETDEV_PRECHANGEUPPER && + ocelot_netdevice_dev_check(dev) && netif_is_lag_master(info->upper_dev)) { struct netdev_lag_upper_info *lag_upper_info = info->upper_info; struct netlink_ext_ack *extack; From patchwork Sat Jan 16 00:59:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 365433 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=-15.7 required=3.0 tests=BAYES_00,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 14114C433E6 for ; Sat, 16 Jan 2021 01:01:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E06DF23A3C for ; Sat, 16 Jan 2021 01:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728446AbhAPBBS (ORCPT ); Fri, 15 Jan 2021 20:01:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbhAPBBR (ORCPT ); Fri, 15 Jan 2021 20:01:17 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A269C061794 for ; Fri, 15 Jan 2021 17:00:37 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id by1so9439238ejc.0 for ; Fri, 15 Jan 2021 17:00:36 -0800 (PST) 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=zWY1y/upwUg3KwqCCaa8Z32+CPv07G2C/0JemH6mgoM=; b=iJEO+2PBD+GfL9kSOdFsYfOe4QFeA58aC6yIcwWFG+FKplluiXi8uxDBblh7HQsSWx IOPKNGiUtiK6QV1Fm75C4p2XSkinHK9ct4+e5+h//ntWNcP/2kMmsPrCN/gKQ1g1rneg Ay2xIESCfDvVTILz50yUHVc/i0h0lRStfc4H8yRD7KNPKXuuRvPSbMmxDdju3dwMlmVu 6RIfaesyxe3PsLZVFbEPb3MjeaKY9jVi//hyCk6gr03UyKIR522g0cF/RH++2esqUnf2 yFRsZe5nz1C3YhnPP6pwogIHEhB0QkdCnt7NL1DQSIOh21y8HfhMZJVuHRPW3m1t1/hx 1sug== 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=zWY1y/upwUg3KwqCCaa8Z32+CPv07G2C/0JemH6mgoM=; b=J7DGhiY/MC5VlApFoQZ2E1uJSZoyy9o808oVwzyE0bTf9ESmbqKqy/3oOUD7nxteUx VA54RD9ahKEFyxDBFFn8B0JuUH4uRtWqThDrhJC75uohVwQB6ZA/d2TdI8DnL+McM2ve aXiB1kyzNSFYSF0EQO8ecAtf497hLgBhGTaUwjiGIyloqUY5lxdIE9yNwgo0HLQQGsFc hWTKIpdb5GQB+sX+LnMOsU4hSYTsCg07g4tUTm2Vv3UBqPd+BgLNBexUnIQXlOiIJZBo MCB6SbGDbErhWlrVXUjC8JmprmtzU3pOoQgf7NYzXmg8glX1EVRbOlOPd7x4zSGJjpvf Qfqw== X-Gm-Message-State: AOAM532VfmDLyimDq5+HkeRnqeOcZx4qlrHY2N8c0n+ICg1/I5OZiCS4 AZgK+cxQ353hqUoGMMQ8zXo= X-Google-Smtp-Source: ABdhPJxLNg1rAuN4pcNE3O5GjplzE2LXO800MJFIi/mxqQeFNCVwj5rIDwjoQUUP6kcJ/eUvq8CZ/w== X-Received: by 2002:a17:906:7118:: with SMTP id x24mr10739722ejj.333.1610758835784; Fri, 15 Jan 2021 17:00:35 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:35 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 02/14] net: mscc: ocelot: rename ocelot_netdevice_port_event to ocelot_netdevice_changeupper Date: Sat, 16 Jan 2021 02:59:31 +0200 Message-Id: <20210116005943.219479-3-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean ocelot_netdevice_port_event treats a single event, NETDEV_CHANGEUPPER. So we can remove the check for the type of event, and rename the function to be more suggestive, since there already is a function with a very similar name of ocelot_netdevice_event. Signed-off-by: Vladimir Oltean --- Changes in v2: Fixed build by removing the "event" argument of ocelot_netdevice_changeupper. drivers/net/ethernet/mscc/ocelot_net.c | 59 ++++++++++++-------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index 467170363ab2..f15f38f45249 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -1109,9 +1109,8 @@ static int ocelot_port_obj_del(struct net_device *dev, return ret; } -static int ocelot_netdevice_port_event(struct net_device *dev, - unsigned long event, - struct netdev_notifier_changeupper_info *info) +static int ocelot_netdevice_changeupper(struct net_device *dev, + struct netdev_notifier_changeupper_info *info) { struct ocelot_port_private *priv = netdev_priv(dev); struct ocelot_port *ocelot_port = &priv->port; @@ -1119,28 +1118,22 @@ static int ocelot_netdevice_port_event(struct net_device *dev, int port = priv->chip_port; int err = 0; - switch (event) { - case NETDEV_CHANGEUPPER: - if (netif_is_bridge_master(info->upper_dev)) { - if (info->linking) { - err = ocelot_port_bridge_join(ocelot, port, - info->upper_dev); - } else { - err = ocelot_port_bridge_leave(ocelot, port, - info->upper_dev); - } - } - if (netif_is_lag_master(info->upper_dev)) { - if (info->linking) - err = ocelot_port_lag_join(ocelot, port, - info->upper_dev); - else - ocelot_port_lag_leave(ocelot, port, + if (netif_is_bridge_master(info->upper_dev)) { + if (info->linking) { + err = ocelot_port_bridge_join(ocelot, port, info->upper_dev); + } else { + err = ocelot_port_bridge_leave(ocelot, port, + info->upper_dev); } - break; - default: - break; + } + if (netif_is_lag_master(info->upper_dev)) { + if (info->linking) + err = ocelot_port_lag_join(ocelot, port, + info->upper_dev); + else + ocelot_port_lag_leave(ocelot, port, + info->upper_dev); } return err; @@ -1169,17 +1162,19 @@ static int ocelot_netdevice_event(struct notifier_block *unused, } } - if (netif_is_lag_master(dev)) { - struct net_device *slave; - struct list_head *iter; + if (event == NETDEV_CHANGEUPPER) { + if (netif_is_lag_master(dev)) { + struct net_device *slave; + struct list_head *iter; - netdev_for_each_lower_dev(dev, slave, iter) { - ret = ocelot_netdevice_port_event(slave, event, info); - if (ret) - goto notify; + netdev_for_each_lower_dev(dev, slave, iter) { + ret = ocelot_netdevice_changeupper(slave, info); + if (ret) + goto notify; + } + } else { + ret = ocelot_netdevice_changeupper(dev, info); } - } else { - ret = ocelot_netdevice_port_event(dev, event, info); } notify: From patchwork Sat Jan 16 00:59:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 364358 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=-15.8 required=3.0 tests=BAYES_00,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, 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 275ADC43381 for ; Sat, 16 Jan 2021 01:01:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0420F22BE8 for ; Sat, 16 Jan 2021 01:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728537AbhAPBBU (ORCPT ); Fri, 15 Jan 2021 20:01:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbhAPBBS (ORCPT ); Fri, 15 Jan 2021 20:01:18 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 745A5C061795 for ; Fri, 15 Jan 2021 17:00:38 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id l9so10107916ejx.3 for ; Fri, 15 Jan 2021 17:00:38 -0800 (PST) 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=yt4MFZFXIJYwPOPeihpYqLUWKvpxa3mc0RtRQNXcEOE=; b=GygOi8ZtJZLg1CtenA7yKAqcrCFfqDae8lYh+VoTPjTzBBkycWy+ZxtwsaHVfCWOf1 sxrgCUpA6AjeTA/f6QLc5NbCpJQQZNLr81she5cW9cSUX9u9O1Ps6JPLzzadntHQ7cdp g5vCGoR43If1hzrrAtdjDhFRVgFkYePcaSwHucS9kh8OPyVAoWKgB88foCxXKVGvdzZC OebxVhzKj40OMAU7drM721lXEDMOs91RYcgb1SDJ5OIj5bHEGyoFmCs6IPFer7RUn/5F Ua9QTf1yukajIo4c7Vbsi0H6BdmJ0V8nwudY1yBXcNszCus9fobZH9T6igyasmZtQGns 8r/Q== 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=yt4MFZFXIJYwPOPeihpYqLUWKvpxa3mc0RtRQNXcEOE=; b=lyTY7VA4GNolZsQN2a3JL8WgJbA1m8Jn3JS1OuKX0P1AImtlXofBncT9FyQYYgquMu JZrlKji0vffx/jTf4OylykvehkaYbVrH6stkRG6v4ITTq5qBSnrJP4tz9PqXWjZ2rqYm 9hzLu/749Vqkyn+4IH14QjElr11qFQ/fN4BKMCMgQUTPx/4fty7R2l4oZAAlkyQY+LM3 JnV++gzwMd0MktY8mlhJIlE9pfSmsXmvn29OdSs9tvnc5CMqFWwSdnkJP5ZfWx57T2ru 4IbkfJCr647u0jKe6upc+FNnZ18eCE7WVu7Xh4sL7B0+puRliNmh2PUsiSYyBczIFrrb gMQw== X-Gm-Message-State: AOAM530U+jstODA5QoRKDNEQ3zKfEQwWI2nxXvnhiFlRKOlSRarfegr/ 3gkYhW5bqpzDjmcPlIot7Gc= X-Google-Smtp-Source: ABdhPJxPOqswJ7PYfs9wPBEHLzb3LiUSNQaMPzEGoaU02uOCwq4jc0qiFKlBabHYqK9T4NHuf1QeqA== X-Received: by 2002:a17:907:16a2:: with SMTP id hc34mr10817539ejc.9.1610758837090; Fri, 15 Jan 2021 17:00:37 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:36 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 03/14] net: mscc: ocelot: use a switch-case statement in ocelot_netdevice_event Date: Sat, 16 Jan 2021 02:59:32 +0200 Message-Id: <20210116005943.219479-4-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Make ocelot's net device event handler more streamlined by structuring it in a similar way with others. The inspiration here was dsa_slave_netdevice_event. Signed-off-by: Vladimir Oltean Reviewed-by: Alexandre Belloni --- Changes in v2: Addressed Alex's feedback: > This changes the return value in case of error, I'm not sure how > important this is. by keeping the return code of notifier_from_errno(-EINVAL) drivers/net/ethernet/mscc/ocelot_net.c | 68 +++++++++++++++++--------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index f15f38f45249..b80a5bb95163 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -1136,49 +1136,71 @@ static int ocelot_netdevice_changeupper(struct net_device *dev, info->upper_dev); } - return err; + return notifier_from_errno(err); +} + +static int +ocelot_netdevice_lag_changeupper(struct net_device *dev, + struct netdev_notifier_changeupper_info *info) +{ + struct net_device *lower; + struct list_head *iter; + int err = NOTIFY_DONE; + + netdev_for_each_lower_dev(dev, lower, iter) { + err = ocelot_netdevice_changeupper(lower, info); + if (err) + return notifier_from_errno(err); + } + + return NOTIFY_DONE; } static int ocelot_netdevice_event(struct notifier_block *unused, unsigned long event, void *ptr) { - struct netdev_notifier_changeupper_info *info = ptr; struct net_device *dev = netdev_notifier_info_to_dev(ptr); - int ret = 0; - if (event == NETDEV_PRECHANGEUPPER && - ocelot_netdevice_dev_check(dev) && - netif_is_lag_master(info->upper_dev)) { - struct netdev_lag_upper_info *lag_upper_info = info->upper_info; + switch (event) { + case NETDEV_PRECHANGEUPPER: { + struct netdev_notifier_changeupper_info *info = ptr; + struct netdev_lag_upper_info *lag_upper_info; struct netlink_ext_ack *extack; + if (!ocelot_netdevice_dev_check(dev)) + break; + + if (!netif_is_lag_master(info->upper_dev)) + break; + + lag_upper_info = info->upper_info; + if (lag_upper_info && lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH) { extack = netdev_notifier_info_to_extack(&info->info); NL_SET_ERR_MSG_MOD(extack, "LAG device using unsupported Tx type"); - ret = -EINVAL; - goto notify; + return notifier_from_errno(-EINVAL); } + + break; } + case NETDEV_CHANGEUPPER: { + struct netdev_notifier_changeupper_info *info = ptr; - if (event == NETDEV_CHANGEUPPER) { - if (netif_is_lag_master(dev)) { - struct net_device *slave; - struct list_head *iter; + if (ocelot_netdevice_dev_check(dev)) + return ocelot_netdevice_changeupper(dev, info); - netdev_for_each_lower_dev(dev, slave, iter) { - ret = ocelot_netdevice_changeupper(slave, info); - if (ret) - goto notify; - } - } else { - ret = ocelot_netdevice_changeupper(dev, info); - } + if (netif_is_lag_master(dev)) + return ocelot_netdevice_lag_changeupper(dev, info); + + break; + } + default: + break; } -notify: - return notifier_from_errno(ret); + return NOTIFY_DONE; } struct notifier_block ocelot_netdevice_nb __read_mostly = { From patchwork Sat Jan 16 00:59:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 365432 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=-15.7 required=3.0 tests=BAYES_00,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 1B09EC433DB for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CEAB023A34 for ; Sat, 16 Jan 2021 01:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728553AbhAPBBv (ORCPT ); Fri, 15 Jan 2021 20:01:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726236AbhAPBBq (ORCPT ); Fri, 15 Jan 2021 20:01:46 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A94CAC061796 for ; Fri, 15 Jan 2021 17:00:39 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id q22so15848388eja.2 for ; Fri, 15 Jan 2021 17:00:39 -0800 (PST) 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=95JRoMYzZ1WZMoMU7A/chkV3G/NZyLsEv9E0hpd8Aa8=; b=IQDfwbH+DW9HDrvvqCx5XQBOUG1L4GHPdI0RLiqSTSsXZbzbhr0842pz3QkD4b7O+u wVax4UFXaaZhHY8v+4W5msppb7DayAQsWxZagXJ+wlYoNGxog8T4/nCLVSdmm9V8NneI k1yEe9QmhtcmSrDfVC8cHLneIkRCV37y6mmzqPeW3mWZzFV/opUQ4EVjXD2hnXCBeMCP kTmiOH7fZePbuzgx1Qc7tK2qIS34nqHtKJExGMXpsnF1lhvpvtqe63e85R8kcFtCHpoM t5UM0h1wzsurSM2/GCD9I7nE7/CnEjhpTwpTmDzjXGA5RmrZrocn3ssz6fwa2vb/MSeW 8wcw== 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=95JRoMYzZ1WZMoMU7A/chkV3G/NZyLsEv9E0hpd8Aa8=; b=MXij4ZElj4n78Z5mVFpaE4T9etO+H+HT9G2ABnthPZt6qs4pXRAX8h06jKK78rVeoV IZsIMaLT6cDxWBbqnAjxM97DadXI7KFTDsUvn+ZUrijKDMiwWQmq445WgH4QaT7VNXXA 7UQnGTtGyll/8r7RE8kB5T+oLMFFiMpXRWFkEkGpGuZt4J4mAw3bdglpJeQfhrU9FZd8 VVv2KaN8XmYQ0DoBy2fUPRw3TcmTj/76oi5MUrwRp4tEnJXxuhUkOxKrMsJ03vefnQfc 4LxH6NL7/gem/IKM3UAEkRig21kU61xbMMffvxD83tzt80ayBRAA0AEntr2olWQ0vQdR vgHg== X-Gm-Message-State: AOAM5331jSGco7RQMI8N3RGKLWCVlSCGJUpvV5KSSJ11r3929x+yS5lu HLMntPvjR9jq+7uqNDW9dy0= X-Google-Smtp-Source: ABdhPJyTFzUOVDjZk9G+uUlHdVzRrqXufVL7dU+G7xA+9pzaT05zfZVdvOSlMnnU32Yz19DoHCvb+A== X-Received: by 2002:a17:907:96a2:: with SMTP id hd34mr5801697ejc.494.1610758838384; Fri, 15 Jan 2021 17:00:38 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:37 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 04/14] net: mscc: ocelot: don't refuse bonding interfaces we can't offload Date: Sat, 16 Jan 2021 02:59:33 +0200 Message-Id: <20210116005943.219479-5-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Since switchdev/DSA exposes network interfaces that fulfill many of the same user space expectations that dedicated NICs do, it makes sense to not deny bonding interfaces with a bonding policy that we cannot offload, but instead allow the bonding driver to select the egress interface in software. Signed-off-by: Vladimir Oltean Reviewed-by: Alexandre Belloni --- Changes in v2: Adapted to the merged version of the DSA API for LAG offload (i.e. rejecting a bonding interface due to tx_type now done within the .port_lag_join callback, caller is supposed to handle -EOPNOTSUPP). drivers/net/ethernet/mscc/ocelot.c | 6 ++++- drivers/net/ethernet/mscc/ocelot.h | 3 ++- drivers/net/ethernet/mscc/ocelot_net.c | 36 +++++++------------------- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index a560d6be2a44..d3a92c46f610 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1251,12 +1251,16 @@ static void ocelot_setup_lag(struct ocelot *ocelot, int lag) } int ocelot_port_lag_join(struct ocelot *ocelot, int port, - struct net_device *bond) + struct net_device *bond, + struct netdev_lag_upper_info *info) { struct net_device *ndev; u32 bond_mask = 0; int lag, lp; + if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) + return -EOPNOTSUPP; + rcu_read_lock(); for_each_netdev_in_bond_rcu(bond, ndev) { struct ocelot_port_private *priv = netdev_priv(ndev); diff --git a/drivers/net/ethernet/mscc/ocelot.h b/drivers/net/ethernet/mscc/ocelot.h index e8621dbc14f7..b6c9ddcee554 100644 --- a/drivers/net/ethernet/mscc/ocelot.h +++ b/drivers/net/ethernet/mscc/ocelot.h @@ -110,7 +110,8 @@ int ocelot_mact_learn(struct ocelot *ocelot, int port, int ocelot_mact_forget(struct ocelot *ocelot, const unsigned char mac[ETH_ALEN], unsigned int vid); int ocelot_port_lag_join(struct ocelot *ocelot, int port, - struct net_device *bond); + struct net_device *bond, + struct netdev_lag_upper_info *info); void ocelot_port_lag_leave(struct ocelot *ocelot, int port, struct net_device *bond); struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port); diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index b80a5bb95163..f246f8fc535d 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -1128,12 +1128,19 @@ static int ocelot_netdevice_changeupper(struct net_device *dev, } } if (netif_is_lag_master(info->upper_dev)) { - if (info->linking) + if (info->linking) { err = ocelot_port_lag_join(ocelot, port, - info->upper_dev); - else + info->upper_dev, + info->upper_info); + if (err == -EOPNOTSUPP) { + NL_SET_ERR_MSG_MOD(info->info.extack, + "Offloading not supported"); + err = 0; + } + } else { ocelot_port_lag_leave(ocelot, port, info->upper_dev); + } } return notifier_from_errno(err); @@ -1162,29 +1169,6 @@ static int ocelot_netdevice_event(struct notifier_block *unused, struct net_device *dev = netdev_notifier_info_to_dev(ptr); switch (event) { - case NETDEV_PRECHANGEUPPER: { - struct netdev_notifier_changeupper_info *info = ptr; - struct netdev_lag_upper_info *lag_upper_info; - struct netlink_ext_ack *extack; - - if (!ocelot_netdevice_dev_check(dev)) - break; - - if (!netif_is_lag_master(info->upper_dev)) - break; - - lag_upper_info = info->upper_info; - - if (lag_upper_info && - lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH) { - extack = netdev_notifier_info_to_extack(&info->info); - NL_SET_ERR_MSG_MOD(extack, "LAG device using unsupported Tx type"); - - return notifier_from_errno(-EINVAL); - } - - break; - } case NETDEV_CHANGEUPPER: { struct netdev_notifier_changeupper_info *info = ptr; From patchwork Sat Jan 16 00:59:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 364357 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=-15.7 required=3.0 tests=BAYES_00,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 F2343C433E0 for ; Sat, 16 Jan 2021 01:02:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADB4422BE8 for ; Sat, 16 Jan 2021 01:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727080AbhAPBBt (ORCPT ); Fri, 15 Jan 2021 20:01:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726287AbhAPBBq (ORCPT ); Fri, 15 Jan 2021 20:01:46 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC691C061798 for ; Fri, 15 Jan 2021 17:00:40 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id u19so11544832edx.2 for ; Fri, 15 Jan 2021 17:00:40 -0800 (PST) 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=7XIru9YSoOQaS1swKibuoVI0XxqPGJLS/vhoFQlVy90=; b=koqnNFsLm3jQd2ZVwKu886UTvHEKqODcIi84dm3QUTBpvD9ZzmK7CtZ/S/Km/E3quK wAX0Kr9CCMwMD3Aa76KnYevdA5cn3Py9QSLHZ7FOaCXUuB9e0HhSJU2jtVqc3Sd8OfO7 eiAxBt9zIUCJx/J0/qqI2iX1Q0q/4JAnrcJnWdhjoH9ZNS8rfDLGdNrgWkM+5whHvIan 949esH6RbdRSd9dW2aJrVw+Df000DiMCFJ+P9o3ebBXqX9M6KxCQIol76VlVpvA64j5v ERHc1zJMdhstWmZH7VYX1mEnJbLZE9OP4mJ9nfSzTk69b6mJGz6FHHp8E9wf220yxZX3 Ws7A== 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=7XIru9YSoOQaS1swKibuoVI0XxqPGJLS/vhoFQlVy90=; b=od/HQpesNTH+CgEk2yUTaSKXU/mDvNhJR8J5CWrF2eiC8tlPjICNQyCFqM45PtpMJz dnkIpMJu6GKAX+s69T5hYitL3eqKtEMk8bIsHZMDKk67PiDEQGWSkDznE9QJPmqlWSvg 15gdg4Pj7A02xSIwl39mR2NQp2nbL0R9rdpGDt5GMbrXNj5R0+CwDtnNgovPpfltlWoz 39yi/ZdWUdfi+NkzSPE2yK6QGUunrB4dXHeMPFZmcHoQpRCWChYMX9G9bVKYjuZYUfGI pr42gETw7ncd1wErHA65fLrVQ3hW/cFDBq8RVTrX0Fq3PDBciSoiuOhFA6mqoHOAdzLO ikeQ== X-Gm-Message-State: AOAM532DtEtsygDQnQChZX7rFibAHHobbGXmgRWuX9w0v1il0eP36XXP ulToV8AWRsEdZL2QXhcWhDI= X-Google-Smtp-Source: ABdhPJyv28e6JcvffFNPKDe0M9E6DFHCKv1NbxAuzQ6DQfrjPCcCbNk0RpJdqK10He7cjaANEfG3ng== X-Received: by 2002:a05:6402:1ad1:: with SMTP id ba17mr11502112edb.51.1610758839611; Fri, 15 Jan 2021 17:00:39 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:39 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 05/14] net: mscc: ocelot: use ipv6 in the aggregation code Date: Sat, 16 Jan 2021 02:59:34 +0200 Message-Id: <20210116005943.219479-6-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean IPv6 header information is not currently part of the entropy source for the 4-bit aggregation code used for LAG offload, even though it could be. The hardware reference manual says about these fields: ANA::AGGR_CFG.AC_IP6_TCPUDP_PORT_ENA Use IPv6 TCP/UDP port when calculating aggregation code. Configure identically for all ports. Recommended value is 1. ANA::AGGR_CFG.AC_IP6_FLOW_LBL_ENA Use IPv6 flow label when calculating AC. Configure identically for all ports. Recommended value is 1. Integration with the xmit_hash_policy of the bonding interface is TBD. Signed-off-by: Vladimir Oltean Reviewed-by: Alexandre Belloni --- Changes in v2: None. drivers/net/ethernet/mscc/ocelot.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index d3a92c46f610..2b542f286739 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1548,7 +1548,10 @@ int ocelot_init(struct ocelot *ocelot) ocelot_write(ocelot, ANA_AGGR_CFG_AC_SMAC_ENA | ANA_AGGR_CFG_AC_DMAC_ENA | ANA_AGGR_CFG_AC_IP4_SIPDIP_ENA | - ANA_AGGR_CFG_AC_IP4_TCPUDP_ENA, ANA_AGGR_CFG); + ANA_AGGR_CFG_AC_IP4_TCPUDP_ENA | + ANA_AGGR_CFG_AC_IP6_FLOW_LBL_ENA | + ANA_AGGR_CFG_AC_IP6_TCPUDP_ENA, + ANA_AGGR_CFG); /* Set MAC age time to default value. The entry is aged after * 2*AGE_PERIOD From patchwork Sat Jan 16 00:59:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 364353 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=-15.7 required=3.0 tests=BAYES_00,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 5BFEDC433DB for ; Sat, 16 Jan 2021 01:02:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EBEA22BE8 for ; Sat, 16 Jan 2021 01:02:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728696AbhAPBB5 (ORCPT ); Fri, 15 Jan 2021 20:01:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726236AbhAPBBz (ORCPT ); Fri, 15 Jan 2021 20:01:55 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10EA7C061799 for ; Fri, 15 Jan 2021 17:00:42 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id d22so498636edy.1 for ; Fri, 15 Jan 2021 17:00:41 -0800 (PST) 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=vYPOvC8LD5eCXYawgiYS1T39o/4TAiOe81TLJkBUT5I=; b=XuW8tLy74tIFeHoYauzVm33WP5t9q/HEMmmcHE8A5kpI+EiF3yIehHJMJF56GdotpJ VplT3WQgUgvakkp2c7PxTQXTLlMyQmBOATr1lWmNiO+Z+DqhpASbzTax/gO6ZDa3xUES vjwocQ2gdiIk2xq7UhlBq6vYf8v0ULghGDo27GElgCB+uCjbBM6+J56hzooAun8aaZ0V nP/WicdtxBVm/x1bY6f8w/MzOuRAxKeNuio/TQks7dd+nwbTq+Dt8VDw8leOmxrDaXqO s1OwlOKT+wOwCbP0VnyLT2JRtIZ7i2uBy+eIo2WtGubAyn0Naqn0ptIX1dhG192Fl7n0 hd6Q== 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=vYPOvC8LD5eCXYawgiYS1T39o/4TAiOe81TLJkBUT5I=; b=pAHd67dpZL7Dfx+Soxv7neLQhSc+fc/qyRsPnJuiPvuMWhlEJ3I11Om8OFa+/4UL8x pXcwkQGjyd1smiiI9KfzgaU4WsS5Cj+vtQZPZaufNFAI6HLIckfUNr3uMbTmGeGIm3o0 mMhDHdOjB7t0k8ny3NMgSNJzIwsftYF/HAbiICTseYrQVHctRLGVNDKEWyfrCyUdRqCq f3yFj359h+qTRJ9lPjJ8fkJl5FP/31cG6ju3zE0Tb44+pQatlCUNIn+dGMXEZSSuUMZ1 fuUryz2Zsi+EpkJbisxSkQCdBDKFvvBh89qsEVupvce0E6TNS1SZwdCWh0/EYC0RhjO8 h4Cw== X-Gm-Message-State: AOAM532LW89DZ4P1h4ufc4RgNeAGS85dH8QwUQuvIeIub9rEQBF3wEkL 5togwvcOQCjcb4MBa9w4kMQ= X-Google-Smtp-Source: ABdhPJzJTtQ5rhGAKP5L1jJGLsYRro8LsmsTlabyOCrcNcHmn4JHz2k+5cH6tmnzO7+jTk6ImVp+uA== X-Received: by 2002:a05:6402:1748:: with SMTP id v8mr11969137edx.136.1610758840838; Fri, 15 Jan 2021 17:00:40 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:40 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 06/14] net: mscc: ocelot: set up the bonding mask in a way that avoids a net_device Date: Sat, 16 Jan 2021 02:59:35 +0200 Message-Id: <20210116005943.219479-7-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Since this code should be called from pure switchdev as well as from DSA, we must find a way to determine the bonding mask not by looking directly at the net_device lowers of the bonding interface, since those could have different private structures. We keep a pointer to the bonding upper interface, if present, in struct ocelot_port. Then the bonding mask becomes the bitwise OR of all ports that have the same bonding upper interface. This adds a duplication of functionality with the current "lags" array, but the duplication will be short-lived, since further patches will remove the latter completely. Signed-off-by: Vladimir Oltean Reviewed-by: Alexandre Belloni --- Changes in v2: Adapted to the merged version of the DSA API for LAG offload (i.e. rejecting a bonding interface due to tx_type now done within the .port_lag_join callback, caller is supposed to handle -EOPNOTSUPP). drivers/net/ethernet/mscc/ocelot.c | 29 ++++++++++++++++++++++------- include/soc/mscc/ocelot.h | 2 ++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 2b542f286739..e2744b921a97 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -876,6 +876,24 @@ int ocelot_get_ts_info(struct ocelot *ocelot, int port, } EXPORT_SYMBOL(ocelot_get_ts_info); +static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond) +{ + u32 bond_mask = 0; + int port; + + for (port = 0; port < ocelot->num_phys_ports; port++) { + struct ocelot_port *ocelot_port = ocelot->ports[port]; + + if (!ocelot_port) + continue; + + if (ocelot_port->bond == bond) + bond_mask |= BIT(port); + } + + return bond_mask; +} + void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state) { u32 port_cfg; @@ -1254,20 +1272,15 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, struct net_device *bond, struct netdev_lag_upper_info *info) { - struct net_device *ndev; u32 bond_mask = 0; int lag, lp; if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) return -EOPNOTSUPP; - rcu_read_lock(); - for_each_netdev_in_bond_rcu(bond, ndev) { - struct ocelot_port_private *priv = netdev_priv(ndev); + ocelot->ports[port]->bond = bond; - bond_mask |= BIT(priv->chip_port); - } - rcu_read_unlock(); + bond_mask = ocelot_get_bond_mask(ocelot, bond); lp = __ffs(bond_mask); @@ -1300,6 +1313,8 @@ void ocelot_port_lag_leave(struct ocelot *ocelot, int port, u32 port_cfg; int i; + ocelot->ports[port]->bond = NULL; + /* Remove port from any lag */ for (i = 0; i < ocelot->num_phys_ports; i++) ocelot->lags[i] &= ~BIT(port); diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index cdc33fa05660..d2c587f099c8 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -610,6 +610,8 @@ struct ocelot_port { phy_interface_t phy_mode; u8 *xmit_template; + + struct net_device *bond; }; struct ocelot { From patchwork Sat Jan 16 00:59:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 364355 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=-15.8 required=3.0 tests=BAYES_00,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, 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 39999C433E6 for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF37223A3C for ; Sat, 16 Jan 2021 01:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728773AbhAPBB6 (ORCPT ); Fri, 15 Jan 2021 20:01:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727798AbhAPBBz (ORCPT ); Fri, 15 Jan 2021 20:01:55 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 469FAC06179A for ; Fri, 15 Jan 2021 17:00:43 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id p22so11489594edu.11 for ; Fri, 15 Jan 2021 17:00:43 -0800 (PST) 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=n5BibzNtUVWtkQIdfb1fd0X382vN/3t8GEzoEkNaObM=; b=jeUL462tbWbqHVVxoNpbYrJKmeTaJc3rTQQp1sAt+YiVTKvExhVbM/f+LmK8mcQaqF SibUZzCNjJOUmx5ONxQWijySw3Jgn9EifFcmi0HkIAz5CAVL5IqfCYupm+V46L+x8S5Y oe3qiZulG438WEqw/pBY56lWK+E6ydeR87Rl2yVioCkPErVKjCuMOdRcSyD1b0bvOehz lUtZcGKP4sE3o+1JzckHjM4mPosfg5ZFq3ER7F0bcKbYdlHLOWa9RjlcOSKMReAKKDFH MeTDMUZFnj16H/KHUKB2Yvo52ve1lIF2lNIDlSVf0NKdgwx5+5cYoxa56XDY8NUZoMNT iqUA== 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=n5BibzNtUVWtkQIdfb1fd0X382vN/3t8GEzoEkNaObM=; b=SZI0WcbCVYiS3wd6wYdZgWnNMebqxyGUPYzxAeYtpKHewYOUsPk9/P6ZAAxqXaKdLq /PKyVM4gOa8VrZDnb7C8z3ItY8MnrXgd+zFJZkHzJvzRAUQR34r6iFbmSgw6n3AoK7d6 D/NyXmuecQrPi40gYb1Ci/wCNHkFbxsPjYzRzVVDEm1Fa9ysitNNv/Y/T5FD05cBTcUv O7kwurN/zm3AwjLkkVZ+Nl+Xb/clh1UCgenN0daSNnm1PBtIjS5s3sG1CpTeQEIIuwtb ZU8hv0xWXkO8pIHqDGLZyor96YYHPHDDOdSaXTabo1LVWoew25gGS0bVqn4Vyvn39bBJ dBpg== X-Gm-Message-State: AOAM533a2ef4YFcmCbdr87zcs86pBukDZOFtNl37nC3g447Mrzn8lM8H M3DENjSWpZUS+RvS6li2o5s= X-Google-Smtp-Source: ABdhPJzmSP5a1agOgZAfAOKuhXQ3wDuWvUaJ8Pn7vPxZhPUwWxijfoymMSUM/DH3PzBfRq+NVxgJIg== X-Received: by 2002:a50:b246:: with SMTP id o64mr11104151edd.132.1610758842032; Fri, 15 Jan 2021 17:00:42 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:41 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 07/14] net: mscc: ocelot: avoid unneeded "lp" variable in LAG join Date: Sat, 16 Jan 2021 02:59:36 +0200 Message-Id: <20210116005943.219479-8-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean The index of the LAG is equal to the logical port ID that all the physical port members have, which is further equal to the index of the first physical port that is a member of the LAG. The code gets a bit carried away with logic like this: if (a == b) c = a; else c = b; which can be simplified, of course, into: c = b; (with a being port, b being lp, c being lag) This further makes the "lp" variable redundant, since we can use "lag" everywhere where "lp" (logical port) was used. So instead of a "c = b" assignment, we can do a complete deletion of b. Only one comment here: if (bond_mask) { lp = __ffs(bond_mask); ocelot->lags[lp] = 0; } lp was clobbered before, because it was used as a temporary variable to hold the new smallest port ID from the bond. Now that we don't have "lp" any longer, we'll just avoid the temporary variable and zeroize the bonding mask directly. Signed-off-by: Vladimir Oltean Reviewed-by: Alexandre Belloni --- Changes in v2: None. drivers/net/ethernet/mscc/ocelot.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index e2744b921a97..ce52bf892f9b 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1273,7 +1273,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, struct netdev_lag_upper_info *info) { u32 bond_mask = 0; - int lag, lp; + int lag; if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) return -EOPNOTSUPP; @@ -1282,22 +1282,18 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, bond_mask = ocelot_get_bond_mask(ocelot, bond); - lp = __ffs(bond_mask); + lag = __ffs(bond_mask); /* If the new port is the lowest one, use it as the logical port from * now on */ - if (port == lp) { - lag = port; + if (port == lag) { ocelot->lags[port] = bond_mask; bond_mask &= ~BIT(port); - if (bond_mask) { - lp = __ffs(bond_mask); - ocelot->lags[lp] = 0; - } + if (bond_mask) + ocelot->lags[__ffs(bond_mask)] = 0; } else { - lag = lp; - ocelot->lags[lp] |= BIT(port); + ocelot->lags[lag] |= BIT(port); } ocelot_setup_lag(ocelot, lag); From patchwork Sat Jan 16 00:59:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 364352 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=-15.8 required=3.0 tests=BAYES_00,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, 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 A82BCC433E6 for ; Sat, 16 Jan 2021 01:02:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65C1222BE8 for ; Sat, 16 Jan 2021 01:02:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727257AbhAPBCO (ORCPT ); Fri, 15 Jan 2021 20:02:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728560AbhAPBB4 (ORCPT ); Fri, 15 Jan 2021 20:01:56 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C1A7C06179B for ; Fri, 15 Jan 2021 17:00:44 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id w1so15797689ejf.11 for ; Fri, 15 Jan 2021 17:00:44 -0800 (PST) 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=UX/lJ4lr146a+hMYkf2pbnGPcIK0sUkdje3PPIr+qcA=; b=cYb/EfEgO6ryrwcnyjyUFDaRc0L6r8PrkXgNxMQzQHhPqu/AgF94sjzG0sXIcP3KaF 04LQxA8wMpwulqKJ0zIZ3sdNQ+18rSqrFm3d+HsJyEw5SlJMoINZtYvseOoZ79WX+zdl wE3VthpEB7xtzY2ArDsCIhB+TvOp+y9HXKf/0/brFW9ut/3OZLliusUPVxZgnPCcu3U3 8FU64ytN5pZQnjpAP2W+ikQZCGmDtHhwOXKReMMRYOOvfLEushm5Ur44L9jkQeoGUi49 U0zefAHQSQgg5csdLZp8tL1zXkaE78m7mSSNpKMy6Zo5tuWicXnCuLJZdgGZtRuUfTHy 19ew== 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=UX/lJ4lr146a+hMYkf2pbnGPcIK0sUkdje3PPIr+qcA=; b=mv5DUZdqOYXqv74EB8Apf/DpwmAIj37DfSmdKi0AhHAyrhiqUSFypPU9moZG9p8yaP iI9wCjtEwDvro9oNO16Sdk78XkNLcv0IBCweIFoSjQ8MvsXrDTrBRyBq9/npOylT54Ya 4gfBsOoZnNfx1XW4qTZDeKpLV1ejHB+15GYJMuVBvEfn/tkQh6DWq/0+XhJc9/3F6b3H /rmjPnd7gIiRAEpqRaggzknxuNHOE0RXmxjxDxSRQ72SHtmgRzbyQGKYxAXouHieBBZS I42y9B6BBfYCdfg2XIJK7xFMbLhqB6UxEGWOHRfkLXaZgrMqBlLvqE35fF/MWVeHom4D TZYg== X-Gm-Message-State: AOAM531pYzwMXZ108sh/bhpf3DoeBzOuGGGlMnpjTuJK59BMlSlw4o4Q xtKXXA0mE418fNQ/jitzij0= X-Google-Smtp-Source: ABdhPJyY+p+f9ZB44P4HfoMepr8GlmFs8I4v5//xoK1hj4LvjYYL3k1fxaqj1qGLOBJeXfGYJB5cbg== X-Received: by 2002:a17:906:748:: with SMTP id z8mr6049077ejb.233.1610758843274; Fri, 15 Jan 2021 17:00:43 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:42 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 08/14] net: mscc: ocelot: use "lag" variable name in ocelot_bridge_stp_state_set Date: Sat, 16 Jan 2021 02:59:37 +0200 Message-Id: <20210116005943.219479-9-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean In anticipation of further simplification, make it more clear what we're iterating over. Signed-off-by: Vladimir Oltean Reviewed-by: Alexandre Belloni --- Changes in v2: None. drivers/net/ethernet/mscc/ocelot.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index ce52bf892f9b..915cf81f602a 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -897,7 +897,7 @@ static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond) void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state) { u32 port_cfg; - int p, i; + int p; if (!(BIT(port) & ocelot->bridge_mask)) return; @@ -921,14 +921,17 @@ void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state) ocelot_write_gix(ocelot, port_cfg, ANA_PORT_PORT_CFG, port); /* Apply FWD mask. The loop is needed to add/remove the current port as - * a source for the other ports. + * a source for the other ports. If the source port is in a bond, then + * all the other ports from that bond need to be removed from this + * source port's forwarding mask. */ for (p = 0; p < ocelot->num_phys_ports; p++) { if (ocelot->bridge_fwd_mask & BIT(p)) { unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(p); + int lag; - for (i = 0; i < ocelot->num_phys_ports; i++) { - unsigned long bond_mask = ocelot->lags[i]; + for (lag = 0; lag < ocelot->num_phys_ports; lag++) { + unsigned long bond_mask = ocelot->lags[lag]; if (!bond_mask) continue; From patchwork Sat Jan 16 00:59:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 365428 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=-15.8 required=3.0 tests=BAYES_00,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, 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 8DCA2C433E0 for ; Sat, 16 Jan 2021 01:02:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 417A223A34 for ; Sat, 16 Jan 2021 01:02:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729069AbhAPBCK (ORCPT ); Fri, 15 Jan 2021 20:02:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728604AbhAPBB4 (ORCPT ); Fri, 15 Jan 2021 20:01:56 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC425C06179C for ; Fri, 15 Jan 2021 17:00:45 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id w1so15797756ejf.11 for ; Fri, 15 Jan 2021 17:00:45 -0800 (PST) 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=38njsxJ3FWx1u0iWIDZPp+d4mrwHS6vkGES4CWjer7Q=; b=uzVLSUH18bF0rOl2XaB+/sPysgPXDwVNk/jpbvNAU0ST0tqgxUxHEJBgWX8cWFs57g Ig+OFuBWQ7ao7K/NXXcnX9t+wJOA6DHN338wk/yWQqW0AG+N/EzNnNRAxYwSKv92fRq0 qJXwkLpJVD7U2twM5pMVuzUwplQ3CrZ58x6ohR7GqhD1QndXjt8RRJp+WfrEhrM/8DPc ARPO/bBB/cUld2ZHuqTTa+32KJTyx7ZD0ND4PdOq8UUGgP1EtLrDjVXYtYuX+e6NPcXq piwuCfhVrKAYLWn/ZzVLSKu7r5DT0gC0xFl9NP/jgqc8KhUcYokHAv933ep2V8T+NR+f 2rbg== 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=38njsxJ3FWx1u0iWIDZPp+d4mrwHS6vkGES4CWjer7Q=; b=l9VY2EVgHkN2ajwXvOFNeK/zOG68j+eecWYb24nrsQDSybm1b5Q949vcco+u9JxxAT FOlJagHDhH2gr9xw91LzFByUx3qzCUtl0UPzqxSABo9h44P3xi87Zv9+sSTGwEY3d7O0 BXAmzjuaqL4NI4g+cv8QGYI4xCxY85idQ9zQ8PgeJg6dkbKEtA3LoWFfLvXj/6vQfpQd kWf7Qzeb4j8B6cCRy7Qhwe4Er8O99DC3+oTZ8/5zjFcC6ycLQxHC3h4Mq7WJI3davD2j S5QiqmtEBqwtqkwnvDdloQqZwMPExkfH2uewMN4CHbadK3/pHywGSDIp1yxmcOYBxFXO ZABA== X-Gm-Message-State: AOAM530VcGDI8cFoOgLACIpSFVuqdaYZw/RFWxkNmlHJB49W0aaJcnVF /frhTvHJXFQTT94z6QOtMFQ= X-Google-Smtp-Source: ABdhPJwHempbVMhHwlgPPi96IQr3G42XV5U/8h9slhvJ9m/PQGK1jWOGe7fYnQZoPAXtthg2vqzjjg== X-Received: by 2002:a17:906:c09:: with SMTP id s9mr10711936ejf.539.1610758844565; Fri, 15 Jan 2021 17:00:44 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:44 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 09/14] net: mscc: ocelot: reapply bridge forwarding mask on bonding join/leave Date: Sat, 16 Jan 2021 02:59:38 +0200 Message-Id: <20210116005943.219479-10-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Applying the bridge forwarding mask currently is done only on the STP state changes for any port. But it depends on both STP state changes, and bonding interface state changes. Export the bit that recalculates the forwarding mask so that it could be reused, and call it when a port starts and stops offloading a bonding interface. Signed-off-by: Vladimir Oltean Reviewed-by: Alexandre Belloni --- Changes in v2: Found a better strategic placement for the ocelot_apply_bridge_fwd_mask function (i.e. just code ordering). drivers/net/ethernet/mscc/ocelot.c | 68 +++++++++++++++++------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 915cf81f602a..8ab74325eb78 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -894,40 +894,18 @@ static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond) return bond_mask; } -void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state) +static void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot) { - u32 port_cfg; - int p; - - if (!(BIT(port) & ocelot->bridge_mask)) - return; - - port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); - - switch (state) { - case BR_STATE_FORWARDING: - ocelot->bridge_fwd_mask |= BIT(port); - fallthrough; - case BR_STATE_LEARNING: - port_cfg |= ANA_PORT_PORT_CFG_LEARN_ENA; - break; - - default: - port_cfg &= ~ANA_PORT_PORT_CFG_LEARN_ENA; - ocelot->bridge_fwd_mask &= ~BIT(port); - break; - } - - ocelot_write_gix(ocelot, port_cfg, ANA_PORT_PORT_CFG, port); + int port; /* Apply FWD mask. The loop is needed to add/remove the current port as * a source for the other ports. If the source port is in a bond, then * all the other ports from that bond need to be removed from this * source port's forwarding mask. */ - for (p = 0; p < ocelot->num_phys_ports; p++) { - if (ocelot->bridge_fwd_mask & BIT(p)) { - unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(p); + for (port = 0; port < ocelot->num_phys_ports; port++) { + if (ocelot->bridge_fwd_mask & BIT(port)) { + unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(port); int lag; for (lag = 0; lag < ocelot->num_phys_ports; lag++) { @@ -936,20 +914,48 @@ void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state) if (!bond_mask) continue; - if (bond_mask & BIT(p)) { + if (bond_mask & BIT(port)) { mask &= ~bond_mask; break; } } ocelot_write_rix(ocelot, mask, - ANA_PGID_PGID, PGID_SRC + p); + ANA_PGID_PGID, PGID_SRC + port); } else { ocelot_write_rix(ocelot, 0, - ANA_PGID_PGID, PGID_SRC + p); + ANA_PGID_PGID, PGID_SRC + port); } } } + +void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state) +{ + u32 port_cfg; + + if (!(BIT(port) & ocelot->bridge_mask)) + return; + + port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); + + switch (state) { + case BR_STATE_FORWARDING: + ocelot->bridge_fwd_mask |= BIT(port); + fallthrough; + case BR_STATE_LEARNING: + port_cfg |= ANA_PORT_PORT_CFG_LEARN_ENA; + break; + + default: + port_cfg &= ~ANA_PORT_PORT_CFG_LEARN_ENA; + ocelot->bridge_fwd_mask &= ~BIT(port); + break; + } + + ocelot_write_gix(ocelot, port_cfg, ANA_PORT_PORT_CFG, port); + + ocelot_apply_bridge_fwd_mask(ocelot); +} EXPORT_SYMBOL(ocelot_bridge_stp_state_set); void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs) @@ -1300,6 +1306,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, } ocelot_setup_lag(ocelot, lag); + ocelot_apply_bridge_fwd_mask(ocelot); ocelot_set_aggr_pgids(ocelot); return 0; @@ -1335,6 +1342,7 @@ void ocelot_port_lag_leave(struct ocelot *ocelot, int port, ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port), ANA_PORT_PORT_CFG, port); + ocelot_apply_bridge_fwd_mask(ocelot); ocelot_set_aggr_pgids(ocelot); } EXPORT_SYMBOL(ocelot_port_lag_leave); From patchwork Sat Jan 16 00:59:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 364356 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=-15.7 required=3.0 tests=BAYES_00,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 64104C43381 for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B1C223A34 for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728887AbhAPBCA (ORCPT ); Fri, 15 Jan 2021 20:02:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728712AbhAPBB5 (ORCPT ); Fri, 15 Jan 2021 20:01:57 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DCC1C06179E for ; Fri, 15 Jan 2021 17:00:47 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id n26so15810928eju.6 for ; Fri, 15 Jan 2021 17:00:47 -0800 (PST) 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=200TmBKtTfL2h/FLWqy8HgcNhiwZAAkB1z4+Zrk5ZnQ=; b=aDhZw33Hf7wzVmjrpqR9vV0o/2UprQjRdkQKm4I085KIVF2D4mBsKpOmyGoz0Py0Mo 2WFiHMBUvtx8gNrjeY9Uo9yrTz6kWvW1NoYw2BO1drcyG4zh94tZktj9qKF8EtZE4WWu b+JHx9bjnYwFaAkEqCSeqxPImaZE8n+EVdviHlmAklZyKoOiXOrrw3GIBy+SqhNz38Pz 50BY/qhGYSpcLInj8Bujt9RTdWArNkmrkqg1nz+f9rod6ftGY8ZAKL1VlWQpuQNs8ahK zsAMUetHUyxvHF81EwaXfU9JqFQYCvFanMlqrRSmiwaV5/Qey2Z7Shq2t213mKv1F7zT RyKw== 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=200TmBKtTfL2h/FLWqy8HgcNhiwZAAkB1z4+Zrk5ZnQ=; b=uJRvTP/sLt+LDb9nhowXQN86Xtedl7VViF3WN5JYQd4PsNQezK4GiFVKJHDU2Sl8yZ IJ8YdFT2xL9iomqvspY0xlB3D3CL8vMir4jUfMvoyyOdYNTXd+lXs6rFPuhlg+RaRRm4 S5pEMkWA0BlAZ6cBwAyWDyUBHa8gPiQt2Lj1Mpo3sfiJWC3Ue1//OmdZL0pNfDQ+LumR uHNAI+Z8pWAozJVWsLKEftW+JVHcrS4I+FwQvvBsQKI/PQsmagOiALZWKi7LdoX9I+yW sAvXllMhd536KV39uizxeR+9XLgxY2A2PEyPPE7acsFkz78Nj74b5qHrfH5eLpgB8UWt DOEw== X-Gm-Message-State: AOAM530umKQOfMgcLq8MaCwtQHtosLJJzE+YgXRc9bggyTDkeGYMwI1J vZTxzzUrVWQ352+BNTR8M+I= X-Google-Smtp-Source: ABdhPJy3FfGIWbZZdvy5YnRMRnJYnVLszV3wkEaMcoZBTBsdoeiHcJ2/Tr6dZtMPwYmV0vQW6vmznw== X-Received: by 2002:a17:906:9497:: with SMTP id t23mr7138398ejx.523.1610758845816; Fri, 15 Jan 2021 17:00:45 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:45 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 10/14] net: mscc: ocelot: set up logical port IDs centrally Date: Sat, 16 Jan 2021 02:59:39 +0200 Message-Id: <20210116005943.219479-11-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean The setup of logical port IDs is done in two places: from the inconclusively named ocelot_setup_lag and from ocelot_port_lag_leave, a function that also calls ocelot_setup_lag (which apparently does an incomplete setup of the LAG). To improve this situation, we can rename ocelot_setup_lag into ocelot_setup_logical_port_ids, and drop the "lag" argument. It will now set up the logical port IDs of all switch ports, which may be just slightly more inefficient but more maintainable. Signed-off-by: Vladimir Oltean --- Changes in v2: None. drivers/net/ethernet/mscc/ocelot.c | 47 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 8ab74325eb78..1bcf68bd1bff 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1260,20 +1260,36 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot) } } -static void ocelot_setup_lag(struct ocelot *ocelot, int lag) +/* When offloading a bonding interface, the switch ports configured under the + * same bond must have the same logical port ID, equal to the physical port ID + * of the lowest numbered physical port in that bond. Otherwise, in standalone/ + * bridged mode, each port has a logical port ID equal to its physical port ID. + */ +static void ocelot_setup_logical_port_ids(struct ocelot *ocelot) { - unsigned long bond_mask = ocelot->lags[lag]; - unsigned int p; + int port; - for_each_set_bit(p, &bond_mask, ocelot->num_phys_ports) { - u32 port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, p); + for (port = 0; port < ocelot->num_phys_ports; port++) { + struct ocelot_port *ocelot_port = ocelot->ports[port]; + struct net_device *bond; + + if (!ocelot_port) + continue; - port_cfg &= ~ANA_PORT_PORT_CFG_PORTID_VAL_M; + bond = ocelot_port->bond; + if (bond) { + int lag = __ffs(ocelot_get_bond_mask(ocelot, bond)); - /* Use lag port as logical port for port i */ - ocelot_write_gix(ocelot, port_cfg | - ANA_PORT_PORT_CFG_PORTID_VAL(lag), - ANA_PORT_PORT_CFG, p); + ocelot_rmw_gix(ocelot, + ANA_PORT_PORT_CFG_PORTID_VAL(lag), + ANA_PORT_PORT_CFG_PORTID_VAL_M, + ANA_PORT_PORT_CFG, port); + } else { + ocelot_rmw_gix(ocelot, + ANA_PORT_PORT_CFG_PORTID_VAL(port), + ANA_PORT_PORT_CFG_PORTID_VAL_M, + ANA_PORT_PORT_CFG, port); + } } } @@ -1305,7 +1321,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, ocelot->lags[lag] |= BIT(port); } - ocelot_setup_lag(ocelot, lag); + ocelot_setup_logical_port_ids(ocelot); ocelot_apply_bridge_fwd_mask(ocelot); ocelot_set_aggr_pgids(ocelot); @@ -1316,7 +1332,6 @@ EXPORT_SYMBOL(ocelot_port_lag_join); void ocelot_port_lag_leave(struct ocelot *ocelot, int port, struct net_device *bond) { - u32 port_cfg; int i; ocelot->ports[port]->bond = NULL; @@ -1333,15 +1348,9 @@ void ocelot_port_lag_leave(struct ocelot *ocelot, int port, ocelot->lags[n] = ocelot->lags[port]; ocelot->lags[port] = 0; - - ocelot_setup_lag(ocelot, n); } - port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); - port_cfg &= ~ANA_PORT_PORT_CFG_PORTID_VAL_M; - ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port), - ANA_PORT_PORT_CFG, port); - + ocelot_setup_logical_port_ids(ocelot); ocelot_apply_bridge_fwd_mask(ocelot); ocelot_set_aggr_pgids(ocelot); } From patchwork Sat Jan 16 00:59:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 365431 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=-15.7 required=3.0 tests=BAYES_00,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 505A7C433E9 for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B2C122BE8 for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728818AbhAPBB7 (ORCPT ); Fri, 15 Jan 2021 20:01:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728758AbhAPBB6 (ORCPT ); Fri, 15 Jan 2021 20:01:58 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65A0DC06179F for ; Fri, 15 Jan 2021 17:00:48 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id q22so15848743eja.2 for ; Fri, 15 Jan 2021 17:00:48 -0800 (PST) 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=pKD28HIKQQp15q4L/I295JSmURZh7prtkZRo0P59bf8=; b=dE35oUhCtolz66u4FWe+rFmfMMvCJlt9HpLLBvSvCBuxrdDG9+sJ3NLaj0jUinWtet QFwsYOg7WD0hyr3rrlddwa2M+VOW/aqBJPhKEFV948e8vdMq8jg6N84WAj/3EjM1wUiY NkocUl92010OsIBUw1/4qlV9Bn+O+p7wcPdVkcRAUlaMWLBYx/tMtpkHP0Szzzo9Ck5a /EZfzf5ndBRAcS+MYlKZJ9fpzGVYPzgQ1BA1lPmnJBdtcEbjJOpr29qot+L1hofdNR5B sZDLsIbhSh6LbWpGyzbec7AoqOtGohqxBuFTTuvO66f7ffAopDZk/ZpaEshKIcbI/35g nfeA== 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=pKD28HIKQQp15q4L/I295JSmURZh7prtkZRo0P59bf8=; b=n8TTOzLy7MlLOoc2P4Mxuh9DdGbwuo871xhQB0G9xKwlH/F1FZcJPeI3wQd0PICh5p 4TXLNw1d9SE/a6JPU7sqxnVSVOhsjRqNvv8Uz7qYA8RM1GObhl7qEHycx+QAaXWj/tjz mZs8pL3fmIc8/v8DTjvfZXeud3SfuVMsQFrNVUYGnsMdoU0JQoqZFqqkNHYDURa5fpoN OKze99+CugDrV1LyeuT1uICwEFyvXB8m8nVfIXl+ifv67ifibUYm9+fnlJHlUxBJfLkv gCVWblY/DUMwPkCpm8mc6p0VuPlx0hkqpI6U93XlNWL1SA41rJWHoLOAIllPAo3FdSZu bqhg== X-Gm-Message-State: AOAM531prkpQUjZOGt/w4GXjAhlX1EEEpgHGYVF/yVWEzxWFb7FPBtVm +JulPcatEJMxnLAX/DHkSSjL2nfxMsM= X-Google-Smtp-Source: ABdhPJyy1/BgmisT3dpsKo8vQoxnWeFZGtZ46EsIo87wkKX1eupmhOQxNhSxCYmz8yFK+g1oavfOFw== X-Received: by 2002:a17:906:d0c2:: with SMTP id bq2mr10679203ejb.1.1610758847141; Fri, 15 Jan 2021 17:00:47 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:46 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 11/14] net: mscc: ocelot: drop the use of the "lags" array Date: Sat, 16 Jan 2021 02:59:40 +0200 Message-Id: <20210116005943.219479-12-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean We can now simplify the implementation by always using ocelot_get_bond_mask to look up the other ports that are offloading the same bonding interface as us. In ocelot_set_aggr_pgids, the code had a way to uniquely iterate through LAGs. We need to achieve the same behavior by marking each LAG as visited, which we do now by temporarily allocating an array of pointers to bonding uppers of each port, and marking each bonding upper as NULL once it has been treated by the first port that is a member. And because we now do some dynamic allocation, we need to propagate errors from ocelot_set_aggr_pgid all the way to ocelot_port_lag_leave. Signed-off-by: Vladimir Oltean --- Changes in v2: Context looks a bit different. drivers/net/ethernet/mscc/ocelot.c | 104 ++++++++++--------------- drivers/net/ethernet/mscc/ocelot.h | 4 +- drivers/net/ethernet/mscc/ocelot_net.c | 4 +- include/soc/mscc/ocelot.h | 2 - 4 files changed, 47 insertions(+), 67 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 1bcf68bd1bff..fa2ebfbb33eb 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -904,21 +904,17 @@ static void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot) * source port's forwarding mask. */ for (port = 0; port < ocelot->num_phys_ports; port++) { - if (ocelot->bridge_fwd_mask & BIT(port)) { - unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(port); - int lag; + struct ocelot_port *ocelot_port = ocelot->ports[port]; - for (lag = 0; lag < ocelot->num_phys_ports; lag++) { - unsigned long bond_mask = ocelot->lags[lag]; + if (!ocelot_port) + continue; - if (!bond_mask) - continue; + if (ocelot->bridge_fwd_mask & BIT(port)) { + unsigned long mask = ocelot->bridge_fwd_mask & ~BIT(port); + struct net_device *bond = ocelot_port->bond; - if (bond_mask & BIT(port)) { - mask &= ~bond_mask; - break; - } - } + if (bond) + mask &= ~ocelot_get_bond_mask(ocelot, bond); ocelot_write_rix(ocelot, mask, ANA_PGID_PGID, PGID_SRC + port); @@ -1219,10 +1215,16 @@ int ocelot_port_bridge_leave(struct ocelot *ocelot, int port, } EXPORT_SYMBOL(ocelot_port_bridge_leave); -static void ocelot_set_aggr_pgids(struct ocelot *ocelot) +static int ocelot_set_aggr_pgids(struct ocelot *ocelot) { + struct net_device **bonds; int i, port, lag; + bonds = kcalloc(ocelot->num_phys_ports, sizeof(struct net_device *), + GFP_KERNEL); + if (!bonds) + return -ENOMEM; + /* Reset destination and aggregation PGIDS */ for_each_unicast_dest_pgid(ocelot, port) ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port); @@ -1231,16 +1233,26 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot) ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0), ANA_PGID_PGID, i); + for (port = 0; port < ocelot->num_phys_ports; port++) { + struct ocelot_port *ocelot_port = ocelot->ports[port]; + + if (!ocelot_port) + continue; + + bonds[port] = ocelot_port->bond; + } + /* Now, set PGIDs for each LAG */ for (lag = 0; lag < ocelot->num_phys_ports; lag++) { unsigned long bond_mask; int aggr_count = 0; u8 aggr_idx[16]; - bond_mask = ocelot->lags[lag]; - if (!bond_mask) + if (!bonds[lag]) continue; + bond_mask = ocelot_get_bond_mask(ocelot, bonds[lag]); + for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) { // Destination mask ocelot_write_rix(ocelot, bond_mask, @@ -1257,7 +1269,19 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot) ac |= BIT(aggr_idx[i % aggr_count]); ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i); } + + /* Mark the bonding interface as visited to avoid applying + * the same config again + */ + for (i = lag + 1; i < ocelot->num_phys_ports; i++) + if (bonds[i] == bonds[lag]) + bonds[i] = NULL; + + bonds[lag] = NULL; } + + kfree(bonds); + return 0; } /* When offloading a bonding interface, the switch ports configured under the @@ -1297,62 +1321,25 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, struct net_device *bond, struct netdev_lag_upper_info *info) { - u32 bond_mask = 0; - int lag; - if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) return -EOPNOTSUPP; ocelot->ports[port]->bond = bond; - bond_mask = ocelot_get_bond_mask(ocelot, bond); - - lag = __ffs(bond_mask); - - /* If the new port is the lowest one, use it as the logical port from - * now on - */ - if (port == lag) { - ocelot->lags[port] = bond_mask; - bond_mask &= ~BIT(port); - if (bond_mask) - ocelot->lags[__ffs(bond_mask)] = 0; - } else { - ocelot->lags[lag] |= BIT(port); - } - ocelot_setup_logical_port_ids(ocelot); ocelot_apply_bridge_fwd_mask(ocelot); - ocelot_set_aggr_pgids(ocelot); - - return 0; + return ocelot_set_aggr_pgids(ocelot); } EXPORT_SYMBOL(ocelot_port_lag_join); -void ocelot_port_lag_leave(struct ocelot *ocelot, int port, - struct net_device *bond) +int ocelot_port_lag_leave(struct ocelot *ocelot, int port, + struct net_device *bond) { - int i; - ocelot->ports[port]->bond = NULL; - /* Remove port from any lag */ - for (i = 0; i < ocelot->num_phys_ports; i++) - ocelot->lags[i] &= ~BIT(port); - - /* if it was the logical port of the lag, move the lag config to the - * next port - */ - if (ocelot->lags[port]) { - int n = __ffs(ocelot->lags[port]); - - ocelot->lags[n] = ocelot->lags[port]; - ocelot->lags[port] = 0; - } - ocelot_setup_logical_port_ids(ocelot); ocelot_apply_bridge_fwd_mask(ocelot); - ocelot_set_aggr_pgids(ocelot); + return ocelot_set_aggr_pgids(ocelot); } EXPORT_SYMBOL(ocelot_port_lag_leave); @@ -1531,11 +1518,6 @@ int ocelot_init(struct ocelot *ocelot) } } - ocelot->lags = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports, - sizeof(u32), GFP_KERNEL); - if (!ocelot->lags) - return -ENOMEM; - ocelot->stats = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports * ocelot->num_stats, sizeof(u64), GFP_KERNEL); diff --git a/drivers/net/ethernet/mscc/ocelot.h b/drivers/net/ethernet/mscc/ocelot.h index b6c9ddcee554..c018a54f4e49 100644 --- a/drivers/net/ethernet/mscc/ocelot.h +++ b/drivers/net/ethernet/mscc/ocelot.h @@ -112,8 +112,8 @@ int ocelot_mact_forget(struct ocelot *ocelot, int ocelot_port_lag_join(struct ocelot *ocelot, int port, struct net_device *bond, struct netdev_lag_upper_info *info); -void ocelot_port_lag_leave(struct ocelot *ocelot, int port, - struct net_device *bond); +int ocelot_port_lag_leave(struct ocelot *ocelot, int port, + struct net_device *bond); struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port); int ocelot_netdev_to_port(struct net_device *dev); diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index f246f8fc535d..871bfbaa8ff1 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -1138,8 +1138,8 @@ static int ocelot_netdevice_changeupper(struct net_device *dev, err = 0; } } else { - ocelot_port_lag_leave(ocelot, port, - info->upper_dev); + err = ocelot_port_lag_leave(ocelot, port, + info->upper_dev); } } diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index d2c587f099c8..1bb16527f490 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -656,8 +656,6 @@ struct ocelot { enum ocelot_tag_prefix inj_prefix; enum ocelot_tag_prefix xtr_prefix; - u32 *lags; - struct list_head multicast; struct list_head pgids; From patchwork Sat Jan 16 00:59:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 365429 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=-15.8 required=3.0 tests=BAYES_00,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, 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 CDC9FC43331 for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A52B923A3C for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728989AbhAPBCD (ORCPT ); Fri, 15 Jan 2021 20:02:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728800AbhAPBB7 (ORCPT ); Fri, 15 Jan 2021 20:01:59 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA15C0617A0 for ; Fri, 15 Jan 2021 17:00:49 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id r12so4479829ejb.9 for ; Fri, 15 Jan 2021 17:00:49 -0800 (PST) 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=mx4MOhohDXzuBINH5jwpAk3u0L8oYJBbC4BCZjybXw8=; b=aOfC9G283WHtZ8NGU6obJVy5lplXpK40/aVW8xASIOuZytHUT0vOjdl2ABLMVxSSLL BYLoLjFEOA1hXBAIy501sd+2miv4aw6rwAXmtbkB/rFfvWMWH2bAG4tjbYtPGdywpXa/ nZ2I8lKpYAfTkUjr3lJ0NGatOHScJHc0Hi0ZmZES7hzOIez2DaVZ7ayfQTUj0sP8WegN IOSds+kH0LVzwyNH69tgRd95RbkaC9S548LoO7rTLCLxZIf2hU/Hskwz9BG9rflF5QTS Njpgmq0ENp631qHbBzXqIFZvLbNEgZfTFqvDSOCIpS4nqUECaVFfYRkwe1ZbIBf60/Wk rJIw== 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=mx4MOhohDXzuBINH5jwpAk3u0L8oYJBbC4BCZjybXw8=; b=VwgnsJ8hqIxVIDEgifcHPofLk95FUrA1F8GMKFpBGpjocS3xvqeaRqzJAibGnEUUDX uK2aF28cJffXdDurCcUWI4cwGN5pBmHkgPFdmJuVPHxm0O9r7xM808HtvzQk8auCSH6y DN4WVn1SM2U4nJnW21Bfs/8Pv41ArKxiTM6Mvee6mXD9DnrDsenOr7iQDVSJE33z1uA6 IwmG4q+m25R8q16wO0t5TnlnAhURJOYwX7QNG0sEFjOUM4rgyd7SV0aCYjTzmoZz2eks dIZi5YT1yjh63dt/8pSwG8hzqJO+Q+mfnSxdtxy8qHDqsrNCZ0poAqhPKcOOMUy3i1aa HG5g== X-Gm-Message-State: AOAM533MP5hcoSZAm8W00TIW9f+B7IFdY6YNfLs+A8dxwQOW0EsMNJgU ISi4xi8JHfs8/ZuFgJmGtNg= X-Google-Smtp-Source: ABdhPJzHZxCKyHbgv+yI2zeTbNcw5h5e+sPZj+8hV0XnX1giZmK9a6LAvkTy/d4uSX7zFsq6a0viXw== X-Received: by 2002:a17:906:3d4a:: with SMTP id q10mr10831866ejf.85.1610758848370; Fri, 15 Jan 2021 17:00:48 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:47 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 12/14] net: mscc: ocelot: rename aggr_count to num_ports_in_lag Date: Sat, 16 Jan 2021 02:59:41 +0200 Message-Id: <20210116005943.219479-13-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean It makes it a bit easier to read and understand the code that deals with balancing the 16 aggregation codes among the ports in a certain LAG. Signed-off-by: Vladimir Oltean --- Changes in v2: None. drivers/net/ethernet/mscc/ocelot.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index fa2ebfbb33eb..78a468d39e9b 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1244,8 +1244,8 @@ static int ocelot_set_aggr_pgids(struct ocelot *ocelot) /* Now, set PGIDs for each LAG */ for (lag = 0; lag < ocelot->num_phys_ports; lag++) { + int num_ports_in_lag = 0; unsigned long bond_mask; - int aggr_count = 0; u8 aggr_idx[16]; if (!bonds[lag]) @@ -1257,8 +1257,7 @@ static int ocelot_set_aggr_pgids(struct ocelot *ocelot) // Destination mask ocelot_write_rix(ocelot, bond_mask, ANA_PGID_PGID, port); - aggr_idx[aggr_count] = port; - aggr_count++; + aggr_idx[num_ports_in_lag++] = port; } for_each_aggr_pgid(ocelot, i) { @@ -1266,7 +1265,7 @@ static int ocelot_set_aggr_pgids(struct ocelot *ocelot) ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i); ac &= ~bond_mask; - ac |= BIT(aggr_idx[i % aggr_count]); + ac |= BIT(aggr_idx[i % num_ports_in_lag]); ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i); } From patchwork Sat Jan 16 00:59:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 364354 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=-15.8 required=3.0 tests=BAYES_00,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, 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 A2DCEC4332B for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D2C922BE8 for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728954AbhAPBCC (ORCPT ); Fri, 15 Jan 2021 20:02:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728803AbhAPBB7 (ORCPT ); Fri, 15 Jan 2021 20:01:59 -0500 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 06436C0617A1 for ; Fri, 15 Jan 2021 17:00:51 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id hs11so13505710ejc.1 for ; Fri, 15 Jan 2021 17:00:50 -0800 (PST) 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=37LfDkexTqbGj/RF1ETXVQpjIqqqNvve6EvhfPw+lnQ=; b=luryd/zG3KZN12C2MxZBUxIM5j3Naw8xalJl2WOSLdZVrgGuP5ZGGQLXs/fkt7NC3F 7b3W0A66S/dXD2RQxDk3s6eISMRxhgulgMiw/IAI/aEK5+8vX6rRDeuMiYxPseV1Jm9k pAGFDE0BUMbl8pUvGuih5IQ0eKcRo8L11La8KNqT+38KLYOd6iwsdIl6iXID2Phb//YH lxNe018FjK5+iTpuvRt55g+goMzf5OfcYgVeY0rBD8R+5JK7odzivWl42x9i0fjGXKgU VIPe0D6NIXYdbJF5bngnsJFiCQG3PVgTXNyDrOuS1SFCtyVOsYhaNMROqIC0ukZxPqtO qwAg== 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=37LfDkexTqbGj/RF1ETXVQpjIqqqNvve6EvhfPw+lnQ=; b=R9wibvM1B2PWsVUxsnZMf3ZrpUfmZfKut7xMw1M6zAV61rOQPjqcZY5wm65tGgW0+Z aSQtOihgA/O4MckRFjRV1wLAcFNcHuwt1t2+2f59jhXwx7HTsZSxT40uafLf+s/7dM4X LMEZXGe62lwRNVnY6Du9+4DtqMHLUEdca7GSs2tqWeoYW+U0Y5kyW4w9h0xwJegBjQhy voisYiqFFw64tqveXXUmgXtzTsgODN6Vn8MqC7eXxI/YyMo1s3iHAj8sGxEpSS2Q/35P d4xiSkOg6ropyYsZGQDZj8TPRukxQxNb8BAlDBbOdYwJYqzSwpSLpwzMK9KjQSkyhNaz A8Ng== X-Gm-Message-State: AOAM532/D+pE2gMlthOjUP87zcSvWQOUf6r84uJOcmy0hGV8gmHMxI7K wJ5FSnLoDrLAS/Uq+Bb78tk= X-Google-Smtp-Source: ABdhPJy8GTR6wfRa+8JyrZZEojZV2Rq0wMT2l1fjCK50/Z0Zr2891r7xI+7KBoukFuWFm9TWz+OYAw== X-Received: by 2002:a17:907:3e04:: with SMTP id hp4mr7851569ejc.188.1610758849690; Fri, 15 Jan 2021 17:00:49 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:49 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 13/14] net: mscc: ocelot: rebalance LAGs on link up/down events Date: Sat, 16 Jan 2021 02:59:42 +0200 Message-Id: <20210116005943.219479-14-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean At present there is an issue when ocelot is offloading a bonding interface, but one of the links of the physical ports goes down. Traffic keeps being hashed towards that destination, and of course gets dropped on egress. Monitor the netdev notifier events emitted by the bonding driver for changes in the physical state of lower interfaces, to determine which ports are active and which ones are no longer. Then extend ocelot_get_bond_mask to return either the configured bonding interfaces, or the active ones, depending on a boolean argument. The code that does rebalancing only needs to do so among the active ports, whereas the bridge forwarding mask and the logical port IDs still need to look at the permanently bonded ports. Signed-off-by: Vladimir Oltean --- Changes in v2: - Adapt to the merged version of the DSA API, which now passes just a bool lag_tx_active in .port_lag_change instead of the full struct netdev_lag_lower_state_info *info. - Renamed "just_active_ports" -> "only_active_ports" drivers/net/ethernet/mscc/ocelot.c | 38 ++++++++++++++++++++------ drivers/net/ethernet/mscc/ocelot.h | 1 + drivers/net/ethernet/mscc/ocelot_net.c | 30 ++++++++++++++++++++ include/soc/mscc/ocelot.h | 1 + 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 78a468d39e9b..c31a63d9fe2a 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -876,7 +876,8 @@ int ocelot_get_ts_info(struct ocelot *ocelot, int port, } EXPORT_SYMBOL(ocelot_get_ts_info); -static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond) +static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond, + bool only_active_ports) { u32 bond_mask = 0; int port; @@ -887,8 +888,12 @@ static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond) if (!ocelot_port) continue; - if (ocelot_port->bond == bond) + if (ocelot_port->bond == bond) { + if (only_active_ports && !ocelot_port->lag_tx_active) + continue; + bond_mask |= BIT(port); + } } return bond_mask; @@ -914,7 +919,7 @@ static void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot) struct net_device *bond = ocelot_port->bond; if (bond) - mask &= ~ocelot_get_bond_mask(ocelot, bond); + mask &= ~ocelot_get_bond_mask(ocelot, bond, false); ocelot_write_rix(ocelot, mask, ANA_PGID_PGID, PGID_SRC + port); @@ -1242,22 +1247,22 @@ static int ocelot_set_aggr_pgids(struct ocelot *ocelot) bonds[port] = ocelot_port->bond; } - /* Now, set PGIDs for each LAG */ + /* Now, set PGIDs for each active LAG */ for (lag = 0; lag < ocelot->num_phys_ports; lag++) { - int num_ports_in_lag = 0; + int num_active_ports = 0; unsigned long bond_mask; u8 aggr_idx[16]; if (!bonds[lag]) continue; - bond_mask = ocelot_get_bond_mask(ocelot, bonds[lag]); + bond_mask = ocelot_get_bond_mask(ocelot, bonds[lag], true); for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) { // Destination mask ocelot_write_rix(ocelot, bond_mask, ANA_PGID_PGID, port); - aggr_idx[num_ports_in_lag++] = port; + aggr_idx[num_active_ports++] = port; } for_each_aggr_pgid(ocelot, i) { @@ -1265,7 +1270,11 @@ static int ocelot_set_aggr_pgids(struct ocelot *ocelot) ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i); ac &= ~bond_mask; - ac |= BIT(aggr_idx[i % num_ports_in_lag]); + /* Don't do division by zero if there was no active + * port. Just make all aggregation codes zero. + */ + if (num_active_ports) + ac |= BIT(aggr_idx[i % num_active_ports]); ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i); } @@ -1301,7 +1310,8 @@ static void ocelot_setup_logical_port_ids(struct ocelot *ocelot) bond = ocelot_port->bond; if (bond) { - int lag = __ffs(ocelot_get_bond_mask(ocelot, bond)); + int lag = __ffs(ocelot_get_bond_mask(ocelot, bond, + false)); ocelot_rmw_gix(ocelot, ANA_PORT_PORT_CFG_PORTID_VAL(lag), @@ -1342,6 +1352,16 @@ int ocelot_port_lag_leave(struct ocelot *ocelot, int port, } EXPORT_SYMBOL(ocelot_port_lag_leave); +int ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active) +{ + struct ocelot_port *ocelot_port = ocelot->ports[port]; + + ocelot_port->lag_tx_active = lag_tx_active; + + /* Rebalance the LAGs */ + return ocelot_set_aggr_pgids(ocelot); +} + /* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu. * The length of VLAN tags is accounted for automatically via DEV_MAC_TAGS_CFG. * In the special case that it's the NPI port that we're configuring, the diff --git a/drivers/net/ethernet/mscc/ocelot.h b/drivers/net/ethernet/mscc/ocelot.h index c018a54f4e49..fc055525fd88 100644 --- a/drivers/net/ethernet/mscc/ocelot.h +++ b/drivers/net/ethernet/mscc/ocelot.h @@ -114,6 +114,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, struct netdev_lag_upper_info *info); int ocelot_port_lag_leave(struct ocelot *ocelot, int port, struct net_device *bond); +int ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active); struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port); int ocelot_netdev_to_port(struct net_device *dev); diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index 871bfbaa8ff1..3cba1c2de6fe 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -1163,6 +1163,27 @@ ocelot_netdevice_lag_changeupper(struct net_device *dev, return NOTIFY_DONE; } +static int +ocelot_netdevice_changelowerstate(struct net_device *dev, + struct netdev_lag_lower_state_info *info) +{ + struct ocelot_port_private *priv = netdev_priv(dev); + bool is_active = info->link_up && info->tx_enabled; + struct ocelot_port *ocelot_port = &priv->port; + struct ocelot *ocelot = ocelot_port->ocelot; + int port = priv->chip_port; + int err; + + if (!ocelot_port->bond) + return NOTIFY_DONE; + + if (ocelot_port->lag_tx_active == is_active) + return 0; + + err = ocelot_port_lag_change(ocelot, port, is_active); + return notifier_from_errno(err); +} + static int ocelot_netdevice_event(struct notifier_block *unused, unsigned long event, void *ptr) { @@ -1180,6 +1201,15 @@ static int ocelot_netdevice_event(struct notifier_block *unused, break; } + case NETDEV_CHANGELOWERSTATE: { + struct netdev_notifier_changelowerstate_info *info = ptr; + + if (!ocelot_netdevice_dev_check(dev)) + break; + + return ocelot_netdevice_changelowerstate(dev, + info->lower_state_info); + } default: break; } diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index 1bb16527f490..7bd7c58a7490 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -612,6 +612,7 @@ struct ocelot_port { u8 *xmit_template; struct net_device *bond; + bool lag_tx_active; }; struct ocelot { From patchwork Sat Jan 16 00:59:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 365430 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=-15.7 required=3.0 tests=BAYES_00,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 BB5A9C4332D for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C12D23A34 for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729036AbhAPBCE (ORCPT ); Fri, 15 Jan 2021 20:02:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728712AbhAPBCB (ORCPT ); Fri, 15 Jan 2021 20:02:01 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F27BC0617A2 for ; Fri, 15 Jan 2021 17:00:52 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id f4so15835418ejx.7 for ; Fri, 15 Jan 2021 17:00:52 -0800 (PST) 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=NjEAA2DJmjSD/q4DlZ6it26CzmdA3ef8cg3M5pyv52M=; b=fm97Tnt5MwI9Wpmy85ICZGxAMA2zJ25cvTS1ydDeJgmN39PYAB3x2JxYqRhwQICKLT 2oLQvN3NoItEzEW2YAUO5dYKe3BEa6PzA4NC0QZlUZfVPnOIX3aT+4Ylj7f1GA2tdLIt goVBrOlQNzXznds5ISbCVN3zzoFEoOpFaYlM4XWS/IW+zegyH3Cws6LD0C7V5jmGfRp2 D3lWzFpIZhKRqgs5zydF7YA9tKnmiY+iSkumZ3M+9umWBauZ63GyU2QG7C3bKwhYZTfB EhVeMy55ISzGA1F0s/K3xTJUxQ62R973eaxjsQyrZbM6LoxOkifyS2JVwvgWeayoeivS sueg== 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=NjEAA2DJmjSD/q4DlZ6it26CzmdA3ef8cg3M5pyv52M=; b=Z4qi46V1mao34N6wNK3LA1bku0TkfGoZaLrCKDNXKHao1q8OOesUf9fAFE6V12qtlz Ik2I8OQ0jsjNPrRE9GjG6jkkPk1KV1/Q5yEpCZx4+s/ZAa6FoxFhsN6gT4pFFMfWa/FU Eo5rhEgvOGwlA/yyeCOKgHBTjDBHVzlxfz9Gg7PrLxD2gt6JO6/XBEzb0L8De3zJOdxu JAo04wFELDdivHvIdQHoH2nfmd36K4OjTHW5VUaM3uT7B8SxhxsLExQvGen1JJNTdPpR tWqGBGhVnqcO1fii+2PSZvjplCgzWX3SjnCRb8vuVb5w3rINGKrlb/IP3Gg/uP9Sfqav G2Ng== X-Gm-Message-State: AOAM530JMcT2OXGy0l2SaDYw8vgF6fJxpnlyiaqbokzm8q8K7HfYWSCc sXcwFl2kwflqXyN67FK4h9Q= X-Google-Smtp-Source: ABdhPJxymBwuNtKGeQMx2JHwgXbqh+Mx/qa1m28S2mkmkmVe/lddltlI9Wa/zvOl/ap0qhoteKGSBw== X-Received: by 2002:a17:906:65a:: with SMTP id t26mr10378870ejb.394.1610758850998; Fri, 15 Jan 2021 17:00:50 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:50 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 14/14] net: dsa: felix: propagate the LAG offload ops towards the ocelot lib Date: Sat, 16 Jan 2021 02:59:43 +0200 Message-Id: <20210116005943.219479-15-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean The ocelot switch has been supporting LAG offload since its initial commit, however felix could not make use of that, due to lack of a LAG abstraction in DSA. Now that we have that, let's forward DSA's calls towards the ocelot library, who will deal with setting up the bonding. Note that ocelot_port_lag_leave can return an error due to memory allocation but we are currently ignoring that, because the DSA method returns void. Signed-off-by: Vladimir Oltean --- Changes in v2: s/lag_dev/bond/g drivers/net/dsa/ocelot/felix.c | 28 ++++++++++++++++++++++++++++ drivers/net/ethernet/mscc/ocelot.c | 1 + drivers/net/ethernet/mscc/ocelot.h | 6 ------ include/soc/mscc/ocelot.h | 6 ++++++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index 2c6ac2b137ec..af867535f9eb 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -105,6 +105,31 @@ static void felix_bridge_leave(struct dsa_switch *ds, int port, ocelot_port_bridge_leave(ocelot, port, br); } +static int felix_lag_join(struct dsa_switch *ds, int port, + struct net_device *bond, + struct netdev_lag_upper_info *info) +{ + struct ocelot *ocelot = ds->priv; + + return ocelot_port_lag_join(ocelot, port, bond, info); +} + +static int felix_lag_leave(struct dsa_switch *ds, int port, + struct net_device *bond) +{ + struct ocelot *ocelot = ds->priv; + + return ocelot_port_lag_leave(ocelot, port, bond); +} + +static int felix_lag_change(struct dsa_switch *ds, int port) +{ + struct dsa_port *dp = dsa_to_port(ds, port); + struct ocelot *ocelot = ds->priv; + + return ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled); +} + static int felix_vlan_prepare(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { @@ -881,6 +906,9 @@ const struct dsa_switch_ops felix_switch_ops = { .port_mdb_del = felix_mdb_del, .port_bridge_join = felix_bridge_join, .port_bridge_leave = felix_bridge_leave, + .port_lag_join = felix_lag_join, + .port_lag_leave = felix_lag_leave, + .port_lag_change = felix_lag_change, .port_stp_state_set = felix_bridge_stp_state_set, .port_vlan_filtering = felix_vlan_filtering, .port_vlan_add = felix_vlan_add, diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index c31a63d9fe2a..b2fdee8a713c 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1361,6 +1361,7 @@ int ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active) /* Rebalance the LAGs */ return ocelot_set_aggr_pgids(ocelot); } +EXPORT_SYMBOL(ocelot_port_lag_change); /* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu. * The length of VLAN tags is accounted for automatically via DEV_MAC_TAGS_CFG. diff --git a/drivers/net/ethernet/mscc/ocelot.h b/drivers/net/ethernet/mscc/ocelot.h index fc055525fd88..e3352ae7b11f 100644 --- a/drivers/net/ethernet/mscc/ocelot.h +++ b/drivers/net/ethernet/mscc/ocelot.h @@ -109,12 +109,6 @@ int ocelot_mact_learn(struct ocelot *ocelot, int port, unsigned int vid, enum macaccess_entry_type type); int ocelot_mact_forget(struct ocelot *ocelot, const unsigned char mac[ETH_ALEN], unsigned int vid); -int ocelot_port_lag_join(struct ocelot *ocelot, int port, - struct net_device *bond, - struct netdev_lag_upper_info *info); -int ocelot_port_lag_leave(struct ocelot *ocelot, int port, - struct net_device *bond); -int ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active); struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port); int ocelot_netdev_to_port(struct net_device *dev); diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index 7bd7c58a7490..d9b5d31bb181 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -796,6 +796,12 @@ int ocelot_port_mdb_add(struct ocelot *ocelot, int port, const struct switchdev_obj_port_mdb *mdb); int ocelot_port_mdb_del(struct ocelot *ocelot, int port, const struct switchdev_obj_port_mdb *mdb); +int ocelot_port_lag_join(struct ocelot *ocelot, int port, + struct net_device *bond, + struct netdev_lag_upper_info *info); +int ocelot_port_lag_leave(struct ocelot *ocelot, int port, + struct net_device *bond); +int ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active); int ocelot_devlink_sb_register(struct ocelot *ocelot); void ocelot_devlink_sb_unregister(struct ocelot *ocelot);