Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/165047301643.3841827.11222723219862233060.stgit@djiang5-desk3.ch.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Dave Jiang and committed by
Vinod Koul
63c14ae6 b21fe492

+43 -61
+3 -3
drivers/dma/idxd/cdev.c
··· 314 314 315 315 mutex_lock(&wq->wq_lock); 316 316 wq->type = IDXD_WQT_USER; 317 - rc = __drv_enable_wq(wq); 317 + rc = drv_enable_wq(wq); 318 318 if (rc < 0) 319 319 goto err; 320 320 ··· 329 329 return 0; 330 330 331 331 err_cdev: 332 - __drv_disable_wq(wq); 332 + drv_disable_wq(wq); 333 333 err: 334 334 wq->type = IDXD_WQT_NONE; 335 335 mutex_unlock(&wq->wq_lock); ··· 342 342 343 343 mutex_lock(&wq->wq_lock); 344 344 idxd_wq_del_cdev(wq); 345 - __drv_disable_wq(wq); 345 + drv_disable_wq(wq); 346 346 wq->type = IDXD_WQT_NONE; 347 347 mutex_unlock(&wq->wq_lock); 348 348 }
+37 -21
drivers/dma/idxd/device.c
··· 1196 1196 struct idxd_irq_entry *ie; 1197 1197 int rc; 1198 1198 1199 + if (wq->type != IDXD_WQT_KERNEL) 1200 + return 0; 1201 + 1199 1202 ie = &wq->ie; 1200 1203 ie->vector = pci_irq_vector(pdev, ie->id); 1201 1204 ie->pasid = device_pasid_enabled(idxd) ? idxd->pasid : INVALID_IOASID; ··· 1230 1227 return rc; 1231 1228 } 1232 1229 1233 - int __drv_enable_wq(struct idxd_wq *wq) 1230 + int drv_enable_wq(struct idxd_wq *wq) 1234 1231 { 1235 1232 struct idxd_device *idxd = wq->idxd; 1236 1233 struct device *dev = &idxd->pdev->dev; ··· 1331 1328 } 1332 1329 1333 1330 wq->client_count = 0; 1331 + 1332 + rc = idxd_wq_request_irq(wq); 1333 + if (rc < 0) { 1334 + idxd->cmd_status = IDXD_SCMD_WQ_IRQ_ERR; 1335 + dev_dbg(dev, "WQ %d irq setup failed: %d\n", wq->id, rc); 1336 + goto err_irq; 1337 + } 1338 + 1339 + rc = idxd_wq_alloc_resources(wq); 1340 + if (rc < 0) { 1341 + idxd->cmd_status = IDXD_SCMD_WQ_RES_ALLOC_ERR; 1342 + dev_dbg(dev, "WQ resource alloc failed\n"); 1343 + goto err_res_alloc; 1344 + } 1345 + 1346 + rc = idxd_wq_init_percpu_ref(wq); 1347 + if (rc < 0) { 1348 + idxd->cmd_status = IDXD_SCMD_PERCPU_ERR; 1349 + dev_dbg(dev, "percpu_ref setup failed\n"); 1350 + goto err_ref; 1351 + } 1352 + 1334 1353 return 0; 1335 1354 1355 + err_ref: 1356 + idxd_wq_free_resources(wq); 1357 + err_res_alloc: 1358 + idxd_wq_free_irq(wq); 1359 + err_irq: 1360 + idxd_wq_unmap_portal(wq); 1336 1361 err_map_portal: 1337 1362 rc = idxd_wq_disable(wq, false); 1338 1363 if (rc < 0) ··· 1369 1338 return rc; 1370 1339 } 1371 1340 1372 - int drv_enable_wq(struct idxd_wq *wq) 1373 - { 1374 - int rc; 1375 - 1376 - mutex_lock(&wq->wq_lock); 1377 - rc = __drv_enable_wq(wq); 1378 - mutex_unlock(&wq->wq_lock); 1379 - return rc; 1380 - } 1381 - 1382 - void __drv_disable_wq(struct idxd_wq *wq) 1341 + void drv_disable_wq(struct idxd_wq *wq) 1383 1342 { 1384 1343 struct idxd_device *idxd = wq->idxd; 1385 1344 struct device *dev = &idxd->pdev->dev; ··· 1380 1359 dev_warn(dev, "Clients has claim on wq %d: %d\n", 1381 1360 wq->id, idxd_wq_refcount(wq)); 1382 1361 1362 + idxd_wq_free_resources(wq); 1383 1363 idxd_wq_unmap_portal(wq); 1384 - 1385 1364 idxd_wq_drain(wq); 1386 1365 idxd_wq_reset(wq); 1387 - 1366 + percpu_ref_exit(&wq->wq_active); 1367 + idxd_wq_free_irq(wq); 1368 + wq->type = IDXD_WQT_NONE; 1388 1369 wq->client_count = 0; 1389 - } 1390 - 1391 - void drv_disable_wq(struct idxd_wq *wq) 1392 - { 1393 - mutex_lock(&wq->wq_lock); 1394 - __drv_disable_wq(wq); 1395 - mutex_unlock(&wq->wq_lock); 1396 1370 } 1397 1371 1398 1372 int idxd_device_drv_probe(struct idxd_dev *idxd_dev)
+3 -35
drivers/dma/idxd/dma.c
··· 291 291 mutex_lock(&wq->wq_lock); 292 292 wq->type = IDXD_WQT_KERNEL; 293 293 294 - rc = __drv_enable_wq(wq); 294 + rc = drv_enable_wq(wq); 295 295 if (rc < 0) { 296 296 dev_dbg(dev, "Enable wq %d failed: %d\n", wq->id, rc); 297 297 rc = -ENXIO; 298 298 goto err; 299 - } 300 - 301 - rc = idxd_wq_request_irq(wq); 302 - if (rc < 0) { 303 - idxd->cmd_status = IDXD_SCMD_WQ_IRQ_ERR; 304 - dev_dbg(dev, "WQ %d irq setup failed: %d\n", wq->id, rc); 305 - goto err_irq; 306 - } 307 - 308 - rc = idxd_wq_alloc_resources(wq); 309 - if (rc < 0) { 310 - idxd->cmd_status = IDXD_SCMD_WQ_RES_ALLOC_ERR; 311 - dev_dbg(dev, "WQ resource alloc failed\n"); 312 - goto err_res_alloc; 313 - } 314 - 315 - rc = idxd_wq_init_percpu_ref(wq); 316 - if (rc < 0) { 317 - idxd->cmd_status = IDXD_SCMD_PERCPU_ERR; 318 - dev_dbg(dev, "percpu_ref setup failed\n"); 319 - goto err_ref; 320 299 } 321 300 322 301 rc = idxd_register_dma_channel(wq); ··· 310 331 return 0; 311 332 312 333 err_dma: 313 - __idxd_wq_quiesce(wq); 314 - percpu_ref_exit(&wq->wq_active); 315 - err_ref: 316 - idxd_wq_free_resources(wq); 317 - err_res_alloc: 318 - idxd_wq_free_irq(wq); 319 - err_irq: 320 - __drv_disable_wq(wq); 334 + drv_disable_wq(wq); 321 335 err: 322 336 wq->type = IDXD_WQT_NONE; 323 337 mutex_unlock(&wq->wq_lock); ··· 324 352 mutex_lock(&wq->wq_lock); 325 353 __idxd_wq_quiesce(wq); 326 354 idxd_unregister_dma_channel(wq); 327 - idxd_wq_free_resources(wq); 328 - __drv_disable_wq(wq); 329 - percpu_ref_exit(&wq->wq_active); 330 - idxd_wq_free_irq(wq); 331 - wq->type = IDXD_WQT_NONE; 355 + drv_disable_wq(wq); 332 356 mutex_unlock(&wq->wq_lock); 333 357 } 334 358
-2
drivers/dma/idxd/idxd.h
··· 559 559 int idxd_device_drv_probe(struct idxd_dev *idxd_dev); 560 560 void idxd_device_drv_remove(struct idxd_dev *idxd_dev); 561 561 int drv_enable_wq(struct idxd_wq *wq); 562 - int __drv_enable_wq(struct idxd_wq *wq); 563 562 void drv_disable_wq(struct idxd_wq *wq); 564 - void __drv_disable_wq(struct idxd_wq *wq); 565 563 int idxd_device_init_reset(struct idxd_device *idxd); 566 564 int idxd_device_enable(struct idxd_device *idxd); 567 565 int idxd_device_disable(struct idxd_device *idxd);