diff mbox series

[2/6] nvme: assign of_node to nvme device

Message ID 20240804114108.1893-3-ansuelsmth@gmail.com
State New
Headers show
Series mtd: improve block2mtd + airoha parser | expand

Commit Message

Christian Marangi Aug. 4, 2024, 11:41 a.m. UTC
Introduce support for a dedicated node for a nvme card. This will be a
subnode of the nvme controller node that will have the "nvme-card"
compatible.

This follow a similar implementation done for mmc where the specific mmc
card have a dedicated of_node.

This can be used for scenario where block2mtd module is used to declare
partition in DT and block2mtd is called on the root block of the nvme
card, permitting the usage of fixed-partition parser or alternative
ones.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/nvme/host/core.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

kernel test robot Aug. 4, 2024, 1:48 p.m. UTC | #1
Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on linus/master v6.11-rc1 next-20240802]
[cannot apply to mtd/mtd/next mtd/mtd/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/dt-bindings-nvme-Document-nvme-card-compatible/20240804-194357
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240804114108.1893-3-ansuelsmth%40gmail.com
patch subject: [PATCH 2/6] nvme: assign of_node to nvme device
config: i386-buildonly-randconfig-002-20240804 (https://download.01.org/0day-ci/archive/20240804/202408042134.wVQ7VdU6-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240804/202408042134.wVQ7VdU6-lkp@intel.com/reproduce)

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/202408042134.wVQ7VdU6-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   drivers/nvme/host/core.c: In function 'nvme_uninit_ctrl':
>> drivers/nvme/host/core.c:4654:9: error: implicit declaration of function 'of_node_put'; did you mean 'bpf_token_put'? [-Werror=implicit-function-declaration]
    4654 |         of_node_put(ctrl->device->of_node);
         |         ^~~~~~~~~~~
         |         bpf_token_put
   drivers/nvme/host/core.c: In function 'nvme_init_ctrl':
>> drivers/nvme/host/core.c:4775:33: error: implicit declaration of function 'of_get_compatible_child' [-Werror=implicit-function-declaration]
    4775 |         ctrl->device->of_node = of_get_compatible_child(ctrl->dev->of_node,
         |                                 ^~~~~~~~~~~~~~~~~~~~~~~
>> drivers/nvme/host/core.c:4775:31: warning: assignment to 'struct device_node *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    4775 |         ctrl->device->of_node = of_get_compatible_child(ctrl->dev->of_node,
         |                               ^
   cc1: some warnings being treated as errors


vim +4654 drivers/nvme/host/core.c

  4648	
  4649	void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
  4650	{
  4651		nvme_hwmon_exit(ctrl);
  4652		nvme_fault_inject_fini(&ctrl->fault_inject);
  4653		dev_pm_qos_hide_latency_tolerance(ctrl->device);
> 4654		of_node_put(ctrl->device->of_node);
  4655		cdev_device_del(&ctrl->cdev, ctrl->device);
  4656		nvme_put_ctrl(ctrl);
  4657	}
  4658	EXPORT_SYMBOL_GPL(nvme_uninit_ctrl);
  4659	
  4660	static void nvme_free_cels(struct nvme_ctrl *ctrl)
  4661	{
  4662		struct nvme_effects_log	*cel;
  4663		unsigned long i;
  4664	
  4665		xa_for_each(&ctrl->cels, i, cel) {
  4666			xa_erase(&ctrl->cels, i);
  4667			kfree(cel);
  4668		}
  4669	
  4670		xa_destroy(&ctrl->cels);
  4671	}
  4672	
  4673	static void nvme_free_ctrl(struct device *dev)
  4674	{
  4675		struct nvme_ctrl *ctrl =
  4676			container_of(dev, struct nvme_ctrl, ctrl_device);
  4677		struct nvme_subsystem *subsys = ctrl->subsys;
  4678	
  4679		if (!subsys || ctrl->instance != subsys->instance)
  4680			ida_free(&nvme_instance_ida, ctrl->instance);
  4681		key_put(ctrl->tls_key);
  4682		nvme_free_cels(ctrl);
  4683		nvme_mpath_uninit(ctrl);
  4684		cleanup_srcu_struct(&ctrl->srcu);
  4685		nvme_auth_stop(ctrl);
  4686		nvme_auth_free(ctrl);
  4687		__free_page(ctrl->discard_page);
  4688		free_opal_dev(ctrl->opal_dev);
  4689	
  4690		if (subsys) {
  4691			mutex_lock(&nvme_subsystems_lock);
  4692			list_del(&ctrl->subsys_entry);
  4693			sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device));
  4694			mutex_unlock(&nvme_subsystems_lock);
  4695		}
  4696	
  4697		ctrl->ops->free_ctrl(ctrl);
  4698	
  4699		if (subsys)
  4700			nvme_put_subsystem(subsys);
  4701	}
  4702	
  4703	/*
  4704	 * Initialize a NVMe controller structures.  This needs to be called during
  4705	 * earliest initialization so that we have the initialized structured around
  4706	 * during probing.
  4707	 *
  4708	 * On success, the caller must use the nvme_put_ctrl() to release this when
  4709	 * needed, which also invokes the ops->free_ctrl() callback.
  4710	 */
  4711	int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
  4712			const struct nvme_ctrl_ops *ops, unsigned long quirks)
  4713	{
  4714		int ret;
  4715	
  4716		WRITE_ONCE(ctrl->state, NVME_CTRL_NEW);
  4717		ctrl->passthru_err_log_enabled = false;
  4718		clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags);
  4719		spin_lock_init(&ctrl->lock);
  4720		mutex_init(&ctrl->namespaces_lock);
  4721	
  4722		ret = init_srcu_struct(&ctrl->srcu);
  4723		if (ret)
  4724			return ret;
  4725	
  4726		mutex_init(&ctrl->scan_lock);
  4727		INIT_LIST_HEAD(&ctrl->namespaces);
  4728		xa_init(&ctrl->cels);
  4729		ctrl->dev = dev;
  4730		ctrl->ops = ops;
  4731		ctrl->quirks = quirks;
  4732		ctrl->numa_node = NUMA_NO_NODE;
  4733		INIT_WORK(&ctrl->scan_work, nvme_scan_work);
  4734		INIT_WORK(&ctrl->async_event_work, nvme_async_event_work);
  4735		INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work);
  4736		INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work);
  4737		init_waitqueue_head(&ctrl->state_wq);
  4738	
  4739		INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work);
  4740		INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work);
  4741		memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd));
  4742		ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive;
  4743		ctrl->ka_last_check_time = jiffies;
  4744	
  4745		BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) >
  4746				PAGE_SIZE);
  4747		ctrl->discard_page = alloc_page(GFP_KERNEL);
  4748		if (!ctrl->discard_page) {
  4749			ret = -ENOMEM;
  4750			goto out;
  4751		}
  4752	
  4753		ret = ida_alloc(&nvme_instance_ida, GFP_KERNEL);
  4754		if (ret < 0)
  4755			goto out;
  4756		ctrl->instance = ret;
  4757	
  4758		ret = nvme_auth_init_ctrl(ctrl);
  4759		if (ret)
  4760			goto out_release_instance;
  4761	
  4762		nvme_mpath_init_ctrl(ctrl);
  4763	
  4764		device_initialize(&ctrl->ctrl_device);
  4765		ctrl->device = &ctrl->ctrl_device;
  4766		ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt),
  4767				ctrl->instance);
  4768		ctrl->device->class = &nvme_class;
  4769		ctrl->device->parent = ctrl->dev;
  4770		if (ops->dev_attr_groups)
  4771			ctrl->device->groups = ops->dev_attr_groups;
  4772		else
  4773			ctrl->device->groups = nvme_dev_attr_groups;
  4774		ctrl->device->release = nvme_free_ctrl;
> 4775		ctrl->device->of_node = of_get_compatible_child(ctrl->dev->of_node,
  4776								"nvme-card");
  4777		dev_set_drvdata(ctrl->device, ctrl);
  4778	
  4779		return ret;
  4780	
  4781	out_release_instance:
  4782		ida_free(&nvme_instance_ida, ctrl->instance);
  4783	out:
  4784		if (ctrl->discard_page)
  4785			__free_page(ctrl->discard_page);
  4786		cleanup_srcu_struct(&ctrl->srcu);
  4787		return ret;
  4788	}
  4789	EXPORT_SYMBOL_GPL(nvme_init_ctrl);
  4790
kernel test robot Aug. 4, 2024, 3:21 p.m. UTC | #2
Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on linus/master v6.11-rc1 next-20240802]
[cannot apply to mtd/mtd/next mtd/mtd/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/dt-bindings-nvme-Document-nvme-card-compatible/20240804-194357
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240804114108.1893-3-ansuelsmth%40gmail.com
patch subject: [PATCH 2/6] nvme: assign of_node to nvme device
config: i386-buildonly-randconfig-005-20240804 (https://download.01.org/0day-ci/archive/20240804/202408042203.CNpuv8Wt-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240804/202408042203.CNpuv8Wt-lkp@intel.com/reproduce)

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/202408042203.CNpuv8Wt-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/nvme/host/core.c:4654:2: error: call to undeclared function 'of_node_put'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    4654 |         of_node_put(ctrl->device->of_node);
         |         ^
>> drivers/nvme/host/core.c:4775:26: error: call to undeclared function 'of_get_compatible_child'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    4775 |         ctrl->device->of_node = of_get_compatible_child(ctrl->dev->of_node,
         |                                 ^
>> drivers/nvme/host/core.c:4775:24: error: incompatible integer to pointer conversion assigning to 'struct device_node *' from 'int' [-Wint-conversion]
    4775 |         ctrl->device->of_node = of_get_compatible_child(ctrl->dev->of_node,
         |                               ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4776 |                                                         "nvme-card");
         |                                                         ~~~~~~~~~~~~
   3 errors generated.


vim +/of_node_put +4654 drivers/nvme/host/core.c

  4648	
  4649	void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
  4650	{
  4651		nvme_hwmon_exit(ctrl);
  4652		nvme_fault_inject_fini(&ctrl->fault_inject);
  4653		dev_pm_qos_hide_latency_tolerance(ctrl->device);
> 4654		of_node_put(ctrl->device->of_node);
  4655		cdev_device_del(&ctrl->cdev, ctrl->device);
  4656		nvme_put_ctrl(ctrl);
  4657	}
  4658	EXPORT_SYMBOL_GPL(nvme_uninit_ctrl);
  4659	
  4660	static void nvme_free_cels(struct nvme_ctrl *ctrl)
  4661	{
  4662		struct nvme_effects_log	*cel;
  4663		unsigned long i;
  4664	
  4665		xa_for_each(&ctrl->cels, i, cel) {
  4666			xa_erase(&ctrl->cels, i);
  4667			kfree(cel);
  4668		}
  4669	
  4670		xa_destroy(&ctrl->cels);
  4671	}
  4672	
  4673	static void nvme_free_ctrl(struct device *dev)
  4674	{
  4675		struct nvme_ctrl *ctrl =
  4676			container_of(dev, struct nvme_ctrl, ctrl_device);
  4677		struct nvme_subsystem *subsys = ctrl->subsys;
  4678	
  4679		if (!subsys || ctrl->instance != subsys->instance)
  4680			ida_free(&nvme_instance_ida, ctrl->instance);
  4681		key_put(ctrl->tls_key);
  4682		nvme_free_cels(ctrl);
  4683		nvme_mpath_uninit(ctrl);
  4684		cleanup_srcu_struct(&ctrl->srcu);
  4685		nvme_auth_stop(ctrl);
  4686		nvme_auth_free(ctrl);
  4687		__free_page(ctrl->discard_page);
  4688		free_opal_dev(ctrl->opal_dev);
  4689	
  4690		if (subsys) {
  4691			mutex_lock(&nvme_subsystems_lock);
  4692			list_del(&ctrl->subsys_entry);
  4693			sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device));
  4694			mutex_unlock(&nvme_subsystems_lock);
  4695		}
  4696	
  4697		ctrl->ops->free_ctrl(ctrl);
  4698	
  4699		if (subsys)
  4700			nvme_put_subsystem(subsys);
  4701	}
  4702	
  4703	/*
  4704	 * Initialize a NVMe controller structures.  This needs to be called during
  4705	 * earliest initialization so that we have the initialized structured around
  4706	 * during probing.
  4707	 *
  4708	 * On success, the caller must use the nvme_put_ctrl() to release this when
  4709	 * needed, which also invokes the ops->free_ctrl() callback.
  4710	 */
  4711	int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
  4712			const struct nvme_ctrl_ops *ops, unsigned long quirks)
  4713	{
  4714		int ret;
  4715	
  4716		WRITE_ONCE(ctrl->state, NVME_CTRL_NEW);
  4717		ctrl->passthru_err_log_enabled = false;
  4718		clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags);
  4719		spin_lock_init(&ctrl->lock);
  4720		mutex_init(&ctrl->namespaces_lock);
  4721	
  4722		ret = init_srcu_struct(&ctrl->srcu);
  4723		if (ret)
  4724			return ret;
  4725	
  4726		mutex_init(&ctrl->scan_lock);
  4727		INIT_LIST_HEAD(&ctrl->namespaces);
  4728		xa_init(&ctrl->cels);
  4729		ctrl->dev = dev;
  4730		ctrl->ops = ops;
  4731		ctrl->quirks = quirks;
  4732		ctrl->numa_node = NUMA_NO_NODE;
  4733		INIT_WORK(&ctrl->scan_work, nvme_scan_work);
  4734		INIT_WORK(&ctrl->async_event_work, nvme_async_event_work);
  4735		INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work);
  4736		INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work);
  4737		init_waitqueue_head(&ctrl->state_wq);
  4738	
  4739		INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work);
  4740		INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work);
  4741		memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd));
  4742		ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive;
  4743		ctrl->ka_last_check_time = jiffies;
  4744	
  4745		BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) >
  4746				PAGE_SIZE);
  4747		ctrl->discard_page = alloc_page(GFP_KERNEL);
  4748		if (!ctrl->discard_page) {
  4749			ret = -ENOMEM;
  4750			goto out;
  4751		}
  4752	
  4753		ret = ida_alloc(&nvme_instance_ida, GFP_KERNEL);
  4754		if (ret < 0)
  4755			goto out;
  4756		ctrl->instance = ret;
  4757	
  4758		ret = nvme_auth_init_ctrl(ctrl);
  4759		if (ret)
  4760			goto out_release_instance;
  4761	
  4762		nvme_mpath_init_ctrl(ctrl);
  4763	
  4764		device_initialize(&ctrl->ctrl_device);
  4765		ctrl->device = &ctrl->ctrl_device;
  4766		ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt),
  4767				ctrl->instance);
  4768		ctrl->device->class = &nvme_class;
  4769		ctrl->device->parent = ctrl->dev;
  4770		if (ops->dev_attr_groups)
  4771			ctrl->device->groups = ops->dev_attr_groups;
  4772		else
  4773			ctrl->device->groups = nvme_dev_attr_groups;
  4774		ctrl->device->release = nvme_free_ctrl;
> 4775		ctrl->device->of_node = of_get_compatible_child(ctrl->dev->of_node,
  4776								"nvme-card");
  4777		dev_set_drvdata(ctrl->device, ctrl);
  4778	
  4779		return ret;
  4780	
  4781	out_release_instance:
  4782		ida_free(&nvme_instance_ida, ctrl->instance);
  4783	out:
  4784		if (ctrl->discard_page)
  4785			__free_page(ctrl->discard_page);
  4786		cleanup_srcu_struct(&ctrl->srcu);
  4787		return ret;
  4788	}
  4789	EXPORT_SYMBOL_GPL(nvme_init_ctrl);
  4790
diff mbox series

Patch

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 053d5b4909cd..b9553bb8fade 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4651,6 +4651,7 @@  void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
 	nvme_hwmon_exit(ctrl);
 	nvme_fault_inject_fini(&ctrl->fault_inject);
 	dev_pm_qos_hide_latency_tolerance(ctrl->device);
+	of_node_put(ctrl->device->of_node);
 	cdev_device_del(&ctrl->cdev, ctrl->device);
 	nvme_put_ctrl(ctrl);
 }
@@ -4771,6 +4772,8 @@  int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
 	else
 		ctrl->device->groups = nvme_dev_attr_groups;
 	ctrl->device->release = nvme_free_ctrl;
+	ctrl->device->of_node = of_get_compatible_child(ctrl->dev->of_node,
+							"nvme-card");
 	dev_set_drvdata(ctrl->device, ctrl);
 
 	return ret;