This commit allows the setting of the MAC table aging in the R-Car S4 Rswitch using the SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME attribute. Signed-off-by: Michael Dege --- drivers/net/ethernet/renesas/rswitch.h | 1 + drivers/net/ethernet/renesas/rswitch_l2.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/net/ethernet/renesas/rswitch.h b/drivers/net/ethernet/renesas/rswitch.h index 45a9d02c5b5d3e7b62554bd56c6c0cb9231f684c..11ff1102668b081e395664ea73e19e0ecef74e24 100644 --- a/drivers/net/ethernet/renesas/rswitch.h +++ b/drivers/net/ethernet/renesas/rswitch.h @@ -849,6 +849,7 @@ enum rswitch_gwca_mode { #define FWMACAGC_MACDESOG BIT(29) #define RSW_AGEING_TIME 300 +#define RSW_MAX_AGEING_TIME 65535 /* TOP */ #define TPEMIMC7(queue) (TPEMIMC70 + (queue) * 4) diff --git a/drivers/net/ethernet/renesas/rswitch_l2.c b/drivers/net/ethernet/renesas/rswitch_l2.c index 242beb1f15c089585f5fe5019f626df8824b971a..c8a8a60a20e70f7ce421280ed35c0c4afe1ed039 100644 --- a/drivers/net/ethernet/renesas/rswitch_l2.c +++ b/drivers/net/ethernet/renesas/rswitch_l2.c @@ -196,6 +196,30 @@ static int rswitch_netdevice_event(struct notifier_block *nb, return NOTIFY_OK; } +static int rswitch_update_ageing_time(struct net_device *ndev, clock_t time) +{ + struct rswitch_device *rdev = netdev_priv(ndev); + u32 reg_val, time_val; + + if (!is_rdev(ndev)) + return -ENODEV; + + /* Although brctl accepts the ageing time parameter in seconds, the value + * passed to the driver is multiplied by 100. We need it in seconds. + */ + time_val = (u32)time / 100; + + if (time_val > RSW_MAX_AGEING_TIME) + return -EINVAL; + + rdev = netdev_priv(ndev); + reg_val = FIELD_PREP(FWMACAGC_MACAGT, time_val); + reg_val |= FWMACAGC_MACAGE | FWMACAGC_MACAGSL; + iowrite32(reg_val, rdev->priv->addr + FWMACAGC); + + return 0; +} + static int rswitch_port_attr_set(struct net_device *ndev, const void *ctx, const struct switchdev_attr *attr, struct netlink_ext_ack *extack) @@ -203,6 +227,8 @@ static int rswitch_port_attr_set(struct net_device *ndev, const void *ctx, switch (attr->id) { case SWITCHDEV_ATTR_ID_PORT_STP_STATE: return rswitch_port_update_stp_state(ndev, attr->u.stp_state); + case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME: + return rswitch_update_ageing_time(ndev, attr->u.ageing_time); default: return -EOPNOTSUPP; } -- 2.49.0