netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: libwx: fix firmware mailbox abnormal return
@ 2024-12-26  3:18 Jiawen Wu
  2024-12-31  2:11 ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Jiawen Wu @ 2024-12-26  3:18 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni, horms, rmk+kernel,
	netdev
  Cc: mengyuanlou, Jiawen Wu

Firmware writes back 'firmware ready' and 'unknown command' in the mailbox
message if there is an unknown command sent by driver. It tends to happen
with the use of custom firmware. So move the check for 'unknown command'
out of the poll timeout for 'firmware ready'. And adjust the debug log so
that mailbox messages are always printed when commands timeout.

Fixes: 1efa9bfe58c5 ("net: libwx: Implement interaction with firmware")
Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 drivers/net/ethernet/wangxun/libwx/wx_hw.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
index 1bf9c38e4125..7059e0100c7c 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
@@ -334,27 +334,25 @@ int wx_host_interface_command(struct wx *wx, u32 *buffer,
 	status = read_poll_timeout(rd32, hicr, hicr & WX_MNG_MBOX_CTL_FWRDY, 1000,
 				   timeout * 1000, false, wx, WX_MNG_MBOX_CTL);
 
+	buf[0] = rd32(wx, WX_MNG_MBOX);
+	if ((buf[0] & 0xff0000) >> 16 == 0x80) {
+		wx_dbg(wx, "It's unknown cmd.\n");
+		status = -EINVAL;
+		goto rel_out;
+	}
+
 	/* Check command completion */
 	if (status) {
 		wx_dbg(wx, "Command has failed with no status valid.\n");
-
-		buf[0] = rd32(wx, WX_MNG_MBOX);
-		if ((buffer[0] & 0xff) != (~buf[0] >> 24)) {
-			status = -EINVAL;
-			goto rel_out;
-		}
-		if ((buf[0] & 0xff0000) >> 16 == 0x80) {
-			wx_dbg(wx, "It's unknown cmd.\n");
-			status = -EINVAL;
-			goto rel_out;
-		}
-
 		wx_dbg(wx, "write value:\n");
 		for (i = 0; i < dword_len; i++)
 			wx_dbg(wx, "%x ", buffer[i]);
 		wx_dbg(wx, "read value:\n");
 		for (i = 0; i < dword_len; i++)
 			wx_dbg(wx, "%x ", buf[i]);
+		wx_dbg(wx, "check: %x %x\n", buffer[0] & 0xff, ~buf[0] >> 24);
+		if ((buffer[0] & 0xff) != (~buf[0] >> 24))
+			goto rel_out;
 	}
 
 	if (!return_data)
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: libwx: fix firmware mailbox abnormal return
  2024-12-26  3:18 [PATCH net] net: libwx: fix firmware mailbox abnormal return Jiawen Wu
@ 2024-12-31  2:11 ` Jakub Kicinski
  2025-01-02  6:42   ` Jiawen Wu
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2024-12-31  2:11 UTC (permalink / raw)
  To: Jiawen Wu
  Cc: andrew+netdev, davem, edumazet, pabeni, horms, rmk+kernel, netdev,
	mengyuanlou

On Thu, 26 Dec 2024 11:18:10 +0800 Jiawen Wu wrote:
> Firmware writes back 'firmware ready' and 'unknown command' in the mailbox
> message if there is an unknown command sent by driver. It tends to happen
> with the use of custom firmware. So move the check for 'unknown command'
> out of the poll timeout for 'firmware ready'. And adjust the debug log so
> that mailbox messages are always printed when commands timeout.

The commit message doesn't really explain what the problem is, 
just what the code does. What is the problem you're solving 
and how does it impact the user?

> Fixes: 1efa9bfe58c5 ("net: libwx: Implement interaction with firmware")
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> ---
>  drivers/net/ethernet/wangxun/libwx/wx_hw.c | 22 ++++++++++------------
>  1 file changed, 10 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> index 1bf9c38e4125..7059e0100c7c 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> @@ -334,27 +334,25 @@ int wx_host_interface_command(struct wx *wx, u32 *buffer,
>  	status = read_poll_timeout(rd32, hicr, hicr & WX_MNG_MBOX_CTL_FWRDY, 1000,
>  				   timeout * 1000, false, wx, WX_MNG_MBOX_CTL);
>  
> +	buf[0] = rd32(wx, WX_MNG_MBOX);
> +	if ((buf[0] & 0xff0000) >> 16 == 0x80) {
> +		wx_dbg(wx, "It's unknown cmd.\n");
> +		status = -EINVAL;
> +		goto rel_out;
> +	}

Why check this before the status check? If the poll timed out doesn't
it mean the FW did not respond?

>  	/* Check command completion */
>  	if (status) {
>  		wx_dbg(wx, "Command has failed with no status valid.\n");
> -
> -		buf[0] = rd32(wx, WX_MNG_MBOX);
> -		if ((buffer[0] & 0xff) != (~buf[0] >> 24)) {
> -			status = -EINVAL;
> -			goto rel_out;
> -		}
> -		if ((buf[0] & 0xff0000) >> 16 == 0x80) {
> -			wx_dbg(wx, "It's unknown cmd.\n");
> -			status = -EINVAL;
> -			goto rel_out;
> -		}
> 
> +		wx_dbg(wx, "check: %x %x\n", buffer[0] & 0xff, ~buf[0] >> 24);
> +		if ((buffer[0] & 0xff) != (~buf[0] >> 24))
> +			goto rel_out;

Inverse question here, I guess. Why is it only an error for FW not 
to be ready if cmd doesn't match?
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH net] net: libwx: fix firmware mailbox abnormal return
  2024-12-31  2:11 ` Jakub Kicinski
@ 2025-01-02  6:42   ` Jiawen Wu
  2025-01-03  0:37     ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Jiawen Wu @ 2025-01-02  6:42 UTC (permalink / raw)
  To: 'Jakub Kicinski'
  Cc: andrew+netdev, davem, edumazet, pabeni, horms, rmk+kernel, netdev,
	mengyuanlou

On Tue, Dec 31, 2024 10:12 AM, Jakub Kicinski wrote:
> On Thu, 26 Dec 2024 11:18:10 +0800 Jiawen Wu wrote:
> > Firmware writes back 'firmware ready' and 'unknown command' in the mailbox
> > message if there is an unknown command sent by driver. It tends to happen
> > with the use of custom firmware. So move the check for 'unknown command'
> > out of the poll timeout for 'firmware ready'. And adjust the debug log so
> > that mailbox messages are always printed when commands timeout.
> 
> The commit message doesn't really explain what the problem is,
> just what the code does. What is the problem you're solving
> and how does it impact the user?

The problem has not happened yet, but the code behavior is wrong. 
Follow this wrong flow, driver would never return error if there is a unknown
command. Since reading 'firmware ready' does not timeout. Thus driver would
mistakenly believe that the interaction has completed successfully.

> 
> > Fixes: 1efa9bfe58c5 ("net: libwx: Implement interaction with firmware")
> > Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> > ---
> >  drivers/net/ethernet/wangxun/libwx/wx_hw.c | 22 ++++++++++------------
> >  1 file changed, 10 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> > index 1bf9c38e4125..7059e0100c7c 100644
> > --- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> > +++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
> > @@ -334,27 +334,25 @@ int wx_host_interface_command(struct wx *wx, u32 *buffer,
> >  	status = read_poll_timeout(rd32, hicr, hicr & WX_MNG_MBOX_CTL_FWRDY, 1000,
> >  				   timeout * 1000, false, wx, WX_MNG_MBOX_CTL);
> >
> > +	buf[0] = rd32(wx, WX_MNG_MBOX);
> > +	if ((buf[0] & 0xff0000) >> 16 == 0x80) {
> > +		wx_dbg(wx, "It's unknown cmd.\n");
> > +		status = -EINVAL;
> > +		goto rel_out;
> > +	}
> 
> Why check this before the status check? If the poll timed out doesn't
> it mean the FW did not respond?

Firmware writes back 'firmware ready' and 'unknown command', so the poll
will not time out.

> 
> >  	/* Check command completion */
> >  	if (status) {
> >  		wx_dbg(wx, "Command has failed with no status valid.\n");
> > -
> > -		buf[0] = rd32(wx, WX_MNG_MBOX);
> > -		if ((buffer[0] & 0xff) != (~buf[0] >> 24)) {
> > -			status = -EINVAL;
> > -			goto rel_out;
> > -		}
> > -		if ((buf[0] & 0xff0000) >> 16 == 0x80) {
> > -			wx_dbg(wx, "It's unknown cmd.\n");
> > -			status = -EINVAL;
> > -			goto rel_out;
> > -		}
> >
> > +		wx_dbg(wx, "check: %x %x\n", buffer[0] & 0xff, ~buf[0] >> 24);
> > +		if ((buffer[0] & 0xff) != (~buf[0] >> 24))
> > +			goto rel_out;
> 
> Inverse question here, I guess. Why is it only an error for FW not
> to be ready if cmd doesn't match?

It is to check if the cmd has been processed by FW. If it matches, it means
that FW has already processed the cmd, but FWRDY timeout for some
unknown reason.
 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: libwx: fix firmware mailbox abnormal return
  2025-01-02  6:42   ` Jiawen Wu
@ 2025-01-03  0:37     ` Jakub Kicinski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2025-01-03  0:37 UTC (permalink / raw)
  To: Jiawen Wu
  Cc: andrew+netdev, davem, edumazet, pabeni, horms, rmk+kernel, netdev,
	mengyuanlou

On Thu, 2 Jan 2025 14:42:30 +0800 Jiawen Wu wrote:
> > >  	/* Check command completion */
> > >  	if (status) {
> > >  		wx_dbg(wx, "Command has failed with no status valid.\n");
> > > -
> > > -		buf[0] = rd32(wx, WX_MNG_MBOX);
> > > -		if ((buffer[0] & 0xff) != (~buf[0] >> 24)) {
> > > -			status = -EINVAL;
> > > -			goto rel_out;
> > > -		}
> > > -		if ((buf[0] & 0xff0000) >> 16 == 0x80) {
> > > -			wx_dbg(wx, "It's unknown cmd.\n");
> > > -			status = -EINVAL;
> > > -			goto rel_out;
> > > -		}
> > >
> > > +		wx_dbg(wx, "check: %x %x\n", buffer[0] & 0xff, ~buf[0] >> 24);
> > > +		if ((buffer[0] & 0xff) != (~buf[0] >> 24))
> > > +			goto rel_out;  
> > 
> > Inverse question here, I guess. Why is it only an error for FW not
> > to be ready if cmd doesn't match?  
> 
> It is to check if the cmd has been processed by FW. If it matches, it means
> that FW has already processed the cmd, but FWRDY timeout for some
> unknown reason.

Feels a little risky. AFAICT the value we're comparing is just 
a checksum (potentially always set to 0xff?) It doesn't seem to
identify the command very well. If the command timed out let's
always return an error.

The other explanations make sense, please include them in the commit
msg.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-03  0:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-26  3:18 [PATCH net] net: libwx: fix firmware mailbox abnormal return Jiawen Wu
2024-12-31  2:11 ` Jakub Kicinski
2025-01-02  6:42   ` Jiawen Wu
2025-01-03  0:37     ` Jakub Kicinski

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