OSDN Git Service

mlxsw: spectrum: Set up PTP shaper when port status has changed
authorShalom Toledo <shalomt@mellanox.com>
Thu, 4 Jul 2019 07:07:39 +0000 (10:07 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 5 Jul 2019 22:28:57 +0000 (15:28 -0700)
When getting port up down event (PUDE), change the PTP shaper
configuration based on hardware time stamping on/off and the port's
speed.

Signed-off-by: Shalom Toledo <shalomt@mellanox.com>
Reviewed-by: Petr Machata <petrm@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/spectrum.h
drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.h

index 7cfca2b..ce285fb 100644 (file)
@@ -171,6 +171,7 @@ struct mlxsw_sp_ptp_ops {
                            struct hwtstamp_config *config);
        int (*hwtstamp_set)(struct mlxsw_sp_port *mlxsw_sp_port,
                            struct hwtstamp_config *config);
+       void (*shaper_work)(struct work_struct *work);
        int (*get_ts_info)(struct mlxsw_sp *mlxsw_sp,
                           struct ethtool_ts_info *info);
 };
@@ -3716,6 +3717,9 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
        }
        mlxsw_sp_port->default_vlan = mlxsw_sp_port_vlan;
 
+       INIT_DELAYED_WORK(&mlxsw_sp_port->ptp.shaper_dw,
+                         mlxsw_sp->ptp_ops->shaper_work);
+
        mlxsw_sp->ports[local_port] = mlxsw_sp_port;
        err = register_netdev(dev);
        if (err) {
@@ -3770,6 +3774,7 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u8 local_port)
        struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
 
        cancel_delayed_work_sync(&mlxsw_sp_port->periodic_hw_stats.update_dw);
+       cancel_delayed_work_sync(&mlxsw_sp_port->ptp.shaper_dw);
        mlxsw_sp_port_ptp_clear(mlxsw_sp_port);
        mlxsw_core_port_clear(mlxsw_sp->core, local_port, mlxsw_sp);
        unregister_netdev(mlxsw_sp_port->dev); /* This calls ndo_stop */
@@ -4055,6 +4060,7 @@ static void mlxsw_sp_pude_event_func(const struct mlxsw_reg_info *reg,
        if (status == MLXSW_PORT_OPER_STATUS_UP) {
                netdev_info(mlxsw_sp_port->dev, "link up\n");
                netif_carrier_on(mlxsw_sp_port->dev);
+               mlxsw_core_schedule_dw(&mlxsw_sp_port->ptp.shaper_dw, 0);
        } else {
                netdev_info(mlxsw_sp_port->dev, "link down\n");
                netif_carrier_off(mlxsw_sp_port->dev);
@@ -4572,6 +4578,7 @@ static const struct mlxsw_sp_ptp_ops mlxsw_sp1_ptp_ops = {
        .transmitted    = mlxsw_sp1_ptp_transmitted,
        .hwtstamp_get   = mlxsw_sp1_ptp_hwtstamp_get,
        .hwtstamp_set   = mlxsw_sp1_ptp_hwtstamp_set,
+       .shaper_work    = mlxsw_sp1_ptp_shaper_work,
        .get_ts_info    = mlxsw_sp1_ptp_get_ts_info,
 };
 
@@ -4584,6 +4591,7 @@ static const struct mlxsw_sp_ptp_ops mlxsw_sp2_ptp_ops = {
        .transmitted    = mlxsw_sp2_ptp_transmitted,
        .hwtstamp_get   = mlxsw_sp2_ptp_hwtstamp_get,
        .hwtstamp_set   = mlxsw_sp2_ptp_hwtstamp_set,
+       .shaper_work    = mlxsw_sp2_ptp_shaper_work,
        .get_ts_info    = mlxsw_sp2_ptp_get_ts_info,
 };
 
index c21cd1a..abbb563 100644 (file)
@@ -267,6 +267,7 @@ struct mlxsw_sp_port {
        struct mlxsw_sp_acl_block *ing_acl_block;
        struct mlxsw_sp_acl_block *eg_acl_block;
        struct {
+               struct delayed_work shaper_dw;
                struct hwtstamp_config hwtstamp_config;
                u16 ing_types;
                u16 egr_types;
index 49aba0c..0f7c4bd 100644 (file)
@@ -1000,6 +1000,23 @@ static int mlxsw_sp1_ptp_port_shaper_check(struct mlxsw_sp_port *mlxsw_sp_port)
        return mlxsw_sp1_ptp_port_shaper_set(mlxsw_sp_port, ptps);
 }
 
+void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
+{
+       struct delayed_work *dwork = to_delayed_work(work);
+       struct mlxsw_sp_port *mlxsw_sp_port;
+       int err;
+
+       mlxsw_sp_port = container_of(dwork, struct mlxsw_sp_port,
+                                    ptp.shaper_dw);
+
+       if (!mlxsw_sp1_ptp_hwtstamp_enabled(mlxsw_sp_port))
+               return;
+
+       err = mlxsw_sp1_ptp_port_shaper_check(mlxsw_sp_port);
+       if (err)
+               netdev_err(mlxsw_sp_port->dev, "Failed to set up PTP shaper\n");
+}
+
 int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
                               struct hwtstamp_config *config)
 {
index b23abfc..72e55f6 100644 (file)
@@ -54,6 +54,8 @@ int mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
 int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
                               struct hwtstamp_config *config);
 
+void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
+
 int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
                              struct ethtool_ts_info *info);
 
@@ -113,6 +115,10 @@ mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
        return -EOPNOTSUPP;
 }
 
+static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
+{
+}
+
 static inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
                                            struct ethtool_ts_info *info)
 {
@@ -167,6 +173,10 @@ mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
        return -EOPNOTSUPP;
 }
 
+static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
+{
+}
+
 static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
                                            struct ethtool_ts_info *info)
 {