From bd42805b5da33b9c75f3ce0ae9d6ff0ec3f2cd6b Mon Sep 17 00:00:00 2001
From: Dave Jiang <dave.jiang@intel.com>
Date: Thu, 15 Jul 2021 11:44:01 -0700
Subject: [PATCH] dmaengine: idxd: move probe() bits for idxd 'struct device' to device.c
Git-commit: bd42805b5da33b9c75f3ce0ae9d6ff0ec3f2cd6b
Patch-mainline: v5.15-rc1
References: jsc#SLE-18899
Move the code related to a ->probe() function for the idxd
'struct device' to device.c to prep for the idxd device
sub-driver in device.c.
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/162637464189.744545.17423830646786162194.stgit@djiang5-desk3.ch.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Acked-by: Takashi Iwai <tiwai@suse.de>
---
drivers/dma/idxd/device.c | 37 ++++++++++++++++++++++++++++++++++++
drivers/dma/idxd/idxd.h | 1 +
drivers/dma/idxd/sysfs.c | 40 ++-------------------------------------
3 files changed, 40 insertions(+), 38 deletions(-)
diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index 8d8e249931a9..b9aa209efee4 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -1290,3 +1290,40 @@ void drv_disable_wq(struct idxd_wq *wq)
__drv_disable_wq(wq);
mutex_unlock(&wq->wq_lock);
}
+
+int idxd_device_drv_probe(struct idxd_dev *idxd_dev)
+{
+ struct idxd_device *idxd = idxd_dev_to_idxd(idxd_dev);
+ unsigned long flags;
+ int rc = 0;
+
+ /*
+ * Device should be in disabled state for the idxd_drv to load. If it's in
+ * enabled state, then the device was altered outside of driver's control.
+ * If the state is in halted state, then we don't want to proceed.
+ */
+ if (idxd->state != IDXD_DEV_DISABLED)
+ return -ENXIO;
+
+ /* Device configuration */
+ spin_lock_irqsave(&idxd->dev_lock, flags);
+ if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
+ rc = idxd_device_config(idxd);
+ spin_unlock_irqrestore(&idxd->dev_lock, flags);
+ if (rc < 0)
+ return -ENXIO;
+
+ /* Start device */
+ rc = idxd_device_enable(idxd);
+ if (rc < 0)
+ return rc;
+
+ /* Setup DMA device without channels */
+ rc = idxd_register_dma_device(idxd);
+ if (rc < 0) {
+ idxd_device_disable(idxd);
+ return rc;
+ }
+
+ return 0;
+}
diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
index 493958ecc208..dbbd36feb462 100644
--- a/drivers/dma/idxd/idxd.h
+++ b/drivers/dma/idxd/idxd.h
@@ -498,6 +498,7 @@ void idxd_mask_msix_vector(struct idxd_device *idxd, int vec_id);
void idxd_unmask_msix_vector(struct idxd_device *idxd, int vec_id);
/* device control */
+int idxd_device_drv_probe(struct idxd_dev *idxd_dev);
int drv_enable_wq(struct idxd_wq *wq);
void drv_disable_wq(struct idxd_wq *wq);
int idxd_device_init_reset(struct idxd_device *idxd);
diff --git a/drivers/dma/idxd/sysfs.c b/drivers/dma/idxd/sysfs.c
index f82416eec926..221a61e3bb9c 100644
--- a/drivers/dma/idxd/sysfs.c
+++ b/drivers/dma/idxd/sysfs.c
@@ -52,44 +52,8 @@ struct bus_type dsa_bus_type = {
static int idxd_dsa_drv_probe(struct idxd_dev *idxd_dev)
{
- struct device *dev = &idxd_dev->conf_dev;
- unsigned long flags;
- int rc;
-
- if (is_idxd_dev(idxd_dev)) {
- struct idxd_device *idxd = idxd_dev_to_idxd(idxd_dev);
-
- if (idxd->state != IDXD_DEV_DISABLED)
- return -ENXIO;
-
- /* Device configuration */
- spin_lock_irqsave(&idxd->dev_lock, flags);
- if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
- rc = idxd_device_config(idxd);
- spin_unlock_irqrestore(&idxd->dev_lock, flags);
- if (rc < 0) {
- dev_dbg(dev, "Device config failed: %d\n", rc);
- return rc;
- }
-
- /* Start device */
- rc = idxd_device_enable(idxd);
- if (rc < 0) {
- dev_warn(dev, "Device enable failed: %d\n", rc);
- return rc;
- }
-
- /* Setup DMA device without channels */
- rc = idxd_register_dma_device(idxd);
- if (rc < 0) {
- dev_dbg(dev, "Failed to register dmaengine device\n");
- idxd_device_disable(idxd);
- return rc;
- }
-
- dev_info(dev, "Device %s enabled\n", dev_name(dev));
- return 0;
- }
+ if (is_idxd_dev(idxd_dev))
+ return idxd_device_drv_probe(idxd_dev);
if (is_idxd_wq_dev(idxd_dev)) {
struct idxd_wq *wq = idxd_dev_to_wq(idxd_dev);
--
2.26.2