Skip to content

Commit 6fd2a71

Browse files
sgoutham-marvelldavem330
authored andcommitted
octeontx2-af: Cleanup CGX config permission checks
Most of the CGX register config is restricted to mapped RVU PFs, this patch cleans up these permission checks spread across the rvu_cgx.c file by moving the checks to a common fn(). Signed-off-by: Sunil Goutham <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 07a835d commit 6fd2a71

File tree

1 file changed

+24
-31
lines changed
  • drivers/net/ethernet/marvell/octeontx2/af

1 file changed

+24
-31
lines changed

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

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,18 @@ int rvu_cgx_exit(struct rvu *rvu)
350350
return 0;
351351
}
352352

353+
/* Most of the CGX configuration is restricted to the mapped PF only,
354+
* VF's of mapped PF and other PFs are not allowed. This fn() checks
355+
* whether a PFFUNC is permitted to do the config or not.
356+
*/
357+
static bool is_cgx_config_permitted(struct rvu *rvu, u16 pcifunc)
358+
{
359+
if ((pcifunc & RVU_PFVF_FUNC_MASK) ||
360+
!is_pf_cgxmapped(rvu, rvu_get_pf(pcifunc)))
361+
return false;
362+
return true;
363+
}
364+
353365
void rvu_cgx_enadis_rx_bp(struct rvu *rvu, int pf, bool enable)
354366
{
355367
u8 cgx_id, lmac_id;
@@ -373,11 +385,8 @@ int rvu_cgx_config_rxtx(struct rvu *rvu, u16 pcifunc, bool start)
373385
int pf = rvu_get_pf(pcifunc);
374386
u8 cgx_id, lmac_id;
375387

376-
/* This msg is expected only from PFs that are mapped to CGX LMACs,
377-
* if received from other PF/VF simply ACK, nothing to do.
378-
*/
379-
if ((pcifunc & RVU_PFVF_FUNC_MASK) || !is_pf_cgxmapped(rvu, pf))
380-
return -ENODEV;
388+
if (!is_cgx_config_permitted(rvu, pcifunc))
389+
return -EPERM;
381390

382391
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
383392

@@ -409,8 +418,7 @@ int rvu_mbox_handler_cgx_stats(struct rvu *rvu, struct msg_req *req,
409418
u8 cgx_idx, lmac;
410419
void *cgxd;
411420

412-
if ((req->hdr.pcifunc & RVU_PFVF_FUNC_MASK) ||
413-
!is_pf_cgxmapped(rvu, pf))
421+
if (!is_cgx_config_permitted(rvu, req->hdr.pcifunc))
414422
return -ENODEV;
415423

416424
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_idx, &lmac);
@@ -477,12 +485,8 @@ int rvu_mbox_handler_cgx_promisc_enable(struct rvu *rvu, struct msg_req *req,
477485
int pf = rvu_get_pf(pcifunc);
478486
u8 cgx_id, lmac_id;
479487

480-
/* This msg is expected only from PFs that are mapped to CGX LMACs,
481-
* if received from other PF/VF simply ACK, nothing to do.
482-
*/
483-
if ((req->hdr.pcifunc & RVU_PFVF_FUNC_MASK) ||
484-
!is_pf_cgxmapped(rvu, pf))
485-
return -ENODEV;
488+
if (!is_cgx_config_permitted(rvu, req->hdr.pcifunc))
489+
return -EPERM;
486490

487491
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
488492

@@ -493,16 +497,11 @@ int rvu_mbox_handler_cgx_promisc_enable(struct rvu *rvu, struct msg_req *req,
493497
int rvu_mbox_handler_cgx_promisc_disable(struct rvu *rvu, struct msg_req *req,
494498
struct msg_rsp *rsp)
495499
{
496-
u16 pcifunc = req->hdr.pcifunc;
497-
int pf = rvu_get_pf(pcifunc);
500+
int pf = rvu_get_pf(req->hdr.pcifunc);
498501
u8 cgx_id, lmac_id;
499502

500-
/* This msg is expected only from PFs that are mapped to CGX LMACs,
501-
* if received from other PF/VF simply ACK, nothing to do.
502-
*/
503-
if ((req->hdr.pcifunc & RVU_PFVF_FUNC_MASK) ||
504-
!is_pf_cgxmapped(rvu, pf))
505-
return -ENODEV;
503+
if (!is_cgx_config_permitted(rvu, req->hdr.pcifunc))
504+
return -EPERM;
506505

507506
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
508507

@@ -515,11 +514,8 @@ static int rvu_cgx_config_linkevents(struct rvu *rvu, u16 pcifunc, bool en)
515514
int pf = rvu_get_pf(pcifunc);
516515
u8 cgx_id, lmac_id;
517516

518-
/* This msg is expected only from PFs that are mapped to CGX LMACs,
519-
* if received from other PF/VF simply ACK, nothing to do.
520-
*/
521-
if ((pcifunc & RVU_PFVF_FUNC_MASK) || !is_pf_cgxmapped(rvu, pf))
522-
return -ENODEV;
517+
if (!is_cgx_config_permitted(rvu, pcifunc))
518+
return -EPERM;
523519

524520
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
525521

@@ -571,11 +567,8 @@ static int rvu_cgx_config_intlbk(struct rvu *rvu, u16 pcifunc, bool en)
571567
int pf = rvu_get_pf(pcifunc);
572568
u8 cgx_id, lmac_id;
573569

574-
/* This msg is expected only from PFs that are mapped to CGX LMACs,
575-
* if received from other PF/VF simply ACK, nothing to do.
576-
*/
577-
if ((pcifunc & RVU_PFVF_FUNC_MASK) || !is_pf_cgxmapped(rvu, pf))
578-
return -ENODEV;
570+
if (!is_cgx_config_permitted(rvu, pcifunc))
571+
return -EPERM;
579572

580573
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
581574

0 commit comments

Comments
 (0)