Commit 63c14ae6 authored by Dave Jiang's avatar Dave Jiang Committed by Vinod Koul

dmaengine: idxd: refactor wq driver enable/disable operations

Move the core driver operations from wq driver to the drv_enable_wq() and
drv_disable_wq() functions. The move should reduce the wq driver's
knowledge of the core driver operations and prevent code confusion for
future wq drivers.
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/165047301643.3841827.11222723219862233060.stgit@djiang5-desk3.ch.intel.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent b21fe492
...@@ -314,7 +314,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev) ...@@ -314,7 +314,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
mutex_lock(&wq->wq_lock); mutex_lock(&wq->wq_lock);
wq->type = IDXD_WQT_USER; wq->type = IDXD_WQT_USER;
rc = __drv_enable_wq(wq); rc = drv_enable_wq(wq);
if (rc < 0) if (rc < 0)
goto err; goto err;
...@@ -329,7 +329,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev) ...@@ -329,7 +329,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
return 0; return 0;
err_cdev: err_cdev:
__drv_disable_wq(wq); drv_disable_wq(wq);
err: err:
wq->type = IDXD_WQT_NONE; wq->type = IDXD_WQT_NONE;
mutex_unlock(&wq->wq_lock); mutex_unlock(&wq->wq_lock);
...@@ -342,7 +342,7 @@ static void idxd_user_drv_remove(struct idxd_dev *idxd_dev) ...@@ -342,7 +342,7 @@ static void idxd_user_drv_remove(struct idxd_dev *idxd_dev)
mutex_lock(&wq->wq_lock); mutex_lock(&wq->wq_lock);
idxd_wq_del_cdev(wq); idxd_wq_del_cdev(wq);
__drv_disable_wq(wq); drv_disable_wq(wq);
wq->type = IDXD_WQT_NONE; wq->type = IDXD_WQT_NONE;
mutex_unlock(&wq->wq_lock); mutex_unlock(&wq->wq_lock);
} }
......
...@@ -1196,6 +1196,9 @@ int idxd_wq_request_irq(struct idxd_wq *wq) ...@@ -1196,6 +1196,9 @@ int idxd_wq_request_irq(struct idxd_wq *wq)
struct idxd_irq_entry *ie; struct idxd_irq_entry *ie;
int rc; int rc;
if (wq->type != IDXD_WQT_KERNEL)
return 0;
ie = &wq->ie; ie = &wq->ie;
ie->vector = pci_irq_vector(pdev, ie->id); ie->vector = pci_irq_vector(pdev, ie->id);
ie->pasid = device_pasid_enabled(idxd) ? idxd->pasid : INVALID_IOASID; ie->pasid = device_pasid_enabled(idxd) ? idxd->pasid : INVALID_IOASID;
...@@ -1227,7 +1230,7 @@ int idxd_wq_request_irq(struct idxd_wq *wq) ...@@ -1227,7 +1230,7 @@ int idxd_wq_request_irq(struct idxd_wq *wq)
return rc; return rc;
} }
int __drv_enable_wq(struct idxd_wq *wq) int drv_enable_wq(struct idxd_wq *wq)
{ {
struct idxd_device *idxd = wq->idxd; struct idxd_device *idxd = wq->idxd;
struct device *dev = &idxd->pdev->dev; struct device *dev = &idxd->pdev->dev;
...@@ -1328,8 +1331,36 @@ int __drv_enable_wq(struct idxd_wq *wq) ...@@ -1328,8 +1331,36 @@ int __drv_enable_wq(struct idxd_wq *wq)
} }
wq->client_count = 0; wq->client_count = 0;
rc = idxd_wq_request_irq(wq);
if (rc < 0) {
idxd->cmd_status = IDXD_SCMD_WQ_IRQ_ERR;
dev_dbg(dev, "WQ %d irq setup failed: %d\n", wq->id, rc);
goto err_irq;
}
rc = idxd_wq_alloc_resources(wq);
if (rc < 0) {
idxd->cmd_status = IDXD_SCMD_WQ_RES_ALLOC_ERR;
dev_dbg(dev, "WQ resource alloc failed\n");
goto err_res_alloc;
}
rc = idxd_wq_init_percpu_ref(wq);
if (rc < 0) {
idxd->cmd_status = IDXD_SCMD_PERCPU_ERR;
dev_dbg(dev, "percpu_ref setup failed\n");
goto err_ref;
}
return 0; return 0;
err_ref:
idxd_wq_free_resources(wq);
err_res_alloc:
idxd_wq_free_irq(wq);
err_irq:
idxd_wq_unmap_portal(wq);
err_map_portal: err_map_portal:
rc = idxd_wq_disable(wq, false); rc = idxd_wq_disable(wq, false);
if (rc < 0) if (rc < 0)
...@@ -1338,17 +1369,7 @@ int __drv_enable_wq(struct idxd_wq *wq) ...@@ -1338,17 +1369,7 @@ int __drv_enable_wq(struct idxd_wq *wq)
return rc; return rc;
} }
int drv_enable_wq(struct idxd_wq *wq) void drv_disable_wq(struct idxd_wq *wq)
{
int rc;
mutex_lock(&wq->wq_lock);
rc = __drv_enable_wq(wq);
mutex_unlock(&wq->wq_lock);
return rc;
}
void __drv_disable_wq(struct idxd_wq *wq)
{ {
struct idxd_device *idxd = wq->idxd; struct idxd_device *idxd = wq->idxd;
struct device *dev = &idxd->pdev->dev; struct device *dev = &idxd->pdev->dev;
...@@ -1359,21 +1380,16 @@ void __drv_disable_wq(struct idxd_wq *wq) ...@@ -1359,21 +1380,16 @@ void __drv_disable_wq(struct idxd_wq *wq)
dev_warn(dev, "Clients has claim on wq %d: %d\n", dev_warn(dev, "Clients has claim on wq %d: %d\n",
wq->id, idxd_wq_refcount(wq)); wq->id, idxd_wq_refcount(wq));
idxd_wq_free_resources(wq);
idxd_wq_unmap_portal(wq); idxd_wq_unmap_portal(wq);
idxd_wq_drain(wq); idxd_wq_drain(wq);
idxd_wq_reset(wq); idxd_wq_reset(wq);
percpu_ref_exit(&wq->wq_active);
idxd_wq_free_irq(wq);
wq->type = IDXD_WQT_NONE;
wq->client_count = 0; wq->client_count = 0;
} }
void drv_disable_wq(struct idxd_wq *wq)
{
mutex_lock(&wq->wq_lock);
__drv_disable_wq(wq);
mutex_unlock(&wq->wq_lock);
}
int idxd_device_drv_probe(struct idxd_dev *idxd_dev) int idxd_device_drv_probe(struct idxd_dev *idxd_dev)
{ {
struct idxd_device *idxd = idxd_dev_to_idxd(idxd_dev); struct idxd_device *idxd = idxd_dev_to_idxd(idxd_dev);
......
...@@ -291,34 +291,13 @@ static int idxd_dmaengine_drv_probe(struct idxd_dev *idxd_dev) ...@@ -291,34 +291,13 @@ static int idxd_dmaengine_drv_probe(struct idxd_dev *idxd_dev)
mutex_lock(&wq->wq_lock); mutex_lock(&wq->wq_lock);
wq->type = IDXD_WQT_KERNEL; wq->type = IDXD_WQT_KERNEL;
rc = __drv_enable_wq(wq); rc = drv_enable_wq(wq);
if (rc < 0) { if (rc < 0) {
dev_dbg(dev, "Enable wq %d failed: %d\n", wq->id, rc); dev_dbg(dev, "Enable wq %d failed: %d\n", wq->id, rc);
rc = -ENXIO; rc = -ENXIO;
goto err; goto err;
} }
rc = idxd_wq_request_irq(wq);
if (rc < 0) {
idxd->cmd_status = IDXD_SCMD_WQ_IRQ_ERR;
dev_dbg(dev, "WQ %d irq setup failed: %d\n", wq->id, rc);
goto err_irq;
}
rc = idxd_wq_alloc_resources(wq);
if (rc < 0) {
idxd->cmd_status = IDXD_SCMD_WQ_RES_ALLOC_ERR;
dev_dbg(dev, "WQ resource alloc failed\n");
goto err_res_alloc;
}
rc = idxd_wq_init_percpu_ref(wq);
if (rc < 0) {
idxd->cmd_status = IDXD_SCMD_PERCPU_ERR;
dev_dbg(dev, "percpu_ref setup failed\n");
goto err_ref;
}
rc = idxd_register_dma_channel(wq); rc = idxd_register_dma_channel(wq);
if (rc < 0) { if (rc < 0) {
idxd->cmd_status = IDXD_SCMD_DMA_CHAN_ERR; idxd->cmd_status = IDXD_SCMD_DMA_CHAN_ERR;
...@@ -331,14 +310,7 @@ static int idxd_dmaengine_drv_probe(struct idxd_dev *idxd_dev) ...@@ -331,14 +310,7 @@ static int idxd_dmaengine_drv_probe(struct idxd_dev *idxd_dev)
return 0; return 0;
err_dma: err_dma:
__idxd_wq_quiesce(wq); drv_disable_wq(wq);
percpu_ref_exit(&wq->wq_active);
err_ref:
idxd_wq_free_resources(wq);
err_res_alloc:
idxd_wq_free_irq(wq);
err_irq:
__drv_disable_wq(wq);
err: err:
wq->type = IDXD_WQT_NONE; wq->type = IDXD_WQT_NONE;
mutex_unlock(&wq->wq_lock); mutex_unlock(&wq->wq_lock);
...@@ -352,11 +324,7 @@ static void idxd_dmaengine_drv_remove(struct idxd_dev *idxd_dev) ...@@ -352,11 +324,7 @@ static void idxd_dmaengine_drv_remove(struct idxd_dev *idxd_dev)
mutex_lock(&wq->wq_lock); mutex_lock(&wq->wq_lock);
__idxd_wq_quiesce(wq); __idxd_wq_quiesce(wq);
idxd_unregister_dma_channel(wq); idxd_unregister_dma_channel(wq);
idxd_wq_free_resources(wq); drv_disable_wq(wq);
__drv_disable_wq(wq);
percpu_ref_exit(&wq->wq_active);
idxd_wq_free_irq(wq);
wq->type = IDXD_WQT_NONE;
mutex_unlock(&wq->wq_lock); mutex_unlock(&wq->wq_lock);
} }
......
...@@ -559,9 +559,7 @@ void idxd_unregister_idxd_drv(void); ...@@ -559,9 +559,7 @@ void idxd_unregister_idxd_drv(void);
int idxd_device_drv_probe(struct idxd_dev *idxd_dev); int idxd_device_drv_probe(struct idxd_dev *idxd_dev);
void idxd_device_drv_remove(struct idxd_dev *idxd_dev); void idxd_device_drv_remove(struct idxd_dev *idxd_dev);
int drv_enable_wq(struct idxd_wq *wq); int drv_enable_wq(struct idxd_wq *wq);
int __drv_enable_wq(struct idxd_wq *wq);
void drv_disable_wq(struct idxd_wq *wq); void drv_disable_wq(struct idxd_wq *wq);
void __drv_disable_wq(struct idxd_wq *wq);
int idxd_device_init_reset(struct idxd_device *idxd); int idxd_device_init_reset(struct idxd_device *idxd);
int idxd_device_enable(struct idxd_device *idxd); int idxd_device_enable(struct idxd_device *idxd);
int idxd_device_disable(struct idxd_device *idxd); int idxd_device_disable(struct idxd_device *idxd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment