Re: [PATCH v3 net-next 04/15] ptp: netc: add NETC V4 Timer PTP driver support
From: Vladimir Oltean
Date: Tue Aug 12 2025 - 10:07:13 EST
On Tue, Aug 12, 2025 at 05:46:23PM +0800, Wei Fang wrote:
> +int netc_timer_get_phc_index(struct pci_dev *timer_pdev)
> +{
> + struct netc_timer *priv;
> +
> + if (!timer_pdev)
> + return -ENODEV;
> +
> + priv = pci_get_drvdata(timer_pdev);
> + if (!priv)
> + return -EINVAL;
> +
> + return priv->phc_index;
> +}
> +EXPORT_SYMBOL_GPL(netc_timer_get_phc_index);
...
> @@ -16,4 +17,13 @@ static inline void netc_write(void __iomem *reg, u32 val)
> iowrite32(val, reg);
> }
>
> +#if IS_ENABLED(CONFIG_PTP_NETC_V4_TIMER)
> +int netc_timer_get_phc_index(struct pci_dev *timer_pdev);
> +#else
> +static inline int netc_timer_get_phc_index(struct pci_dev *timer_pdev)
> +{
> + return -ENODEV;
> +}
> +#endif
> +
I was expecting that with the generic ptp-timer phandle you'd also offer
a generic mechanism of retrieving the PHC index, instead of cooking up a
custom API convention between the NETC MAC and the NETC timer.
Something like below, completely untested:
struct ptp_clock_fwnode_match {
struct fwnode_handle *fwnode;
struct ptp_clock *clock;
};
static int ptp_clock_fwnode_match(struct device *dev, void *data)
{
struct ptp_clock_fwnode_match *match = data;
if (!dev->parent || dev_fwnode(dev->parent) != match->fwnode)
return 0;
match->clock = dev_get_drvdata(dev);
return 1;
}
static struct ptp_clock *ptp_clock_find_by_fwnode(struct fwnode_handle *fwnode)
{
struct ptp_clock_fwnode_match match = { .fwnode = fwnode };
class_for_each_device(&ptp_class, NULL, &match, ptp_clock_fwnode_match);
return match.clock;
}
int ptp_clock_index_by_fwnode_handle(struct fwnode_handle *fwnode)
{
struct fwnode_handle *ptp_fwnode;
struct ptp_clock *clock;
int phc_index;
ptp_fwnode = fwnode_find_reference(fwnode, "ptp-timer", 0);
if (!ptp_fwnode)
return -1;
clock = ptp_clock_find_by_fwnode(ptp_fwnode);
fwnode_handle_put(ptp_fwnode);
if (!clock)
return -1;
phc_index = ptp_clock_index(clock);
put_device(&clock->dev);
return phc_index;
}
EXPORT_SYMBOL_GPL(ptp_clock_index_by_fwnode_handle);