net: dsa: microchip: fix devicetree parsing of cpu node
PATCH 1/2 net: dsa: microchip: fix devicetree parsing of cpu node
From: Sven Van Asbroeck <[email protected]>
On the ksz8795, if the devicetree contains a cpu node, devicetree parsing fails and the whole driver errors out.
Fix the devicetree parsing code by making it use the correct number of ports.
---
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git # 905b2032fa42
To: Woojung Huh <[email protected]>
To: Microchip Linux Driver Support <[email protected]>
To: Andrew Lunn <[email protected]>
To: Vivien Didelot <[email protected]>
To: Florian Fainelli <[email protected]>
To: Vladimir Oltean <[email protected]>
To: "David S. Miller" <[email protected]>
To: Jakub Kicinski <[email protected]>
Cc: Helmut Grohne <[email protected]>
Cc: [email protected]
Cc: [email protected]
drivers/net/dsa/microchip/ksz_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/microchip/ksz_common.c +1 -1
@@ -431,7 +431,7 @@ int ksz_switch_register(struct ksz_device *dev,if (of_property_read_u32 (port,"reg" , &port_num))continue ; -if (port_num >= dev->port_cnt) +if (port_num >= dev->ds->num_ports)return -EINVAL ;of_get_phy_mode (port, &dev->ports[port_num].interface);
Signature · 1 line
2.17.1
PATCH 2/2 net: dsa: microchip: improve port count comments
From: Sven Van Asbroeck <[email protected]>
Port counts in microchip dsa drivers can be quite confusing:
on the ksz8795, ksz_chip_data->port_cnt excludes the cpu port, yet on the ksz9477, it includes the cpu port.
Add comments to document this situation explicitly.
---
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git # 905b2032fa42
To: Woojung Huh <[email protected]>
To: Microchip Linux Driver Support <[email protected]>
To: Andrew Lunn <[email protected]>
To: Vivien Didelot <[email protected]>
To: Florian Fainelli <[email protected]>
To: Vladimir Oltean <[email protected]>
To: "David S. Miller" <[email protected]>
To: Jakub Kicinski <[email protected]>
Cc: Helmut Grohne <[email protected]>
Cc: [email protected]
Cc: [email protected]
drivers/net/dsa/microchip/ksz8795.c | 12 +++++++++--- drivers/net/dsa/microchip/ksz9477.c | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +9 -3
@@ -1190,7 +1190,9 @@ static const struct ksz_chip_data ksz8795_switch_chips[] = { .num_alus = 0, .num_statics = 8, .cpu_ports = 0x10, /* can be configured as cpu port */ - .port_cnt = 4, /* total physical port count */ + .port_cnt = 4, /* total physical port count, excluding + * the cpu port + */ }, { .chip_id = 0x8794,
@@ -1199,7 +1201,9 @@ static const struct ksz_chip_data ksz8795_switch_chips[] = { .num_alus = 0, .num_statics = 8, .cpu_ports = 0x10, /* can be configured as cpu port */ - .port_cnt = 3, /* total physical port count */ + .port_cnt = 3, /* total physical port count, excluding + * the cpu port + */ }, { .chip_id = 0x8765,
@@ -1208,7 +1212,9 @@ static const struct ksz_chip_data ksz8795_switch_chips[] = { .num_alus = 0, .num_statics = 8, .cpu_ports = 0x10, /* can be configured as cpu port */ - .port_cnt = 4, /* total physical port count */ + .port_cnt = 4, /* total physical port count, excluding + * the cpu port + */ }, };
drivers/net/dsa/microchip/ksz9477.c +12 -4
@@ -1482,7 +1482,9 @@ static const struct ksz_chip_data ksz9477_switch_chips[] = { .num_alus = 4096, .num_statics = 16, .cpu_ports = 0x7F, /* can be configured as cpu port */ - .port_cnt = 7, /* total physical port count */ + .port_cnt = 7, /* total physical port count, including + * the cpu port + */ .phy_errata_9477 = true, }, {
@@ -1492,7 +1494,9 @@ static const struct ksz_chip_data ksz9477_switch_chips[] = { .num_alus = 4096, .num_statics = 16, .cpu_ports = 0x7F, /* can be configured as cpu port */ - .port_cnt = 7, /* total physical port count */ + .port_cnt = 7, /* total physical port count, including + * the cpu port + */ .phy_errata_9477 = true, }, {
@@ -1502,7 +1506,9 @@ static const struct ksz_chip_data ksz9477_switch_chips[] = { .num_alus = 4096, .num_statics = 16, .cpu_ports = 0x07, /* can be configured as cpu port */ - .port_cnt = 3, /* total port count */ + .port_cnt = 3, /* total physical port count, including + * the cpu port + */ }, { .chip_id = 0x00956700,
@@ -1511,7 +1517,9 @@ static const struct ksz_chip_data ksz9477_switch_chips[] = { .num_alus = 4096, .num_statics = 16, .cpu_ports = 0x7F, /* can be configured as cpu port */ - .port_cnt = 7, /* total physical port count */ + .port_cnt = 7, /* total physical port count, including + * the cpu port + */ }, };
Signature · 1 line
2.17.1
Andrew Lunn
maintainerRe: [PATCH net v1 2/2] net: dsa: microchip: improve port count comments
Quoted 7 lines · Sven Van Asbroeck
From: Sven Van Asbroeck <[email protected]>
Port counts in microchip dsa drivers can be quite confusing:
on the ksz8795,ksz_chip_data->port_cntexcludes the cpu port, yet on the ksz9477, it includes the cpu port.Add comments to document this situation explicitly.
Rather than document it, we should make it uniform. Unless there is a valid reason to require them to mean different things.
Andrew
Jakub Kicinski
maintainerRe: [PATCH net v1 2/2] net: dsa: microchip: improve port count comments
Quoted 11 lines · On Tue, 8 Dec 2020 00:31:16 +0100 Andrew Lunn wrote:
Quoted 7 lines · Sven Van Asbroeck
From: Sven Van Asbroeck <[email protected]>
Port counts in microchip dsa drivers can be quite confusing:
on the ksz8795,ksz_chip_data->port_cntexcludes the cpu port, yet on the ksz9477, it includes the cpu port.Add comments to document this situation explicitly.
Rather than document it, we should make it uniform. Unless there is a valid reason to require them to mean different things.
Agreed.
I wonder if we should make this effort target net-next.
My concern is that for the 3 port switch the cpu_ports variable is set to 0x10, the same as for the 4 port one. Which makes me worried that if we just allow the "+ 1" - the CPU port will not actually hit the register offsets its supposed to on 3 port platforms.
Since configuring the CPU port never worked here (AFAICT) we can view this as a new feature / config option (even tho an important one).
So let's move to net-next, and we can "do this right".
Does that sound sane?
Andrew, Jakub,
Quoted 6 lines · Sven Van Asbroeck
From: Sven Van Asbroeck <[email protected]>
On the ksz8795, if the devicetree contains a cpu node, devicetree parsing fails and the whole driver errors out.
Quoted 7 lines
Fix the devicetree parsing code by making it use the correct number of ports.
Fixes 912aae27c6af ("net: dsa: microchip: really look for phy-mode in port nodes")Signed-off-by Sven Van Asbroeck <[email protected]>---
Any chance that this patch could still get merged?
I believe this will work fine on both ksz8795 and ksz9477, even though num_ports is defined differently, because:
ksz8795:
/* set the real number of ports */dev->ds->num_ports = dev->port_cnt + 1;
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/dsa/microchip/ksz8795.c?h=v5.10-rc7#n1266
ksz9477:
/* set the real number of ports */dev->ds->num_ports = dev->port_cnt;
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/dsa/microchip/ksz9477.c?h=v5.10-rc7#n1585
Would it be possible to merge this into net, so users get working cpu nodes? I don't think this will prevent you from harmonizing port_cnt in net-next.
Jakub Kicinski
maintainerQuoted 26 lines · On Tue, 8 Dec 2020 10:33:28 -0500 Sven Van Asbroeck wrote:
Andrew, Jakub,
Quoted 6 lines · Sven Van Asbroeck
From: Sven Van Asbroeck <[email protected]>
On the ksz8795, if the devicetree contains a cpu node, devicetree parsing fails and the whole driver errors out.
Quoted 7 lines
Fix the devicetree parsing code by making it use the correct number of ports.
Fixes 912aae27c6af ("net: dsa: microchip: really look for phy-mode in port nodes")Signed-off-by Sven Van Asbroeck <[email protected]>---
Any chance that this patch could still get merged?
I believe this will work fine on both ksz8795 and ksz9477, even thoughnum_portsis defined differently, because:ksz8795:
/* set the real number of ports */dev->ds->num_ports=dev->port_cnt+ 1;
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/dsa/microchip/ksz8795.c?h=v5.10-rc7#n1266
Quoted 7 lines
ksz9477:
/* set the real number of ports */dev->ds->num_ports=dev->port_cnt;
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/dsa/microchip/ksz9477.c?h=v5.10-rc7#n1585Would it be possible to merge this into net, so users get working cpu nodes? I don't think this will prevent you from harmonizing
port_cntin net-next.
What I was talking about in the email yesterday was 0x8794 support in ksz8795.c. Is the cpu port configuration going to work there? Isn't the CPU port always port 5 (index 4)?
It sure as hell looked like it until commit c9f4633b93ea ("net: dsa:
microchip: remove usage of mib_port_count") came along. I wonder if ksz8794 works on net-next :/
Quoted 4 lines · Jakub Kicinski
What I was talking about in the email yesterday was
0x8794support inksz8795.c. Is the cpu port configuration going to work there? Isn't the CPU port always port 5 (index 4)?
Understood. You expressed concern that .cpu_ports = 0x10 even on the 3-port switch.
I noticed that .cpu_ports is never used in ksz8794.c, so I hoped the fix would be fine. But digging a bit deeper, I see in ksz8795.c:
dev->mib_port_cnt = TOTAL_PORT_NUM; /* = 5 */
...
dev->cpu_port = dev->mib_port_cnt - 1; /* = 4 */And that is unlikely to work on the 3-port switch.
So yeah, you are right, my patch won't fix the general issues here :(