Commit efee95f4 authored by Nicolas Pitre's avatar Nicolas Pitre Committed by David S. Miller

ptp_clock: future-proofing drivers against PTP subsystem becoming optional

Drivers must be ready to accept NULL from ptp_clock_register() if the
PTP clock subsystem is configured out.

This patch documents that and ensures that all drivers cope well
with a NULL return.
Signed-off-by: default avatarNicolas Pitre <nico@linaro.org>
Reviewed-by: default avatarEugenia Emantayev <eugenia@mellanox.com>
Acked-by: default avatarRichard Cochran <richardcochran@gmail.com>
Acked-by: default avatarEdward Cree <ecree@solarflare.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d270f76c
...@@ -334,7 +334,7 @@ void e1000e_ptp_init(struct e1000_adapter *adapter) ...@@ -334,7 +334,7 @@ void e1000e_ptp_init(struct e1000_adapter *adapter)
if (IS_ERR(adapter->ptp_clock)) { if (IS_ERR(adapter->ptp_clock)) {
adapter->ptp_clock = NULL; adapter->ptp_clock = NULL;
e_err("ptp_clock_register failed\n"); e_err("ptp_clock_register failed\n");
} else { } else if (adapter->ptp_clock) {
e_info("registered PHC clock\n"); e_info("registered PHC clock\n");
} }
} }
......
...@@ -669,7 +669,7 @@ void i40e_ptp_init(struct i40e_pf *pf) ...@@ -669,7 +669,7 @@ void i40e_ptp_init(struct i40e_pf *pf)
pf->ptp_clock = NULL; pf->ptp_clock = NULL;
dev_err(&pf->pdev->dev, "%s: ptp_clock_register failed\n", dev_err(&pf->pdev->dev, "%s: ptp_clock_register failed\n",
__func__); __func__);
} else { } else if (pf->ptp_clock) {
struct timespec64 ts; struct timespec64 ts;
u32 regval; u32 regval;
......
...@@ -1159,7 +1159,7 @@ void igb_ptp_init(struct igb_adapter *adapter) ...@@ -1159,7 +1159,7 @@ void igb_ptp_init(struct igb_adapter *adapter)
if (IS_ERR(adapter->ptp_clock)) { if (IS_ERR(adapter->ptp_clock)) {
adapter->ptp_clock = NULL; adapter->ptp_clock = NULL;
dev_err(&adapter->pdev->dev, "ptp_clock_register failed\n"); dev_err(&adapter->pdev->dev, "ptp_clock_register failed\n");
} else { } else if (adapter->ptp_clock) {
dev_info(&adapter->pdev->dev, "added PHC on %s\n", dev_info(&adapter->pdev->dev, "added PHC on %s\n",
adapter->netdev->name); adapter->netdev->name);
adapter->ptp_flags |= IGB_PTP_ENABLED; adapter->ptp_flags |= IGB_PTP_ENABLED;
......
...@@ -1254,7 +1254,7 @@ static long ixgbe_ptp_create_clock(struct ixgbe_adapter *adapter) ...@@ -1254,7 +1254,7 @@ static long ixgbe_ptp_create_clock(struct ixgbe_adapter *adapter)
adapter->ptp_clock = NULL; adapter->ptp_clock = NULL;
e_dev_err("ptp_clock_register failed\n"); e_dev_err("ptp_clock_register failed\n");
return err; return err;
} else } else if (adapter->ptp_clock)
e_dev_info("registered PHC device on %s\n", netdev->name); e_dev_info("registered PHC device on %s\n", netdev->name);
/* set default timestamp mode to disabled here. We do this in /* set default timestamp mode to disabled here. We do this in
......
...@@ -298,7 +298,7 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev) ...@@ -298,7 +298,7 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
if (IS_ERR(mdev->ptp_clock)) { if (IS_ERR(mdev->ptp_clock)) {
mdev->ptp_clock = NULL; mdev->ptp_clock = NULL;
mlx4_err(mdev, "ptp_clock_register failed\n"); mlx4_err(mdev, "ptp_clock_register failed\n");
} else { } else if (mdev->ptp_clock) {
mlx4_info(mdev, "registered PHC clock\n"); mlx4_info(mdev, "registered PHC clock\n");
} }
......
...@@ -273,7 +273,7 @@ void mlx5e_timestamp_init(struct mlx5e_priv *priv) ...@@ -273,7 +273,7 @@ void mlx5e_timestamp_init(struct mlx5e_priv *priv)
tstamp->ptp = ptp_clock_register(&tstamp->ptp_info, tstamp->ptp = ptp_clock_register(&tstamp->ptp_info,
&priv->mdev->pdev->dev); &priv->mdev->pdev->dev);
if (IS_ERR_OR_NULL(tstamp->ptp)) { if (IS_ERR(tstamp->ptp)) {
mlx5_core_warn(priv->mdev, "ptp_clock_register failed %ld\n", mlx5_core_warn(priv->mdev, "ptp_clock_register failed %ld\n",
PTR_ERR(tstamp->ptp)); PTR_ERR(tstamp->ptp));
tstamp->ptp = NULL; tstamp->ptp = NULL;
......
...@@ -1269,13 +1269,13 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel) ...@@ -1269,13 +1269,13 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel)
if (IS_ERR(ptp->phc_clock)) { if (IS_ERR(ptp->phc_clock)) {
rc = PTR_ERR(ptp->phc_clock); rc = PTR_ERR(ptp->phc_clock);
goto fail3; goto fail3;
} } else if (ptp->phc_clock) {
INIT_WORK(&ptp->pps_work, efx_ptp_pps_worker);
INIT_WORK(&ptp->pps_work, efx_ptp_pps_worker); ptp->pps_workwq = create_singlethread_workqueue("sfc_pps");
ptp->pps_workwq = create_singlethread_workqueue("sfc_pps"); if (!ptp->pps_workwq) {
if (!ptp->pps_workwq) { rc = -ENOMEM;
rc = -ENOMEM; goto fail4;
goto fail4; }
} }
} }
ptp->nic_ts_enabled = false; ptp->nic_ts_enabled = false;
......
...@@ -187,7 +187,7 @@ int stmmac_ptp_register(struct stmmac_priv *priv) ...@@ -187,7 +187,7 @@ int stmmac_ptp_register(struct stmmac_priv *priv)
if (IS_ERR(priv->ptp_clock)) { if (IS_ERR(priv->ptp_clock)) {
priv->ptp_clock = NULL; priv->ptp_clock = NULL;
pr_err("ptp_clock_register() failed on %s\n", priv->dev->name); pr_err("ptp_clock_register() failed on %s\n", priv->dev->name);
} else } else if (priv->ptp_clock)
pr_debug("Added PTP HW clock successfully on %s\n", pr_debug("Added PTP HW clock successfully on %s\n",
priv->dev->name); priv->dev->name);
......
...@@ -127,6 +127,11 @@ struct ptp_clock; ...@@ -127,6 +127,11 @@ struct ptp_clock;
* *
* @info: Structure describing the new clock. * @info: Structure describing the new clock.
* @parent: Pointer to the parent device of the new clock. * @parent: Pointer to the parent device of the new clock.
*
* Returns a valid pointer on success or PTR_ERR on failure. If PHC
* support is missing at the configuration level, this function
* returns NULL, and drivers are expected to gracefully handle that
* case separately.
*/ */
extern struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, extern struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
......
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