linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible
@ 2017-08-18 14:57 Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 01/18] PCI: endpoint: pci-epc-core: Use of_dma_configure() to set initial dma mask Kishon Vijay Abraham I
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:57 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

Hi Bjorn,

I've collected all the patches for PCI Endpoint in this series. This
series contains PCI endpoint fixes and making pci-epf-test more
flexible in terms of mapping PCI_ENDPOINT_TEST regs to any BARs,
work with linkup notification etc.

I've been having most of these patches in my local tree created while
adding support for endpoint in TI's K2G platform. I've also included fix
from others who are trying to use the PCI Endpoint Framework in their
own platforms.

It also contains minor changes in pci/dwc/ like resetting BARs in the
EP controller and providing a page size to pci_epc_mem. I can send this
part separately based on some of your branch if you'd prefer that.

This also contains patches for host side pci_endpoint_test driver
in drivers/misc.

I've pushed the series to pci-endpoint tree, the details of which are
given below.

Thanks
Kishon

The following changes since commit 5771a8c08880cdca3bfb4a3fc6d309d6bba20877:

  Linux v4.13-rc1 (2017-07-15 15:22:10 -0700)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/kishon/pci-endpoint.git tags/pci-ep-for-4.14

for you to fetch changes up to 31802acb56e040bf5f269b2bad159583fc804d68:

  tools: PCI: Add a missing option help line (2017-08-18 19:23:36 +0530)

----------------------------------------------------------------
PCI: endpoint: for 4.14

PCI endpoint core:
 *) Add support for page size to be configurable (for managing address
    region within the controller)
 *) Add an API to get matching "pci_epf_device_id"
 *) Use of_dma_configure() to set initial dma mask of pci_epf device
 *) Do not abort if endpoint function drivers have not populated
    ->remove() callback

pci-epf-test function driver:
 *) Add support to poll early for host commands
 *) Add support to use _any_ BAR's to map PCI_ENDPOINT_TEST regs

pci_endpoint_test PCI driver:
 *) Add support for PCI_ENDPOINT_TEST regs to be mapped to any BAR
 *) Add support to provide aligned buffer addresses
 *) Enable/Disable MSI using module param

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

----------------------------------------------------------------
Kishon Vijay Abraham I (16):
      PCI: endpoint: pci-epc-core: Use of_dma_configure() to set initial dma mask
      PCI: endpoint: pci-epf-core: Add an API to get matching "pci_epf_device_id"
      PCI: endpoint: pci-epf-core: Make ->remove() callback optional
      PCI: endpoint: pci-epc-mem: Add support for configurable page size
      PCI: endpoint: functions/pci-epf-test: Add "volatile" to pci_epf_test_reg
      PCI: endpoint: functions/pci-epf-test: Do not reset *command* inadvertently
      PCI: endpoint: functions/pci-epf-test: Add support to use _any_ BAR's to map PCI_ENDPOINT_TEST regs
      PCI: endpoint: functions/pci-epf-test: Add support to poll early for host commands
      PCI: dwc: designware: Provide page_size to pci_epc_mem
      PCI: dwc: dra7xx: Reset all BARs during initialization
      PCI: dwc: designware-ep: Do not disable BARs during initialization
      misc: pci_endpoint_test: Add support for PCI_ENDPOINT_TEST regs to be mapped to any BAR
      misc: pci_endpoint_test: Add support to provide aligned buffer addresses
      misc: pci_endpoint_test: Add support to not enable MSI interrupts
      misc: pci_endpoint_test: Avoid using hard coded BAR sizes
      misc: pci_endpoint_test: Enable/Disable MSI using module param

Shawn Lin (1):
      PCI: endpoint: functions/pci-epf-test: Remove the ->remove() callback

Stan Drozd (1):
      tools: PCI: Add a missing option help line

 drivers/misc/pci_endpoint_test.c              | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
 drivers/pci/dwc/pci-dra7xx.c                  |  13 +++++++++++++
 drivers/pci/dwc/pcie-designware-ep.c          |   7 ++-----
 drivers/pci/dwc/pcie-designware.h             |   1 +
 drivers/pci/endpoint/functions/pci-epf-test.c |  99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------
 drivers/pci/endpoint/pci-epc-core.c           |  11 +++++++++--
 drivers/pci/endpoint/pci-epc-mem.c            |  59 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 drivers/pci/endpoint/pci-epf-core.c           |  21 +++++++++++++++++++--
 include/linux/pci-epc.h                       |   8 +++++++-
 include/linux/pci-epf.h                       |   2 ++
 tools/pci/pcitest.c                           |   1 +
 11 files changed, 276 insertions(+), 78 deletions(-)
-- 
2.11.0

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 01/18] PCI: endpoint: pci-epc-core: Use of_dma_configure() to set initial dma mask
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
@ 2017-08-18 14:57 ` Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 02/18] PCI: endpoint: pci-epf-core: Add an API to get matching "pci_epf_device_id" Kishon Vijay Abraham I
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:57 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

Use of_dma_configure() to set the initial dma mask of epf device. This
helps to get rid of "Coherent DMA mask 0x0 (pfn 0x0-0x1) covers a smaller
range of system memory than the DMA zone pfn" warning in certain platforms
like TI's K2G resulting in coherent dma mask not being set.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/endpoint/pci-epc-core.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index caa7be10e473..42c2a1156325 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -21,6 +21,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/of_device.h>
 
 #include <linux/pci-epc.h>
 #include <linux/pci-epf.h>
@@ -370,6 +371,7 @@ EXPORT_SYMBOL_GPL(pci_epc_write_header);
 int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf)
 {
 	unsigned long flags;
+	struct device *dev = epc->dev.parent;
 
 	if (epf->epc)
 		return -EBUSY;
@@ -381,8 +383,12 @@ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf)
 		return -EINVAL;
 
 	epf->epc = epc;
-	dma_set_coherent_mask(&epf->dev, epc->dev.coherent_dma_mask);
-	epf->dev.dma_mask = epc->dev.dma_mask;
+	if (dev->of_node) {
+		of_dma_configure(&epf->dev, dev->of_node);
+	} else {
+		dma_set_coherent_mask(&epf->dev, epc->dev.coherent_dma_mask);
+		epf->dev.dma_mask = epc->dev.dma_mask;
+	}
 
 	spin_lock_irqsave(&epc->lock, flags);
 	list_add_tail(&epf->list, &epc->pci_epf);
@@ -500,6 +506,7 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
 	dma_set_coherent_mask(&epc->dev, dev->coherent_dma_mask);
 	epc->dev.class = pci_epc_class;
 	epc->dev.dma_mask = dev->dma_mask;
+	epc->dev.parent = dev;
 	epc->ops = ops;
 
 	ret = dev_set_name(&epc->dev, "%s", dev_name(dev));
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 02/18] PCI: endpoint: pci-epf-core: Add an API to get matching "pci_epf_device_id"
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 01/18] PCI: endpoint: pci-epc-core: Use of_dma_configure() to set initial dma mask Kishon Vijay Abraham I
@ 2017-08-18 14:57 ` Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 03/18] PCI: endpoint: pci-epf-core: Make ->remove() callback optional Kishon Vijay Abraham I
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:57 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

Add an API to get "pci_epf_device_id" matching the epf name. This can be
used by the epf driver to get the driver data corresponding to the epf
device name.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/endpoint/pci-epf-core.c | 16 ++++++++++++++++
 include/linux/pci-epf.h             |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 6877d6a5bcc9..60ea0c51161e 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -267,6 +267,22 @@ struct pci_epf *pci_epf_create(const char *name)
 }
 EXPORT_SYMBOL_GPL(pci_epf_create);
 
+const struct pci_epf_device_id *
+pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf)
+{
+	if (!id || !epf)
+		return NULL;
+
+	while (id) {
+		if (strcmp(epf->name, id->name) == 0)
+			return id;
+		id++;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(pci_epf_match_device);
+
 static void pci_epf_dev_release(struct device *dev)
 {
 	struct pci_epf *epf = to_pci_epf(dev);
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index 0d529cb90143..6ed63b5e106b 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -149,6 +149,8 @@ static inline void *epf_get_drvdata(struct pci_epf *epf)
 	return dev_get_drvdata(&epf->dev);
 }
 
+const struct pci_epf_device_id *
+pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf);
 struct pci_epf *pci_epf_create(const char *name);
 void pci_epf_destroy(struct pci_epf *epf);
 int __pci_epf_register_driver(struct pci_epf_driver *driver,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 03/18] PCI: endpoint: pci-epf-core: Make ->remove() callback optional
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 01/18] PCI: endpoint: pci-epc-core: Use of_dma_configure() to set initial dma mask Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 02/18] PCI: endpoint: pci-epf-core: Add an API to get matching "pci_epf_device_id" Kishon Vijay Abraham I
@ 2017-08-18 14:57 ` Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 04/18] PCI: endpoint: pci-epc-mem: Add support for configurable page size Kishon Vijay Abraham I
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:57 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

Make ->remove() callback optional so that endpoint function drivers
don't have to populate empty ->remove() callback functions.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/endpoint/pci-epf-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 60ea0c51161e..ae6fac5995e3 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -333,11 +333,12 @@ static int pci_epf_device_probe(struct device *dev)
 
 static int pci_epf_device_remove(struct device *dev)
 {
-	int ret;
+	int ret = 0;
 	struct pci_epf *epf = to_pci_epf(dev);
 	struct pci_epf_driver *driver = to_pci_epf_driver(dev->driver);
 
-	ret = driver->remove(epf);
+	if (driver->remove)
+		ret = driver->remove(epf);
 	epf->driver = NULL;
 
 	return ret;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 04/18] PCI: endpoint: pci-epc-mem: Add support for configurable page size
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (2 preceding siblings ...)
  2017-08-18 14:57 ` [PATCH 03/18] PCI: endpoint: pci-epf-core: Make ->remove() callback optional Kishon Vijay Abraham I
@ 2017-08-18 14:57 ` Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 05/18] PCI: endpoint: functions/pci-epf-test: Add "volatile" to pci_epf_test_reg Kishon Vijay Abraham I
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:57 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

pci-epc-mem uses a page size equal to *PAGE_SIZE* (usually 4KB) to
manage the address space. However certain platforms like TI's K2G
has a restriction that this address space should be either divided
into 1MB/2MB/4MB or 8MB sizes (Ref: 11.14.4.9.1 Outbound Address
Translation in K2G TRM SPRUHY8F January 2016 – Revised May 2017).
Add support to handle different page sizes here.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/endpoint/pci-epc-mem.c | 59 ++++++++++++++++++++++++++++++++------
 include/linux/pci-epc.h            |  8 +++++-
 2 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/endpoint/pci-epc-mem.c b/drivers/pci/endpoint/pci-epc-mem.c
index 3a94cc1caf22..83b7d5d3fc3e 100644
--- a/drivers/pci/endpoint/pci-epc-mem.c
+++ b/drivers/pci/endpoint/pci-epc-mem.c
@@ -24,21 +24,54 @@
 #include <linux/pci-epc.h>
 
 /**
- * pci_epc_mem_init() - initialize the pci_epc_mem structure
+ * pci_epc_mem_get_order() - determine the allocation order of a memory size
+ * @mem: address space of the endpoint controller
+ * @size: the size for which to get the order
+ *
+ * Reimplement get_order() for mem->page_size since the generic get_order
+ * always gets order with a constant PAGE_SIZE.
+ */
+static int pci_epc_mem_get_order(struct pci_epc_mem *mem, size_t size)
+{
+	int order;
+	unsigned int page_shift = ilog2(mem->page_size);
+
+	size--;
+	size >>= page_shift;
+#if BITS_PER_LONG == 32
+	order = fls(size);
+#else
+	order = fls64(size);
+#endif
+	return order;
+}
+
+/**
+ * __pci_epc_mem_init() - initialize the pci_epc_mem structure
  * @epc: the EPC device that invoked pci_epc_mem_init
  * @phys_base: the physical address of the base
  * @size: the size of the address space
+ * @page_size: size of each page
  *
  * Invoke to initialize the pci_epc_mem structure used by the
  * endpoint functions to allocate mapped PCI address.
  */
-int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_base, size_t size)
+int __pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_base, size_t size,
+		       size_t page_size)
 {
 	int ret;
 	struct pci_epc_mem *mem;
 	unsigned long *bitmap;
-	int pages = size >> PAGE_SHIFT;
-	int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
+	unsigned int page_shift;
+	int pages;
+	int bitmap_size;
+
+	if (page_size < PAGE_SIZE)
+		page_size = PAGE_SIZE;
+
+	page_shift = ilog2(page_size);
+	pages = size >> page_shift;
+	bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
 
 	mem = kzalloc(sizeof(*mem), GFP_KERNEL);
 	if (!mem) {
@@ -54,6 +87,7 @@ int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_base, size_t size)
 
 	mem->bitmap = bitmap;
 	mem->phys_base = phys_base;
+	mem->page_size = page_size;
 	mem->pages = pages;
 	mem->size = size;
 
@@ -67,7 +101,7 @@ int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_base, size_t size)
 err:
 return ret;
 }
-EXPORT_SYMBOL_GPL(pci_epc_mem_init);
+EXPORT_SYMBOL_GPL(__pci_epc_mem_init);
 
 /**
  * pci_epc_mem_exit() - cleanup the pci_epc_mem structure
@@ -101,13 +135,17 @@ void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
 	int pageno;
 	void __iomem *virt_addr;
 	struct pci_epc_mem *mem = epc->mem;
-	int order = get_order(size);
+	unsigned int page_shift = ilog2(mem->page_size);
+	int order;
+
+	size = ALIGN(size, mem->page_size);
+	order = pci_epc_mem_get_order(mem, size);
 
 	pageno = bitmap_find_free_region(mem->bitmap, mem->pages, order);
 	if (pageno < 0)
 		return NULL;
 
-	*phys_addr = mem->phys_base + (pageno << PAGE_SHIFT);
+	*phys_addr = mem->phys_base + (pageno << page_shift);
 	virt_addr = ioremap(*phys_addr, size);
 	if (!virt_addr)
 		bitmap_release_region(mem->bitmap, pageno, order);
@@ -129,11 +167,14 @@ void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr,
 			   void __iomem *virt_addr, size_t size)
 {
 	int pageno;
-	int order = get_order(size);
 	struct pci_epc_mem *mem = epc->mem;
+	unsigned int page_shift = ilog2(mem->page_size);
+	int order;
 
 	iounmap(virt_addr);
-	pageno = (phys_addr - mem->phys_base) >> PAGE_SHIFT;
+	pageno = (phys_addr - mem->phys_base) >> page_shift;
+	size = ALIGN(size, mem->page_size);
+	order = pci_epc_mem_get_order(mem, size);
 	bitmap_release_region(mem->bitmap, pageno, order);
 }
 EXPORT_SYMBOL_GPL(pci_epc_mem_free_addr);
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
index af5edbf3eea3..f7a04e1af112 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -62,11 +62,13 @@ struct pci_epc_ops {
  * @size: the size of the PCI address space
  * @bitmap: bitmap to manage the PCI address space
  * @pages: number of bits representing the address region
+ * @page_size: size of each page
  */
 struct pci_epc_mem {
 	phys_addr_t	phys_base;
 	size_t		size;
 	unsigned long	*bitmap;
+	size_t		page_size;
 	int		pages;
 };
 
@@ -98,6 +100,9 @@ struct pci_epc {
 #define devm_pci_epc_create(dev, ops)    \
 		__devm_pci_epc_create((dev), (ops), THIS_MODULE)
 
+#define pci_epc_mem_init(epc, phys_addr, size)	\
+		__pci_epc_mem_init((epc), (phys_addr), (size), PAGE_SIZE)
+
 static inline void epc_set_drvdata(struct pci_epc *epc, void *data)
 {
 	dev_set_drvdata(&epc->dev, data);
@@ -135,7 +140,8 @@ void pci_epc_stop(struct pci_epc *epc);
 struct pci_epc *pci_epc_get(const char *epc_name);
 void pci_epc_put(struct pci_epc *epc);
 
-int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_addr, size_t size);
+int __pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_addr, size_t size,
+		       size_t page_size);
 void pci_epc_mem_exit(struct pci_epc *epc);
 void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
 				     phys_addr_t *phys_addr, size_t size);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 05/18] PCI: endpoint: functions/pci-epf-test: Add "volatile" to pci_epf_test_reg
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (3 preceding siblings ...)
  2017-08-18 14:57 ` [PATCH 04/18] PCI: endpoint: pci-epc-mem: Add support for configurable page size Kishon Vijay Abraham I
@ 2017-08-18 14:57 ` Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 06/18] PCI: endpoint: functions/pci-epf-test: Do not reset *command* inadvertently Kishon Vijay Abraham I
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:57 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

struct pci_epf_test_reg is the MEMSPACE of pci-epf-test function driver
that will be accessed by the "host" for programming the pci-epf-test
device. So this structure shouldn't be subjected to compiler optimization
in pci_epf_test_cmd_handler() since the values can be changed by code
outside the scope of current code at any time.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 53fff8030337..5cbc05a0762d 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -267,7 +267,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
 						     cmd_handler.work);
 	struct pci_epf *epf = epf_test->epf;
 	struct pci_epc *epc = epf->epc;
-	struct pci_epf_test_reg *reg = epf_test->reg[0];
+	volatile struct pci_epf_test_reg *reg = epf_test->reg[0];
 
 	if (!reg->command)
 		goto reset_handler;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 06/18] PCI: endpoint: functions/pci-epf-test: Do not reset *command* inadvertently
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (4 preceding siblings ...)
  2017-08-18 14:57 ` [PATCH 05/18] PCI: endpoint: functions/pci-epf-test: Add "volatile" to pci_epf_test_reg Kishon Vijay Abraham I
@ 2017-08-18 14:57 ` Kishon Vijay Abraham I
  2017-08-18 14:57 ` [PATCH 07/18] PCI: endpoint: functions/pci-epf-test: Add support to use _any_ BAR's to map PCI_ENDPOINT_TEST regs Kishon Vijay Abraham I
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:57 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

pci_epf_test_cmd_handler() is the delayed work function which reads
*command* (set by the host) and performs various actions requested
by the host periodically. If the value in *command* is '0', it
goes to the reset_handler where it resets *command* to '0' and queues
pci_epf_test_cmd_handler().
However if the host writes a value to the *command* just after the
pci-epf-test driver checks *command* for '0' and before the control goes
to reset_handler, the *command* will be reset to '0' and the pci-epf-test
driver won't be able to perform the actions requested by the host.
Fix it here by not resetting the *command* in the reset_handler.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 5cbc05a0762d..1a27d7950f2c 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -263,22 +263,26 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
 	int ret;
 	u8 irq;
 	u8 msi_count;
+	u32 command;
 	struct pci_epf_test *epf_test = container_of(work, struct pci_epf_test,
 						     cmd_handler.work);
 	struct pci_epf *epf = epf_test->epf;
 	struct pci_epc *epc = epf->epc;
 	volatile struct pci_epf_test_reg *reg = epf_test->reg[0];
 
-	if (!reg->command)
+	command = reg->command;
+	if (!command)
 		goto reset_handler;
 
-	if (reg->command & COMMAND_RAISE_LEGACY_IRQ) {
+	reg->command = 0;
+
+	if (command & COMMAND_RAISE_LEGACY_IRQ) {
 		reg->status = STATUS_IRQ_RAISED;
 		pci_epc_raise_irq(epc, PCI_EPC_IRQ_LEGACY, 0);
 		goto reset_handler;
 	}
 
-	if (reg->command & COMMAND_WRITE) {
+	if (command & COMMAND_WRITE) {
 		ret = pci_epf_test_write(epf_test);
 		if (ret)
 			reg->status |= STATUS_WRITE_FAIL;
@@ -288,7 +292,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
 		goto reset_handler;
 	}
 
-	if (reg->command & COMMAND_READ) {
+	if (command & COMMAND_READ) {
 		ret = pci_epf_test_read(epf_test);
 		if (!ret)
 			reg->status |= STATUS_READ_SUCCESS;
@@ -298,7 +302,7 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
 		goto reset_handler;
 	}
 
-	if (reg->command & COMMAND_COPY) {
+	if (command & COMMAND_COPY) {
 		ret = pci_epf_test_copy(epf_test);
 		if (!ret)
 			reg->status |= STATUS_COPY_SUCCESS;
@@ -308,9 +312,9 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
 		goto reset_handler;
 	}
 
-	if (reg->command & COMMAND_RAISE_MSI_IRQ) {
+	if (command & COMMAND_RAISE_MSI_IRQ) {
 		msi_count = pci_epc_get_msi(epc);
-		irq = (reg->command & MSI_NUMBER_MASK) >> MSI_NUMBER_SHIFT;
+		irq = (command & MSI_NUMBER_MASK) >> MSI_NUMBER_SHIFT;
 		if (irq > msi_count || msi_count <= 0)
 			goto reset_handler;
 		reg->status = STATUS_IRQ_RAISED;
@@ -319,8 +323,6 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
 	}
 
 reset_handler:
-	reg->command = 0;
-
 	queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler,
 			   msecs_to_jiffies(1));
 }
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 07/18] PCI: endpoint: functions/pci-epf-test: Add support to use _any_ BAR's to map PCI_ENDPOINT_TEST regs
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (5 preceding siblings ...)
  2017-08-18 14:57 ` [PATCH 06/18] PCI: endpoint: functions/pci-epf-test: Do not reset *command* inadvertently Kishon Vijay Abraham I
@ 2017-08-18 14:57 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 08/18] PCI: endpoint: functions/pci-epf-test: Add support to poll early for host commands Kishon Vijay Abraham I
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:57 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

pci_epf_test always maps the PCI_ENDPOINT_TEST registers to BAR_0. But if
BAR_0 is reserved for some other purpose (like in TI's K2G BAR_0 is
mapped to application registers and cannot be used to map any other
regions), PCI_ENDPOINT_TEST registers cannot be mapped making pci_epf_test
unusable. Add support to use any BAR's to map PCI_ENDPOINT_TEST registers.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 60 +++++++++++++++++++--------
 1 file changed, 42 insertions(+), 18 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 1a27d7950f2c..e378dae9e510 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -54,6 +54,7 @@ static struct workqueue_struct *kpcitest_workqueue;
 struct pci_epf_test {
 	void			*reg[6];
 	struct pci_epf		*epf;
+	enum pci_barno		test_reg_bar;
 	struct delayed_work	cmd_handler;
 };
 
@@ -74,7 +75,11 @@ static struct pci_epf_header test_header = {
 	.interrupt_pin	= PCI_INTERRUPT_INTA,
 };
 
-static int bar_size[] = { 512, 1024, 16384, 131072, 1048576 };
+struct pci_epf_test_data {
+	enum pci_barno	test_reg_bar;
+};
+
+static int bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 };
 
 static int pci_epf_test_copy(struct pci_epf_test *epf_test)
 {
@@ -86,7 +91,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test)
 	struct pci_epf *epf = epf_test->epf;
 	struct device *dev = &epf->dev;
 	struct pci_epc *epc = epf->epc;
-	struct pci_epf_test_reg *reg = epf_test->reg[0];
+	enum pci_barno test_reg_bar = epf_test->test_reg_bar;
+	struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
 
 	src_addr = pci_epc_mem_alloc_addr(epc, &src_phys_addr, reg->size);
 	if (!src_addr) {
@@ -145,7 +151,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test)
 	struct pci_epf *epf = epf_test->epf;
 	struct device *dev = &epf->dev;
 	struct pci_epc *epc = epf->epc;
-	struct pci_epf_test_reg *reg = epf_test->reg[0];
+	enum pci_barno test_reg_bar = epf_test->test_reg_bar;
+	struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
 
 	src_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size);
 	if (!src_addr) {
@@ -195,7 +202,8 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test)
 	struct pci_epf *epf = epf_test->epf;
 	struct device *dev = &epf->dev;
 	struct pci_epc *epc = epf->epc;
-	struct pci_epf_test_reg *reg = epf_test->reg[0];
+	enum pci_barno test_reg_bar = epf_test->test_reg_bar;
+	struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
 
 	dst_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size);
 	if (!dst_addr) {
@@ -247,7 +255,8 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test)
 	u8 msi_count;
 	struct pci_epf *epf = epf_test->epf;
 	struct pci_epc *epc = epf->epc;
-	struct pci_epf_test_reg *reg = epf_test->reg[0];
+	enum pci_barno test_reg_bar = epf_test->test_reg_bar;
+	struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
 
 	reg->status |= STATUS_IRQ_RAISED;
 	msi_count = pci_epc_get_msi(epc);
@@ -268,13 +277,15 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
 						     cmd_handler.work);
 	struct pci_epf *epf = epf_test->epf;
 	struct pci_epc *epc = epf->epc;
-	volatile struct pci_epf_test_reg *reg = epf_test->reg[0];
+	enum pci_barno test_reg_bar = epf_test->test_reg_bar;
+	struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
 
 	command = reg->command;
 	if (!command)
 		goto reset_handler;
 
 	reg->command = 0;
+	reg->status = 0;
 
 	if (command & COMMAND_RAISE_LEGACY_IRQ) {
 		reg->status = STATUS_IRQ_RAISED;
@@ -360,6 +371,7 @@ static int pci_epf_test_set_bar(struct pci_epf *epf)
 	struct pci_epc *epc = epf->epc;
 	struct device *dev = &epf->dev;
 	struct pci_epf_test *epf_test = epf_get_drvdata(epf);
+	enum pci_barno test_reg_bar = epf_test->test_reg_bar;
 
 	flags = PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_32;
 	if (sizeof(dma_addr_t) == 0x8)
@@ -372,7 +384,7 @@ static int pci_epf_test_set_bar(struct pci_epf *epf)
 		if (ret) {
 			pci_epf_free_space(epf, epf_test->reg[bar], bar);
 			dev_err(dev, "failed to set BAR%d\n", bar);
-			if (bar == BAR_0)
+			if (bar == test_reg_bar)
 				return ret;
 		}
 	}
@@ -386,17 +398,20 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
 	struct device *dev = &epf->dev;
 	void *base;
 	int bar;
+	enum pci_barno test_reg_bar = epf_test->test_reg_bar;
 
 	base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg),
-				   BAR_0);
+				   test_reg_bar);
 	if (!base) {
 		dev_err(dev, "failed to allocated register space\n");
 		return -ENOMEM;
 	}
-	epf_test->reg[0] = base;
+	epf_test->reg[test_reg_bar] = base;
 
-	for (bar = BAR_1; bar <= BAR_5; bar++) {
-		base = pci_epf_alloc_space(epf, bar_size[bar - 1], bar);
+	for (bar = BAR_0; bar <= BAR_5; bar++) {
+		if (bar == test_reg_bar)
+			continue;
+		base = pci_epf_alloc_space(epf, bar_size[bar], bar);
 		if (!base)
 			dev_err(dev, "failed to allocate space for BAR%d\n",
 				bar);
@@ -437,10 +452,25 @@ static int pci_epf_test_bind(struct pci_epf *epf)
 	return 0;
 }
 
+static const struct pci_epf_device_id pci_epf_test_ids[] = {
+	{
+		.name = "pci_epf_test",
+	},
+	{},
+};
+
 static int pci_epf_test_probe(struct pci_epf *epf)
 {
 	struct pci_epf_test *epf_test;
 	struct device *dev = &epf->dev;
+	const struct pci_epf_device_id *match;
+	struct pci_epf_test_data *data;
+	enum pci_barno test_reg_bar = BAR_0;
+
+	match = pci_epf_match_device(pci_epf_test_ids, epf);
+	data = (struct pci_epf_test_data *)match->driver_data;
+	if (data)
+		test_reg_bar = data->test_reg_bar;
 
 	epf_test = devm_kzalloc(dev, sizeof(*epf_test), GFP_KERNEL);
 	if (!epf_test)
@@ -448,6 +478,7 @@ static int pci_epf_test_probe(struct pci_epf *epf)
 
 	epf->header = &test_header;
 	epf_test->epf = epf;
+	epf_test->test_reg_bar = test_reg_bar;
 
 	INIT_DELAYED_WORK(&epf_test->cmd_handler, pci_epf_test_cmd_handler);
 
@@ -469,13 +500,6 @@ static struct pci_epf_ops ops = {
 	.linkup = pci_epf_test_linkup,
 };
 
-static const struct pci_epf_device_id pci_epf_test_ids[] = {
-	{
-		.name = "pci_epf_test",
-	},
-	{},
-};
-
 static struct pci_epf_driver test_driver = {
 	.driver.name	= "pci_epf_test",
 	.probe		= pci_epf_test_probe,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 08/18] PCI: endpoint: functions/pci-epf-test: Add support to poll early for host commands
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (6 preceding siblings ...)
  2017-08-18 14:57 ` [PATCH 07/18] PCI: endpoint: functions/pci-epf-test: Add support to use _any_ BAR's to map PCI_ENDPOINT_TEST regs Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 09/18] PCI: endpoint: functions/pci-epf-test: Remove the ->remove() callback Kishon Vijay Abraham I
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

Certain platforms like TI's K2G doesn't support link-up notification. Add
support to poll early (without waiting for the linkup notification)
for commands from the host.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index e378dae9e510..a0aea2500690 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -55,6 +55,7 @@ struct pci_epf_test {
 	void			*reg[6];
 	struct pci_epf		*epf;
 	enum pci_barno		test_reg_bar;
+	bool			linkup_notifier;
 	struct delayed_work	cmd_handler;
 };
 
@@ -77,6 +78,7 @@ static struct pci_epf_header test_header = {
 
 struct pci_epf_test_data {
 	enum pci_barno	test_reg_bar;
+	bool		linkup_notifier;
 };
 
 static int bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 };
@@ -424,6 +426,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
 static int pci_epf_test_bind(struct pci_epf *epf)
 {
 	int ret;
+	struct pci_epf_test *epf_test = epf_get_drvdata(epf);
 	struct pci_epf_header *header = epf->header;
 	struct pci_epc *epc = epf->epc;
 	struct device *dev = &epf->dev;
@@ -449,6 +452,9 @@ static int pci_epf_test_bind(struct pci_epf *epf)
 	if (ret)
 		return ret;
 
+	if (!epf_test->linkup_notifier)
+		queue_work(kpcitest_workqueue, &epf_test->cmd_handler.work);
+
 	return 0;
 }
 
@@ -466,11 +472,14 @@ static int pci_epf_test_probe(struct pci_epf *epf)
 	const struct pci_epf_device_id *match;
 	struct pci_epf_test_data *data;
 	enum pci_barno test_reg_bar = BAR_0;
+	bool linkup_notifier = true;
 
 	match = pci_epf_match_device(pci_epf_test_ids, epf);
 	data = (struct pci_epf_test_data *)match->driver_data;
-	if (data)
+	if (data) {
 		test_reg_bar = data->test_reg_bar;
+		linkup_notifier = data->linkup_notifier;
+	}
 
 	epf_test = devm_kzalloc(dev, sizeof(*epf_test), GFP_KERNEL);
 	if (!epf_test)
@@ -479,6 +488,7 @@ static int pci_epf_test_probe(struct pci_epf *epf)
 	epf->header = &test_header;
 	epf_test->epf = epf;
 	epf_test->test_reg_bar = test_reg_bar;
+	epf_test->linkup_notifier = linkup_notifier;
 
 	INIT_DELAYED_WORK(&epf_test->cmd_handler, pci_epf_test_cmd_handler);
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 09/18] PCI: endpoint: functions/pci-epf-test: Remove the ->remove() callback
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (7 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 08/18] PCI: endpoint: functions/pci-epf-test: Add support to poll early for host commands Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 10/18] PCI: dwc: designware: Provide page_size to pci_epc_mem Kishon Vijay Abraham I
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap, Shawn Lin

From: Shawn Lin <shawn.lin@rock-chips.com>

epf_test is allocated using devm_kzalloc. Hence it's not required to
explicitly free it in remove() callback. Since ->remove() callback
doesn't do anything other than freeing epf_test, remove the
->remove() callback.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index a0aea2500690..4ddc6e8f9fe7 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -496,14 +496,6 @@ static int pci_epf_test_probe(struct pci_epf *epf)
 	return 0;
 }
 
-static int pci_epf_test_remove(struct pci_epf *epf)
-{
-	struct pci_epf_test *epf_test = epf_get_drvdata(epf);
-
-	kfree(epf_test);
-	return 0;
-}
-
 static struct pci_epf_ops ops = {
 	.unbind	= pci_epf_test_unbind,
 	.bind	= pci_epf_test_bind,
@@ -513,7 +505,6 @@ static struct pci_epf_ops ops = {
 static struct pci_epf_driver test_driver = {
 	.driver.name	= "pci_epf_test",
 	.probe		= pci_epf_test_probe,
-	.remove		= pci_epf_test_remove,
 	.id_table	= pci_epf_test_ids,
 	.ops		= &ops,
 	.owner		= THIS_MODULE,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 10/18] PCI: dwc: designware: Provide page_size to pci_epc_mem
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (8 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 09/18] PCI: endpoint: functions/pci-epf-test: Remove the ->remove() callback Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 11/18] PCI: dwc: dra7xx: Reset all BARs during initialization Kishon Vijay Abraham I
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

Use the newly introduced __pci_epc_mem_init instead of pci_epc_mem_init
to provide page_size to pci_epc_mem. This is in preparation for
adding EP support to K2G which has a restriction that the
address region should be either divided into 1MB/2MB/4MB or 8MB
sizes (Ref: 11.14.4.9.1 Outbound Address Translation in K2G TRM SPRUHY8F
January 2016 – Revised May 2017).

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/dwc/pcie-designware-ep.c | 3 ++-
 drivers/pci/dwc/pcie-designware.h    | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/dwc/pcie-designware-ep.c b/drivers/pci/dwc/pcie-designware-ep.c
index 398406393f37..e70ebe3b9b6f 100644
--- a/drivers/pci/dwc/pcie-designware-ep.c
+++ b/drivers/pci/dwc/pcie-designware-ep.c
@@ -328,7 +328,8 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 	if (ret < 0)
 		epc->max_functions = 1;
 
-	ret = pci_epc_mem_init(epc, ep->phys_base, ep->addr_size);
+	ret = __pci_epc_mem_init(epc, ep->phys_base, ep->addr_size,
+				 ep->page_size);
 	if (ret < 0) {
 		dev_err(dev, "Failed to initialize address space\n");
 		return ret;
diff --git a/drivers/pci/dwc/pcie-designware.h b/drivers/pci/dwc/pcie-designware.h
index b4d2a89f8e58..714f6f21ea93 100644
--- a/drivers/pci/dwc/pcie-designware.h
+++ b/drivers/pci/dwc/pcie-designware.h
@@ -186,6 +186,7 @@ struct dw_pcie_ep {
 	struct dw_pcie_ep_ops	*ops;
 	phys_addr_t		phys_base;
 	size_t			addr_size;
+	size_t			page_size;
 	u8			bar_to_atu[6];
 	phys_addr_t		*outbound_addr;
 	unsigned long		ib_window_map;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 11/18] PCI: dwc: dra7xx: Reset all BARs during initialization
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (9 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 10/18] PCI: dwc: designware: Provide page_size to pci_epc_mem Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 12/18] PCI: dwc: designware-ep: Do not disable " Kishon Vijay Abraham I
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

dra7xx has all base address registers (BAR) enabled by default. Reset all
BARs during initialization and so that BARs are enabled only if they are
actually used.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/dwc/pci-dra7xx.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
index f2fc5f47064e..ee61f833b62c 100644
--- a/drivers/pci/dwc/pci-dra7xx.c
+++ b/drivers/pci/dwc/pci-dra7xx.c
@@ -335,10 +335,23 @@ static irqreturn_t dra7xx_pcie_irq_handler(int irq, void *arg)
 	return IRQ_HANDLED;
 }
 
+static void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
+{
+	u32 reg;
+
+	reg = PCI_BASE_ADDRESS_0 + (4 * bar);
+	dw_pcie_writel_dbi2(pci, reg, 0x0);
+	dw_pcie_writel_dbi(pci, reg, 0x0);
+}
+
 static void dra7xx_pcie_ep_init(struct dw_pcie_ep *ep)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
+	enum pci_barno bar;
+
+	for (bar = BAR_0; bar <= BAR_5; bar++)
+		dw_pcie_ep_reset_bar(pci, bar);
 
 	dra7xx_pcie_enable_wrapper_interrupts(dra7xx);
 }
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 12/18] PCI: dwc: designware-ep: Do not disable BARs during initialization
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (10 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 11/18] PCI: dwc: dra7xx: Reset all BARs during initialization Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 13/18] misc: pci_endpoint_test: Add support for PCI_ENDPOINT_TEST regs to be mapped to any BAR Kishon Vijay Abraham I
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

Some platforms like K2G has reserved use of BAR_0 which shouldn't be
disabled by software. Avoid disabling all BARs during initialization.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/pci/dwc/pcie-designware-ep.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/pci/dwc/pcie-designware-ep.c b/drivers/pci/dwc/pcie-designware-ep.c
index e70ebe3b9b6f..b3205df38d52 100644
--- a/drivers/pci/dwc/pcie-designware-ep.c
+++ b/drivers/pci/dwc/pcie-designware-ep.c
@@ -283,7 +283,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 {
 	int ret;
 	void *addr;
-	enum pci_barno bar;
 	struct pci_epc *epc;
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	struct device *dev = pci->dev;
@@ -312,9 +311,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 		return -ENOMEM;
 	ep->outbound_addr = addr;
 
-	for (bar = BAR_0; bar <= BAR_5; bar++)
-		dw_pcie_ep_reset_bar(pci, bar);
-
 	if (ep->ops->ep_init)
 		ep->ops->ep_init(ep);
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 13/18] misc: pci_endpoint_test: Add support for PCI_ENDPOINT_TEST regs to be mapped to any BAR
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (11 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 12/18] PCI: dwc: designware-ep: Do not disable " Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 14/18] misc: pci_endpoint_test: Add support to provide aligned buffer addresses Kishon Vijay Abraham I
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

pci_endpoint_test driver assumes the PCI_ENDPOINT_TEST registers will
always be mapped to BAR_0. This need not always be the case like in
TI's K2G where BAR_0 is mapped to PCI controller application registers.
Add support so that PCI_ENDPOINT_TEST registers can be mapped to any BAR.
Change the bar_size used for BAR test accordingly.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/misc/pci_endpoint_test.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 09c10f426b64..5fc0f6c6a9e5 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -90,9 +90,14 @@ struct pci_endpoint_test {
 	/* mutex to protect the ioctls */
 	struct mutex	mutex;
 	struct miscdevice miscdev;
+	enum pci_barno test_reg_bar;
 };
 
-static int bar_size[] = { 4, 512, 1024, 16384, 131072, 1048576 };
+struct pci_endpoint_test_data {
+	enum pci_barno test_reg_bar;
+};
+
+static int bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 };
 
 static inline u32 pci_endpoint_test_readl(struct pci_endpoint_test *test,
 					  u32 offset)
@@ -147,6 +152,9 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
 
 	size = bar_size[barno];
 
+	if (barno == test->test_reg_bar)
+		size = 0x4;
+
 	for (j = 0; j < size; j += 4)
 		pci_endpoint_test_bar_writel(test, barno, j, 0xA0A0A0A0);
 
@@ -390,6 +398,8 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 	void __iomem *base;
 	struct device *dev = &pdev->dev;
 	struct pci_endpoint_test *test;
+	struct pci_endpoint_test_data *data;
+	enum pci_barno test_reg_bar = BAR_0;
 	struct miscdevice *misc_device;
 
 	if (pci_is_bridge(pdev))
@@ -399,7 +409,13 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 	if (!test)
 		return -ENOMEM;
 
+	test->test_reg_bar = 0;
 	test->pdev = pdev;
+
+	data = (struct pci_endpoint_test_data *)ent->driver_data;
+	if (data)
+		test_reg_bar = data->test_reg_bar;
+
 	init_completion(&test->irq_raised);
 	mutex_init(&test->mutex);
 
@@ -441,14 +457,15 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 		base = pci_ioremap_bar(pdev, bar);
 		if (!base) {
 			dev_err(dev, "failed to read BAR%d\n", bar);
-			WARN_ON(bar == BAR_0);
+			WARN_ON(bar == test_reg_bar);
 		}
 		test->bar[bar] = base;
 	}
 
-	test->base = test->bar[0];
+	test->base = test->bar[test_reg_bar];
 	if (!test->base) {
-		dev_err(dev, "Cannot perform PCI test without BAR0\n");
+		dev_err(dev, "Cannot perform PCI test without BAR%d\n",
+			test_reg_bar);
 		goto err_iounmap;
 	}
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 14/18] misc: pci_endpoint_test: Add support to provide aligned buffer addresses
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (12 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 13/18] misc: pci_endpoint_test: Add support for PCI_ENDPOINT_TEST regs to be mapped to any BAR Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 15/18] misc: pci_endpoint_test: Add support to not enable MSI interrupts Kishon Vijay Abraham I
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

Some platforms like TI's K2G have a restriction that the host side
buffer address should be aligned to either 1MB/2MB/4MB or 8MB
(Ref: 11.14.4.9.1 Outbound Address Translation in K2G TRM SPRUHY8F
January 2016 – Revised May 2017) addresses depending on how it is
configured in the endpoint. Add support to provide such aligned address
here so that pci_endpoint_test driver can be used to test K2G EP.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/misc/pci_endpoint_test.c | 91 +++++++++++++++++++++++++++++++++-------
 1 file changed, 76 insertions(+), 15 deletions(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 5fc0f6c6a9e5..5f6bd23ab657 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -91,10 +91,12 @@ struct pci_endpoint_test {
 	struct mutex	mutex;
 	struct miscdevice miscdev;
 	enum pci_barno test_reg_bar;
+	size_t alignment;
 };
 
 struct pci_endpoint_test_data {
 	enum pci_barno test_reg_bar;
+	size_t alignment;
 };
 
 static int bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 };
@@ -210,16 +212,32 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size)
 	dma_addr_t dst_phys_addr;
 	struct pci_dev *pdev = test->pdev;
 	struct device *dev = &pdev->dev;
+	void *orig_src_addr;
+	dma_addr_t orig_src_phys_addr;
+	void *orig_dst_addr;
+	dma_addr_t orig_dst_phys_addr;
+	size_t offset;
+	size_t alignment = test->alignment;
 	u32 src_crc32;
 	u32 dst_crc32;
 
-	src_addr = dma_alloc_coherent(dev, size, &src_phys_addr, GFP_KERNEL);
-	if (!src_addr) {
+	orig_src_addr = dma_alloc_coherent(dev, size + alignment,
+					   &orig_src_phys_addr, GFP_KERNEL);
+	if (!orig_src_addr) {
 		dev_err(dev, "failed to allocate source buffer\n");
 		ret = false;
 		goto err;
 	}
 
+	if (alignment && !IS_ALIGNED(orig_src_phys_addr, alignment)) {
+		src_phys_addr = PTR_ALIGN(orig_src_phys_addr, alignment);
+		offset = src_phys_addr - orig_src_phys_addr;
+		src_addr = orig_src_addr + offset;
+	} else {
+		src_phys_addr = orig_src_phys_addr;
+		src_addr = orig_src_addr;
+	}
+
 	pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR,
 				 lower_32_bits(src_phys_addr));
 
@@ -229,11 +247,21 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size)
 	get_random_bytes(src_addr, size);
 	src_crc32 = crc32_le(~0, src_addr, size);
 
-	dst_addr = dma_alloc_coherent(dev, size, &dst_phys_addr, GFP_KERNEL);
-	if (!dst_addr) {
+	orig_dst_addr = dma_alloc_coherent(dev, size + alignment,
+					   &orig_dst_phys_addr, GFP_KERNEL);
+	if (!orig_dst_addr) {
 		dev_err(dev, "failed to allocate destination address\n");
 		ret = false;
-		goto err_src_addr;
+		goto err_orig_src_addr;
+	}
+
+	if (alignment && !IS_ALIGNED(orig_dst_phys_addr, alignment)) {
+		dst_phys_addr = PTR_ALIGN(orig_dst_phys_addr, alignment);
+		offset = dst_phys_addr - orig_dst_phys_addr;
+		dst_addr = orig_dst_addr + offset;
+	} else {
+		dst_phys_addr = orig_dst_phys_addr;
+		dst_addr = orig_dst_addr;
 	}
 
 	pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR,
@@ -253,10 +281,12 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size)
 	if (dst_crc32 == src_crc32)
 		ret = true;
 
-	dma_free_coherent(dev, size, dst_addr, dst_phys_addr);
+	dma_free_coherent(dev, size + alignment, orig_dst_addr,
+			  orig_dst_phys_addr);
 
-err_src_addr:
-	dma_free_coherent(dev, size, src_addr, src_phys_addr);
+err_orig_src_addr:
+	dma_free_coherent(dev, size + alignment, orig_src_addr,
+			  orig_src_phys_addr);
 
 err:
 	return ret;
@@ -270,15 +300,29 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size)
 	dma_addr_t phys_addr;
 	struct pci_dev *pdev = test->pdev;
 	struct device *dev = &pdev->dev;
+	void *orig_addr;
+	dma_addr_t orig_phys_addr;
+	size_t offset;
+	size_t alignment = test->alignment;
 	u32 crc32;
 
-	addr = dma_alloc_coherent(dev, size, &phys_addr, GFP_KERNEL);
-	if (!addr) {
+	orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr,
+				       GFP_KERNEL);
+	if (!orig_addr) {
 		dev_err(dev, "failed to allocate address\n");
 		ret = false;
 		goto err;
 	}
 
+	if (alignment && !IS_ALIGNED(orig_phys_addr, alignment)) {
+		phys_addr =  PTR_ALIGN(orig_phys_addr, alignment);
+		offset = phys_addr - orig_phys_addr;
+		addr = orig_addr + offset;
+	} else {
+		phys_addr = orig_phys_addr;
+		addr = orig_addr;
+	}
+
 	get_random_bytes(addr, size);
 
 	crc32 = crc32_le(~0, addr, size);
@@ -301,7 +345,7 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size)
 	if (reg & STATUS_READ_SUCCESS)
 		ret = true;
 
-	dma_free_coherent(dev, size, addr, phys_addr);
+	dma_free_coherent(dev, size + alignment, orig_addr, orig_phys_addr);
 
 err:
 	return ret;
@@ -314,15 +358,29 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size)
 	dma_addr_t phys_addr;
 	struct pci_dev *pdev = test->pdev;
 	struct device *dev = &pdev->dev;
+	void *orig_addr;
+	dma_addr_t orig_phys_addr;
+	size_t offset;
+	size_t alignment = test->alignment;
 	u32 crc32;
 
-	addr = dma_alloc_coherent(dev, size, &phys_addr, GFP_KERNEL);
-	if (!addr) {
+	orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr,
+				       GFP_KERNEL);
+	if (!orig_addr) {
 		dev_err(dev, "failed to allocate destination address\n");
 		ret = false;
 		goto err;
 	}
 
+	if (alignment && !IS_ALIGNED(orig_phys_addr, alignment)) {
+		phys_addr = PTR_ALIGN(orig_phys_addr, alignment);
+		offset = phys_addr - orig_phys_addr;
+		addr = orig_addr + offset;
+	} else {
+		phys_addr = orig_phys_addr;
+		addr = orig_addr;
+	}
+
 	pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR,
 				 lower_32_bits(phys_addr));
 	pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR,
@@ -339,7 +397,7 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size)
 	if (crc32 == pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM))
 		ret = true;
 
-	dma_free_coherent(dev, size, addr, phys_addr);
+	dma_free_coherent(dev, size + alignment, orig_addr, orig_phys_addr);
 err:
 	return ret;
 }
@@ -410,11 +468,14 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 		return -ENOMEM;
 
 	test->test_reg_bar = 0;
+	test->alignment = 0;
 	test->pdev = pdev;
 
 	data = (struct pci_endpoint_test_data *)ent->driver_data;
-	if (data)
+	if (data) {
 		test_reg_bar = data->test_reg_bar;
+		test->alignment = data->alignment;
+	}
 
 	init_completion(&test->irq_raised);
 	mutex_init(&test->mutex);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 15/18] misc: pci_endpoint_test: Add support to not enable MSI interrupts
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (13 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 14/18] misc: pci_endpoint_test: Add support to provide aligned buffer addresses Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 16/18] misc: pci_endpoint_test: Avoid using hard coded BAR sizes Kishon Vijay Abraham I
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

Some platforms like TI's K2G have a restriction that the host side
buffer address should be aligned to either 1MB/2MB/4MB or 8MB
addresses depending on how it is configured in the endpoint
(Ref: 11.14.4.9.1 Outbound Address Translation in K2G TRM SPRUHY8F
January 2016 – Revised May 2017). This restriction also applies to
the MSI addresses provided by the RC. However it's not possible
for the RC to know about this restriction and it may not provide
1MB/2MB/4MB or 8MB aligned address. So MSI interrupts should be
disabled even if the K2G EP has MSI capabiltiy register. Add
support to not enable MSI interrupts in pci_endpoint_test driver
so that it can be used to test K2G EP.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/misc/pci_endpoint_test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 5f6bd23ab657..5cbb25cf276c 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -97,6 +97,7 @@ struct pci_endpoint_test {
 struct pci_endpoint_test_data {
 	enum pci_barno test_reg_bar;
 	size_t alignment;
+	bool no_msi;
 };
 
 static int bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 };
@@ -449,8 +450,9 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 {
 	int i;
 	int err;
-	int irq;
+	int irq = 0;
 	int id;
+	bool no_msi = false;
 	char name[20];
 	enum pci_barno bar;
 	void __iomem *base;
@@ -475,6 +477,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 	if (data) {
 		test_reg_bar = data->test_reg_bar;
 		test->alignment = data->alignment;
+		no_msi = data->no_msi;
 	}
 
 	init_completion(&test->irq_raised);
@@ -494,9 +497,11 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 
 	pci_set_master(pdev);
 
-	irq = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI);
-	if (irq < 0)
-		dev_err(dev, "failed to get MSI interrupts\n");
+	if (!no_msi) {
+		irq = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI);
+		if (irq < 0)
+			dev_err(dev, "failed to get MSI interrupts\n");
+	}
 
 	err = devm_request_irq(dev, pdev->irq, pci_endpoint_test_irqhandler,
 			       IRQF_SHARED, DRV_MODULE_NAME, test);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 16/18] misc: pci_endpoint_test: Avoid using hard coded BAR sizes
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (14 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 15/18] misc: pci_endpoint_test: Add support to not enable MSI interrupts Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 17/18] misc: pci_endpoint_test: Enable/Disable MSI using module param Kishon Vijay Abraham I
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

BAR sizes are hard coded in pci_endpoint_test driver corresponding to
the sizes used in pci-epf-test function driver. This might break if
the sizes in pci-epf-test function driver is modified (and the
corresponding change is not done in pci_endpoint_test pci driver).
To avoid hard coding BAR sizes, use pci_resource_len API.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/misc/pci_endpoint_test.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 5cbb25cf276c..1f37ad39b169 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -100,8 +100,6 @@ struct pci_endpoint_test_data {
 	bool no_msi;
 };
 
-static int bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 };
-
 static inline u32 pci_endpoint_test_readl(struct pci_endpoint_test *test,
 					  u32 offset)
 {
@@ -149,11 +147,12 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
 	int j;
 	u32 val;
 	int size;
+	struct pci_dev *pdev = test->pdev;
 
 	if (!test->bar[barno])
 		return false;
 
-	size = bar_size[barno];
+	size = pci_resource_len(pdev, barno);
 
 	if (barno == test->test_reg_bar)
 		size = 0x4;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 17/18] misc: pci_endpoint_test: Enable/Disable MSI using module param
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (15 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 16/18] misc: pci_endpoint_test: Avoid using hard coded BAR sizes Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 14:58 ` [PATCH 18/18] tools: PCI: Add a missing option help line Kishon Vijay Abraham I
  2017-08-18 15:53 ` [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Bjorn Helgaas
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap

In certain platforms like TI's DRA7 SoCs, use of legacy PCI
interrupt is exclusive with use of MSI (Section 24.9.4.6.2.1
Legacy PCI Interrupts in
http://www.ti.com/lit/ug/spruhz6i/spruhz6i.pdf).

However pci_endpoint_test driver enables MSI by default in probe.
In order for pci_endpoint_test to be able to test legacy interrupt,
MSI should be disabled. Add a module param 'no_msi' to disable MSI
(only when legacy interrupt has to be tested).

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/misc/pci_endpoint_test.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 1f37ad39b169..1f64d943794d 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -72,6 +72,11 @@ static DEFINE_IDA(pci_endpoint_test_ida);
 
 #define to_endpoint_test(priv) container_of((priv), struct pci_endpoint_test, \
 					    miscdev)
+
+bool no_msi;
+module_param(no_msi, bool, 0444);
+MODULE_PARM_DESC(no_msi, "Disable MSI interrupt in pci_endpoint_test");
+
 enum pci_barno {
 	BAR_0,
 	BAR_1,
@@ -451,7 +456,6 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 	int err;
 	int irq = 0;
 	int id;
-	bool no_msi = false;
 	char name[20];
 	enum pci_barno bar;
 	void __iomem *base;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 18/18] tools: PCI: Add a missing option help line
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (16 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 17/18] misc: pci_endpoint_test: Enable/Disable MSI using module param Kishon Vijay Abraham I
@ 2017-08-18 14:58 ` Kishon Vijay Abraham I
  2017-08-18 15:53 ` [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Bjorn Helgaas
  18 siblings, 0 replies; 20+ messages in thread
From: Kishon Vijay Abraham I @ 2017-08-18 14:58 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Joao Pinto, Arnd Bergmann, gregkh, kishon, nsekhar, linux-pci,
	linux-kernel, linux-omap, Stan Drozd

From: Stan Drozd <drozdziak1@gmail.com>

Add a missing option help line for performing legacy interrupt
test.

Signed-off-by: Stan Drozd <drozdziak1@gmail.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 tools/pci/pcitest.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c
index ad54a58d7dda..caf38c3959bf 100644
--- a/tools/pci/pcitest.c
+++ b/tools/pci/pcitest.c
@@ -173,6 +173,7 @@ int main(int argc, char **argv)
 			"\t-D <dev>		PCI endpoint test device {default: /dev/pci-endpoint-test.0}\n"
 			"\t-b <bar num>		BAR test (bar number between 0..5)\n"
 			"\t-m <msi num>		MSI test (msi number between 1..32)\n"
+			"\t-l			Legacy irq test\n"
 			"\t-r			Read buffer test\n"
 			"\t-w			Write buffer test\n"
 			"\t-c			Copy buffer test\n"
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible
  2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
                   ` (17 preceding siblings ...)
  2017-08-18 14:58 ` [PATCH 18/18] tools: PCI: Add a missing option help line Kishon Vijay Abraham I
@ 2017-08-18 15:53 ` Bjorn Helgaas
  18 siblings, 0 replies; 20+ messages in thread
From: Bjorn Helgaas @ 2017-08-18 15:53 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: Bjorn Helgaas, Joao Pinto, Arnd Bergmann, gregkh, nsekhar,
	linux-pci, linux-kernel, linux-omap

On Fri, Aug 18, 2017 at 08:27:52PM +0530, Kishon Vijay Abraham I wrote:
> Hi Bjorn,
> 
> I've collected all the patches for PCI Endpoint in this series. This
> series contains PCI endpoint fixes and making pci-epf-test more
> flexible in terms of mapping PCI_ENDPOINT_TEST regs to any BARs,
> work with linkup notification etc.
> 
> I've been having most of these patches in my local tree created while
> adding support for endpoint in TI's K2G platform. I've also included fix
> from others who are trying to use the PCI Endpoint Framework in their
> own platforms.
> 
> It also contains minor changes in pci/dwc/ like resetting BARs in the
> EP controller and providing a page size to pci_epc_mem. I can send this
> part separately based on some of your branch if you'd prefer that.
> 
> This also contains patches for host side pci_endpoint_test driver
> in drivers/misc.
> 
> I've pushed the series to pci-endpoint tree, the details of which are
> given below.

Applied to pci/endpoint for v4.14, thanks!

> The following changes since commit 5771a8c08880cdca3bfb4a3fc6d309d6bba20877:
> 
>   Linux v4.13-rc1 (2017-07-15 15:22:10 -0700)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/kishon/pci-endpoint.git tags/pci-ep-for-4.14
> 
> for you to fetch changes up to 31802acb56e040bf5f269b2bad159583fc804d68:
> 
>   tools: PCI: Add a missing option help line (2017-08-18 19:23:36 +0530)
> 
> ----------------------------------------------------------------
> PCI: endpoint: for 4.14
> 
> PCI endpoint core:
>  *) Add support for page size to be configurable (for managing address
>     region within the controller)
>  *) Add an API to get matching "pci_epf_device_id"
>  *) Use of_dma_configure() to set initial dma mask of pci_epf device
>  *) Do not abort if endpoint function drivers have not populated
>     ->remove() callback
> 
> pci-epf-test function driver:
>  *) Add support to poll early for host commands
>  *) Add support to use _any_ BAR's to map PCI_ENDPOINT_TEST regs
> 
> pci_endpoint_test PCI driver:
>  *) Add support for PCI_ENDPOINT_TEST regs to be mapped to any BAR
>  *) Add support to provide aligned buffer addresses
>  *) Enable/Disable MSI using module param
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> 
> ----------------------------------------------------------------
> Kishon Vijay Abraham I (16):
>       PCI: endpoint: pci-epc-core: Use of_dma_configure() to set initial dma mask
>       PCI: endpoint: pci-epf-core: Add an API to get matching "pci_epf_device_id"
>       PCI: endpoint: pci-epf-core: Make ->remove() callback optional
>       PCI: endpoint: pci-epc-mem: Add support for configurable page size
>       PCI: endpoint: functions/pci-epf-test: Add "volatile" to pci_epf_test_reg
>       PCI: endpoint: functions/pci-epf-test: Do not reset *command* inadvertently
>       PCI: endpoint: functions/pci-epf-test: Add support to use _any_ BAR's to map PCI_ENDPOINT_TEST regs
>       PCI: endpoint: functions/pci-epf-test: Add support to poll early for host commands
>       PCI: dwc: designware: Provide page_size to pci_epc_mem
>       PCI: dwc: dra7xx: Reset all BARs during initialization
>       PCI: dwc: designware-ep: Do not disable BARs during initialization
>       misc: pci_endpoint_test: Add support for PCI_ENDPOINT_TEST regs to be mapped to any BAR
>       misc: pci_endpoint_test: Add support to provide aligned buffer addresses
>       misc: pci_endpoint_test: Add support to not enable MSI interrupts
>       misc: pci_endpoint_test: Avoid using hard coded BAR sizes
>       misc: pci_endpoint_test: Enable/Disable MSI using module param
> 
> Shawn Lin (1):
>       PCI: endpoint: functions/pci-epf-test: Remove the ->remove() callback
> 
> Stan Drozd (1):
>       tools: PCI: Add a missing option help line
> 
>  drivers/misc/pci_endpoint_test.c              | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
>  drivers/pci/dwc/pci-dra7xx.c                  |  13 +++++++++++++
>  drivers/pci/dwc/pcie-designware-ep.c          |   7 ++-----
>  drivers/pci/dwc/pcie-designware.h             |   1 +
>  drivers/pci/endpoint/functions/pci-epf-test.c |  99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------
>  drivers/pci/endpoint/pci-epc-core.c           |  11 +++++++++--
>  drivers/pci/endpoint/pci-epc-mem.c            |  59 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
>  drivers/pci/endpoint/pci-epf-core.c           |  21 +++++++++++++++++++--
>  include/linux/pci-epc.h                       |   8 +++++++-
>  include/linux/pci-epf.h                       |   2 ++
>  tools/pci/pcitest.c                           |   1 +
>  11 files changed, 276 insertions(+), 78 deletions(-)
> -- 
> 2.11.0
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2017-08-18 15:53 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-18 14:57 [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Kishon Vijay Abraham I
2017-08-18 14:57 ` [PATCH 01/18] PCI: endpoint: pci-epc-core: Use of_dma_configure() to set initial dma mask Kishon Vijay Abraham I
2017-08-18 14:57 ` [PATCH 02/18] PCI: endpoint: pci-epf-core: Add an API to get matching "pci_epf_device_id" Kishon Vijay Abraham I
2017-08-18 14:57 ` [PATCH 03/18] PCI: endpoint: pci-epf-core: Make ->remove() callback optional Kishon Vijay Abraham I
2017-08-18 14:57 ` [PATCH 04/18] PCI: endpoint: pci-epc-mem: Add support for configurable page size Kishon Vijay Abraham I
2017-08-18 14:57 ` [PATCH 05/18] PCI: endpoint: functions/pci-epf-test: Add "volatile" to pci_epf_test_reg Kishon Vijay Abraham I
2017-08-18 14:57 ` [PATCH 06/18] PCI: endpoint: functions/pci-epf-test: Do not reset *command* inadvertently Kishon Vijay Abraham I
2017-08-18 14:57 ` [PATCH 07/18] PCI: endpoint: functions/pci-epf-test: Add support to use _any_ BAR's to map PCI_ENDPOINT_TEST regs Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 08/18] PCI: endpoint: functions/pci-epf-test: Add support to poll early for host commands Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 09/18] PCI: endpoint: functions/pci-epf-test: Remove the ->remove() callback Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 10/18] PCI: dwc: designware: Provide page_size to pci_epc_mem Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 11/18] PCI: dwc: dra7xx: Reset all BARs during initialization Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 12/18] PCI: dwc: designware-ep: Do not disable " Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 13/18] misc: pci_endpoint_test: Add support for PCI_ENDPOINT_TEST regs to be mapped to any BAR Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 14/18] misc: pci_endpoint_test: Add support to provide aligned buffer addresses Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 15/18] misc: pci_endpoint_test: Add support to not enable MSI interrupts Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 16/18] misc: pci_endpoint_test: Avoid using hard coded BAR sizes Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 17/18] misc: pci_endpoint_test: Enable/Disable MSI using module param Kishon Vijay Abraham I
2017-08-18 14:58 ` [PATCH 18/18] tools: PCI: Add a missing option help line Kishon Vijay Abraham I
2017-08-18 15:53 ` [PATCH 00/18] PCI: endpoint: Make pci-epf-test more flexible Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).