[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
<PAXPR04MB8510193754000AB8FE6E1C47882AA@PAXPR04MB8510.eurprd04.prod.outlook.com>
Date: Wed, 13 Aug 2025 02:21:08 +0000
From: Wei Fang <wei.fang@....com>
To: Vladimir Oltean <vladimir.oltean@....com>
CC: "robh@...nel.org" <robh@...nel.org>, "krzk+dt@...nel.org"
<krzk+dt@...nel.org>, "conor+dt@...nel.org" <conor+dt@...nel.org>,
"richardcochran@...il.com" <richardcochran@...il.com>, Claudiu Manoil
<claudiu.manoil@....com>, Clark Wang <xiaoning.wang@....com>,
"andrew+netdev@...n.ch" <andrew+netdev@...n.ch>, "davem@...emloft.net"
<davem@...emloft.net>, "edumazet@...gle.com" <edumazet@...gle.com>,
"kuba@...nel.org" <kuba@...nel.org>, "pabeni@...hat.com" <pabeni@...hat.com>,
"vadim.fedorenko@...ux.dev" <vadim.fedorenko@...ux.dev>, Frank Li
<frank.li@....com>, "shawnguo@...nel.org" <shawnguo@...nel.org>,
"s.hauer@...gutronix.de" <s.hauer@...gutronix.de>, "festevam@...il.com"
<festevam@...il.com>, "F.S. Peng" <fushi.peng@....com>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"imx@...ts.linux.dev" <imx@...ts.linux.dev>, "kernel@...gutronix.de"
<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.
>
Good advice, I did not realize that, I will try to apply your proposal,
many thanks.
> 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