Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@nxp.com>
To: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Cc: "Krzysztof Wilczyński" <kw@linux.com>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	imx@lists.linux.dev, "Niklas Cassel" <cassel@kernel.org>,
	dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de,
	jdmason@kudzu.us
Subject: Re: [PATCH v8 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support
Date: Mon, 25 Nov 2024 14:17:04 -0500	[thread overview]
Message-ID: <Z0TNMIX4ehaB+mSn@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20241124075645.szue5nzm4gcjspxf@thinkpad>

On Sun, Nov 24, 2024 at 01:26:45PM +0530, Manivannan Sadhasivam wrote:
> On Sat, Nov 16, 2024 at 09:40:44AM -0500, Frank Li wrote:
> > Add three registers: doorbell_bar, doorbell_addr, and doorbell_data,
> > along with doorbell_done. Use pci_epf_alloc_doorbell() to allocate a
>
> I don't see 'doorbell_done' defined anywhere.
>
> > doorbell address space.
> >
> > Enable the Root Complex (RC) side driver to trigger pci-epc-test's doorbell
> > callback handler by writing doorbell_data to the mapped doorbell_bar's
> > address space.
> >
> > Set doorbell_done in the doorbell callback to indicate completion.
> >
>
> Same here.
>
> > To avoid broken compatibility, add new command COMMAND_ENABLE_DOORBELL
>
> 'avoid breaking compatibility between host and endpoint,...'
>
> > and COMMAND_DISABLE_DOORBELL. Host side need send COMMAND_ENABLE_DOORBELL
> > to map one bar's inbound address to MSI space. the command
> > COMMAND_DISABLE_DOORBELL to recovery original inbound address mapping.
> >
> > 	 	Host side new driver	Host side old driver
> >
> > EP: new driver      S				F
> > EP: old driver      F				F
>
> So the last case of old EP and host drivers will fail?

doorbell test will fail if old EP.

>
> >
> > S: If EP side support MSI, 'pcitest -B' return success.
> >    If EP side doesn't support MSI, the same to 'F'.
> >
> > F: 'pcitest -B' return failure, other case as usual.
> >
> > Tested-by: Niklas Cassel <cassel@kernel.org>
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> > Change from v7 to v8
> > - rename to pci_epf_align_inbound_addr_lo_hi()
> >
> > Change from v6 to v7
> > - use help function pci_epf_align_addr_lo_hi()
> >
> > Change from v5 to v6
> > - rename doorbell_addr to doorbell_offset
> >
> > Chagne from v4 to v5
> > - Add doorbell free at unbind function.
> > - Move msi irq handler to here to more complex user case, such as differece
> > doorbell can use difference handler function.
> > - Add Niklas's code to handle fixed bar's case. If need add your signed-off
> > tag or co-developer tag, please let me know.
> >
> > change from v3 to v4
> > - remove revid requirement
> > - Add command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL.
> > - call pci_epc_set_bar() to map inbound address to MSI space only at
> > COMMAND_ENABLE_DOORBELL.
> > ---
> >  drivers/pci/endpoint/functions/pci-epf-test.c | 117 ++++++++++++++++++++++++++
> >  1 file changed, 117 insertions(+)
> >
> > diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
> > index ef6677f34116e..410b2f4bb7ce7 100644
> > --- a/drivers/pci/endpoint/functions/pci-epf-test.c
> > +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
> > @@ -11,12 +11,14 @@
> >  #include <linux/dmaengine.h>
> >  #include <linux/io.h>
> >  #include <linux/module.h>
> > +#include <linux/msi.h>
> >  #include <linux/slab.h>
> >  #include <linux/pci_ids.h>
> >  #include <linux/random.h>
> >
> >  #include <linux/pci-epc.h>
> >  #include <linux/pci-epf.h>
> > +#include <linux/pci-ep-msi.h>
> >  #include <linux/pci_regs.h>
> >
> >  #define IRQ_TYPE_INTX			0
> > @@ -29,6 +31,8 @@
> >  #define COMMAND_READ			BIT(3)
> >  #define COMMAND_WRITE			BIT(4)
> >  #define COMMAND_COPY			BIT(5)
> > +#define COMMAND_ENABLE_DOORBELL		BIT(6)
> > +#define COMMAND_DISABLE_DOORBELL	BIT(7)
> >
> >  #define STATUS_READ_SUCCESS		BIT(0)
> >  #define STATUS_READ_FAIL		BIT(1)
> > @@ -39,6 +43,11 @@
> >  #define STATUS_IRQ_RAISED		BIT(6)
> >  #define STATUS_SRC_ADDR_INVALID		BIT(7)
> >  #define STATUS_DST_ADDR_INVALID		BIT(8)
> > +#define STATUS_DOORBELL_SUCCESS		BIT(9)
> > +#define STATUS_DOORBELL_ENABLE_SUCCESS	BIT(10)
> > +#define STATUS_DOORBELL_ENABLE_FAIL	BIT(11)
> > +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12)
> > +#define STATUS_DOORBELL_DISABLE_FAIL	BIT(13)
> >
> >  #define FLAG_USE_DMA			BIT(0)
> >
> > @@ -74,6 +83,9 @@ struct pci_epf_test_reg {
> >  	u32	irq_type;
> >  	u32	irq_number;
> >  	u32	flags;
> > +	u32	doorbell_bar;
> > +	u32	doorbell_offset;
> > +	u32	doorbell_data;
> >  } __packed;
> >
> >  static struct pci_epf_header test_header = {
> > @@ -642,6 +654,63 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test,
> >  	}
> >  }
> >
> > +static void pci_epf_enable_doorbell(struct pci_epf_test *epf_test, struct pci_epf_test_reg *reg)
> > +{
> > +	enum pci_barno bar = reg->doorbell_bar;
> > +	struct pci_epf *epf = epf_test->epf;
> > +	struct pci_epc *epc = epf->epc;
> > +	struct pci_epf_bar db_bar;
>
> db_bar = {};
>
> > +	struct msi_msg *msg;
> > +	size_t offset;
> > +	int ret;
> > +
> > +	if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) {
>
> What is the need of BAR check here and below? pci_epf_alloc_doorbell() should've
> allocated proper BAR already.

Not check it at call pci_epf_alloc_doorbell() because it optional feature.
It return failure when it actually use it.

>
> > +		reg->status |= STATUS_DOORBELL_ENABLE_FAIL;
> > +		return;
> > +	}
> > +
> > +	msg = &epf->db_msg[0].msg;
> > +	ret = pci_epf_align_inbound_addr_lo_hi(epf, bar, msg->address_lo, msg->address_hi,
> > +					       &db_bar.phys_addr, &offset);
> > +
> > +	if (ret) {
> > +		reg->status |= STATUS_DOORBELL_ENABLE_FAIL;
> > +		return;
> > +	}
> > +
> > +	reg->doorbell_offset = offset;
> > +
> > +	db_bar.barno = bar;
> > +	db_bar.size = epf->bar[bar].size;
> > +	db_bar.flags = epf->bar[bar].flags;
> > +	db_bar.addr = NULL;
>
> Not needed if you initialize above.
>
> > +
> > +	ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar);
> > +	if (!ret)
> > +		reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS;
> > +	else
> > +		reg->status |= STATUS_DOORBELL_ENABLE_FAIL;
> > +}
> > +
>
> [...]
>
> >  static const struct pci_epc_event_ops pci_epf_test_event_ops = {
> >  	.epc_init = pci_epf_test_epc_init,
> >  	.epc_deinit = pci_epf_test_epc_deinit,
> > @@ -921,12 +1010,34 @@ static int pci_epf_test_bind(struct pci_epf *epf)
> >  	if (ret)
> >  		return ret;
> >
> > +	ret = pci_epf_alloc_doorbell(epf, 1);
> > +	if (!ret) {
> > +		struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
> > +		struct msi_msg *msg = &epf->db_msg[0].msg;
> > +		enum pci_barno bar;
> > +
> > +		bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1);
>
> NO_BAR check?

This is optional feature, It should check when use it.

Frank

>
> - Mani
>
> --
> மணிவண்ணன் சதாசிவம்

  reply	other threads:[~2024-11-25 19:17 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-16 14:40 [PATCH v8 0/6] PCI: EP: Add RC-to-EP doorbell with platform MSI controller Frank Li
2024-11-16 14:40 ` [PATCH v8 1/6] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Frank Li
2024-11-16 14:40 ` [PATCH v8 2/6] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Frank Li
2024-11-24  7:11   ` Manivannan Sadhasivam
2024-11-24  9:56     ` Niklas Cassel
2024-11-24 13:17       ` Manivannan Sadhasivam
2024-11-24 15:26         ` Niklas Cassel
2024-11-25 18:03     ` Frank Li
2024-11-26  4:14       ` Manivannan Sadhasivam
2024-11-26 17:19         ` Frank Li
2024-11-27  6:20           ` Manivannan Sadhasivam
2024-11-16 14:40 ` [PATCH v8 3/6] PCI: endpoint: Add pci_epf_align_addr() helper for address alignment Frank Li
2024-11-24  7:32   ` Manivannan Sadhasivam
2024-11-25 19:22     ` Frank Li
2024-11-26  4:19       ` Manivannan Sadhasivam
2024-11-26  9:36         ` Niklas Cassel
2024-11-26 10:27         ` Niklas Cassel
2024-11-16 14:40 ` [PATCH v8 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support Frank Li
2024-11-24  7:56   ` Manivannan Sadhasivam
2024-11-25 19:17     ` Frank Li [this message]
2024-11-26  4:25       ` Manivannan Sadhasivam
2024-11-26 10:00         ` Niklas Cassel
2024-11-26 12:41           ` Manivannan Sadhasivam
2024-11-26 16:55             ` Frank Li
2024-11-27  8:53               ` Niklas Cassel
2024-11-26 16:46         ` Frank Li
2024-11-16 14:40 ` [PATCH v8 5/6] misc: pci_endpoint_test: Add doorbell test case Frank Li
2024-11-24 13:51   ` Manivannan Sadhasivam
2024-11-25 19:12     ` Frank Li
2024-11-16 14:40 ` [PATCH v8 6/6] tools: PCI: Add 'B' option for test doorbell Frank Li

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=Z0TNMIX4ehaB+mSn@lizhi-Precision-Tower-5810 \
    --to=frank.li@nxp.com \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=jdmason@kudzu.us \
    --cc=kishon@kernel.org \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=maz@kernel.org \
    --cc=tglx@linutronix.de \
    /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