┌────────────┐ ┌───────────────────────────────────┐ ┌────────────────┐
│ │ │ │ │ │
│ │ │ PCI Endpoint │ │ PCI Host │
│ │ │ │ │ │
│ │◄──┤ 1.platform_msi_domain_alloc_irqs()│ │ │
│ │ │ │ │ │
│ MSI ├──►│ 2.write_msi_msg() ├──►├─BAR<n> │
│ Controller │ │ update doorbell register address│ │ │
│ │ │ for BAR │ │ │
│ │ │ │ │ 3. Write BAR<n>│
│ │◄──┼───────────────────────────────────┼───┤ │
│ │ │ │ │ │
│ ├──►│ 4.Irq Handle │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└────────────┘ └───────────────────────────────────┘ └────────────────┘
This patches based on old https://lore.kernel.org/imx/[email protected]/
Original patch only target to vntb driver. But actually it is common
method.
This patches add new API to pci-epf-core, so any EP driver can use it.
The key point is comments from Thomas Gleixner, who suggest use new
PCI/IMS. But arm platform change still not be merged yet.
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git devmsi-v2-arm
So I still use existed method implement RC to EP doorbell.
If Thomas Gleixner want to continue work on devmsi-v2-arm, I can help test
and update this patch.
Frank Li (3):
PCI: endpoint: Add RC-to-EP doorbell support using platform MSI
controller
misc: pci_endpoint_test: Add doorbell test case
tools: PCI: Add 'B' option for test doorbell
drivers/misc/pci_endpoint_test.c | 41 +++++++++++
drivers/pci/endpoint/pci-epf-core.c | 109 ++++++++++++++++++++++++++++
include/linux/pci-epf.h | 16 ++++
include/uapi/linux/pcitest.h | 1 +
tools/pci/pcitest.c | 16 +++-
5 files changed, 182 insertions(+), 1 deletion(-)
--
2.34.1
This commit introduces a common method for sending messages from the Root Complex
(RC) to the Endpoint (EP) by utilizing the platform MSI interrupt controller,
such as ARM GIC, as an EP doorbell. Maps the memory assigned for the BAR region
by the PCI host to the message address of the platform MSI interrupt controller
in the PCI EP. As a result, when the PCI RC writes to the BAR region, it triggers
an IRQ at the EP. This implementation serves as a common method for all endpoint
function drivers.
However, it currently supports only one EP physical function due to limitations
in ARM MSI/IMS readiness.
Signed-off-by: Frank Li <[email protected]>
---
drivers/pci/endpoint/pci-epf-core.c | 109 ++++++++++++++++++++++++++++
include/linux/pci-epf.h | 16 ++++
2 files changed, 125 insertions(+)
diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 355a6f56fcea..94ac82bf84c5 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -6,10 +6,12 @@
* Author: Kishon Vijay Abraham I <[email protected]>
*/
+#include <linux/irqreturn.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/slab.h>
#include <linux/module.h>
+#include <linux/msi.h>
#include <linux/pci-epc.h>
#include <linux/pci-epf.h>
@@ -300,6 +302,113 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
}
EXPORT_SYMBOL_GPL(pci_epf_alloc_space);
+static enum irqreturn pci_epf_interrupt_handler(int irq, void *data)
+{
+ struct pci_epf *epf = data;
+
+ if (epf->event_ops && epf->event_ops->doorbell)
+ epf->event_ops->doorbell(epf, irq - epf->virq_base);
+
+ return IRQ_HANDLED;
+}
+
+static void pci_epf_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg)
+{
+ struct pci_epc *epc = container_of(desc->dev, struct pci_epc, dev);
+ struct pci_epf *epf;
+
+ /* Todo: Need check correct epf if multi epf supported */
+ list_for_each_entry(epf, &epc->pci_epf, list) {
+ if (epf->msg && desc->msi_index < epf->num_msgs)
+ epf->msg[desc->msi_index] = *msg;
+ }
+}
+
+int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_msgs)
+{
+ struct irq_domain *domain;
+ struct pci_epc *epc;
+ struct device *dev;
+ int virq;
+ int ret;
+ int i;
+
+ epc = epf->epc;
+ dev = &epc->dev;
+
+ /*
+ * Current only support 1 function.
+ * PCI IMS(interrupt message store) ARM support have not been
+ * ready yet.
+ */
+ if (epc->function_num_map != 1)
+ return -EOPNOTSUPP;
+
+ domain = dev_get_msi_domain(dev->parent);
+ if (!domain)
+ return -EOPNOTSUPP;
+ dev_set_msi_domain(dev, domain);
+
+ /* use parent of_node to get device id information */
+ dev->of_node = dev->parent->of_node;
+
+ epf->msg = kcalloc(num_msgs, sizeof(struct msi_msg), GFP_KERNEL);
+ if (!epf->msg)
+ return -ENOMEM;
+
+ epf->num_msgs = num_msgs;
+
+ ret = platform_msi_domain_alloc_irqs(dev, num_msgs, pci_epf_write_msi_msg);
+ if (ret) {
+ dev_err(dev, "Can't allocate MSI from system MSI controller\n");
+ goto err_mem;
+ }
+
+ for (i = 0; i < num_msgs; i++) {
+ virq = msi_get_virq(dev, i);
+ if (i == 0)
+ epf->virq_base = virq;
+
+ ret = request_irq(virq, pci_epf_interrupt_handler, 0,
+ "pci-epf-doorbell", epf);
+
+ if (ret) {
+ dev_err(dev, "Failure request doorbell IRQ\n");
+ goto err_irq;
+ }
+ }
+
+ epf->num_msgs = num_msgs;
+ return ret;
+
+err_irq:
+ platform_msi_domain_free_irqs(dev);
+err_mem:
+ kfree(epf->msg);
+ epf->msg = NULL;
+ epf->num_msgs = 0;
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell);
+
+void pci_epf_free_doorbell(struct pci_epf *epf)
+{
+ struct pci_epc *epc;
+ int i;
+
+ epc = epf->epc;
+
+ for (i = 0; i < epf->num_msgs; i++)
+ free_irq(epf->virq_base + i, epf);
+
+ platform_msi_domain_free_irqs(&epc->dev);
+ kfree(epf->msg);
+ epf->msg = NULL;
+ epf->num_msgs = 0;
+}
+EXPORT_SYMBOL_GPL(pci_epf_free_doorbell);
+
static void pci_epf_remove_cfs(struct pci_epf_driver *driver)
{
struct config_group *group, *tmp;
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index b8441db2fa52..e187e3ee48d2 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -75,6 +75,7 @@ struct pci_epf_ops {
struct pci_epc_event_ops {
int (*core_init)(struct pci_epf *epf);
int (*link_up)(struct pci_epf *epf);
+ int (*doorbell)(struct pci_epf *epf, int index);
};
/**
@@ -173,6 +174,9 @@ struct pci_epf {
unsigned long vfunction_num_map;
struct list_head pci_vepf;
const struct pci_epc_event_ops *event_ops;
+ struct msi_msg *msg;
+ u16 num_msgs;
+ int virq_base;
};
/**
@@ -216,4 +220,16 @@ int pci_epf_bind(struct pci_epf *epf);
void pci_epf_unbind(struct pci_epf *epf);
int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
+int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 nums);
+void pci_epf_free_doorbell(struct pci_epf *epf);
+
+static inline struct msi_msg *epf_get_msg(struct pci_epf *epf)
+{
+ return epf->msg;
+}
+
+static inline u16 epf_get_msg_num(struct pci_epf *epf)
+{
+ return epf->num_msgs;
+}
#endif /* __LINUX_PCI_EPF_H */
--
2.34.1
Reused flags as capability register in pci_endpoint_test struct to
support older driver versions. Save capability flags to 'cap' field
of struct pci_endpoint_test to prevent reading non-existent address.
Add three registers: PCIE_ENDPOINT_TEST_DB_BAR, PCIE_ENDPOINT_TEST_DB_ADDR,
PCIE_ENDPOINT_TEST_DB_DATA.
Write data from PCI_ENDPOINT_TEST_DB_DATA to address from
PCI_ENDPOINT_TEST_DB_ADDR to trigger doorbell and wait for remote
endpoint feedback.
Signed-off-by: Frank Li <[email protected]>
---
drivers/misc/pci_endpoint_test.c | 41 ++++++++++++++++++++++++++++++++
include/uapi/linux/pcitest.h | 1 +
2 files changed, 42 insertions(+)
diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index ed4d0ef5e5c3..3320a3334594 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -52,6 +52,7 @@
#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 PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c
#define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10
@@ -66,7 +67,12 @@
#define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28
#define PCI_ENDPOINT_TEST_FLAGS 0x2c
+#define PCI_ENDPOINT_TEST_DB_BAR 0x30
+#define PCI_ENDPOINT_TEST_DB_ADDR 0x34
+#define PCI_ENDPOINT_TEST_DB_DATA 0x38
+
#define FLAG_USE_DMA BIT(0)
+#define FLAG_SUPPORT_DOORBELL BIT(1)
#define PCI_DEVICE_ID_TI_AM654 0xb00c
#define PCI_DEVICE_ID_TI_J7200 0xb00f
@@ -102,6 +108,7 @@ enum pci_barno {
BAR_3,
BAR_4,
BAR_5,
+ NO_BAR = -1,
};
struct pci_endpoint_test {
@@ -118,6 +125,7 @@ struct pci_endpoint_test {
enum pci_barno test_reg_bar;
size_t alignment;
const char *name;
+ u32 cap;
};
struct pci_endpoint_test_data {
@@ -713,6 +721,35 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test,
return false;
}
+static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test)
+{
+ enum pci_barno bar;
+ u32 data;
+ u32 addr;
+
+ if (!(test->cap & FLAG_SUPPORT_DOORBELL))
+ return false;
+
+ bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR);
+ if (bar == NO_BAR)
+ return false;
+
+ data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA);
+ addr = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_ADDR);
+ bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR);
+
+ pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0);
+ pci_endpoint_test_bar_writel(test, bar, addr, data);
+
+ wait_for_completion(&test->irq_raised);
+
+ data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS);
+ if (data & STATUS_DOORBELL_SUCCESS)
+ return true;
+
+ return false;
+}
+
static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
@@ -760,6 +797,9 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
case PCITEST_CLEAR_IRQ:
ret = pci_endpoint_test_clear_irq(test);
break;
+ case PCITEST_DOORBELL:
+ ret = pci_endpoint_test_doorbell(test);
+ break;
}
ret:
@@ -887,6 +927,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
misc_device->parent = &pdev->dev;
misc_device->fops = &pci_endpoint_test_fops;
+ test->cap = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_FLAGS);
err = misc_register(misc_device);
if (err) {
dev_err(dev, "Failed to register device\n");
diff --git a/include/uapi/linux/pcitest.h b/include/uapi/linux/pcitest.h
index f9c1af8d141b..479ca1aa3ae0 100644
--- a/include/uapi/linux/pcitest.h
+++ b/include/uapi/linux/pcitest.h
@@ -20,6 +20,7 @@
#define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int)
#define PCITEST_GET_IRQTYPE _IO('P', 0x9)
#define PCITEST_CLEAR_IRQ _IO('P', 0x10)
+#define PCITEST_DOORBELL _IO('P', 0x11)
#define PCITEST_FLAGS_USE_DMA 0x00000001
--
2.34.1
Add doorbell test support.
Signed-off-by: Frank Li <[email protected]>
---
tools/pci/pcitest.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c
index 441b54234635..215d0aa8a09f 100644
--- a/tools/pci/pcitest.c
+++ b/tools/pci/pcitest.c
@@ -36,6 +36,7 @@ struct pci_test {
bool copy;
unsigned long size;
bool use_dma;
+ bool doorbell;
};
static int run_test(struct pci_test *test)
@@ -149,6 +150,15 @@ static int run_test(struct pci_test *test)
fprintf(stdout, "%s\n", result[ret]);
}
+ if (test->doorbell) {
+ ret = ioctl(fd, PCITEST_DOORBELL, 0);
+ fprintf(stdout, "Push doorbell\t\t");
+ if (ret < 0)
+ fprintf(stdout, "TEST FAILED\n");
+ else
+ fprintf(stdout, "%s\n", result[ret]);
+ }
+
fflush(stdout);
close(fd);
return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */
@@ -174,7 +184,7 @@ int main(int argc, char **argv)
/* set default endpoint device */
test->device = "/dev/pci-endpoint-test.0";
- while ((c = getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) != EOF)
+ while ((c = getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) != EOF)
switch (c) {
case 'D':
test->device = optarg;
@@ -224,6 +234,9 @@ int main(int argc, char **argv)
case 'd':
test->use_dma = true;
continue;
+ case 'B':
+ test->doorbell = true;
+ continue;
case 'h':
default:
usage:
@@ -243,6 +256,7 @@ int main(int argc, char **argv)
"\t-w Write buffer test\n"
"\t-c Copy buffer test\n"
"\t-s <size> Size of buffer {default: 100KB}\n"
+ "\t-B Doorbell test\n"
"\t-h Print this help message\n",
argv[0]);
return -EINVAL;
--
2.34.1
>
> This patches add new API to pci-epf-core, so any EP driver can use it.
>
> The key point is comments from Thomas Gleixner, who suggest use new
> PCI/IMS. But arm platform change still not be merged yet.
>
> git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git devmsi-v2-arm
>
> So I still use existed method implement RC to EP doorbell.
>
> If Thomas Gleixner want to continue work on devmsi-v2-arm, I can help test
> and update this patch.
>
Ping?
> Frank Li (3):
> PCI: endpoint: Add RC-to-EP doorbell support using platform MSI
> controller
> misc: pci_endpoint_test: Add doorbell test case
> tools: PCI: Add 'B' option for test doorbell
>
> drivers/misc/pci_endpoint_test.c | 41 +++++++++++
> drivers/pci/endpoint/pci-epf-core.c | 109
> ++++++++++++++++++++++++++++
> include/linux/pci-epf.h | 16 ++++
> include/uapi/linux/pcitest.h | 1 +
> tools/pci/pcitest.c | 16 +++-
> 5 files changed, 182 insertions(+), 1 deletion(-)
>
> --
> 2.34.1
On Fri, May 12, 2023 at 02:45:12PM +0000, Frank Li wrote:
> >
> > This patches add new API to pci-epf-core, so any EP driver can use it.
> >
> > The key point is comments from Thomas Gleixner, who suggest use new
> > PCI/IMS. But arm platform change still not be merged yet.
> >
> > git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git devmsi-v2-arm
> >
> > So I still use existed method implement RC to EP doorbell.
> >
> > If Thomas Gleixner want to continue work on devmsi-v2-arm, I can help test
> > and update this patch.
> >
>
> Ping?
Ping?
>
> > Frank Li (3):
> > PCI: endpoint: Add RC-to-EP doorbell support using platform MSI
> > controller
> > misc: pci_endpoint_test: Add doorbell test case
> > tools: PCI: Add 'B' option for test doorbell
> >
> > drivers/misc/pci_endpoint_test.c | 41 +++++++++++
> > drivers/pci/endpoint/pci-epf-core.c | 109
> > ++++++++++++++++++++++++++++
> > include/linux/pci-epf.h | 16 ++++
> > include/uapi/linux/pcitest.h | 1 +
> > tools/pci/pcitest.c | 16 +++-
> > 5 files changed, 182 insertions(+), 1 deletion(-)
> >
> > --
> > 2.34.1
>
On Mon, Jun 12, 2023 at 12:17:25PM -0400, Frank Li wrote:
> On Fri, May 12, 2023 at 02:45:12PM +0000, Frank Li wrote:
> > >
> > > This patches add new API to pci-epf-core, so any EP driver can use it.
> > >
> > > The key point is comments from Thomas Gleixner, who suggest use new
> > > PCI/IMS. But arm platform change still not be merged yet.
> > >
> > > git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git devmsi-v2-arm
> > >
> > > So I still use existed method implement RC to EP doorbell.
> > >
> > > If Thomas Gleixner want to continue work on devmsi-v2-arm, I can help test
> > > and update this patch.
> > >
> >
> > Ping?
>
> Ping?
ping?
>
> >
> > > Frank Li (3):
> > > PCI: endpoint: Add RC-to-EP doorbell support using platform MSI
> > > controller
> > > misc: pci_endpoint_test: Add doorbell test case
> > > tools: PCI: Add 'B' option for test doorbell
> > >
> > > drivers/misc/pci_endpoint_test.c | 41 +++++++++++
> > > drivers/pci/endpoint/pci-epf-core.c | 109
> > > ++++++++++++++++++++++++++++
> > > include/linux/pci-epf.h | 16 ++++
> > > include/uapi/linux/pcitest.h | 1 +
> > > tools/pci/pcitest.c | 16 +++-
> > > 5 files changed, 182 insertions(+), 1 deletion(-)
> > >
> > > --
> > > 2.34.1
> >
On Thu, Aug 24, 2023 at 03:01:30PM -0400, Frank Li wrote:
> On Mon, Jul 17, 2023 at 10:06:39AM -0400, Frank Li wrote:
> > On Mon, Jun 12, 2023 at 12:17:25PM -0400, Frank Li wrote:
> > > On Fri, May 12, 2023 at 02:45:12PM +0000, Frank Li wrote:
> > > > >
> > > > > This patches add new API to pci-epf-core, so any EP driver can use it.
> > > > >
> > > > > The key point is comments from Thomas Gleixner, who suggest use new
> > > > > PCI/IMS. But arm platform change still not be merged yet.
> > > > >
> > > > > git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git devmsi-v2-arm
> > > > >
> > > > > So I still use existed method implement RC to EP doorbell.
> > > > >
> > > > > If Thomas Gleixner want to continue work on devmsi-v2-arm, I can help test
> > > > > and update this patch.
> > > > >
> > > >
> > > > Ping?
> > >
> > > Ping?
> >
> > ping?
>
> @Mani
> Do you have chance to review these patches? It provide a common
> method with GIC ITS to implement notification from RC to EP.
>
Sorry for the delay. I was wating for a review from Thomas. But since this
series hasn't caught his attention, I'll provide my review next week.
- Mani
> Frank
>
> >
> > >
> > > >
> > > > > Frank Li (3):
> > > > > PCI: endpoint: Add RC-to-EP doorbell support using platform MSI
> > > > > controller
> > > > > misc: pci_endpoint_test: Add doorbell test case
> > > > > tools: PCI: Add 'B' option for test doorbell
> > > > >
> > > > > drivers/misc/pci_endpoint_test.c | 41 +++++++++++
> > > > > drivers/pci/endpoint/pci-epf-core.c | 109
> > > > > ++++++++++++++++++++++++++++
> > > > > include/linux/pci-epf.h | 16 ++++
> > > > > include/uapi/linux/pcitest.h | 1 +
> > > > > tools/pci/pcitest.c | 16 +++-
> > > > > 5 files changed, 182 insertions(+), 1 deletion(-)
> > > > >
> > > > > --
> > > > > 2.34.1
> > > >
--
மணிவண்ணன் சதாசிவம்
On Wed, Apr 26, 2023 at 04:34:35PM -0400, Frank Li wrote:
> Reused flags as capability register in pci_endpoint_test struct to
> support older driver versions. Save capability flags to 'cap' field
> of struct pci_endpoint_test to prevent reading non-existent address.
>
This won't work, please see below.
> Add three registers: PCIE_ENDPOINT_TEST_DB_BAR, PCIE_ENDPOINT_TEST_DB_ADDR,
> PCIE_ENDPOINT_TEST_DB_DATA.
>
> Write data from PCI_ENDPOINT_TEST_DB_DATA to address from
> PCI_ENDPOINT_TEST_DB_ADDR to trigger doorbell and wait for remote
> endpoint feedback.
"wait for endpoint response"
>
> Signed-off-by: Frank Li <[email protected]>
> ---
> drivers/misc/pci_endpoint_test.c | 41 ++++++++++++++++++++++++++++++++
> include/uapi/linux/pcitest.h | 1 +
> 2 files changed, 42 insertions(+)
>
> diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
> index ed4d0ef5e5c3..3320a3334594 100644
> --- a/drivers/misc/pci_endpoint_test.c
> +++ b/drivers/misc/pci_endpoint_test.c
> @@ -52,6 +52,7 @@
> #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 PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c
> #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10
> @@ -66,7 +67,12 @@
> #define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28
>
> #define PCI_ENDPOINT_TEST_FLAGS 0x2c
> +#define PCI_ENDPOINT_TEST_DB_BAR 0x30
> +#define PCI_ENDPOINT_TEST_DB_ADDR 0x34
> +#define PCI_ENDPOINT_TEST_DB_DATA 0x38
> +
> #define FLAG_USE_DMA BIT(0)
> +#define FLAG_SUPPORT_DOORBELL BIT(1)
>
> #define PCI_DEVICE_ID_TI_AM654 0xb00c
> #define PCI_DEVICE_ID_TI_J7200 0xb00f
> @@ -102,6 +108,7 @@ enum pci_barno {
> BAR_3,
> BAR_4,
> BAR_5,
> + NO_BAR = -1,
> };
>
> struct pci_endpoint_test {
> @@ -118,6 +125,7 @@ struct pci_endpoint_test {
> enum pci_barno test_reg_bar;
> size_t alignment;
> const char *name;
> + u32 cap;
> };
>
> struct pci_endpoint_test_data {
> @@ -713,6 +721,35 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test,
> return false;
> }
>
> +static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test)
> +{
> + enum pci_barno bar;
> + u32 data;
> + u32 addr;
> +
> + if (!(test->cap & FLAG_SUPPORT_DOORBELL))
> + return false;
> +
> + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR);
> + if (bar == NO_BAR)
> + return false;
Is this possible?
> +
> + data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA);
> + addr = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_ADDR);
> + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR);
> +
> + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0);
> + pci_endpoint_test_bar_writel(test, bar, addr, data);
From patch 1, I understood that EP supports multiple doorbell. But you are not
making use of it here?
> +
> + wait_for_completion(&test->irq_raised);
> +
No timeout?
> + data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS);
> + if (data & STATUS_DOORBELL_SUCCESS)
Please use a separate variable.
> + return true;
> +
> + return false;
> +}
> +
> static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
> unsigned long arg)
> {
> @@ -760,6 +797,9 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
> case PCITEST_CLEAR_IRQ:
> ret = pci_endpoint_test_clear_irq(test);
> break;
> + case PCITEST_DOORBELL:
> + ret = pci_endpoint_test_doorbell(test);
> + break;
> }
>
> ret:
> @@ -887,6 +927,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
> misc_device->parent = &pdev->dev;
> misc_device->fops = &pci_endpoint_test_fops;
>
> + test->cap = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_FLAGS);
This register will be overwritten by this driver during (copy,read,write) tests.
So this logic will not work.
- Mani
> err = misc_register(misc_device);
> if (err) {
> dev_err(dev, "Failed to register device\n");
> diff --git a/include/uapi/linux/pcitest.h b/include/uapi/linux/pcitest.h
> index f9c1af8d141b..479ca1aa3ae0 100644
> --- a/include/uapi/linux/pcitest.h
> +++ b/include/uapi/linux/pcitest.h
> @@ -20,6 +20,7 @@
> #define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int)
> #define PCITEST_GET_IRQTYPE _IO('P', 0x9)
> #define PCITEST_CLEAR_IRQ _IO('P', 0x10)
> +#define PCITEST_DOORBELL _IO('P', 0x11)
>
> #define PCITEST_FLAGS_USE_DMA 0x00000001
>
> --
> 2.34.1
>
--
மணிவண்ணன் சதாசிவம்