netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Divya Koppera <divya.koppera@microchip.com>
Cc: andrew@lunn.ch, arun.ramadoss@microchip.com,
	UNGLinuxDriver@microchip.com, hkallweit1@gmail.com,
	linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, richardcochran@gmail.com
Subject: Re: [PATCH net-next 2/5] net: phy: microchip_ptp : Add ptp library for Microchip phys
Date: Thu, 7 Nov 2024 14:34:04 +0000	[thread overview]
Message-ID: <20241107143404.GV4507@kernel.org> (raw)
In-Reply-To: <20241104090750.12942-3-divya.koppera@microchip.com>

On Mon, Nov 04, 2024 at 02:37:47PM +0530, Divya Koppera wrote:
> Add ptp library for Microchip phys
> 1-step and 2-step modes are supported, over Ethernet and UDP(ipv4, ipv6)
> 
> Signed-off-by: Divya Koppera <divya.koppera@microchip.com>
> ---
>  drivers/net/phy/microchip_ptp.c | 990 ++++++++++++++++++++++++++++++++
>  1 file changed, 990 insertions(+)
>  create mode 100644 drivers/net/phy/microchip_ptp.c
> 
> diff --git a/drivers/net/phy/microchip_ptp.c b/drivers/net/phy/microchip_ptp.c

...

> +static bool mchp_ptp_get_sig_tx(struct sk_buff *skb, u16 *sig)
> +{
> +	struct ptp_header *ptp_header;
> +	int type;
> +
> +	type = ptp_classify_raw(skb);
> +	if (type == PTP_CLASS_NONE)
> +		return false;
> +
> +	ptp_header = ptp_parse_header(skb, type);
> +	if (!ptp_header)
> +		return false;
> +
> +	*sig = htons(ptp_header->sequence_id);

Hi Divya,

The type of *sig is u16, a host-byte order integer.
But htons() returns __be16, a big-endian integer.
This does not seem right.

Likewise, in the caller, and beyond, if these are big-endian integers
then appropriate types - probably __be16 - should be used.

Flagged by Sparse.

> +
> +	return true;
> +}

...

> +static struct mchp_ptp_rx_ts *mchp_ptp_get_rx_ts(struct mchp_ptp_clock *ptp_clock)
> +{
> +	struct phy_device *phydev = ptp_clock->phydev;
> +	struct mchp_ptp_rx_ts *rx_ts = NULL;
> +	u32 sec, nsec;
> +	u16 seq;
> +	int rc;
> +
> +	rc = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			  MCHP_PTP_RX_INGRESS_NS_HI(BASE_PORT(ptp_clock)));
> +	if (rc < 0)
> +		goto error;
> +	if (!(rc & MCHP_PTP_RX_INGRESS_NS_HI_TS_VALID)) {
> +		phydev_err(phydev, "RX Timestamp is not valid!\n");
> +		goto error;
> +	}
> +	nsec = (rc & GENMASK(13, 0)) << 16;
> +
> +	rc = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			  MCHP_PTP_RX_INGRESS_NS_LO(BASE_PORT(ptp_clock)));
> +	if (rc < 0)
> +		goto error;
> +	nsec |= rc;
> +
> +	rc = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			  MCHP_PTP_RX_INGRESS_SEC_HI(BASE_PORT(ptp_clock)));
> +	if (rc < 0)
> +		goto error;
> +	sec = rc << 16;
> +
> +	rc = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			  MCHP_PTP_RX_INGRESS_SEC_LO(BASE_PORT(ptp_clock)));
> +	if (rc < 0)
> +		goto error;
> +	sec |= rc;
> +
> +	seq = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			   MCHP_PTP_RX_MSG_HEADER2(BASE_PORT(ptp_clock)));
> +	if (seq < 0)

seq is unsigned; it can never be less than 0.

Flagged by Smatch.

> +		goto error;
> +
> +	rx_ts = kzalloc(sizeof(*rx_ts), GFP_KERNEL);
> +	if (!rx_ts)
> +		return NULL;
> +
> +	rx_ts->seconds = sec;
> +	rx_ts->nsec = nsec;
> +	rx_ts->seq_id = seq;
> +
> +error:
> +	return rx_ts;
> +}

...

> +static bool mchp_ptp_get_tx_ts(struct mchp_ptp_clock *ptp_clock,
> +			       u32 *sec, u32 *nsec, u16 *seq)
> +{
> +	struct phy_device *phydev = ptp_clock->phydev;
> +	int rc;
> +
> +	rc = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			  MCHP_PTP_TX_EGRESS_NS_HI(BASE_PORT(ptp_clock)));
> +	if (rc < 0)
> +		return false;
> +	if (!(rc & MCHP_PTP_TX_EGRESS_NS_HI_TS_VALID))
> +		return false;
> +	*nsec = (rc & GENMASK(13, 0)) << 16;
> +
> +	rc = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			  MCHP_PTP_TX_EGRESS_NS_LO(BASE_PORT(ptp_clock)));
> +	if (rc < 0)
> +		return false;
> +	*nsec = *nsec | rc;
> +
> +	rc = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			  MCHP_PTP_TX_EGRESS_SEC_HI(BASE_PORT(ptp_clock)));
> +	if (rc < 0)
> +		return false;
> +	*sec = rc << 16;
> +
> +	rc = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			  MCHP_PTP_TX_EGRESS_SEC_LO(BASE_PORT(ptp_clock)));
> +	if (rc < 0)
> +		return false;
> +	*sec = *sec | rc;
> +
> +	*seq = phy_read_mmd(phydev, PTP_MMD(ptp_clock),
> +			    MCHP_PTP_TX_MSG_HEADER2(BASE_PORT(ptp_clock)));
> +	if (*seq < 0)

Likewise, *seq is unsigned; it can never be less than 0.

> +		return false;
> +
> +	return true;
> +}

...

  parent reply	other threads:[~2024-11-07 14:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-04  9:07 [PATCH net-next 0/5] Add ptp library for Microchip phys Divya Koppera
2024-11-04  9:07 ` [PATCH net-next 1/5] net: phy: microchip_ptp : Add header file for Microchip ptp library Divya Koppera
2024-11-04  9:07 ` [PATCH net-next 2/5] net: phy: microchip_ptp : Add ptp library for Microchip phys Divya Koppera
2024-11-04 12:32   ` Vadim Fedorenko
2024-11-05 10:08     ` Divya.Koppera
2024-11-07 14:34   ` Simon Horman [this message]
2024-11-11  4:55     ` Divya.Koppera
2024-11-04  9:07 ` [PATCH net-next 3/5] net: phy: Kconfig: Add ptp library support and 1588 optional flag in " Divya Koppera
2024-11-04  9:07 ` [PATCH net-next 4/5] net: phy: Makefile: Add makefile support for ptp " Divya Koppera
2024-11-05  1:40   ` kernel test robot
2024-11-05  3:57   ` kernel test robot
2024-11-04  9:07 ` [PATCH net-next 5/5] net: phy: microchip_t1 : Add initialization of ptp for lan887x Divya Koppera
2024-11-04 14:04   ` Andrew Lunn
2024-11-05  6:17     ` Divya.Koppera
2024-11-05  3:14   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241107143404.GV4507@kernel.org \
    --to=horms@kernel.org \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=arun.ramadoss@microchip.com \
    --cc=davem@davemloft.net \
    --cc=divya.koppera@microchip.com \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).