Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2351529pxb; Mon, 20 Sep 2021 19:47:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzZxbHNYlYceKMJh8H1oEhn5a57RvSGUxEvSvngWG6847Rnm+oDrgDgQWTDpebhJ/+WMNr X-Received: by 2002:a05:6402:198:: with SMTP id r24mr32875263edv.93.1632192460052; Mon, 20 Sep 2021 19:47:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192460; cv=none; d=google.com; s=arc-20160816; b=w7VDsMopc89BrY8VZa8UKi68A7P7llPjYzX3C6zJeNbfxlj7ppFbZFWs5eZOg+GnfL sl5mSzUReyfFnve9GKmFy2NJ+16ExPeHx5aWiF5cGoRg6ZVCFXjhjBqWNfaTxt7hR6DY /xYPcG3lK3jq6kMmQTzq20LxlP5zomZ1FbcfSnXT5TcRJdxiIR/t7vAnPp2i5whDnTuG fk5u5QafPLRAuK3jiqmgH/t+m8tQVPZZhZV5s5BHEY/JYsOpPD6kdzsQtio/JOKS7KU8 1//Hg87/YlygJMZaPGnRHydctsXwx6wArdcIwcmKbmSEFPSiTqIFedW9jHpkXCBi79LC sUJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8qqDJ7NLrhPYG7TmpSP73OpHvbuh4ldjEVUM1bUbtWU=; b=KuC1Jfbi51MP94wrA+ezkTOJlHKHcpwWI2WCstjldCnSYcEulDVzMxgeWuJpJQvp2W 8ZUYpT9LjIqN54mGsPGXk1FJ0+MI53PSfFU4B7oKd/FWF7ySKQfGTfHrc+9rwNk9raUL sTo3FLHdAvEoYLmsZnFmXSeduyl3eTcrFPtE6kBMXzyuNA7UehwnE8fA8/v2TjSnhgn+ 1isgxm2pabVm6Mw0l0MyDE5O1bP5JXmgzO1uYtcjy/AlvtpS9c461YriI1LtnDxn3obO 89vvUMvxMvEPjfE1zTqfCxjwOLREiGrj4EdliqeAE6rt/4S372qI+sjOl2e9nXkwDvmi WRkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bcdT5SSf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hz18si18339008ejc.412.2021.09.20.19.47.16; Mon, 20 Sep 2021 19:47:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bcdT5SSf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238026AbhITS3w (ORCPT + 99 others); Mon, 20 Sep 2021 14:29:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:43766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378179AbhITSX1 (ORCPT ); Mon, 20 Sep 2021 14:23:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ED32461A7D; Mon, 20 Sep 2021 17:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158682; bh=axt4RgSMSFoQ1IYmeYZTr36aIoc0JBcAdtTEwp9SDqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bcdT5SSfc0KULKuVAvo1/zjebp34bBo1QaTLrIWkDqUXAbONwJdNLf1ePiEWksdOW dXurFwJEDORGlJyXXdzxVnqZOm5rNWiFi0sp4XRX/I9YYo+bmyB8a1g5aRw1/xeV/i o4YCbJkBwhNad23um9zA2ZJtwIF20A8xUIj1XxZM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Florian Fainelli , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 255/260] net: dsa: b53: Fix calculating number of switch ports Date: Mon, 20 Sep 2021 18:44:33 +0200 Message-Id: <20210920163939.776599103@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafał Miłecki [ Upstream commit cdb067d31c0fe4cce98b9d15f1f2ef525acaa094 ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 e78b683f7305..825d840cdb8c 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -2353,9 +2353,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)) { -- 2.30.2