Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Chiqijun <chiqijun@huawei.com>,
	Alex Williamson <alex.williamson@redhat.com>
Cc: "bhelgaas@google.com" <bhelgaas@google.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Yinshi (Stone)" <yin.yinshi@huawei.com>,
	"Wangxiaoyun (Cloud)" <cloud.wangxiaoyun@huawei.com>,
	zengweiliang zengweiliang <zengweiliang.zengweiliang@huawei.com>,
	"Chenlizhong (IT Chip)" <chenlizhong@huawei.com>
Subject: Re: [v3] PCI: Add pci reset quirk for Huawei Intelligent NIC virtual function
Date: Thu, 21 Jan 2021 09:30:43 -0600	[thread overview]
Message-ID: <20210121153043.GA2654954@bjorn-Precision-5520> (raw)
In-Reply-To: <7e0a6c6c-a12c-ee54-0468-69079b8edde4@huawei.com>

[Alex is a reset expert, hoping he can chime in]

On Thu, Jan 21, 2021 at 08:53:12PM +0800, Chiqijun wrote:
> On 2021/1/9 6:25, Bjorn Helgaas wrote:
> > On Fri, Dec 25, 2020 at 05:25:30PM +0800, Chiqijun wrote:
> > > When multiple VFs do FLR at the same time, the firmware is
> > > processed serially, resulting in some VF FLRs being delayed more
> > > than 100ms, when the virtual machine restarts and the device
> > > driver is loaded, the firmware is doing the corresponding VF
> > > FLR, causing the driver to fail to load.
> > > 
> > > To solve this problem, add host and firmware status synchronization
> > > during FLR.
> > > 
> > > Signed-off-by: Chiqijun <chiqijun@huawei.com>
> > > ...

> > > +	 * Get and check firmware capabilities.
> > > +	 */
> > > +	val = readl(bar + HINIC_VF_FLR_TYPE);
> > > +	if (!(val & (1UL << HINIC_VF_FLR_CAP_BIT_SHIFT))) {
> > > +		pci_iounmap(pdev, bar);
> > > +		return -ENOTTY;
> > > +	}
> > > +
> > > +	/*
> > > +	 * Set the processing bit for the start of FLR, which will be cleared
> > > +	 * by the firmware after FLR is completed.
> > > +	 */
> > > +	val = readl(bar + HINIC_VF_OP);
> > > +	val = val | (1UL << HINIC_VF_FLR_PROC_BIT_SHIFT);
> > > +	writel(val, bar + HINIC_VF_OP);
> > > +
> > > +	/* Perform the actual device function reset */
> > > +	pcie_flr(pdev);
> > > +
> > > +	/*
> > > +	 * The device must learn BDF after FLR in order to respond to BAR's
> > > +	 * read request, therefore, we issue a configure write request to let
> > > +	 * the device capture BDF.
> > > +	 */
> > > +	pci_read_config_word(pdev, PCI_COMMAND, &command);
> > > +	pci_write_config_word(pdev, PCI_COMMAND, command);
> > 
> > I assume this is because of this requirement from PCIe r5.0, sec
> > 2.2.9:
> > 
> >    Functions must capture the Bus and Device Numbers supplied with all
> >    Type 0 Configuration Write Requests completed by the Function, and
> >    supply these numbers in the Bus and Device Number fields of the
> >    Completer ID for all Completions generated by the Device/Function.
> > 
> > I'm a little concerned because it seems like this requirement should
> > apply to *all* resets, and I don't see where we do a similar write
> > following other resets.  Can you help me out?  Do we need this in
> > other cases?  Do we do it?
> 
> This depends on the hardware device. The HINIC device clears the BDF
> information of the VF during FLR, so it relies on Configuration
> Write Requests to capture BDF. If other devices do not clear the DBF
> information during FLR, this operation is not required.

If the spec says devices must keep the latched BDF during FLR, and the
HINIC doesn't comply with that, then it makes sense to do a config
write here in HINIC-specific code.

But if devices are allowed to clear the BDF during FLR, the OS has to
assume they all do, and the generic code for FLR (and probably other
resets) should do a config write so devices can latch the BDF again.

> In addition, I did not find other devices directly access the BAR register
> after FLR in resets.

I didn't catch your meaning here.

If a device loses the BDF during FLR and we don't do something to
allow it to latch the BDF again, any completions from the device will
have the wrong information.  We will likely do *some* config write to
the device eventually, which will fix this, but we can't rely on some
unknown future write to do this.  If it's a problem, we need to
explicitly do a write for this purpose.

Bjorn

  reply	other threads:[~2021-01-21 15:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-25  9:25 [v3] PCI: Add pci reset quirk for Huawei Intelligent NIC virtual function Chiqijun
2021-01-04 20:13 ` Alex Williamson
2021-01-08 22:25 ` Bjorn Helgaas
2021-01-21 12:53   ` Chiqijun
2021-01-21 15:30     ` Bjorn Helgaas [this message]
2021-02-09 10:57       ` Chiqijun

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=20210121153043.GA2654954@bjorn-Precision-5520 \
    --to=helgaas@kernel.org \
    --cc=alex.williamson@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=chenlizhong@huawei.com \
    --cc=chiqijun@huawei.com \
    --cc=cloud.wangxiaoyun@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=yin.yinshi@huawei.com \
    --cc=zengweiliang.zengweiliang@huawei.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