Skip to content

Commit 87f062e

Browse files
oleremkuba-moo
authored andcommitted
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>
1 parent bed7b22 commit 87f062e

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

drivers/net/dsa/microchip/ksz8.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,9 @@ int ksz8_reset_switch(struct ksz_device *dev);
5656
int ksz8_switch_init(struct ksz_device *dev);
5757
void ksz8_switch_exit(struct ksz_device *dev);
5858
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);
5963

6064
#endif

drivers/net/dsa/microchip/ksz8795.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,57 @@ void ksz8_config_cpu_port(struct dsa_switch *ds)
14391439
}
14401440
}
14411441

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+
14421493
static int ksz8_handle_global_errata(struct dsa_switch *ds)
14431494
{
14441495
struct ksz_device *dev = ds->priv;
@@ -1487,8 +1538,6 @@ int ksz8_setup(struct dsa_switch *ds)
14871538
*/
14881539
ds->vlan_filtering_is_global = true;
14891540

1490-
ksz_cfg(dev, S_REPLACE_VID_CTRL, SW_FLOW_CTRL, true);
1491-
14921541
/* Enable automatic fast aging when link changed detected. */
14931542
ksz_cfg(dev, S_LINK_AGING_CTRL, SW_LINK_AUTO_AGING, true);
14941543

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
277277
.mirror_add = ksz8_port_mirror_add,
278278
.mirror_del = ksz8_port_mirror_del,
279279
.get_caps = ksz8_get_caps,
280+
.phylink_mac_link_up = ksz8_phylink_mac_link_up,
280281
.config_cpu_port = ksz8_config_cpu_port,
281282
.enable_stp_addr = ksz8_enable_stp_addr,
282283
.reset = ksz8_reset_switch,

0 commit comments

Comments
 (0)