From patchwork Thu Sep 2 08:30:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12471027 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-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,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 5EE64C432BE for ; Thu, 2 Sep 2021 08:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E34A60FDA for ; Thu, 2 Sep 2021 08:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243772AbhIBIcA (ORCPT ); Thu, 2 Sep 2021 04:32:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233362AbhIBIb7 (ORCPT ); Thu, 2 Sep 2021 04:31:59 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DFB0C061575 for ; Thu, 2 Sep 2021 01:31:01 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id s12so2155984ljg.0 for ; Thu, 02 Sep 2021 01:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SUiAfSITq6W7njnqVRK/mA6fpjG3fTsAcCU4D+dTTVU=; b=TOVeLzPFPcIGAHOAa3nS9nUtQGqfF89UMXfj5K8qnlkb54AK6G/xJRy3bV1nhXXexn nVJ/fZe93t0cotImcc4aGMEZ7aj0ophB4ITfW8D4O4njqjmiOZ9s49d/1t7EOXEdWyis ngyk98JgqzJSusABCMScQgI3L2js/YoxVUJ6s7N4Ypz7ikH0tcfCkZ9kgWFb39mDXq5Q hC0GrTSfgVBXVbcA5qPR5ED1v3WyNbPagqH3L+jIpu3cYc4g6WkgQBXGRncIqQ1rk2xd cH0cBZOnORYOW5xoxUL8+usd+iBvMqn1wNtwQJ1NI1NYxo7g7WQsT4FMXQdcL6Q13uBh SXCQ== 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=SUiAfSITq6W7njnqVRK/mA6fpjG3fTsAcCU4D+dTTVU=; b=VDWHDze/3npp9R14OCMPIhDzaANGyRfuaXRxisDhtieDEUCB1lf5uJEzzSGgUqSogY 8MwNYcsJbUr/FCgRNzg5BZSk+1BVST71UMj+vot3eS/yM6oAKqmqWAqHENNEekMTlmx5 +ff8cWhJgPhyS6cRqEy8Xw3ENY6T8WS8MTSNs1EsLHbcNd7ryc8zcHoAAAt+jaB6uBb7 h9aIONEIpWRbe097iSgT2V3Z0lXcaHVHtHfxbPAelSzyBK+RB1glE2k+uBI48xmfvQj3 vvVXLPKtKIfWHR9XAUQHNmzInJtd6o5TD93JK6WG3bZiQ5OcXZIPgelT1mQV7/OP5CAZ 6l/g== X-Gm-Message-State: AOAM530u91bEhwWCOcyqN+qboPqmGRUEdR+xjLGd//XEibha5enPeQrO hocXN2WumP/uk6sWBf/3k0c= X-Google-Smtp-Source: ABdhPJwUZ29iEbuxHCu2/LnOTi9dI2ii3RDDV8iubOJoejo6W6b6VWm4fPYeYWhYacX1xOGk6wSuPA== X-Received: by 2002:a2e:8789:: with SMTP id n9mr1561519lji.428.1630571459334; Thu, 02 Sep 2021 01:30:59 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id 131sm137042ljj.52.2021.09.02.01.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 01:30:58 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Andrew Lunn , Vivien Didelot , Vladimir Oltean , "David S . Miller" , Jakub Kicinski Cc: Florian Fainelli , netdev@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 net 1/2] net: dsa: b53: Fix calculating number of switch ports Date: Thu, 2 Sep 2021 10:30:50 +0200 Message-Id: <20210902083051.18206-1-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210901092141.6451-1-zajec5@gmail.com> References: <20210901092141.6451-1-zajec5@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Rafał Miłecki It isn't true that CPU port is always the last one. Switches BCM5301x have 9 ports (port 6 being inactive) and they use port 5 as CPU by default (depending on design some other may be CPU ports too). A more reliable way of determining number of ports is to check for the last set bit in the "enabled_ports" bitfield. This fixes b53 internal state, it will allow providing accurate info to the DSA and is required to fix BCM5301x support. Fixes: 967dd82ffc52 ("net: dsa: b53: Add support for Broadcom RoboSwitch") Signed-off-by: Rafał Miłecki Reviewed-by: Florian Fainelli --- drivers/net/dsa/b53/b53_common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index bd1417a66cbf..dcf9d7e5ae14 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -2612,9 +2612,8 @@ static int b53_switch_init(struct b53_device *dev) dev->cpu_port = 5; } - /* cpu port is always last */ - dev->num_ports = dev->cpu_port + 1; dev->enabled_ports |= BIT(dev->cpu_port); + dev->num_ports = fls(dev->enabled_ports); /* Include non standard CPU port built-in PHYs to be probed */ if (is539x(dev) || is531x5(dev)) { From patchwork Thu Sep 2 08:30:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12471029 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-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,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 7D9CEC4320E for ; Thu, 2 Sep 2021 08:31:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60F0360FDC for ; Thu, 2 Sep 2021 08:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244285AbhIBIcD (ORCPT ); Thu, 2 Sep 2021 04:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243834AbhIBIcA (ORCPT ); Thu, 2 Sep 2021 04:32:00 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC2C2C061575 for ; Thu, 2 Sep 2021 01:31:02 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id t19so2534552lfe.13 for ; Thu, 02 Sep 2021 01:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gNqRw10rZHR5ReQJZ4EZPClJnf+Q+1FVfbcd/gZtEok=; b=PLOI+u+7FCVGOYCubex6gMpoAGkd8ZGlvyZ8/+yHl3A0kDRx6IVQw53SunPh+Bfqds qC8uFq4hRxKHJGuABmqdVeaorq7p4qEf0+46oo+m42N3Lap2hVrvJkbmCIZjblRpkBXJ c2dcUm6MkS7LtmTU7Dr7+rBIU42xsC2UAoXP24dL0psmAjg6uX37nVxY4TgQvlNhLpbY zl/sem6iHPBT4B5D45GDYov96zCYJDJSHEoe+3DEbxcpFa7jrP5wr3WngAfV1fTAydtg S8gH6V3+5yusH80+BcVyb/TflybOCxg4vz9ESh8939i1g5hrC28mbjfhM9NYpWuqPseV UJiQ== 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=gNqRw10rZHR5ReQJZ4EZPClJnf+Q+1FVfbcd/gZtEok=; b=R+0ot8JPlcIFn0HGkNZssTglp8A0eo+AuaaIiTnqoc6Mf1c+tUJxsr9eQbja9zF2oH w7Ad3Qyq3qfPNsF7B7SGY9EN9CwBUlbQPhX9jkJBDPWIS2ZNYjtr0lIZnoNpgKZlb3H5 2LUXM70JpJKzna44xhaC0MHcp62+EkpYVMLfzjoziAH6KwagvFv1RXcJSmodjJvTS+Lz XBQtVgu6uz+8KKBTJWqtb5TLClGB7GrRhRLwCooHFF62j0iAehuiRvkitX77d6gN4IVL E8orZpQtNLnV7/mCyfnhN8gLoc2em3z/nlYR5tn+wB5uQEtiPwtoe9tAB6M/ue8jPwdy SZ1g== X-Gm-Message-State: AOAM530POp6gmnRe+ND8SYg0jNj9OJvOKhlPwMQVwVnbDBKso++yn+X+ iyuusE30OtMxFaAsPOeItwk= X-Google-Smtp-Source: ABdhPJyy0aTxCdokVicJ1N7mtmll8ccC0CTUc1EVe+yoVZRAHit6Jp/dSP4E3MurpeBwIMF9EDjb0Q== X-Received: by 2002:a05:6512:10c1:: with SMTP id k1mr576777lfg.329.1630571461230; Thu, 02 Sep 2021 01:31:01 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id 131sm137042ljj.52.2021.09.02.01.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 01:31:00 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Andrew Lunn , Vivien Didelot , Vladimir Oltean , "David S . Miller" , Jakub Kicinski Cc: Florian Fainelli , netdev@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 net 2/2] net: dsa: b53: Set correct number of ports in the DSA struct Date: Thu, 2 Sep 2021 10:30:51 +0200 Message-Id: <20210902083051.18206-2-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210902083051.18206-1-zajec5@gmail.com> References: <20210901092141.6451-1-zajec5@gmail.com> <20210902083051.18206-1-zajec5@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Rafał Miłecki Setting DSA_MAX_PORTS caused DSA to call b53 callbacks (e.g. b53_disable_port() during dsa_register_switch()) for invalid (non-existent) ports. That made b53 modify unrelated registers and is one of reasons for a broken BCM5301x support. This problem exists for years but DSA_MAX_PORTS usage has changed few times. It seems the most accurate to reference commit dropping dsa_switch_alloc() in the Fixes tag. Fixes: 7e99e3470172 ("net: dsa: remove dsa_switch_alloc helper") Signed-off-by: Rafał Miłecki --- V2: Update commit & add Fixes tag --- drivers/net/dsa/b53/b53_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index dcf9d7e5ae14..5646eb8afe38 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -2615,6 +2615,8 @@ static int b53_switch_init(struct b53_device *dev) dev->enabled_ports |= BIT(dev->cpu_port); dev->num_ports = fls(dev->enabled_ports); + dev->ds->num_ports = min_t(unsigned int, dev->num_ports, DSA_MAX_PORTS); + /* Include non standard CPU port built-in PHYs to be probed */ if (is539x(dev) || is531x5(dev)) { for (i = 0; i < dev->num_ports; i++) { @@ -2659,7 +2661,6 @@ struct b53_device *b53_switch_alloc(struct device *base, return NULL; ds->dev = base; - ds->num_ports = DSA_MAX_PORTS; dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); if (!dev)