Commit 5093406c authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

net: enetc: implement ring reconfiguration procedure for PTP RX timestamping

The crude enetc_stop() -> enetc_open() mechanism suffers from 2
problems:

1. improper error checking
2. it involves phylink_stop() -> phylink_start() which loses the link

Right now, the driver is prepared to offer a better alternative: a ring
reconfiguration procedure which takes the RX BD size (normal or
extended) as argument. It allocates new resources (failing if that
fails), stops the traffic, and assigns the new resources to the rings.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 598ca0d0
...@@ -2489,6 +2489,46 @@ int enetc_close(struct net_device *ndev) ...@@ -2489,6 +2489,46 @@ int enetc_close(struct net_device *ndev)
return 0; return 0;
} }
static int enetc_reconfigure(struct enetc_ndev_priv *priv, bool extended)
{
struct enetc_bdr_resource *tx_res, *rx_res;
int err;
ASSERT_RTNL();
/* If the interface is down, do nothing. */
if (!netif_running(priv->ndev))
return 0;
tx_res = enetc_alloc_tx_resources(priv);
if (IS_ERR(tx_res)) {
err = PTR_ERR(tx_res);
goto out;
}
rx_res = enetc_alloc_rx_resources(priv, extended);
if (IS_ERR(rx_res)) {
err = PTR_ERR(rx_res);
goto out_free_tx_res;
}
enetc_stop(priv->ndev);
enetc_clear_bdrs(priv);
enetc_free_rxtx_rings(priv);
enetc_assign_tx_resources(priv, tx_res);
enetc_assign_rx_resources(priv, rx_res);
enetc_setup_bdrs(priv, extended);
enetc_start(priv->ndev);
return 0;
out_free_tx_res:
enetc_free_tx_resources(tx_res, priv->num_tx_rings);
out:
return err;
}
int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data) int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data)
{ {
struct enetc_ndev_priv *priv = netdev_priv(ndev); struct enetc_ndev_priv *priv = netdev_priv(ndev);
...@@ -2681,43 +2721,47 @@ void enetc_set_features(struct net_device *ndev, netdev_features_t features) ...@@ -2681,43 +2721,47 @@ void enetc_set_features(struct net_device *ndev, netdev_features_t features)
static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr) static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr)
{ {
struct enetc_ndev_priv *priv = netdev_priv(ndev); struct enetc_ndev_priv *priv = netdev_priv(ndev);
int err, new_offloads = priv->active_offloads;
struct hwtstamp_config config; struct hwtstamp_config config;
int ao;
if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
return -EFAULT; return -EFAULT;
switch (config.tx_type) { switch (config.tx_type) {
case HWTSTAMP_TX_OFF: case HWTSTAMP_TX_OFF:
priv->active_offloads &= ~ENETC_F_TX_TSTAMP_MASK; new_offloads &= ~ENETC_F_TX_TSTAMP_MASK;
break; break;
case HWTSTAMP_TX_ON: case HWTSTAMP_TX_ON:
priv->active_offloads &= ~ENETC_F_TX_TSTAMP_MASK; new_offloads &= ~ENETC_F_TX_TSTAMP_MASK;
priv->active_offloads |= ENETC_F_TX_TSTAMP; new_offloads |= ENETC_F_TX_TSTAMP;
break; break;
case HWTSTAMP_TX_ONESTEP_SYNC: case HWTSTAMP_TX_ONESTEP_SYNC:
priv->active_offloads &= ~ENETC_F_TX_TSTAMP_MASK; new_offloads &= ~ENETC_F_TX_TSTAMP_MASK;
priv->active_offloads |= ENETC_F_TX_ONESTEP_SYNC_TSTAMP; new_offloads |= ENETC_F_TX_ONESTEP_SYNC_TSTAMP;
break; break;
default: default:
return -ERANGE; return -ERANGE;
} }
ao = priv->active_offloads;
switch (config.rx_filter) { switch (config.rx_filter) {
case HWTSTAMP_FILTER_NONE: case HWTSTAMP_FILTER_NONE:
priv->active_offloads &= ~ENETC_F_RX_TSTAMP; new_offloads &= ~ENETC_F_RX_TSTAMP;
break; break;
default: default:
priv->active_offloads |= ENETC_F_RX_TSTAMP; new_offloads |= ENETC_F_RX_TSTAMP;
config.rx_filter = HWTSTAMP_FILTER_ALL; config.rx_filter = HWTSTAMP_FILTER_ALL;
} }
if (netif_running(ndev) && ao != priv->active_offloads) { if ((new_offloads ^ priv->active_offloads) & ENETC_F_RX_TSTAMP) {
enetc_close(ndev); bool extended = !!(new_offloads & ENETC_F_RX_TSTAMP);
enetc_open(ndev);
err = enetc_reconfigure(priv, extended);
if (err)
return err;
} }
priv->active_offloads = new_offloads;
return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
-EFAULT : 0; -EFAULT : 0;
} }
......
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