All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: "Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Florian Fainelli" <florian.fainelli@broadcom.com>,
	"Broadcom internal kernel review list"
	<bcm-kernel-feedback-list@broadcom.com>,
	"Marek Behún" <kabel@kernel.org>,
	"Andrei Botila" <andrei.botila@oss.nxp.com>,
	"Sabrina Dubroca" <sd@queasysnail.net>,
	"Eric Woudstra" <ericwouds@gmail.com>,
	"Daniel Golle" <daniel@makrotopia.org>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.or
Subject: Re: [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs
Date: Tue, 15 Apr 2025 13:19:34 +0200	[thread overview]
Message-ID: <67fe40cb.050a0220.130904.f08d@mx.google.com> (raw)
In-Reply-To: <8760a101-4536-474f-a0db-5b88ed4c0ec2@lunn.ch>

On Tue, Apr 15, 2025 at 03:14:13AM +0200, Andrew Lunn wrote:
> > +#define AEON_MAX_LDES			5
> 
> AEON_MAX_LEDS?
> 
> > +#define AEON_IPC_DELAY			10000
> > +#define AEON_IPC_TIMEOUT		(AEON_IPC_DELAY * 100)
> > +#define AEON_IPC_DATA_MAX		(8 * sizeof(u16))
> 
> > +
> 
> > +static int aeon_ipc_rcv_msg(struct phy_device *phydev,
> > +			    u16 ret_sts, u16 *data)
> > +{
> 
> It would be good to add a comment here about what the return value
> means. I'm having to work hard to figure out if it is bytes, or number
> of u16s.
> 
> > +	struct as21xxx_priv *priv = phydev->priv;
> > +	unsigned int size;
> > +	int ret;
> > +	int i;
> > +
> > +	if ((ret_sts & AEON_IPC_STS_STATUS) == AEON_IPC_STS_STATUS_ERROR)
> > +		return -EINVAL;
> > +
> > +	/* Prevent IPC from stack smashing the kernel */
> > +	size = FIELD_GET(AEON_IPC_STS_SIZE, ret_sts);
> > +	if (size > AEON_IPC_DATA_MAX)
> > +		return -EINVAL;
> 
> This suggests size is bytes, and can be upto 16?
> 
> > +
> > +	mutex_lock(&priv->ipc_lock);
> > +
> > +	for (i = 0; i < DIV_ROUND_UP(size, sizeof(u16)); i++) {
> > +		ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, VEND1_IPC_DATA(i));
> > +		if (ret < 0) {
> > +			size = ret;
> > +			goto out;
> > +		}
> > +
> > +		data[i] = ret;
> 
> and this is looping up to 8 times reading words.
> 
> > +static int aeon_ipc_get_fw_version(struct phy_device *phydev)
> > +{
> > +	char fw_version[AEON_IPC_DATA_MAX + 1];
> > +	u16 ret_data[8], data[1];
> 
> I think there should be a #define for this 8. It is pretty fundamental
> to these message transfers.
> 
> > +	u16 ret_sts;
> > +	int ret;
> > +
> > +	data[0] = IPC_INFO_VERSION;
> 
> Not a normal question i would ask for MDIO, but are there any
> endianness issues here? Since everything is in u16, the base size for
> MDIO, i doubt there is.
>

In theory not, anything comes to mine that might be problematic? 

> > +	ret = aeon_ipc_send_msg(phydev, IPC_CMD_INFO, data,
> > +				sizeof(data), &ret_sts);
> > +	if (ret)
> > +		return ret;
> 
> > +	ret = aeon_ipc_rcv_msg(phydev, ret_sts, ret_data);
> > +	if (ret < 0)
> > +		return ret;
> > +
> 
> but ret is in bytes, not words, so we start getting into odd
> situations. Have you seen the firmware return an add number of bytes
> in its message? If it does, is it clear which part of the last word
> should be used.
> 

ret is size from IPC STATUS that return the transmitted data in bytes.
I use u16 to follow the fact that there are 8 rw IPC data register.

The returned firmware value is 1.8.2 for example and that is 5 bytes.

We allocate 17 bytes for the firmware string and we pass a buffer of 8
u16 (16 bytes)

Am I missing something?

> > +
> > +	/* Make sure FW version is NULL terminated */
> > +	memcpy(fw_version, ret_data, ret);
> > +	fw_version[ret] = '\0';
> 
> 
> Given that ret is bytes, this works, despite ret_data being words.
> 
> 	Andrew

-- 
	Ansuel

  reply	other threads:[~2025-04-15 11:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10  9:53 [net-next PATCH v7 0/6] net: phy: Add support for new Aeonsemi PHYs Christian Marangi
2025-04-10  9:53 ` [net-next PATCH v7 1/6] net: phy: pass PHY driver to .match_phy_device OP Christian Marangi
2025-04-10  9:53 ` [net-next PATCH v7 2/6] net: phy: bcm87xx: simplify " Christian Marangi
2025-04-10  9:53 ` [net-next PATCH v7 3/6] net: phy: nxp-c45-tja11xx: " Christian Marangi
2025-04-15 10:56   ` Andrei Botila
2025-04-10  9:53 ` [net-next PATCH v7 4/6] net: phy: introduce genphy_match_phy_device() Christian Marangi
2025-04-10  9:53 ` [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs Christian Marangi
2025-04-14 23:36   ` Jakub Kicinski
2025-04-15  1:14   ` Andrew Lunn
2025-04-15 11:19     ` Christian Marangi [this message]
2025-04-15  9:37   ` Russell King (Oracle)
2025-04-15 11:24     ` Christian Marangi
2025-04-15 12:33       ` Andrew Lunn
2025-04-15 12:55       ` Russell King (Oracle)
2025-04-15 13:04         ` Christian Marangi
2025-04-10  9:53 ` [net-next PATCH v7 6/6] dt-bindings: net: Document support for Aeonsemi PHYs Christian Marangi
2025-04-15  9:56 ` [net-next PATCH v7 0/6] net: phy: Add support for new " Russell King (Oracle)

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=67fe40cb.050a0220.130904.f08d@mx.google.com \
    --to=ansuelsmth@gmail.com \
    --cc=andrei.botila@oss.nxp.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=ericwouds@gmail.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=hkallweit1@gmail.com \
    --cc=kabel@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.or \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=sd@queasysnail.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.