Subject: Re: [PATCH net-next v5 01/10] net: libwx: Add malibox api for wangxun pf drivers

From: Simon Horman <[email-masked]>
Date: Mon, 5 Aug 2024 17:41:54 +0100

On Sun, Aug 04, 2024 at 08:48:32PM +0800, Mengyuan Lou wrote:
> Implements the mailbox interfaces for wangxun pf drivers
> ngbe and txgbe.
> 
> Signed-off-by: Mengyuan Lou <[email-masked]>

...

> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_mbx.c b/drivers/net/ethernet/wangxun/libwx/wx_mbx.c
> new file mode 100644
> index 000000000000..5062ddb2ce39
> --- /dev/null
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_mbx.c
> @@ -0,0 +1,175 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2015 - 2024 Beijing WangXun Technology Co., Ltd. */
> +#include <linux/pci.h>
> +#include "wx_type.h"
> +#include "wx_mbx.h"
> +
> +/**
> + *  wx_obtain_mbx_lock_pf - obtain mailbox lock
> + *  @wx: pointer to the HW structure
> + *  @vf: the VF index
> + *
> + *  return: return 0 on success and -EBUSY on failure
> + **/
> +static int wx_obtain_mbx_lock_pf(struct wx *wx, u16 vf)
> +{
> +	int count = 5;
> +	u32 mailbox;
> +
> +	while (count--) {
> +		/* Take ownership of the buffer */
> +		wr32(wx, WX_PXMAILBOX(vf), WX_PXMAILBOX_PFU);
> +
> +		/* reserve mailbox for vf use */
> +		mailbox = rd32(wx, WX_PXMAILBOX(vf));
> +		if (mailbox & WX_PXMAILBOX_PFU)
> +			return 0;
> +		else if (count != 1)

Should this be 'else if (count)' in order to skip the delay
on the last rather than 2nd to last iteration without success?

> +			udelay(10);
> +	}
> +	wx_err(wx, "Failed to obtain mailbox lock for PF%d", vf);
> +
> +	return -EBUSY;
> +}

...