Skip to content

Commit

Permalink
net: sparx5: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
Browse files Browse the repository at this point in the history
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: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>
Link: https://lore.kernel.org/r/20230801142824.1772134-9-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Vladimir Oltean authored and Jakub Kicinski committed Aug 3, 2023
1 parent 547b006 commit 7bdde44
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
9 changes: 6 additions & 3 deletions drivers/net/ethernet/microchip/sparx5/sparx5_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ enum sparx5_core_clockfreq {
struct sparx5_phc {
struct ptp_clock *clock;
struct ptp_clock_info info;
struct hwtstamp_config hwtstamp_config;
struct kernel_hwtstamp_config hwtstamp_config;
struct sparx5 *sparx5;
u8 index;
};
Expand Down Expand Up @@ -388,8 +388,11 @@ void sparx5_unregister_netdevs(struct sparx5 *sparx5);
/* sparx5_ptp.c */
int sparx5_ptp_init(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_get(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);
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,
u64 timestamp);
int sparx5_ptp_txtstamp_request(struct sparx5_port *port,
Expand Down
41 changes: 29 additions & 12 deletions drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,37 @@ static int sparx5_get_port_parent_id(struct net_device *dev,
return 0;
}

static int sparx5_port_ioctl(struct net_device *dev, struct ifreq *ifr,
int cmd)
static int sparx5_port_hwtstamp_get(struct net_device *dev,
struct kernel_hwtstamp_config *cfg)
{
struct sparx5_port *sparx5_port = netdev_priv(dev);
struct sparx5 *sparx5 = sparx5_port->sparx5;

if (!phy_has_hwtstamp(dev->phydev) && sparx5->ptp) {
switch (cmd) {
case SIOCSHWTSTAMP:
return sparx5_ptp_hwtstamp_set(sparx5_port, ifr);
case SIOCGHWTSTAMP:
return sparx5_ptp_hwtstamp_get(sparx5_port, ifr);
}
}
if (phy_has_hwtstamp(dev->phydev))
return phy_mii_ioctl(dev->phydev, cfg->ifr, SIOCGHWTSTAMP);

if (!sparx5->ptp)
return -EOPNOTSUPP;

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 = {
Expand All @@ -238,8 +253,10 @@ static const struct net_device_ops sparx5_port_netdev_ops = {
.ndo_validate_addr = eth_validate_addr,
.ndo_get_stats64 = sparx5_get_stats64,
.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_hwtstamp_get = sparx5_port_hwtstamp_get,
.ndo_hwtstamp_set = sparx5_port_hwtstamp_set,
};

bool sparx5_netdevice_check(const struct net_device *dev)
Expand Down
24 changes: 11 additions & 13 deletions drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ static u64 sparx5_ptp_get_nominal_value(struct sparx5 *sparx5)
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 hwtstamp_config cfg;
struct sparx5_phc *phc;

/* For now don't allow to run ptp on ports that are part of a bridge,
Expand All @@ -88,10 +89,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
if (test_bit(port->portno, sparx5->bridge_mask))
return -EINVAL;

if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
return -EFAULT;

switch (cfg.tx_type) {
switch (cfg->tx_type) {
case HWTSTAMP_TX_ON:
port->ptp_cmd = IFH_REW_OP_TWO_STEP_PTP;
break;
Expand All @@ -105,7 +103,7 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
return -ERANGE;
}

switch (cfg.rx_filter) {
switch (cfg->rx_filter) {
case HWTSTAMP_FILTER_NONE:
break;
case HWTSTAMP_FILTER_ALL:
Expand All @@ -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_DELAY_REQ:
case HWTSTAMP_FILTER_NTP_ALL:
cfg.rx_filter = HWTSTAMP_FILTER_ALL;
cfg->rx_filter = HWTSTAMP_FILTER_ALL;
break;
default:
return -ERANGE;
Expand All @@ -131,20 +129,20 @@ int sparx5_ptp_hwtstamp_set(struct sparx5_port *port, struct ifreq *ifr)
/* Commit back the result & save it */
mutex_lock(&sparx5->ptp_lock);
phc = &sparx5->phc[SPARX5_PHC_PORT];
memcpy(&phc->hwtstamp_config, &cfg, sizeof(cfg));
phc->hwtstamp_config = *cfg;
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_phc *phc;

phc = &sparx5->phc[SPARX5_PHC_PORT];
return copy_to_user(ifr->ifr_data, &phc->hwtstamp_config,
sizeof(phc->hwtstamp_config)) ? -EFAULT : 0;
*cfg = phc->hwtstamp_config;
}

static void sparx5_ptp_classify(struct sparx5_port *port, struct sk_buff *skb,
Expand Down

0 comments on commit 7bdde44

Please sign in to comment.