Commit 5061e34c authored by David S. Miller's avatar David S. Miller

Merge branch 'mlxsw-fixes'

Petr Machata says:

====================
mlxsw: Fixes for PTP support

This set fixes several issues in mlxsw PTP code.

- Patch #1 fixes compilation warnings.

- Patch #2 adjusts the order of operation during cleanup, thereby
  closing the window after PTP state was already cleaned in the ASIC
  for the given port, but before the port is removed, when the user
  could still in theory make changes to the configuration.

- Patch #3 protects the PTP configuration with a custom mutex, instead
  of relying on RTNL, which is not held in all access paths.

- Patch #4 forbids enablement of PTP only in RX or only in TX. The
  driver implicitly assumed this would be the case, but neglected to
  sanitize the configuration.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 02799571 e01885c3
...@@ -1897,9 +1897,9 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port) ...@@ -1897,9 +1897,9 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port)
cancel_delayed_work_sync(&mlxsw_sp_port->periodic_hw_stats.update_dw); cancel_delayed_work_sync(&mlxsw_sp_port->periodic_hw_stats.update_dw);
cancel_delayed_work_sync(&mlxsw_sp_port->ptp.shaper_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); mlxsw_core_port_clear(mlxsw_sp->core, local_port, mlxsw_sp);
unregister_netdev(mlxsw_sp_port->dev); /* This calls ndo_stop */ unregister_netdev(mlxsw_sp_port->dev); /* This calls ndo_stop */
mlxsw_sp_port_ptp_clear(mlxsw_sp_port);
mlxsw_sp_port_vlan_classification_set(mlxsw_sp_port, true, true); mlxsw_sp_port_vlan_classification_set(mlxsw_sp_port, true, true);
mlxsw_sp->ports[local_port] = NULL; mlxsw_sp->ports[local_port] = NULL;
mlxsw_sp_port_vlan_flush(mlxsw_sp_port, true); mlxsw_sp_port_vlan_flush(mlxsw_sp_port, true);
......
...@@ -46,6 +46,7 @@ struct mlxsw_sp2_ptp_state { ...@@ -46,6 +46,7 @@ struct mlxsw_sp2_ptp_state {
* enabled. * enabled.
*/ */
struct hwtstamp_config config; struct hwtstamp_config config;
struct mutex lock; /* Protects 'config' and HW configuration. */
}; };
struct mlxsw_sp1_ptp_key { struct mlxsw_sp1_ptp_key {
...@@ -1374,6 +1375,7 @@ struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp) ...@@ -1374,6 +1375,7 @@ struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
goto err_ptp_traps_set; goto err_ptp_traps_set;
refcount_set(&ptp_state->ptp_port_enabled_ref, 0); refcount_set(&ptp_state->ptp_port_enabled_ref, 0);
mutex_init(&ptp_state->lock);
return &ptp_state->common; return &ptp_state->common;
err_ptp_traps_set: err_ptp_traps_set:
...@@ -1388,6 +1390,7 @@ void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state_common) ...@@ -1388,6 +1390,7 @@ void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state_common)
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp); ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp);
mutex_destroy(&ptp_state->lock);
mlxsw_sp_ptp_traps_unset(mlxsw_sp); mlxsw_sp_ptp_traps_unset(mlxsw_sp);
kfree(ptp_state); kfree(ptp_state);
} }
...@@ -1461,7 +1464,10 @@ int mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1461,7 +1464,10 @@ int mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp); ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);
mutex_lock(&ptp_state->lock);
*config = ptp_state->config; *config = ptp_state->config;
mutex_unlock(&ptp_state->lock);
return 0; return 0;
} }
...@@ -1523,6 +1529,9 @@ mlxsw_sp2_ptp_get_message_types(const struct hwtstamp_config *config, ...@@ -1523,6 +1529,9 @@ mlxsw_sp2_ptp_get_message_types(const struct hwtstamp_config *config,
return -EINVAL; return -EINVAL;
} }
if ((ing_types && !egr_types) || (!ing_types && egr_types))
return -EINVAL;
*p_ing_types = ing_types; *p_ing_types = ing_types;
*p_egr_types = egr_types; *p_egr_types = egr_types;
return 0; return 0;
...@@ -1574,8 +1583,6 @@ static int mlxsw_sp2_ptp_configure_port(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1574,8 +1583,6 @@ static int mlxsw_sp2_ptp_configure_port(struct mlxsw_sp_port *mlxsw_sp_port,
struct mlxsw_sp2_ptp_state *ptp_state; struct mlxsw_sp2_ptp_state *ptp_state;
int err; int err;
ASSERT_RTNL();
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp); ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);
if (refcount_inc_not_zero(&ptp_state->ptp_port_enabled_ref)) if (refcount_inc_not_zero(&ptp_state->ptp_port_enabled_ref))
...@@ -1597,8 +1604,6 @@ static int mlxsw_sp2_ptp_deconfigure_port(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1597,8 +1604,6 @@ static int mlxsw_sp2_ptp_deconfigure_port(struct mlxsw_sp_port *mlxsw_sp_port,
struct mlxsw_sp2_ptp_state *ptp_state; struct mlxsw_sp2_ptp_state *ptp_state;
int err; int err;
ASSERT_RTNL();
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp); ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);
if (!refcount_dec_and_test(&ptp_state->ptp_port_enabled_ref)) if (!refcount_dec_and_test(&ptp_state->ptp_port_enabled_ref))
...@@ -1618,16 +1623,20 @@ static int mlxsw_sp2_ptp_deconfigure_port(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1618,16 +1623,20 @@ static int mlxsw_sp2_ptp_deconfigure_port(struct mlxsw_sp_port *mlxsw_sp_port,
int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port, int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
struct hwtstamp_config *config) struct hwtstamp_config *config)
{ {
struct mlxsw_sp2_ptp_state *ptp_state;
enum hwtstamp_rx_filters rx_filter; enum hwtstamp_rx_filters rx_filter;
struct hwtstamp_config new_config; struct hwtstamp_config new_config;
u16 new_ing_types, new_egr_types; u16 new_ing_types, new_egr_types;
bool ptp_enabled; bool ptp_enabled;
int err; int err;
ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);
mutex_lock(&ptp_state->lock);
err = mlxsw_sp2_ptp_get_message_types(config, &new_ing_types, err = mlxsw_sp2_ptp_get_message_types(config, &new_ing_types,
&new_egr_types, &rx_filter); &new_egr_types, &rx_filter);
if (err) if (err)
return err; goto err_get_message_types;
new_config.flags = config->flags; new_config.flags = config->flags;
new_config.tx_type = config->tx_type; new_config.tx_type = config->tx_type;
...@@ -1640,11 +1649,11 @@ int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1640,11 +1649,11 @@ int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
err = mlxsw_sp2_ptp_configure_port(mlxsw_sp_port, new_ing_types, err = mlxsw_sp2_ptp_configure_port(mlxsw_sp_port, new_ing_types,
new_egr_types, new_config); new_egr_types, new_config);
if (err) if (err)
return err; goto err_configure_port;
} else if (!new_ing_types && !new_egr_types && ptp_enabled) { } else if (!new_ing_types && !new_egr_types && ptp_enabled) {
err = mlxsw_sp2_ptp_deconfigure_port(mlxsw_sp_port, new_config); err = mlxsw_sp2_ptp_deconfigure_port(mlxsw_sp_port, new_config);
if (err) if (err)
return err; goto err_deconfigure_port;
} }
mlxsw_sp_port->ptp.ing_types = new_ing_types; mlxsw_sp_port->ptp.ing_types = new_ing_types;
...@@ -1652,8 +1661,15 @@ int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1652,8 +1661,15 @@ int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
/* Notify the ioctl caller what we are actually timestamping. */ /* Notify the ioctl caller what we are actually timestamping. */
config->rx_filter = rx_filter; config->rx_filter = rx_filter;
mutex_unlock(&ptp_state->lock);
return 0; return 0;
err_deconfigure_port:
err_configure_port:
err_get_message_types:
mutex_unlock(&ptp_state->lock);
return err;
} }
int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp, int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
......
...@@ -171,10 +171,11 @@ static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -171,10 +171,11 @@ static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
{ {
} }
int mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core, static inline int
struct mlxsw_sp_port *mlxsw_sp_port, mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
struct sk_buff *skb, struct mlxsw_sp_port *mlxsw_sp_port,
const struct mlxsw_tx_info *tx_info) struct sk_buff *skb,
const struct mlxsw_tx_info *tx_info)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -231,10 +232,11 @@ static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp, ...@@ -231,10 +232,11 @@ static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
return mlxsw_sp_ptp_get_ts_info_noptp(info); return mlxsw_sp_ptp_get_ts_info_noptp(info);
} }
int mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core, static inline int
struct mlxsw_sp_port *mlxsw_sp_port, mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
struct sk_buff *skb, struct mlxsw_sp_port *mlxsw_sp_port,
const struct mlxsw_tx_info *tx_info) struct sk_buff *skb,
const struct mlxsw_tx_info *tx_info)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment