1 From cdb067d31c0fe4cce98b9d15f1f2ef525acaa094 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Thu, 2 Sep 2021 10:30:50 +0200
4 Subject: [PATCH] net: dsa: b53: Fix calculating number of switch ports
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 It isn't true that CPU port is always the last one. Switches BCM5301x
10 have 9 ports (port 6 being inactive) and they use port 5 as CPU by
11 default (depending on design some other may be CPU ports too).
13 A more reliable way of determining number of ports is to check for the
14 last set bit in the "enabled_ports" bitfield.
16 This fixes b53 internal state, it will allow providing accurate info to
17 the DSA and is required to fix BCM5301x support.
19 Fixes: 967dd82ffc52 ("net: dsa: b53: Add support for Broadcom RoboSwitch")
20 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
21 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
22 Signed-off-by: David S. Miller <davem@davemloft.net>
24 drivers/net/dsa/b53/b53_common.c | 3 +--
25 1 file changed, 1 insertion(+), 2 deletions(-)
27 --- a/drivers/net/dsa/b53/b53_common.c
28 +++ b/drivers/net/dsa/b53/b53_common.c
29 @@ -2556,9 +2556,8 @@ static int b53_switch_init(struct b53_de
33 - /* cpu port is always last */
34 - dev->num_ports = dev->cpu_port + 1;
35 dev->enabled_ports |= BIT(dev->cpu_port);
36 + dev->num_ports = fls(dev->enabled_ports);
38 /* Include non standard CPU port built-in PHYs to be probed */
39 if (is539x(dev) || is531x5(dev)) {