mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Yibo Dong <dong100@mucse.com>
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	corbet@lwn.net, gur.stavi@huawei.com, maddy@linux.ibm.com,
	mpe@ellerman.id.au, danishanwar@ti.com, lee@trager.us,
	gongfan1@huawei.com, lorenzo@kernel.org, geert+renesas@glider.be,
	Parthiban.Veerasooran@microchip.com, lukas.bulwahn@redhat.com,
	alexanderduyck@fb.com, richardcochran@gmail.com, kees@kernel.org,
	gustavoars@kernel.org, rdunlap@infradead.org,
	vadim.fedorenko@linux.dev, netdev@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH net-next v10 3/5] net: rnpgbe: Add basic mbx ops support
Date: Thu, 4 Sep 2025 14:05:57 +0200	[thread overview]
Message-ID: <908e4c95-81cb-4a95-9235-2d2c8c80d80c@lunn.ch> (raw)
In-Reply-To: <AF92025D9CBFCF3B+20250904031948.GA1022066@nic-Precision-5820-Tower>

On Thu, Sep 04, 2025 at 11:19:48AM +0800, Yibo Dong wrote:
> On Thu, Sep 04, 2025 at 12:24:17AM +0200, Andrew Lunn wrote:
> > >  struct mucse_mbx_info {
> > > +	struct mucse_mbx_stats stats;
> > > +	u32 timeout;
> > > +	u32 usec_delay;
> > > +	u16 size;
> > > +	u16 fw_req;
> > > +	u16 fw_ack;
> > > +	/* lock for only one use mbx */
> > > +	struct mutex lock;
> > >  	/* fw <--> pf mbx */
> > >  	u32 fw_pf_shm_base;
> > >  	u32 pf2fw_mbox_ctrl;
> > 
> > > +/**
> > > + * mucse_obtain_mbx_lock_pf - Obtain mailbox lock
> > > + * @hw: pointer to the HW structure
> > > + *
> > > + * This function maybe used in an irq handler.
> > > + *
> > > + * Return: 0 if we obtained the mailbox lock or else -EIO
> > > + **/
> > > +static int mucse_obtain_mbx_lock_pf(struct mucse_hw *hw)
> > > +{
> > > +	struct mucse_mbx_info *mbx = &hw->mbx;
> > > +	int try_cnt = 5000;
> > > +	u32 reg;
> > > +
> > > +	reg = PF2FW_MBOX_CTRL(mbx);
> > > +	while (try_cnt-- > 0) {
> > > +		mbx_ctrl_wr32(mbx, reg, MBOX_PF_HOLD);
> > > +		/* force write back before check */
> > > +		wmb();
> > > +		if (mbx_ctrl_rd32(mbx, reg) & MBOX_PF_HOLD)
> > > +			return 0;
> > > +		udelay(100);
> > > +	}
> > > +	return -EIO;
> > > +}
> > 
> > If there is a function which obtains a lock, there is normally a
> > function which releases a lock. But i don't see it.
> > 
> 
> The lock is relased when send MBOX_CTRL_REQ in mucse_write_mbx_pf:
> 
> mbx_ctrl_wr32(mbx, ctrl_reg, MBOX_CTRL_REQ);
> 
> Set MBOX_PF_HOLD(bit3) to hold the lock, clear bit3 to release, and set
> MBOX_CTRL_REQ(bit0) to send the req. req and lock are different bits in
> one register. So we send the req along with releasing lock (set bit0 and
> clear bit3).
> Maybe I should add comment like this?
> 
> /* send the req along with releasing the lock */
> mbx_ctrl_wr32(mbx, ctrl_reg, MBOX_CTRL_REQ);

As i said, functions like this come in pairs. obtain/release,
lock/unlock. When reading code, you want to be able to see both of the
pair in a function, to know the unlock is not missing. The kernel even
has tools which will validate all paths through a function releasing
locks. Often error paths get this wrong.

So please make this a function, give it a name which makes it obvious
it is the opposite of mucse_obtain_mbx_lock_pf().

	Andrew

  reply	other threads:[~2025-09-04 12:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-03  2:54 [PATCH net-next v10 0/5] Add driver for 1Gbe network chips from MUCSE Dong Yibo
2025-09-03  2:54 ` [PATCH net-next v10 1/5] net: rnpgbe: Add build support for rnpgbe Dong Yibo
2025-09-03  2:54 ` [PATCH net-next v10 2/5] net: rnpgbe: Add n500/n210 chip support Dong Yibo
2025-09-03  2:54 ` [PATCH net-next v10 3/5] net: rnpgbe: Add basic mbx ops support Dong Yibo
2025-09-03 10:53   ` Vadim Fedorenko
2025-09-03 11:12     ` Yibo Dong
2025-09-03 12:43       ` Vadim Fedorenko
2025-09-04  2:08         ` Yibo Dong
2025-09-03 16:44   ` Simon Horman
2025-09-04  2:38     ` Yibo Dong
2025-09-03 22:24   ` Andrew Lunn
2025-09-04  3:19     ` Yibo Dong
2025-09-04 12:05       ` Andrew Lunn [this message]
2025-09-05  1:16         ` Yibo Dong
2025-09-03  2:54 ` [PATCH net-next v10 4/5] net: rnpgbe: Add basic mbx_fw support Dong Yibo
2025-09-03 22:45   ` Andrew Lunn
2025-09-04  2:57     ` Yibo Dong
2025-09-03  2:54 ` [PATCH net-next v10 5/5] net: rnpgbe: Add register_netdev Dong Yibo
2025-09-03 22:53   ` Andrew Lunn
2025-09-04  3:06     ` Yibo Dong
2025-09-04 12:35       ` Andrew Lunn
2025-09-05  1:27         ` Yibo Dong

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=908e4c95-81cb-4a95-9235-2d2c8c80d80c@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=Parthiban.Veerasooran@microchip.com \
    --cc=alexanderduyck@fb.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=danishanwar@ti.com \
    --cc=davem@davemloft.net \
    --cc=dong100@mucse.com \
    --cc=edumazet@google.com \
    --cc=geert+renesas@glider.be \
    --cc=gongfan1@huawei.com \
    --cc=gur.stavi@huawei.com \
    --cc=gustavoars@kernel.org \
    --cc=horms@kernel.org \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lee@trager.us \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=lukas.bulwahn@redhat.com \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=richardcochran@gmail.com \
    --cc=vadim.fedorenko@linux.dev \
    /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

all inboxes | Powered by JetHome®