netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Jiawen Wu <jiawenwu@trustnetic.com>
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk,
	netdev@vger.kernel.org, mengyuanlou@net-swift.com
Subject: Re: [PATCH net-next v3 1/2] net: txgbe: Add basic support for new AML devices
Date: Wed, 15 Jan 2025 15:29:50 +0000	[thread overview]
Message-ID: <20250115152950.GO5497@kernel.org> (raw)
In-Reply-To: <20250115102408.2225055-1-jiawenwu@trustnetic.com>

On Wed, Jan 15, 2025 at 06:24:07PM +0800, Jiawen Wu wrote:
> There is a new 40/25/10 Gigabit Ethernet device.
> 
> To support basic functions, PHYLINK is temporarily skipped as it is
> intended to implement these configurations in the firmware. And the
> associated link IRQ is also skipped.
> 
> And Implement the new SW-FW interaction interface, which use 64 Byte
> message buffer.
> 
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>

...

> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c

...

> +static bool wx_poll_fw_reply(struct wx *wx, u32 *buffer,
> +			     struct wx_hic_hdr *recv_hdr, u8 send_cmd)
> +{
> +	u32 dword_len = sizeof(struct wx_hic_hdr) >> 2;
> +	u32 i;
> +
> +	/* read hdr */
> +	for (i = 0; i < dword_len; i++) {
> +		buffer[i] = rd32a(wx, WX_FW2SW_MBOX, i);
> +		le32_to_cpus(&buffer[i]);
> +	}
> +
> +	/* check hdr */
> +	recv_hdr = (struct wx_hic_hdr *)buffer;
> +	if (recv_hdr->cmd == send_cmd &&
> +	    recv_hdr->index == wx->swfw_index)
> +		return true;

Hi Jiawen Wu,

Maybe I am misreading this but, given the way that recv_hdr is
passed to this function, it seems that the same result would
he achieved if recv_hdr was a local variable...

> +
> +	return false;
> +}
> +
> +static int wx_host_interface_command_r(struct wx *wx, u32 *buffer,
> +				       u32 length, u32 timeout, bool return_data)
> +{
> +	struct wx_hic_hdr *send_hdr = (struct wx_hic_hdr *)buffer;
> +	u32 hdr_size = sizeof(struct wx_hic_hdr);
> +	struct wx_hic_hdr *recv_hdr;
> +	bool busy, reply;
> +	u32 dword_len;
> +	u16 buf_len;
> +	int err = 0;
> +	u8 send_cmd;
> +	u32 i;
> +
> +	/* wait to get lock */
> +	might_sleep();
> +	err = read_poll_timeout(test_and_set_bit, busy, !busy, 1000, timeout * 1000,
> +				false, WX_STATE_SWFW_BUSY, wx->state);
> +	if (err)
> +		return err;
> +
> +	/* index to unique seq id for each mbox message */
> +	send_hdr->index = wx->swfw_index;
> +	send_cmd = send_hdr->cmd;
> +
> +	dword_len = length >> 2;
> +	/* write data to SW-FW mbox array */
> +	for (i = 0; i < dword_len; i++) {
> +		wr32a(wx, WX_SW2FW_MBOX, i, (__force u32)cpu_to_le32(buffer[i]));
> +		/* write flush */
> +		rd32a(wx, WX_SW2FW_MBOX, i);
> +	}
> +
> +	/* generate interrupt to notify FW */
> +	wr32m(wx, WX_SW2FW_MBOX_CMD, WX_SW2FW_MBOX_CMD_VLD, 0);
> +	wr32m(wx, WX_SW2FW_MBOX_CMD, WX_SW2FW_MBOX_CMD_VLD, WX_SW2FW_MBOX_CMD_VLD);
> +
> +	/* polling reply from FW */
> +	err = read_poll_timeout(wx_poll_fw_reply, reply, reply, 1000, 50000,
> +				true, wx, buffer, recv_hdr, send_cmd);
> +	if (err) {
> +		wx_err(wx, "Polling from FW messages timeout, cmd: 0x%x, index: %d\n",
> +		       send_cmd, wx->swfw_index);
> +		goto rel_out;
> +	}
> +
> +	/* expect no reply from FW then return */
> +	if (!return_data)
> +		goto rel_out;
> +
> +	/* If there is any thing in data position pull it in */
> +	buf_len = recv_hdr->buf_len;

... and most likely related, recv_hdr appears to be uninitialised here.

This part is flagged by W=1 builds with clang-19, and my Smatch.

> +	if (buf_len == 0)
> +		goto rel_out;
> +
> +	if (length < buf_len + hdr_size) {
> +		wx_err(wx, "Buffer not large enough for reply message.\n");
> +		err = -EFAULT;
> +		goto rel_out;
> +	}
> +
> +	/* Calculate length in DWORDs, add 3 for odd lengths */
> +	dword_len = (buf_len + 3) >> 2;
> +	for (i = hdr_size >> 2; i <= dword_len; i++) {
> +		buffer[i] = rd32a(wx, WX_FW2SW_MBOX, i);
> +		le32_to_cpus(&buffer[i]);
> +	}
> +
> +rel_out:
> +	/* index++, index replace wx_hic_hdr.checksum */
> +	if (send_hdr->index == WX_HIC_HDR_INDEX_MAX)
> +		wx->swfw_index = 0;
> +	else
> +		wx->swfw_index = send_hdr->index + 1;
> +
> +	clear_bit(WX_STATE_SWFW_BUSY, wx->state);
> +	return err;
> +}

...

  parent reply	other threads:[~2025-01-15 15:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-15 10:24 [PATCH net-next v3 1/2] net: txgbe: Add basic support for new AML devices Jiawen Wu
2025-01-15 10:24 ` [PATCH net-next v3 2/2] net: wangxun: Replace the judgement of MAC type with flags Jiawen Wu
2025-01-15 15:29 ` Simon Horman [this message]
2025-01-16  6:57   ` [PATCH net-next v3 1/2] net: txgbe: Add basic support for new AML devices Jiawen Wu
2025-01-16 12:33 ` 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=20250115152950.GO5497@kernel.org \
    --to=horms@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jiawenwu@trustnetic.com \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mengyuanlou@net-swift.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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).