diff options
| -rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c | 27 | 
1 files changed, 20 insertions, 7 deletions
| diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c index 2e0b704b8a31..f32c83603b84 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c @@ -46,6 +46,7 @@ struct mlxsw_sp2_ptp_state {  					  * enabled.  					  */  	struct hwtstamp_config config; +	struct mutex lock; /* Protects 'config' and HW configuration. */  };  struct mlxsw_sp1_ptp_key { @@ -1374,6 +1375,7 @@ struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)  		goto err_ptp_traps_set;  	refcount_set(&ptp_state->ptp_port_enabled_ref, 0); +	mutex_init(&ptp_state->lock);  	return &ptp_state->common;  err_ptp_traps_set: @@ -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); +	mutex_destroy(&ptp_state->lock);  	mlxsw_sp_ptp_traps_unset(mlxsw_sp);  	kfree(ptp_state);  } @@ -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); +	mutex_lock(&ptp_state->lock);  	*config = ptp_state->config; +	mutex_unlock(&ptp_state->lock); +  	return 0;  } @@ -1574,8 +1580,6 @@ static int mlxsw_sp2_ptp_configure_port(struct mlxsw_sp_port *mlxsw_sp_port,  	struct mlxsw_sp2_ptp_state *ptp_state;  	int err; -	ASSERT_RTNL(); -  	ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);  	if (refcount_inc_not_zero(&ptp_state->ptp_port_enabled_ref)) @@ -1597,8 +1601,6 @@ static int mlxsw_sp2_ptp_deconfigure_port(struct mlxsw_sp_port *mlxsw_sp_port,  	struct mlxsw_sp2_ptp_state *ptp_state;  	int err; -	ASSERT_RTNL(); -  	ptp_state = mlxsw_sp2_ptp_state(mlxsw_sp_port->mlxsw_sp);  	if (!refcount_dec_and_test(&ptp_state->ptp_port_enabled_ref)) @@ -1618,16 +1620,20 @@ err_ptp_disable:  int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,  			       struct hwtstamp_config *config)  { +	struct mlxsw_sp2_ptp_state *ptp_state;  	enum hwtstamp_rx_filters rx_filter;  	struct hwtstamp_config new_config;  	u16 new_ing_types, new_egr_types;  	bool ptp_enabled;  	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,  					      &new_egr_types, &rx_filter);  	if (err) -		return err; +		goto err_get_message_types;  	new_config.flags = config->flags;  	new_config.tx_type = config->tx_type; @@ -1640,11 +1646,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,  						   new_egr_types, new_config);  		if (err) -			return err; +			goto err_configure_port;  	} else if (!new_ing_types && !new_egr_types && ptp_enabled) {  		err = mlxsw_sp2_ptp_deconfigure_port(mlxsw_sp_port, new_config);  		if (err) -			return err; +			goto err_deconfigure_port;  	}  	mlxsw_sp_port->ptp.ing_types = new_ing_types; @@ -1652,8 +1658,15 @@ int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,  	/* Notify the ioctl caller what we are actually timestamping. */  	config->rx_filter = rx_filter; +	mutex_unlock(&ptp_state->lock);  	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, | 
