Commit 7bdde444 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

net: sparx5: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()

The hardware timestamping through ndo_eth_ioctl() is going away.
Convert the sparx5 driver to the new API before that can be removed.

After removing the timestamping logic from sparx5_port_ioctl(), the rest
is equivalent to phy_do_ioctl().
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Reviewed-by: default avatarSteen Hegelund <Steen.Hegelund@microchip.com>
Link: https://lore.kernel.org/r/20230801142824.1772134-9-vladimir.oltean@nxp.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 547b006d
...@@ -205,7 +205,7 @@ enum sparx5_core_clockfreq { ...@@ -205,7 +205,7 @@ enum sparx5_core_clockfreq {
struct sparx5_phc { struct sparx5_phc {
struct ptp_clock *clock; struct ptp_clock *clock;
struct ptp_clock_info info; struct ptp_clock_info info;
struct hwtstamp_config hwtstamp_config; struct kernel_hwtstamp_config hwtstamp_config;
struct sparx5 *sparx5; struct sparx5 *sparx5;
u8 index; u8 index;
}; };
...@@ -388,8 +388,11 @@ void sparx5_unregister_netdevs(struct sparx5 *sparx5); ...@@ -388,8 +388,11 @@ void sparx5_unregister_netdevs(struct sparx5 *sparx5);
/* sparx5_ptp.c */ /* sparx5_ptp.c */
int sparx5_ptp_init(struct sparx5 *sparx5); int sparx5_ptp_init(struct sparx5 *sparx5);
void sparx5_ptp_deinit(struct sparx5 *sparx5); void sparx5_ptp_deinit(struct sparx5 *sparx5);
int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr); int sparx5_ptp_hwtstamp_set(struct sparx5_port *port,
int sparx5_ptp_hwtstamp_get(struct sparx5_port *port, struct ifreq *ifr); struct kernel_hwtstamp_config *cfg,
struct netlink_ext_ack *extack);
void sparx5_ptp_hwtstamp_get(struct sparx5_port *port,
struct kernel_hwtstamp_config *cfg);
void sparx5_ptp_rxtstamp(struct sparx5 *sparx5, struct sk_buff *skb, void sparx5_ptp_rxtstamp(struct sparx5 *sparx5, struct sk_buff *skb,
u64 timestamp); u64 timestamp);
int sparx5_ptp_txtstamp_request(struct sparx5_port *port, int sparx5_ptp_txtstamp_request(struct sparx5_port *port,
......
...@@ -210,22 +210,37 @@ static int sparx5_get_port_parent_id(struct net_device *dev, ...@@ -210,22 +210,37 @@ static int sparx5_get_port_parent_id(struct net_device *dev,
return 0; return 0;
} }
static int sparx5_port_ioctl(struct net_device *dev, struct ifreq *ifr, static int sparx5_port_hwtstamp_get(struct net_device *dev,
int cmd) struct kernel_hwtstamp_config *cfg)
{ {
struct sparx5_port *sparx5_port = netdev_priv(dev); struct sparx5_port *sparx5_port = netdev_priv(dev);
struct sparx5 *sparx5 = sparx5_port->sparx5; struct sparx5 *sparx5 = sparx5_port->sparx5;
if (!phy_has_hwtstamp(dev->phydev) && sparx5->ptp) { if (phy_has_hwtstamp(dev->phydev))
switch (cmd) { return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCGHWTSTAMP);
case SIOCSHWTSTAMP:
return sparx5_ptp_hwtstamp_set(sparx5_port, ifr); if (!sparx5->ptp)
case SIOCGHWTSTAMP: return -EOPNOTSUPP;
return sparx5_ptp_hwtstamp_get(sparx5_port, ifr);
} sparx5_ptp_hwtstamp_get(sparx5_port, cfg);
}
return 0;
}
static int sparx5_port_hwtstamp_set(struct net_device *dev,
struct kernel_hwtstamp_config *cfg,
struct netlink_ext_ack *extack)
{
struct sparx5_port *sparx5_port = netdev_priv(dev);
struct sparx5 *sparx5 = sparx5_port->sparx5;
if (phy_has_hwtstamp(dev->phydev))
return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCSHWTSTAMP);
if (!sparx5->ptp)
return -EOPNOTSUPP;
return phy_mii_ioctl(dev->phydev, ifr, cmd); return sparx5_ptp_hwtstamp_set(sparx5_port, cfg, extack);
} }
static const struct net_device_ops sparx5_port_netdev_ops = { static const struct net_device_ops sparx5_port_netdev_ops = {
...@@ -238,8 +253,10 @@ static const struct net_device_ops sparx5_port_netdev_ops = { ...@@ -238,8 +253,10 @@ static const struct net_device_ops sparx5_port_netdev_ops = {
.ndo_validate_addr = eth_validate_addr, .ndo_validate_addr = eth_validate_addr,
.ndo_get_stats64 = sparx5_get_stats64, .ndo_get_stats64 = sparx5_get_stats64,
.ndo_get_port_parent_id = sparx5_get_port_parent_id, .ndo_get_port_parent_id = sparx5_get_port_parent_id,
.ndo_eth_ioctl = sparx5_port_ioctl, .ndo_eth_ioctl = phy_do_ioctl,
.ndo_setup_tc = sparx5_port_setup_tc, .ndo_setup_tc = sparx5_port_setup_tc,
.ndo_hwtstamp_get = sparx5_port_hwtstamp_get,
.ndo_hwtstamp_set = sparx5_port_hwtstamp_set,
}; };
bool sparx5_netdevice_check(const struct net_device *dev) bool sparx5_netdevice_check(const struct net_device *dev)
......
...@@ -74,10 +74,11 @@ static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5) ...@@ -74,10 +74,11 @@ static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5)
return res; return res;
} }
int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) int sparx5_ptp_hwtstamp_set(struct sparx5_port *port,
struct kernel_hwtstamp_config *cfg,
struct netlink_ext_ack *extack)
{ {
struct sparx5 *sparx5 = port->sparx5; struct sparx5 *sparx5 = port->sparx5;
struct hwtstamp_config cfg;
struct sparx5_phc *phc; struct sparx5_phc *phc;
/* For now don't allow to run ptp on ports that are part of a bridge, /* For now don't allow to run ptp on ports that are part of a bridge,
...@@ -88,10 +89,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) ...@@ -88,10 +89,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
if (test_bit(port->portno, sparx5->bridge_mask)) if (test_bit(port->portno, sparx5->bridge_mask))
return -EINVAL; return -EINVAL;
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) switch (cfg->tx_type) {
return -EFAULT;
switch (cfg.tx_type) {
case HWTSTAMP_TX_ON: case HWTSTAMP_TX_ON:
port->ptp_cmd = IFH_REW_OP_TWO_STEP_PTP; port->ptp_cmd = IFH_REW_OP_TWO_STEP_PTP;
break; break;
...@@ -105,7 +103,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) ...@@ -105,7 +103,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
return -ERANGE; return -ERANGE;
} }
switch (cfg.rx_filter) { switch (cfg->rx_filter) {
case HWTSTAMP_FILTER_NONE: case HWTSTAMP_FILTER_NONE:
break; break;
case HWTSTAMP_FILTER_ALL: case HWTSTAMP_FILTER_ALL:
...@@ -122,7 +120,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) ...@@ -122,7 +120,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
case HWTSTAMP_FILTER_PTP_V2_SYNC: case HWTSTAMP_FILTER_PTP_V2_SYNC:
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
case HWTSTAMP_FILTER_NTP_ALL: case HWTSTAMP_FILTER_NTP_ALL:
cfg.rx_filter = HWTSTAMP_FILTER_ALL; cfg->rx_filter = HWTSTAMP_FILTER_ALL;
break; break;
default: default:
return -ERANGE; return -ERANGE;
...@@ -131,20 +129,20 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr) ...@@ -131,20 +129,20 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
/* Commit back the result & save it */ /* Commit back the result & save it */
mutex_lock(&sparx5->ptp_lock); mutex_lock(&sparx5->ptp_lock);
phc = &sparx5->phc[SPARX5_PHC_PORT]; phc = &sparx5->phc[SPARX5_PHC_PORT];
memcpy(&phc->hwtstamp_config, &cfg, sizeof(cfg)); phc->hwtstamp_config = *cfg;
mutex_unlock(&sparx5->ptp_lock); mutex_unlock(&sparx5->ptp_lock);
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; return 0;
} }
int sparx5_ptp_hwtstamp_get(struct sparx5_port *port, struct ifreq *ifr) void sparx5_ptp_hwtstamp_get(struct sparx5_port *port,
struct kernel_hwtstamp_config *cfg)
{ {
struct sparx5 *sparx5 = port->sparx5; struct sparx5 *sparx5 = port->sparx5;
struct sparx5_phc *phc; struct sparx5_phc *phc;
phc = &sparx5->phc[SPARX5_PHC_PORT]; phc = &sparx5->phc[SPARX5_PHC_PORT];
return copy_to_user(ifr->ifr_data, &phc->hwtstamp_config, *cfg = phc->hwtstamp_config;
sizeof(phc->hwtstamp_config)) ? -EFAULT : 0;
} }
static void sparx5_ptp_classify(struct sparx5_port *port, struct sk_buff *skb, static void sparx5_ptp_classify(struct sparx5_port *port, struct sk_buff *skb,
......
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