[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aMSTDt0xOzhDH2Gr@lizhi-Precision-Tower-5810>
Date: Fri, 12 Sep 2025 17:39:26 -0400
From: Frank Li <Frank.li@....com>
To: Manivannan Sadhasivam <mani@...nel.org>
Cc: Krzysztof Wilczyński <kwilczynski@...nel.org>,
Kishon Vijay Abraham I <kishon@...nel.org>,
Bjorn Helgaas <bhelgaas@...gle.com>, Jon Mason <jdmason@...zu.us>,
Dave Jiang <dave.jiang@...el.com>, Allen Hubbe <allenbh@...il.com>,
linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
ntb@...ts.linux.dev
Subject: Re: [PATCH 2/2] PCI: endpoint: pci-epf-vntb: Add MSI doorbell support
On Sat, Aug 30, 2025 at 09:14:43PM +0530, Manivannan Sadhasivam wrote:
> On Fri, Aug 15, 2025 at 06:20:54PM GMT, Frank Li wrote:
> > Add MSI doorbell support to reduce latency between PCI host and EP.
> >
> > Before this change:
> > ping 169.254.172.137
> > 64 bytes from 169.254.172.137: icmp_seq=1 ttl=64 time=0.575 ms
> > 64 bytes from 169.254.172.137: icmp_seq=2 ttl=64 time=1.80 ms
> > 64 bytes from 169.254.172.137: icmp_seq=3 ttl=64 time=8.19 ms
> > 64 bytes from 169.254.172.137: icmp_seq=4 ttl=64 time=2.00 ms
> >
> > After this change:
> > ping 169.254.144.71
> > 64 bytes from 169.254.144.71: icmp_seq=1 ttl=64 time=0.215 ms
> > 64 bytes from 169.254.144.71: icmp_seq=2 ttl=64 time=0.456 ms
> > 64 bytes from 169.254.144.71: icmp_seq=3 ttl=64 time=0.448 ms
> >
> > Change u64 db to atomic_64 because difference doorbell may happen at the
> > same time.
> >
>
> Only the atomicity of db variable is enough?
So far yes, atomic OR and AND safe to check doorbell[n]'s each bit.
>
> > Signed-off-by: Frank Li <Frank.Li@....com>
> > ---
> > drivers/pci/endpoint/functions/pci-epf-vntb.c | 153 +++++++++++++++++++++++---
> > 1 file changed, 136 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> > index 83e9ab10f9c4fc2b485d5463faa2172500f12999..1c586205835fe9c7c5352e74819bccb4ece84438 100644
> > --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
> > +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> > @@ -36,11 +36,13 @@
> > * PCIe Root Port PCI EP
> > */
> >
> > +#include <linux/atomic.h>
> > #include <linux/delay.h>
> > #include <linux/io.h>
> > #include <linux/module.h>
> > #include <linux/slab.h>
> >
> > +#include <linux/pci-ep-msi.h>
> > #include <linux/pci-epc.h>
> > #include <linux/pci-epf.h>
> > #include <linux/ntb.h>
> > @@ -126,12 +128,13 @@ struct epf_ntb {
> > u32 db_count;
> > u32 spad_count;
> > u64 mws_size[MAX_MW];
> > - u64 db;
> > + atomic64_t db;
> > u32 vbus_number;
> > u16 vntb_pid;
> > u16 vntb_vid;
> >
> > bool linkup;
> > + bool msi_doorbell;
> > u32 spad_size;
> >
> > enum pci_barno epf_ntb_bar[VNTB_BAR_NUM];
> > @@ -258,9 +261,9 @@ static void epf_ntb_cmd_handler(struct work_struct *work)
> >
> > ntb = container_of(work, struct epf_ntb, cmd_handler.work);
> >
> > - for (i = 1; i < ntb->db_count; i++) {
> > + for (i = 1; i < ntb->db_count && !ntb->msi_doorbell; i++) {
> > if (ntb->epf_db[i]) {
> > - ntb->db |= 1 << (i - 1);
> > + atomic64_or(1 << (i - 1), &ntb->db);
> > ntb_db_event(&ntb->ntb, i);
> > ntb->epf_db[i] = 0;
> > }
> > @@ -319,7 +322,24 @@ static void epf_ntb_cmd_handler(struct work_struct *work)
> >
> > reset_handler:
> > queue_delayed_work(kpcintb_workqueue, &ntb->cmd_handler,
> > - msecs_to_jiffies(5));
> > + ntb->msi_doorbell ? msecs_to_jiffies(500) : msecs_to_jiffies(5));
> > +}
> > +
> > +static irqreturn_t epf_ntb_doorbell_handler(int irq, void *data)
> > +{
> > + struct epf_ntb *ntb = data;
> > + int i = 0;
> > +
> > + for (i = 1; i < ntb->db_count; i++)
> > + if (irq == ntb->epf->db_msg[i].virq) {
> > + atomic64_or(1 << (i - 1), &ntb->db);
> > + ntb_db_event(&ntb->ntb, i);
> > + }
> > +
> > + if (irq == ntb->epf->db_msg[0].virq)
> > + queue_delayed_work(kpcintb_workqueue, &ntb->cmd_handler, 0);
> > +
> > + return IRQ_HANDLED;
> > }
> >
> > /**
> > @@ -500,6 +520,90 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb)
> > return 0;
> > }
> >
> > +static int epf_ntb_db_bar_init_msi_doorbell(struct epf_ntb *ntb,
> > + struct pci_epf_bar *db_bar,
> > + const struct pci_epc_features *epc_features,
> > + enum pci_barno barno)
> > +{
> > + struct pci_epf *epf = ntb->epf;
> > + dma_addr_t low, high;
> > + struct msi_msg *msg;
> > + size_t sz;
> > + int ret;
> > + int i;
> > +
> > + ret = pci_epf_alloc_doorbell(epf, ntb->db_count);
> > + if (ret)
> > + return ret;
> > +
> > + for (i = 0; i < ntb->db_count; i++) {
> > + ret = request_irq(epf->db_msg[i].virq, epf_ntb_doorbell_handler,
> > + 0, "vntb_db", ntb);
> > +
> > + if (ret) {
> > + dev_err(&epf->dev,
> > + "Failed to request doorbell IRQ: %d\n",
> > + epf->db_msg[i].virq);
> > + goto err_request_irq;
> > + }
> > + }
> > +
> > + msg = &epf->db_msg[0].msg;
> > +
> > + high = 0;
> > + low = (u64)msg->address_hi << 32 | msg->address_lo;
>
> Can you remind me when the 'address_{hi/lo}' pairs are set?
set at pci_epf_alloc_doorbell().
Frank
>
> Rest looks OK to me.
>
> - Mani
>
> --
> மணிவண்ணன் சதாசிவம்
Powered by blists - more mailing lists