lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250812134931.fjtrmv6fmdgcagre@skbuf>
Date: Tue, 12 Aug 2025 16:49:31 +0300
From: Vladimir Oltean <vladimir.oltean@....com>
To: Wei Fang <wei.fang@....com>
Cc: robh@...nel.org, krzk+dt@...nel.org, conor+dt@...nel.org,
	richardcochran@...il.com, claudiu.manoil@....com,
	xiaoning.wang@....com, andrew+netdev@...n.ch, davem@...emloft.net,
	edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
	vadim.fedorenko@...ux.dev, Frank.Li@....com, shawnguo@...nel.org,
	s.hauer@...gutronix.de, festevam@...il.com, fushi.peng@....com,
	devicetree@...r.kernel.org, netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org, imx@...ts.linux.dev,
	kernel@...gutronix.de
Subject: Re: [PATCH v3 net-next 04/15] ptp: netc: add NETC V4 Timer PTP
 driver support

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);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ