return 0;
 }
 
+/* Most of the CGX configuration is restricted to the mapped PF only,
+ * VF's of mapped PF and other PFs are not allowed. This fn() checks
+ * whether a PFFUNC is permitted to do the config or not.
+ */
+static bool is_cgx_config_permitted(struct rvu *rvu, u16 pcifunc)
+{
+       if ((pcifunc & RVU_PFVF_FUNC_MASK) ||
+           !is_pf_cgxmapped(rvu, rvu_get_pf(pcifunc)))
+               return false;
+       return true;
+}
+
 void rvu_cgx_enadis_rx_bp(struct rvu *rvu, int pf, bool enable)
 {
        u8 cgx_id, lmac_id;
        int pf = rvu_get_pf(pcifunc);
        u8 cgx_id, lmac_id;
 
-       /* This msg is expected only from PFs that are mapped to CGX LMACs,
-        * if received from other PF/VF simply ACK, nothing to do.
-        */
-       if ((pcifunc & RVU_PFVF_FUNC_MASK) || !is_pf_cgxmapped(rvu, pf))
-               return -ENODEV;
+       if (!is_cgx_config_permitted(rvu, pcifunc))
+               return -EPERM;
 
        rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
 
        u8 cgx_idx, lmac;
        void *cgxd;
 
-       if ((req->hdr.pcifunc & RVU_PFVF_FUNC_MASK) ||
-           !is_pf_cgxmapped(rvu, pf))
+       if (!is_cgx_config_permitted(rvu, req->hdr.pcifunc))
                return -ENODEV;
 
        rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_idx, &lmac);
        int pf = rvu_get_pf(pcifunc);
        u8 cgx_id, lmac_id;
 
-       /* This msg is expected only from PFs that are mapped to CGX LMACs,
-        * if received from other PF/VF simply ACK, nothing to do.
-        */
-       if ((req->hdr.pcifunc & RVU_PFVF_FUNC_MASK) ||
-           !is_pf_cgxmapped(rvu, pf))
-               return -ENODEV;
+       if (!is_cgx_config_permitted(rvu, req->hdr.pcifunc))
+               return -EPERM;
 
        rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
 
 int rvu_mbox_handler_cgx_promisc_disable(struct rvu *rvu, struct msg_req *req,
                                         struct msg_rsp *rsp)
 {
-       u16 pcifunc = req->hdr.pcifunc;
-       int pf = rvu_get_pf(pcifunc);
+       int pf = rvu_get_pf(req->hdr.pcifunc);
        u8 cgx_id, lmac_id;
 
-       /* This msg is expected only from PFs that are mapped to CGX LMACs,
-        * if received from other PF/VF simply ACK, nothing to do.
-        */
-       if ((req->hdr.pcifunc & RVU_PFVF_FUNC_MASK) ||
-           !is_pf_cgxmapped(rvu, pf))
-               return -ENODEV;
+       if (!is_cgx_config_permitted(rvu, req->hdr.pcifunc))
+               return -EPERM;
 
        rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
 
        int pf = rvu_get_pf(pcifunc);
        u8 cgx_id, lmac_id;
 
-       /* This msg is expected only from PFs that are mapped to CGX LMACs,
-        * if received from other PF/VF simply ACK, nothing to do.
-        */
-       if ((pcifunc & RVU_PFVF_FUNC_MASK) || !is_pf_cgxmapped(rvu, pf))
-               return -ENODEV;
+       if (!is_cgx_config_permitted(rvu, pcifunc))
+               return -EPERM;
 
        rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
 
        int pf = rvu_get_pf(pcifunc);
        u8 cgx_id, lmac_id;
 
-       /* This msg is expected only from PFs that are mapped to CGX LMACs,
-        * if received from other PF/VF simply ACK, nothing to do.
-        */
-       if ((pcifunc & RVU_PFVF_FUNC_MASK) || !is_pf_cgxmapped(rvu, pf))
-               return -ENODEV;
+       if (!is_cgx_config_permitted(rvu, pcifunc))
+               return -EPERM;
 
        rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);