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

Merge branch 'pds_core-various-improvements-cleanups'

Brett Creeley says:

====================
pds_core: Various improvements/cleanups

This series contains various improvements and cleanups for the
pds_core driver. These patches were originally part of the following
net-next series:

https://lore.kernel.org/netdev/20240126174255.17052-1-brett.creeley@amd.com/

However, some of the patches from the above series were actually fixes,
so they were pushed and accepted to net. That series can be found here:

https://lore.kernel.org/netdev/20240129234035.69802-1-brett.creeley@amd.com/

Also, the Reviewed-by tags were left in place from the original net-next
reviews as the patches didn't change.
====================

Link: https://lore.kernel.org/r/20240202195911.65338-1-brett.creeley@amd.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

+71 -62
+3 -7
drivers/net/ethernet/amd/pds_core/adminq.c
··· 82 82 unsigned long irqflags; 83 83 int nq_work = 0; 84 84 int aq_work = 0; 85 - int credits; 86 85 87 86 /* Don't process AdminQ when it's not up */ 88 87 if (!pdsc_adminq_inc_if_up(pdsc)) { ··· 127 128 128 129 credits: 129 130 /* Return the interrupt credits, one for each completion */ 130 - credits = nq_work + aq_work; 131 - if (credits) 132 - pds_core_intr_credits(&pdsc->intr_ctrl[qcq->intx], 133 - credits, 134 - PDS_CORE_INTR_CRED_REARM); 131 + pds_core_intr_credits(&pdsc->intr_ctrl[qcq->intx], 132 + nq_work + aq_work, 133 + PDS_CORE_INTR_CRED_REARM); 135 134 refcount_dec(&pdsc->adminq_refcnt); 136 135 } 137 136 ··· 154 157 155 158 qcq = &pdsc->adminqcq; 156 159 queue_work(pdsc->wq, &qcq->work); 157 - pds_core_intr_mask(&pdsc->intr_ctrl[qcq->intx], PDS_CORE_INTR_MASK_CLEAR); 158 160 refcount_dec(&pdsc->adminq_refcnt); 159 161 160 162 return IRQ_HANDLED;
+45 -47
drivers/net/ethernet/amd/pds_core/core.c
··· 129 129 if (index < 0) 130 130 return index; 131 131 qcq->intx = index; 132 + qcq->cq.bound_intr = &pdsc->intr_info[index]; 132 133 133 134 return 0; 134 135 } ··· 223 222 goto err_out_free_irq; 224 223 } 225 224 226 - qcq->cq.bound_intr = &pdsc->intr_info[qcq->intx]; 227 225 qcq->cq.num_descs = num_descs; 228 226 qcq->cq.desc_size = cq_desc_size; 229 227 qcq->cq.tail_idx = 0; ··· 300 300 return err; 301 301 } 302 302 303 + static void pdsc_core_uninit(struct pdsc *pdsc) 304 + { 305 + pdsc_qcq_free(pdsc, &pdsc->notifyqcq); 306 + pdsc_qcq_free(pdsc, &pdsc->adminqcq); 307 + 308 + if (pdsc->kern_dbpage) { 309 + iounmap(pdsc->kern_dbpage); 310 + pdsc->kern_dbpage = NULL; 311 + } 312 + } 313 + 303 314 static int pdsc_core_init(struct pdsc *pdsc) 304 315 { 305 316 union pds_core_dev_comp comp = {}; ··· 321 310 struct pds_core_dev_init_data_in cidi; 322 311 u32 dbid_count; 323 312 u32 dbpage_num; 313 + int numdescs; 324 314 size_t sz; 325 315 int err; 316 + 317 + /* Scale the descriptor ring length based on number of CPUs and VFs */ 318 + numdescs = max_t(int, PDSC_ADMINQ_MIN_LENGTH, num_online_cpus()); 319 + numdescs += 2 * pci_sriov_get_totalvfs(pdsc->pdev); 320 + numdescs = roundup_pow_of_two(numdescs); 321 + err = pdsc_qcq_alloc(pdsc, PDS_CORE_QTYPE_ADMINQ, 0, "adminq", 322 + PDS_CORE_QCQ_F_CORE | PDS_CORE_QCQ_F_INTR, 323 + numdescs, 324 + sizeof(union pds_core_adminq_cmd), 325 + sizeof(union pds_core_adminq_comp), 326 + 0, &pdsc->adminqcq); 327 + if (err) 328 + return err; 329 + 330 + err = pdsc_qcq_alloc(pdsc, PDS_CORE_QTYPE_NOTIFYQ, 0, "notifyq", 331 + PDS_CORE_QCQ_F_NOTIFYQ, 332 + PDSC_NOTIFYQ_LENGTH, 333 + sizeof(struct pds_core_notifyq_cmd), 334 + sizeof(union pds_core_notifyq_comp), 335 + 0, &pdsc->notifyqcq); 336 + if (err) 337 + goto err_out_uninit; 326 338 327 339 cidi.adminq_q_base = cpu_to_le64(pdsc->adminqcq.q_base_pa); 328 340 cidi.adminq_cq_base = cpu_to_le64(pdsc->adminqcq.cq_base_pa); ··· 370 336 if (err) { 371 337 dev_err(pdsc->dev, "Device init command failed: %pe\n", 372 338 ERR_PTR(err)); 373 - return err; 339 + goto err_out_uninit; 374 340 } 375 341 376 342 pdsc->hw_index = le32_to_cpu(cido.core_hw_index); ··· 380 346 pdsc->kern_dbpage = pdsc_map_dbpage(pdsc, dbpage_num); 381 347 if (!pdsc->kern_dbpage) { 382 348 dev_err(pdsc->dev, "Cannot map dbpage, aborting\n"); 383 - return -ENOMEM; 349 + err = -ENOMEM; 350 + goto err_out_uninit; 384 351 } 385 352 386 353 pdsc->adminqcq.q.hw_type = cido.adminq_hw_type; ··· 394 359 395 360 pdsc->last_eid = 0; 396 361 362 + return 0; 363 + 364 + err_out_uninit: 365 + pdsc_core_uninit(pdsc); 397 366 return err; 398 367 } 399 368 ··· 440 401 441 402 int pdsc_setup(struct pdsc *pdsc, bool init) 442 403 { 443 - int numdescs; 444 404 int err; 445 405 446 406 err = pdsc_dev_init(pdsc); 447 407 if (err) 448 408 return err; 449 - 450 - /* Scale the descriptor ring length based on number of CPUs and VFs */ 451 - numdescs = max_t(int, PDSC_ADMINQ_MIN_LENGTH, num_online_cpus()); 452 - numdescs += 2 * pci_sriov_get_totalvfs(pdsc->pdev); 453 - numdescs = roundup_pow_of_two(numdescs); 454 - err = pdsc_qcq_alloc(pdsc, PDS_CORE_QTYPE_ADMINQ, 0, "adminq", 455 - PDS_CORE_QCQ_F_CORE | PDS_CORE_QCQ_F_INTR, 456 - numdescs, 457 - sizeof(union pds_core_adminq_cmd), 458 - sizeof(union pds_core_adminq_comp), 459 - 0, &pdsc->adminqcq); 460 - if (err) 461 - goto err_out_teardown; 462 - 463 - err = pdsc_qcq_alloc(pdsc, PDS_CORE_QTYPE_NOTIFYQ, 0, "notifyq", 464 - PDS_CORE_QCQ_F_NOTIFYQ, 465 - PDSC_NOTIFYQ_LENGTH, 466 - sizeof(struct pds_core_notifyq_cmd), 467 - sizeof(union pds_core_notifyq_comp), 468 - 0, &pdsc->notifyqcq); 469 - if (err) 470 - goto err_out_teardown; 471 - 472 - /* NotifyQ rides on the AdminQ interrupt */ 473 - pdsc->notifyqcq.intx = pdsc->adminqcq.intx; 474 409 475 410 /* Set up the Core with the AdminQ and NotifyQ info */ 476 411 err = pdsc_core_init(pdsc); ··· 471 458 472 459 void pdsc_teardown(struct pdsc *pdsc, bool removing) 473 460 { 474 - int i; 475 - 476 461 if (!pdsc->pdev->is_virtfn) 477 462 pdsc_devcmd_reset(pdsc); 478 463 if (pdsc->adminqcq.work.func) 479 464 cancel_work_sync(&pdsc->adminqcq.work); 480 - pdsc_qcq_free(pdsc, &pdsc->notifyqcq); 481 - pdsc_qcq_free(pdsc, &pdsc->adminqcq); 465 + 466 + pdsc_core_uninit(pdsc); 482 467 483 468 if (removing) { 484 469 kfree(pdsc->viftype_status); 485 470 pdsc->viftype_status = NULL; 486 471 } 487 472 488 - if (pdsc->intr_info) { 489 - for (i = 0; i < pdsc->nintrs; i++) 490 - pdsc_intr_free(pdsc, i); 473 + pdsc_dev_uninit(pdsc); 491 474 492 - kfree(pdsc->intr_info); 493 - pdsc->intr_info = NULL; 494 - pdsc->nintrs = 0; 495 - } 496 - 497 - if (pdsc->kern_dbpage) { 498 - iounmap(pdsc->kern_dbpage); 499 - pdsc->kern_dbpage = NULL; 500 - } 501 - 502 - pci_free_irq_vectors(pdsc->pdev); 503 475 set_bit(PDSC_S_FW_DEAD, &pdsc->state); 504 476 } 505 477
+1
drivers/net/ethernet/amd/pds_core/core.h
··· 282 282 int pdsc_devcmd_init(struct pdsc *pdsc); 283 283 int pdsc_devcmd_reset(struct pdsc *pdsc); 284 284 int pdsc_dev_init(struct pdsc *pdsc); 285 + void pdsc_dev_uninit(struct pdsc *pdsc); 285 286 286 287 void pdsc_reset_prepare(struct pci_dev *pdev); 287 288 void pdsc_reset_done(struct pci_dev *pdev);
+4 -4
drivers/net/ethernet/amd/pds_core/debugfs.c
··· 32 32 33 33 static int identity_show(struct seq_file *seq, void *v) 34 34 { 35 - struct pdsc *pdsc = seq->private; 36 35 struct pds_core_dev_identity *ident; 36 + struct pdsc *pdsc = seq->private; 37 37 int vt; 38 38 39 39 ident = &pdsc->dev_ident; ··· 106 106 107 107 void pdsc_debugfs_add_qcq(struct pdsc *pdsc, struct pdsc_qcq *qcq) 108 108 { 109 - struct dentry *qcq_dentry, *q_dentry, *cq_dentry; 110 - struct dentry *intr_dentry; 109 + struct dentry *qcq_dentry, *q_dentry, *cq_dentry, *intr_dentry; 111 110 struct debugfs_regset32 *intr_ctrl_regset; 112 - struct pdsc_intr_info *intr = &pdsc->intr_info[qcq->intx]; 113 111 struct pdsc_queue *q = &qcq->q; 114 112 struct pdsc_cq *cq = &qcq->cq; 115 113 ··· 145 147 debugfs_create_u16("tail", 0400, cq_dentry, &cq->tail_idx); 146 148 147 149 if (qcq->flags & PDS_CORE_QCQ_F_INTR) { 150 + struct pdsc_intr_info *intr = &pdsc->intr_info[qcq->intx]; 151 + 148 152 intr_dentry = debugfs_create_dir("intr", qcq->dentry); 149 153 if (IS_ERR_OR_NULL(intr_dentry)) 150 154 return;
+18 -4
drivers/net/ethernet/amd/pds_core/dev.c
··· 316 316 return 0; 317 317 } 318 318 319 + void pdsc_dev_uninit(struct pdsc *pdsc) 320 + { 321 + if (pdsc->intr_info) { 322 + int i; 323 + 324 + for (i = 0; i < pdsc->nintrs; i++) 325 + pdsc_intr_free(pdsc, i); 326 + 327 + kfree(pdsc->intr_info); 328 + pdsc->intr_info = NULL; 329 + pdsc->nintrs = 0; 330 + } 331 + 332 + pci_free_irq_vectors(pdsc->pdev); 333 + } 334 + 319 335 int pdsc_dev_init(struct pdsc *pdsc) 320 336 { 321 337 unsigned int nintrs; ··· 357 341 358 342 /* Get intr_info struct array for tracking */ 359 343 pdsc->intr_info = kcalloc(nintrs, sizeof(*pdsc->intr_info), GFP_KERNEL); 360 - if (!pdsc->intr_info) { 361 - err = -ENOMEM; 362 - goto err_out; 363 - } 344 + if (!pdsc->intr_info) 345 + return -ENOMEM; 364 346 365 347 err = pci_alloc_irq_vectors(pdsc->pdev, nintrs, nintrs, PCI_IRQ_MSIX); 366 348 if (err != nintrs) {