Skip to content

Commit 19e4175

Browse files
rkannoth1kuba-moo
authored andcommitted
octeontx2-af: Fix error handling
This commit adds error handling and rollback logic to rvu_mbox_handler_attach_resources() to properly clean up partially attached resources when rvu_attach_block() fails. Fixes: 746ea74 ("octeontx2-af: Add RVU block LF provisioning support") Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com> Link: https://patch.msgid.link/20260121033934.1900761-1-rkannoth@marvell.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e8ca461 commit 19e4175

1 file changed

Lines changed: 64 additions & 22 deletions

File tree

  • drivers/net/ethernet/marvell/octeontx2/af

drivers/net/ethernet/marvell/octeontx2/af/rvu.c

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,8 +1551,8 @@ static int rvu_get_attach_blkaddr(struct rvu *rvu, int blktype,
15511551
return -ENODEV;
15521552
}
15531553

1554-
static void rvu_attach_block(struct rvu *rvu, int pcifunc, int blktype,
1555-
int num_lfs, struct rsrc_attach *attach)
1554+
static int rvu_attach_block(struct rvu *rvu, int pcifunc, int blktype,
1555+
int num_lfs, struct rsrc_attach *attach)
15561556
{
15571557
struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
15581558
struct rvu_hwinfo *hw = rvu->hw;
@@ -1562,21 +1562,21 @@ static void rvu_attach_block(struct rvu *rvu, int pcifunc, int blktype,
15621562
u64 cfg;
15631563

15641564
if (!num_lfs)
1565-
return;
1565+
return -EINVAL;
15661566

15671567
blkaddr = rvu_get_attach_blkaddr(rvu, blktype, pcifunc, attach);
15681568
if (blkaddr < 0)
1569-
return;
1569+
return -EFAULT;
15701570

15711571
block = &hw->block[blkaddr];
15721572
if (!block->lf.bmap)
1573-
return;
1573+
return -ESRCH;
15741574

15751575
for (slot = 0; slot < num_lfs; slot++) {
15761576
/* Allocate the resource */
15771577
lf = rvu_alloc_rsrc(&block->lf);
15781578
if (lf < 0)
1579-
return;
1579+
return -EFAULT;
15801580

15811581
cfg = (1ULL << 63) | (pcifunc << 8) | slot;
15821582
rvu_write64(rvu, blkaddr, block->lfcfg_reg |
@@ -1587,6 +1587,8 @@ static void rvu_attach_block(struct rvu *rvu, int pcifunc, int blktype,
15871587
/* Set start MSIX vector for this LF within this PF/VF */
15881588
rvu_set_msix_offset(rvu, pfvf, block, lf);
15891589
}
1590+
1591+
return 0;
15901592
}
15911593

15921594
static int rvu_check_rsrc_availability(struct rvu *rvu,
@@ -1724,22 +1726,31 @@ int rvu_mbox_handler_attach_resources(struct rvu *rvu,
17241726
int err;
17251727

17261728
/* If first request, detach all existing attached resources */
1727-
if (!attach->modify)
1728-
rvu_detach_rsrcs(rvu, NULL, pcifunc);
1729+
if (!attach->modify) {
1730+
err = rvu_detach_rsrcs(rvu, NULL, pcifunc);
1731+
if (err)
1732+
return err;
1733+
}
17291734

17301735
mutex_lock(&rvu->rsrc_lock);
17311736

17321737
/* Check if the request can be accommodated */
17331738
err = rvu_check_rsrc_availability(rvu, attach, pcifunc);
17341739
if (err)
1735-
goto exit;
1740+
goto fail1;
17361741

17371742
/* Now attach the requested resources */
1738-
if (attach->npalf)
1739-
rvu_attach_block(rvu, pcifunc, BLKTYPE_NPA, 1, attach);
1743+
if (attach->npalf) {
1744+
err = rvu_attach_block(rvu, pcifunc, BLKTYPE_NPA, 1, attach);
1745+
if (err)
1746+
goto fail1;
1747+
}
17401748

1741-
if (attach->nixlf)
1742-
rvu_attach_block(rvu, pcifunc, BLKTYPE_NIX, 1, attach);
1749+
if (attach->nixlf) {
1750+
err = rvu_attach_block(rvu, pcifunc, BLKTYPE_NIX, 1, attach);
1751+
if (err)
1752+
goto fail2;
1753+
}
17431754

17441755
if (attach->sso) {
17451756
/* RVU func doesn't know which exact LF or slot is attached
@@ -1749,33 +1760,64 @@ int rvu_mbox_handler_attach_resources(struct rvu *rvu,
17491760
*/
17501761
if (attach->modify)
17511762
rvu_detach_block(rvu, pcifunc, BLKTYPE_SSO);
1752-
rvu_attach_block(rvu, pcifunc, BLKTYPE_SSO,
1753-
attach->sso, attach);
1763+
err = rvu_attach_block(rvu, pcifunc, BLKTYPE_SSO,
1764+
attach->sso, attach);
1765+
if (err)
1766+
goto fail3;
17541767
}
17551768

17561769
if (attach->ssow) {
17571770
if (attach->modify)
17581771
rvu_detach_block(rvu, pcifunc, BLKTYPE_SSOW);
1759-
rvu_attach_block(rvu, pcifunc, BLKTYPE_SSOW,
1760-
attach->ssow, attach);
1772+
err = rvu_attach_block(rvu, pcifunc, BLKTYPE_SSOW,
1773+
attach->ssow, attach);
1774+
if (err)
1775+
goto fail4;
17611776
}
17621777

17631778
if (attach->timlfs) {
17641779
if (attach->modify)
17651780
rvu_detach_block(rvu, pcifunc, BLKTYPE_TIM);
1766-
rvu_attach_block(rvu, pcifunc, BLKTYPE_TIM,
1767-
attach->timlfs, attach);
1781+
err = rvu_attach_block(rvu, pcifunc, BLKTYPE_TIM,
1782+
attach->timlfs, attach);
1783+
if (err)
1784+
goto fail5;
17681785
}
17691786

17701787
if (attach->cptlfs) {
17711788
if (attach->modify &&
17721789
rvu_attach_from_same_block(rvu, BLKTYPE_CPT, attach))
17731790
rvu_detach_block(rvu, pcifunc, BLKTYPE_CPT);
1774-
rvu_attach_block(rvu, pcifunc, BLKTYPE_CPT,
1775-
attach->cptlfs, attach);
1791+
err = rvu_attach_block(rvu, pcifunc, BLKTYPE_CPT,
1792+
attach->cptlfs, attach);
1793+
if (err)
1794+
goto fail6;
17761795
}
17771796

1778-
exit:
1797+
mutex_unlock(&rvu->rsrc_lock);
1798+
return 0;
1799+
1800+
fail6:
1801+
if (attach->timlfs)
1802+
rvu_detach_block(rvu, pcifunc, BLKTYPE_TIM);
1803+
1804+
fail5:
1805+
if (attach->ssow)
1806+
rvu_detach_block(rvu, pcifunc, BLKTYPE_SSOW);
1807+
1808+
fail4:
1809+
if (attach->sso)
1810+
rvu_detach_block(rvu, pcifunc, BLKTYPE_SSO);
1811+
1812+
fail3:
1813+
if (attach->nixlf)
1814+
rvu_detach_block(rvu, pcifunc, BLKTYPE_NIX);
1815+
1816+
fail2:
1817+
if (attach->npalf)
1818+
rvu_detach_block(rvu, pcifunc, BLKTYPE_NPA);
1819+
1820+
fail1:
17791821
mutex_unlock(&rvu->rsrc_lock);
17801822
return err;
17811823
}

0 commit comments

Comments
 (0)