diff mbox series

[v3,05/13] PCI: endpoint: Assign PCI domain number for endpoint controllers

Message ID 20240731-pci-qcom-hotplug-v3-5-a1426afdee3b@linaro.org
State New
Headers show
Series PCI: qcom: Enumerate endpoints based on Link up event in 'global_irq' interrupt | expand

Commit Message

Manivannan Sadhasivam via B4 Relay July 31, 2024, 10:50 a.m. UTC
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Right now, PCI endpoint subsystem doesn't assign PCI domain number for the
PCI endpoint controllers. But this domain number could be useful to the EPC
drivers to uniquely identify each controller based on the hardware instance
when there are multiple ones present in an SoC (even multiple RC/EP).

So let's make use of the existing pci_bus_find_domain_nr() API to allocate
domain numbers based on either Devicetree (linux,pci-domain) property or
dynamic domain number allocation scheme.

It should be noted that the domain number allocated by this API will be
based on both RC and EP controllers in a SoC. If the 'linux,pci-domain' DT
property is present, then the domain number represents the actual hardware
instance of the PCI endpoint controller. If not, then the domain number
will be allocated based on the PCI EP/RC controller probe order.

If the architecture doesn't support CONFIG_PCI_DOMAINS_GENERIC (rare), then
currently a warning is thrown to indicate that the architecture specific
implementation is needed.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/pci/endpoint/pci-epc-core.c | 14 ++++++++++++++
 include/linux/pci-epc.h             |  2 ++
 2 files changed, 16 insertions(+)

Comments

kernel test robot Aug. 11, 2024, 1:56 a.m. UTC | #1
Hi Manivannan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 8400291e289ee6b2bf9779ff1c83a291501f017b]

url:    https://github.com/intel-lab-lkp/linux/commits/Manivannan-Sadhasivam-via-B4-Relay/PCI-qcom-ep-Drop-the-redundant-masking-of-global-IRQ-events/20240802-024847
base:   8400291e289ee6b2bf9779ff1c83a291501f017b
patch link:    https://lore.kernel.org/r/20240731-pci-qcom-hotplug-v3-5-a1426afdee3b%40linaro.org
patch subject: [PATCH v3 05/13] PCI: endpoint: Assign PCI domain number for endpoint controllers
config: x86_64-randconfig-161-20240810 (https://download.01.org/0day-ci/archive/20240811/202408110938.hFwAHjZo-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408110938.hFwAHjZo-lkp@intel.com/

smatch warnings:
drivers/pci/endpoint/pci-epc-core.c:914 __pci_epc_create() warn: inconsistent indenting

vim +914 drivers/pci/endpoint/pci-epc-core.c

   870	
   871	/**
   872	 * __pci_epc_create() - create a new endpoint controller (EPC) device
   873	 * @dev: device that is creating the new EPC
   874	 * @ops: function pointers for performing EPC operations
   875	 * @owner: the owner of the module that creates the EPC device
   876	 *
   877	 * Invoke to create a new EPC device and add it to pci_epc class.
   878	 */
   879	struct pci_epc *
   880	__pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
   881			 struct module *owner)
   882	{
   883		int ret;
   884		struct pci_epc *epc;
   885	
   886		if (WARN_ON(!dev)) {
   887			ret = -EINVAL;
   888			goto err_ret;
   889		}
   890	
   891		epc = kzalloc(sizeof(*epc), GFP_KERNEL);
   892		if (!epc) {
   893			ret = -ENOMEM;
   894			goto err_ret;
   895		}
   896	
   897		mutex_init(&epc->lock);
   898		mutex_init(&epc->list_lock);
   899		INIT_LIST_HEAD(&epc->pci_epf);
   900	
   901		device_initialize(&epc->dev);
   902		epc->dev.class = &pci_epc_class;
   903		epc->dev.parent = dev;
   904		epc->dev.release = pci_epc_release;
   905		epc->ops = ops;
   906	
   907		#ifdef CONFIG_PCI_DOMAINS_GENERIC
   908			epc->domain_nr = pci_bus_find_domain_nr(NULL, dev);
   909		#else
   910			/*
   911			 * TODO: If the architecture doesn't support generic PCI
   912			 * domains, then a custom implementation has to be used.
   913			 */
 > 914			WARN_ONCE(1, "This architecture doesn't support generic PCI domains\n");
   915		#endif
   916	
   917		ret = dev_set_name(&epc->dev, "%s", dev_name(dev));
   918		if (ret)
   919			goto put_dev;
   920	
   921		ret = device_add(&epc->dev);
   922		if (ret)
   923			goto put_dev;
   924	
   925		epc->group = pci_ep_cfs_add_epc_group(dev_name(dev));
   926	
   927		return epc;
   928	
   929	put_dev:
   930		put_device(&epc->dev);
   931	
   932	err_ret:
   933		return ERR_PTR(ret);
   934	}
   935	EXPORT_SYMBOL_GPL(__pci_epc_create);
   936
kernel test robot Aug. 11, 2024, 2:47 a.m. UTC | #2
Hi Manivannan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 8400291e289ee6b2bf9779ff1c83a291501f017b]

url:    https://github.com/intel-lab-lkp/linux/commits/Manivannan-Sadhasivam-via-B4-Relay/PCI-qcom-ep-Drop-the-redundant-masking-of-global-IRQ-events/20240802-024847
base:   8400291e289ee6b2bf9779ff1c83a291501f017b
patch link:    https://lore.kernel.org/r/20240731-pci-qcom-hotplug-v3-5-a1426afdee3b%40linaro.org
patch subject: [PATCH v3 05/13] PCI: endpoint: Assign PCI domain number for endpoint controllers
config: microblaze-randconfig-r072-20240810 (https://download.01.org/0day-ci/archive/20240811/202408111053.0PLHSTeH-lkp@intel.com/config)
compiler: microblaze-linux-gcc (GCC) 14.1.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408111053.0PLHSTeH-lkp@intel.com/

New smatch warnings:
drivers/pci/endpoint/pci-epc-core.c:843 pci_epc_destroy() warn: inconsistent indenting

Old smatch warnings:
drivers/pci/endpoint/pci-epc-core.c:908 __pci_epc_create() warn: inconsistent indenting

vim +843 drivers/pci/endpoint/pci-epc-core.c

   830	
   831	/**
   832	 * pci_epc_destroy() - destroy the EPC device
   833	 * @epc: the EPC device that has to be destroyed
   834	 *
   835	 * Invoke to destroy the PCI EPC device
   836	 */
   837	void pci_epc_destroy(struct pci_epc *epc)
   838	{
   839		pci_ep_cfs_remove_epc_group(epc->group);
   840		device_unregister(&epc->dev);
   841	
   842		#ifdef CONFIG_PCI_DOMAINS_GENERIC
 > 843			pci_bus_release_domain_nr(NULL, &epc->dev);
   844		#endif
   845	}
   846	EXPORT_SYMBOL_GPL(pci_epc_destroy);
   847
Manivannan Sadhasivam Aug. 15, 2024, 3:59 p.m. UTC | #3
On Sun, Aug 11, 2024 at 10:47:08AM +0800, kernel test robot wrote:
> Hi Manivannan,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on 8400291e289ee6b2bf9779ff1c83a291501f017b]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Manivannan-Sadhasivam-via-B4-Relay/PCI-qcom-ep-Drop-the-redundant-masking-of-global-IRQ-events/20240802-024847
> base:   8400291e289ee6b2bf9779ff1c83a291501f017b
> patch link:    https://lore.kernel.org/r/20240731-pci-qcom-hotplug-v3-5-a1426afdee3b%40linaro.org
> patch subject: [PATCH v3 05/13] PCI: endpoint: Assign PCI domain number for endpoint controllers
> config: microblaze-randconfig-r072-20240810 (https://download.01.org/0day-ci/archive/20240811/202408111053.0PLHSTeH-lkp@intel.com/config)
> compiler: microblaze-linux-gcc (GCC) 14.1.0
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202408111053.0PLHSTeH-lkp@intel.com/
> 
> New smatch warnings:
> drivers/pci/endpoint/pci-epc-core.c:843 pci_epc_destroy() warn: inconsistent indenting
> 
> Old smatch warnings:
> drivers/pci/endpoint/pci-epc-core.c:908 __pci_epc_create() warn: inconsistent indenting
> 

Krzysztof, will you be able to fix the indendation while applying? If not,
please let me know. I'll spin v4.

- Mani

> vim +843 drivers/pci/endpoint/pci-epc-core.c
> 
>    830	
>    831	/**
>    832	 * pci_epc_destroy() - destroy the EPC device
>    833	 * @epc: the EPC device that has to be destroyed
>    834	 *
>    835	 * Invoke to destroy the PCI EPC device
>    836	 */
>    837	void pci_epc_destroy(struct pci_epc *epc)
>    838	{
>    839		pci_ep_cfs_remove_epc_group(epc->group);
>    840		device_unregister(&epc->dev);
>    841	
>    842		#ifdef CONFIG_PCI_DOMAINS_GENERIC
>  > 843			pci_bus_release_domain_nr(NULL, &epc->dev);
>    844		#endif
>    845	}
>    846	EXPORT_SYMBOL_GPL(pci_epc_destroy);
>    847	
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
diff mbox series

Patch

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 84309dfe0c68..178765e2cb03 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -838,6 +838,10 @@  void pci_epc_destroy(struct pci_epc *epc)
 {
 	pci_ep_cfs_remove_epc_group(epc->group);
 	device_unregister(&epc->dev);
+
+	#ifdef CONFIG_PCI_DOMAINS_GENERIC
+		pci_bus_release_domain_nr(NULL, &epc->dev);
+	#endif
 }
 EXPORT_SYMBOL_GPL(pci_epc_destroy);
 
@@ -900,6 +904,16 @@  __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
 	epc->dev.release = pci_epc_release;
 	epc->ops = ops;
 
+	#ifdef CONFIG_PCI_DOMAINS_GENERIC
+		epc->domain_nr = pci_bus_find_domain_nr(NULL, dev);
+	#else
+		/*
+		 * TODO: If the architecture doesn't support generic PCI
+		 * domains, then a custom implementation has to be used.
+		 */
+		WARN_ONCE(1, "This architecture doesn't support generic PCI domains\n");
+	#endif
+
 	ret = dev_set_name(&epc->dev, "%s", dev_name(dev));
 	if (ret)
 		goto put_dev;
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
index 85bdf2adb760..8e3dcac55dcd 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -128,6 +128,7 @@  struct pci_epc_mem {
  * @group: configfs group representing the PCI EPC device
  * @lock: mutex to protect pci_epc ops
  * @function_num_map: bitmap to manage physical function number
+ * @domain_nr: PCI domain number of the endpoint controller
  * @init_complete: flag to indicate whether the EPC initialization is complete
  *                 or not
  */
@@ -145,6 +146,7 @@  struct pci_epc {
 	/* mutex to protect against concurrent access of EP controller */
 	struct mutex			lock;
 	unsigned long			function_num_map;
+	int				domain_nr;
 	bool				init_complete;
 };