Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: microchip: ksz8: Make flow control, speed, and duplex on CPU port configurable

Allow flow control, speed, and duplex settings on the CPU port to be
configurable. Previously, the speed and duplex relied on default switch
values, which limited flexibility. Additionally, flow control was
hardcoded and only functional in duplex mode. This update enhances the
configurability of these parameters.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://lore.kernel.org/r/20231127145101.3039399-2-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Oleksij Rempel and committed by
Jakub Kicinski
87f062ed bed7b22e

+56 -2
+4
drivers/net/dsa/microchip/ksz8.h
··· 56 56 int ksz8_switch_init(struct ksz_device *dev); 57 57 void ksz8_switch_exit(struct ksz_device *dev); 58 58 int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu); 59 + void ksz8_phylink_mac_link_up(struct ksz_device *dev, int port, 60 + unsigned int mode, phy_interface_t interface, 61 + struct phy_device *phydev, int speed, int duplex, 62 + bool tx_pause, bool rx_pause); 59 63 60 64 #endif
+51 -2
drivers/net/dsa/microchip/ksz8795.c
··· 1439 1439 } 1440 1440 } 1441 1441 1442 + /** 1443 + * ksz8_cpu_port_link_up - Configures the CPU port of the switch. 1444 + * @dev: The KSZ device instance. 1445 + * @speed: The desired link speed. 1446 + * @duplex: The desired duplex mode. 1447 + * @tx_pause: If true, enables transmit pause. 1448 + * @rx_pause: If true, enables receive pause. 1449 + * 1450 + * Description: 1451 + * The function configures flow control and speed settings for the CPU 1452 + * port of the switch based on the desired settings, current duplex mode, and 1453 + * speed. 1454 + */ 1455 + static void ksz8_cpu_port_link_up(struct ksz_device *dev, int speed, int duplex, 1456 + bool tx_pause, bool rx_pause) 1457 + { 1458 + const u16 *regs = dev->info->regs; 1459 + u8 ctrl = 0; 1460 + 1461 + /* SW_FLOW_CTRL, SW_HALF_DUPLEX, and SW_10_MBIT bits are bootstrappable 1462 + * at least on KSZ8873. They can have different values depending on your 1463 + * board setup. 1464 + */ 1465 + if (tx_pause || rx_pause) 1466 + ctrl |= SW_FLOW_CTRL; 1467 + 1468 + if (duplex == DUPLEX_HALF) 1469 + ctrl |= SW_HALF_DUPLEX; 1470 + 1471 + /* This hardware only supports SPEED_10 and SPEED_100. For SPEED_10 1472 + * we need to set the SW_10_MBIT bit. Otherwise, we can leave it 0. 1473 + */ 1474 + if (speed == SPEED_10) 1475 + ctrl |= SW_10_MBIT; 1476 + 1477 + ksz_rmw8(dev, regs[S_BROADCAST_CTRL], SW_HALF_DUPLEX | SW_FLOW_CTRL | 1478 + SW_10_MBIT, ctrl); 1479 + } 1480 + 1481 + void ksz8_phylink_mac_link_up(struct ksz_device *dev, int port, 1482 + unsigned int mode, phy_interface_t interface, 1483 + struct phy_device *phydev, int speed, int duplex, 1484 + bool tx_pause, bool rx_pause) 1485 + { 1486 + /* If the port is the CPU port, apply special handling. Only the CPU 1487 + * port is configured via global registers. 1488 + */ 1489 + if (dev->cpu_port == port) 1490 + ksz8_cpu_port_link_up(dev, speed, duplex, tx_pause, rx_pause); 1491 + } 1492 + 1442 1493 static int ksz8_handle_global_errata(struct dsa_switch *ds) 1443 1494 { 1444 1495 struct ksz_device *dev = ds->priv; ··· 1537 1486 * Enable flag 1538 1487 */ 1539 1488 ds->vlan_filtering_is_global = true; 1540 - 1541 - ksz_cfg(dev, S_REPLACE_VID_CTRL, SW_FLOW_CTRL, true); 1542 1489 1543 1490 /* Enable automatic fast aging when link changed detected. */ 1544 1491 ksz_cfg(dev, S_LINK_AGING_CTRL, SW_LINK_AUTO_AGING, true);
+1
drivers/net/dsa/microchip/ksz_common.c
··· 277 277 .mirror_add = ksz8_port_mirror_add, 278 278 .mirror_del = ksz8_port_mirror_del, 279 279 .get_caps = ksz8_get_caps, 280 + .phylink_mac_link_up = ksz8_phylink_mac_link_up, 280 281 .config_cpu_port = ksz8_config_cpu_port, 281 282 .enable_stp_addr = ksz8_enable_stp_addr, 282 283 .reset = ksz8_reset_switch,