[v2,1/4] ethdev: add function to check representor port

Message ID 20240223024217.3052031-2-chaoyong.he@corigine.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series add support of MARK and RSS flow action |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He Feb. 23, 2024, 2:42 a.m. UTC
  From: Long Wu <long.wu@corigine.com>

Add a function to check if a device is representor port, also
modified the related codes for PMDs.

Signed-off-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 doc/guides/rel_notes/release_24_03.rst     |  3 +++
 drivers/net/bnxt/bnxt.h                    |  3 ---
 drivers/net/bnxt/bnxt_ethdev.c             |  4 ++--
 drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c | 12 ++++++------
 drivers/net/bnxt/tf_ulp/bnxt_ulp.c         |  4 ++--
 drivers/net/bnxt/tf_ulp/ulp_def_rules.c    |  4 ++--
 drivers/net/cpfl/cpfl_representor.c        |  2 +-
 drivers/net/enic/enic.h                    |  5 -----
 drivers/net/enic/enic_ethdev.c             |  2 +-
 drivers/net/enic/enic_fm_flow.c            | 20 ++++++++++----------
 drivers/net/enic/enic_main.c               |  4 ++--
 drivers/net/i40e/i40e_ethdev.c             |  2 +-
 drivers/net/ice/ice_dcf_ethdev.c           |  2 +-
 drivers/net/ixgbe/ixgbe_ethdev.c           |  2 +-
 drivers/net/nfp/flower/nfp_flower_flow.c   |  2 +-
 drivers/net/nfp/nfp_mtr.c                  |  2 +-
 drivers/net/nfp/nfp_net_common.c           |  4 ++--
 drivers/net/nfp/nfp_net_flow.c             |  2 +-
 lib/ethdev/ethdev_driver.h                 | 17 +++++++++++++++++
 19 files changed, 54 insertions(+), 42 deletions(-)
  

Comments

Ferruh Yigit Feb. 23, 2024, 9:29 a.m. UTC | #1
On 2/23/2024 2:42 AM, Chaoyong He wrote:
> From: Long Wu <long.wu@corigine.com>
> 
> Add a function to check if a device is representor port, also
> modified the related codes for PMDs.
> 

Thanks Long for the patch.

> Signed-off-by: Long Wu <long.wu@corigine.com>
> Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
> Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
> ---
>  doc/guides/rel_notes/release_24_03.rst     |  3 +++
>  drivers/net/bnxt/bnxt.h                    |  3 ---
>  drivers/net/bnxt/bnxt_ethdev.c             |  4 ++--
>  drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c | 12 ++++++------
>  drivers/net/bnxt/tf_ulp/bnxt_ulp.c         |  4 ++--
>  drivers/net/bnxt/tf_ulp/ulp_def_rules.c    |  4 ++--
>  drivers/net/cpfl/cpfl_representor.c        |  2 +-
>  drivers/net/enic/enic.h                    |  5 -----
>  drivers/net/enic/enic_ethdev.c             |  2 +-
>  drivers/net/enic/enic_fm_flow.c            | 20 ++++++++++----------
>  drivers/net/enic/enic_main.c               |  4 ++--
>  drivers/net/i40e/i40e_ethdev.c             |  2 +-
>  drivers/net/ice/ice_dcf_ethdev.c           |  2 +-
>  drivers/net/ixgbe/ixgbe_ethdev.c           |  2 +-
>  drivers/net/nfp/flower/nfp_flower_flow.c   |  2 +-
>  drivers/net/nfp/nfp_mtr.c                  |  2 +-
>  drivers/net/nfp/nfp_net_common.c           |  4 ++--
>  drivers/net/nfp/nfp_net_flow.c             |  2 +-
>  lib/ethdev/ethdev_driver.h                 | 17 +++++++++++++++++
>  19 files changed, 54 insertions(+), 42 deletions(-)
> 

There are two more instance in 'rte_class_eth.c'

> diff --git a/doc/guides/rel_notes/release_24_03.rst b/doc/guides/rel_notes/release_24_03.rst
> index 879bb4944c..8178417b98 100644
> --- a/doc/guides/rel_notes/release_24_03.rst
> +++ b/doc/guides/rel_notes/release_24_03.rst
> @@ -185,6 +185,9 @@ API Changes
>  * ethdev: Renamed structure ``rte_flow_action_modify_data`` to be
>    ``rte_flow_field_data`` for more generic usage.
>  
> +* ethdev: Add new function ``rte_eth_dev_is_repr()`` to check if a device is
> +  representor port.
> +
>  

This is not user facing API, no need to update the release notes.

<...>

> +/**
> + * @internal
> + * Check if the ethdev is a representor port.
> + *
> + * @param dev
> + *  Pointer to struct rte_eth_dev.
> + *
> + * @return
> + *  false the ethdev is not a representor port.
> + *  true  the ethdev is a representor port.
> + */
> +static inline bool
> +rte_eth_dev_is_repr(const struct rte_eth_dev *dev)
> +{
> +	return ((dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR) != 0);
> +}
> +

There is a 'rte_eth_representor_id_get()' API above, can you move this
new one below it to group them together?
  

Patch

diff --git a/doc/guides/rel_notes/release_24_03.rst b/doc/guides/rel_notes/release_24_03.rst
index 879bb4944c..8178417b98 100644
--- a/doc/guides/rel_notes/release_24_03.rst
+++ b/doc/guides/rel_notes/release_24_03.rst
@@ -185,6 +185,9 @@  API Changes
 * ethdev: Renamed structure ``rte_flow_action_modify_data`` to be
   ``rte_flow_field_data`` for more generic usage.
 
+* ethdev: Add new function ``rte_eth_dev_is_repr()`` to check if a device is
+  representor port.
+
 
 ABI Changes
 -----------
diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index fcf2b8be97..82036a16a1 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -1204,9 +1204,6 @@  extern const struct rte_flow_ops bnxt_flow_meter_ops;
 	} \
 } while (0)
 
-#define	BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)	\
-		((eth_dev)->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
-
 extern int bnxt_logtype_driver;
 #define RTE_LOGTYPE_BNXT bnxt_logtype_driver
 #define PMD_DRV_LOG_RAW(level, fmt, args...) \
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index f8d83662f4..825e9c1941 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -3525,7 +3525,7 @@  bnxt_flow_ops_get_op(struct rte_eth_dev *dev,
 	if (!bp)
 		return -EIO;
 
-	if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
+	if (rte_eth_dev_is_repr(dev)) {
 		struct bnxt_representor *vfr = dev->data->dev_private;
 		bp = vfr->parent_dev->data->dev_private;
 		/* parent is deleted while children are still valid */
@@ -6781,7 +6781,7 @@  static int bnxt_pci_remove(struct rte_pci_device *pci_dev)
 
 	PMD_DRV_LOG(DEBUG, "BNXT Port:%d pci remove\n", eth_dev->data->port_id);
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-		if (eth_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
+		if (rte_eth_dev_is_repr(eth_dev))
 			return rte_eth_dev_destroy(eth_dev,
 						   bnxt_representor_uninit);
 		else
diff --git a/drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c b/drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c
index 239191e14e..96d61c3ed2 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c
+++ b/drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c
@@ -202,7 +202,7 @@  bnxt_pmd_get_svif(uint16_t port_id, bool func_svif,
 	struct bnxt *bp;
 
 	eth_dev = &rte_eth_devices[port_id];
-	if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
+	if (rte_eth_dev_is_repr(eth_dev)) {
 		struct bnxt_representor *vfr = eth_dev->data->dev_private;
 		if (!vfr)
 			return 0;
@@ -260,7 +260,7 @@  bnxt_pmd_get_vnic_id(uint16_t port, enum bnxt_ulp_intf_type type)
 	struct bnxt *bp;
 
 	eth_dev = &rte_eth_devices[port];
-	if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
+	if (rte_eth_dev_is_repr(eth_dev)) {
 		struct bnxt_representor *vfr = eth_dev->data->dev_private;
 		if (!vfr)
 			return 0;
@@ -285,7 +285,7 @@  bnxt_pmd_get_fw_func_id(uint16_t port, enum bnxt_ulp_intf_type type)
 	struct bnxt *bp;
 
 	eth_dev = &rte_eth_devices[port];
-	if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
+	if (rte_eth_dev_is_repr(eth_dev)) {
 		struct bnxt_representor *vfr = eth_dev->data->dev_private;
 		if (!vfr)
 			return 0;
@@ -308,7 +308,7 @@  bnxt_pmd_get_interface_type(uint16_t port)
 	struct bnxt *bp;
 
 	eth_dev = &rte_eth_devices[port];
-	if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev))
+	if (rte_eth_dev_is_repr(eth_dev))
 		return BNXT_ULP_INTF_TYPE_VF_REP;
 
 	bp = eth_dev->data->dev_private;
@@ -330,7 +330,7 @@  bnxt_pmd_get_phy_port_id(uint16_t port_id)
 	struct bnxt *bp;
 
 	eth_dev = &rte_eth_devices[port_id];
-	if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
+	if (rte_eth_dev_is_repr(eth_dev)) {
 		vfr = eth_dev->data->dev_private;
 		if (!vfr)
 			return 0;
@@ -350,7 +350,7 @@  bnxt_pmd_get_parif(uint16_t port_id, enum bnxt_ulp_intf_type type)
 	struct bnxt *bp;
 
 	eth_dev = &rte_eth_devices[port_id];
-	if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
+	if (rte_eth_dev_is_repr(eth_dev)) {
 		struct bnxt_representor *vfr = eth_dev->data->dev_private;
 		if (!vfr)
 			return 0;
diff --git a/drivers/net/bnxt/tf_ulp/bnxt_ulp.c b/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
index 274e935a1f..33028c470f 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
+++ b/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
@@ -1559,7 +1559,7 @@  bnxt_ulp_destroy_vfr_default_rules(struct bnxt *bp, bool global)
 	struct rte_eth_dev *vfr_eth_dev;
 	struct bnxt_representor *vfr_bp;
 
-	if (!BNXT_TRUFLOW_EN(bp) || BNXT_ETH_DEV_IS_REPRESENTOR(bp->eth_dev))
+	if (!BNXT_TRUFLOW_EN(bp) || rte_eth_dev_is_repr(bp->eth_dev))
 		return;
 
 	if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
@@ -2316,7 +2316,7 @@  bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev	*dev)
 {
 	struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
 
-	if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
+	if (rte_eth_dev_is_repr(dev)) {
 		struct bnxt_representor *vfr = dev->data->dev_private;
 
 		bp = vfr->parent_dev->data->dev_private;
diff --git a/drivers/net/bnxt/tf_ulp/ulp_def_rules.c b/drivers/net/bnxt/tf_ulp/ulp_def_rules.c
index fe1f65deb9..8237dbd294 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_def_rules.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_def_rules.c
@@ -449,7 +449,7 @@  bnxt_ulp_destroy_df_rules(struct bnxt *bp, bool global)
 	uint16_t port_id;
 
 	if (!BNXT_TRUFLOW_EN(bp) ||
-	    BNXT_ETH_DEV_IS_REPRESENTOR(bp->eth_dev))
+	    rte_eth_dev_is_repr(bp->eth_dev))
 		return;
 
 	if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
@@ -514,7 +514,7 @@  bnxt_ulp_create_df_rules(struct bnxt *bp)
 	int rc = 0;
 
 	if (!BNXT_TRUFLOW_EN(bp) ||
-	    BNXT_ETH_DEV_IS_REPRESENTOR(bp->eth_dev) || !bp->ulp_ctx)
+	    rte_eth_dev_is_repr(bp->eth_dev) || !bp->ulp_ctx)
 		return 0;
 
 	port_id = bp->eth_dev->data->port_id;
diff --git a/drivers/net/cpfl/cpfl_representor.c b/drivers/net/cpfl/cpfl_representor.c
index e2ed9eda04..60b72b5ec1 100644
--- a/drivers/net/cpfl/cpfl_representor.c
+++ b/drivers/net/cpfl/cpfl_representor.c
@@ -339,7 +339,7 @@  cpfl_repr_link_update(struct rte_eth_dev *ethdev,
 	struct cpfl_vport_id vi;
 	int ret;
 
-	if (!(ethdev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)) {
+	if (!rte_eth_dev_is_repr(ethdev)) {
 		PMD_INIT_LOG(ERR, "This ethdev is not representor.");
 		return -EINVAL;
 	}
diff --git a/drivers/net/enic/enic.h b/drivers/net/enic/enic.h
index 78778704f2..f46903ea9e 100644
--- a/drivers/net/enic/enic.h
+++ b/drivers/net/enic/enic.h
@@ -233,11 +233,6 @@  struct enic_vf_representor {
 #define VF_ENIC_TO_VF_REP(vf_enic) \
 	container_of(vf_enic, struct enic_vf_representor, enic)
 
-static inline int enic_is_vf_rep(struct enic *enic)
-{
-	return !!(enic->rte_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR);
-}
-
 /* Compute ethdev's max packet size from MTU */
 static inline uint32_t enic_mtu_to_max_rx_pktlen(uint32_t mtu)
 {
diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c
index 7e040c36c4..cad8db2f6f 100644
--- a/drivers/net/enic/enic_ethdev.c
+++ b/drivers/net/enic/enic_ethdev.c
@@ -1386,7 +1386,7 @@  static int eth_enic_pci_remove(struct rte_pci_device *pci_dev)
 	ethdev = rte_eth_dev_allocated(pci_dev->device.name);
 	if (!ethdev)
 		return -ENODEV;
-	if (ethdev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
+	if (rte_eth_dev_is_repr(ethdev))
 		return rte_eth_dev_destroy(ethdev, enic_vf_representor_uninit);
 	else
 		return rte_eth_dev_destroy(ethdev, eth_enic_dev_uninit);
diff --git a/drivers/net/enic/enic_fm_flow.c b/drivers/net/enic/enic_fm_flow.c
index 90027dc676..8988148454 100644
--- a/drivers/net/enic/enic_fm_flow.c
+++ b/drivers/net/enic/enic_fm_flow.c
@@ -1535,14 +1535,14 @@  vf_egress_port_id_action(struct enic_flowman *fm,
 	ENICPMD_FUNC_TRACE();
 	src_enic = fm->user_enic;
 	dst_enic = pmd_priv(dst_dev);
-	if (!(src_enic->rte_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)) {
+	if (!rte_eth_dev_is_repr(src_enic->rte_dev)) {
 		return rte_flow_error_set(error, EINVAL,
 			RTE_FLOW_ERROR_TYPE_ACTION,
 			NULL, "source port is not VF representor");
 	}
 
 	/* VF -> PF uplink. dst is not VF representor */
-	if (!(dst_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)) {
+	if (!rte_eth_dev_is_repr(dst_dev)) {
 		/* PF is the VF's PF? Then nothing to do */
 		vf = VF_ENIC_TO_VF_REP(src_enic);
 		if (vf->pf == dst_enic) {
@@ -1954,7 +1954,7 @@  enic_fm_copy_action(struct enic_flowman *fm,
 	if (!(overlap & (FATE | PASSTHRU | COUNT | PORT_ID)))
 		goto unsupported;
 	/* Egress from VF: need implicit WQ match */
-	if (enic_is_vf_rep(enic) && !ingress) {
+	if (rte_eth_dev_is_repr(enic->rte_dev) && !ingress) {
 		fmt->ftm_data.fk_wq_id = 0;
 		fmt->ftm_mask.fk_wq_id = 0xffff;
 		fmt->ftm_data.fk_wq_vnic = enic->fm_vnic_handle;
@@ -3226,7 +3226,7 @@  enic_fm_init(struct enic *enic)
 		return 0;
 	ENICPMD_FUNC_TRACE();
 	/* Get vnic handle and save for port-id action */
-	if (enic_is_vf_rep(enic))
+	if (rte_eth_dev_is_repr(enic->rte_dev))
 		addr = &VF_ENIC_TO_VF_REP(enic)->bdf;
 	else
 		addr = &RTE_ETH_DEV_TO_PCI(enic->rte_dev)->addr;
@@ -3240,7 +3240,7 @@  enic_fm_init(struct enic *enic)
 	enic->fm_vnic_uif = vnic_dev_uif(enic->vdev);
 	ENICPMD_LOG(DEBUG, "uif %u", enic->fm_vnic_uif);
 	/* Nothing else to do for representor. It will share the PF flowman */
-	if (enic_is_vf_rep(enic))
+	if (rte_eth_dev_is_repr(enic->rte_dev))
 		return 0;
 	fm = calloc(1, sizeof(*fm));
 	if (fm == NULL) {
@@ -3321,7 +3321,7 @@  enic_fm_destroy(struct enic *enic)
 	struct enic_fm_fet *fet;
 
 	ENICPMD_FUNC_TRACE();
-	if (enic_is_vf_rep(enic)) {
+	if (rte_eth_dev_is_repr(enic->rte_dev)) {
 		delete_rep_flows(enic);
 		return;
 	}
@@ -3358,7 +3358,7 @@  enic_fm_allocate_switch_domain(struct enic *pf)
 	int ret;
 
 	ENICPMD_FUNC_TRACE();
-	if (enic_is_vf_rep(pf))
+	if (rte_eth_dev_is_repr(pf->rte_dev))
 		return -EINVAL;
 	cur = pf;
 	cur_a = &RTE_ETH_DEV_TO_PCI(cur->rte_dev)->addr;
@@ -3367,7 +3367,7 @@  enic_fm_allocate_switch_domain(struct enic *pf)
 		dev = &rte_eth_devices[pid];
 		if (!dev_is_enic(dev))
 			continue;
-		if (dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
+		if (rte_eth_dev_is_repr(dev))
 			continue;
 		if (dev == cur->rte_dev)
 			continue;
@@ -3597,7 +3597,7 @@  delete_rep_flows(struct enic *enic)
 	struct rte_eth_dev *dev;
 	uint32_t i;
 
-	RTE_ASSERT(enic_is_vf_rep(enic));
+	RTE_ASSERT(rte_eth_dev_is_repr(enic->rte_dev));
 	vf = VF_ENIC_TO_VF_REP(enic);
 	dev = vf->pf->rte_dev;
 	for (i = 0; i < ARRAY_SIZE(vf->vf2rep_flow); i++) {
@@ -3617,7 +3617,7 @@  begin_fm(struct enic *enic)
 	struct enic_flowman *fm;
 
 	/* Representor uses PF flowman */
-	if (enic_is_vf_rep(enic)) {
+	if (rte_eth_dev_is_repr(enic->rte_dev)) {
 		vf = VF_ENIC_TO_VF_REP(enic);
 		fm = vf->pf->fm;
 	} else {
diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c
index a6aaa760ca..2f681315b6 100644
--- a/drivers/net/enic/enic_main.c
+++ b/drivers/net/enic/enic_main.c
@@ -824,7 +824,7 @@  int enic_alloc_rq(struct enic *enic, uint16_t queue_idx,
 	 * Representor uses a reserved PF queue. Translate representor
 	 * queue number to PF queue number.
 	 */
-	if (enic_is_vf_rep(enic)) {
+	if (rte_eth_dev_is_repr(enic->rte_dev)) {
 		RTE_ASSERT(queue_idx == 0);
 		vf = VF_ENIC_TO_VF_REP(enic);
 		sop_queue_idx = vf->pf_rq_sop_idx;
@@ -1053,7 +1053,7 @@  int enic_alloc_wq(struct enic *enic, uint16_t queue_idx,
 	 * Representor uses a reserved PF queue. Translate representor
 	 * queue number to PF queue number.
 	 */
-	if (enic_is_vf_rep(enic)) {
+	if (rte_eth_dev_is_repr(enic->rte_dev)) {
 		RTE_ASSERT(queue_idx == 0);
 		vf = VF_ENIC_TO_VF_REP(enic);
 		queue_idx = vf->pf_wq_idx;
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 4d21341382..ddbc2962bc 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -706,7 +706,7 @@  static int eth_i40e_pci_remove(struct rte_pci_device *pci_dev)
 	if (!ethdev)
 		return 0;
 
-	if (ethdev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
+	if (rte_eth_dev_is_repr(ethdev))
 		return rte_eth_dev_pci_generic_remove(pci_dev,
 					i40e_vf_representor_uninit);
 	else
diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
index bebf356f4d..d58ec9d907 100644
--- a/drivers/net/ice/ice_dcf_ethdev.c
+++ b/drivers/net/ice/ice_dcf_ethdev.c
@@ -2131,7 +2131,7 @@  eth_ice_dcf_pci_remove(struct rte_pci_device *pci_dev)
 	if (!eth_dev)
 		return 0;
 
-	if (eth_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
+	if (rte_eth_dev_is_repr(eth_dev))
 		return rte_eth_dev_pci_generic_remove(pci_dev,
 						      ice_dcf_vf_repr_uninit);
 	else
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 0cd3d0b105..c61c52b296 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -1842,7 +1842,7 @@  static int eth_ixgbe_pci_remove(struct rte_pci_device *pci_dev)
 	if (!ethdev)
 		return 0;
 
-	if (ethdev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
+	if (rte_eth_dev_is_repr(ethdev))
 		return rte_eth_dev_pci_generic_remove(pci_dev,
 					ixgbe_vf_representor_uninit);
 	else
diff --git a/drivers/net/nfp/flower/nfp_flower_flow.c b/drivers/net/nfp/flower/nfp_flower_flow.c
index e26be30d18..501a8d87bd 100644
--- a/drivers/net/nfp/flower/nfp_flower_flow.c
+++ b/drivers/net/nfp/flower/nfp_flower_flow.c
@@ -4321,7 +4321,7 @@  int
 nfp_flow_ops_get(struct rte_eth_dev *dev,
 		const struct rte_flow_ops **ops)
 {
-	if ((dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0) {
+	if (!rte_eth_dev_is_repr(dev)) {
 		*ops = NULL;
 		PMD_DRV_LOG(ERR, "Port is not a representor.");
 		return -EINVAL;
diff --git a/drivers/net/nfp/nfp_mtr.c b/drivers/net/nfp/nfp_mtr.c
index 255977ec22..6abc6dc9bc 100644
--- a/drivers/net/nfp/nfp_mtr.c
+++ b/drivers/net/nfp/nfp_mtr.c
@@ -1066,7 +1066,7 @@  static const struct rte_mtr_ops nfp_mtr_ops = {
 int
 nfp_net_mtr_ops_get(struct rte_eth_dev *dev, void *arg)
 {
-	if ((dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0) {
+	if (!rte_eth_dev_is_repr(dev)) {
 		PMD_DRV_LOG(ERR, "Port is not a representor");
 		return -EINVAL;
 	}
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 99c319eb2d..0ee2811926 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -241,7 +241,7 @@  nfp_net_get_hw(const struct rte_eth_dev *dev)
 {
 	struct nfp_net_hw *hw;
 
-	if ((dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR) != 0) {
+	if (rte_eth_dev_is_repr(dev)) {
 		struct nfp_flower_representor *repr;
 		repr = dev->data->dev_private;
 		hw = repr->app_fw_flower->pf_hw;
@@ -2143,7 +2143,7 @@  nfp_net_firmware_version_get(struct rte_eth_dev *dev,
 
 	hw = nfp_net_get_hw(dev);
 
-	if ((dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR) != 0) {
+	if (rte_eth_dev_is_repr(dev)) {
 		snprintf(vnic_version, FW_VER_LEN, "%d.%d.%d.%d",
 			hw->ver.extend, hw->ver.class,
 			hw->ver.major, hw->ver.minor);
diff --git a/drivers/net/nfp/nfp_net_flow.c b/drivers/net/nfp/nfp_net_flow.c
index 98e8499756..3b33f3b6e9 100644
--- a/drivers/net/nfp/nfp_net_flow.c
+++ b/drivers/net/nfp/nfp_net_flow.c
@@ -932,7 +932,7 @@  nfp_net_flow_ops_get(struct rte_eth_dev *dev,
 {
 	struct nfp_net_hw *hw;
 
-	if ((dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR) != 0) {
+	if (rte_eth_dev_is_repr(dev)) {
 		*ops = NULL;
 		PMD_DRV_LOG(ERR, "Port is a representor.");
 		return -EINVAL;
diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h
index 0e4c1f0743..f46c102558 100644
--- a/lib/ethdev/ethdev_driver.h
+++ b/lib/ethdev/ethdev_driver.h
@@ -2120,6 +2120,23 @@  struct rte_eth_fdir_conf {
 	struct rte_eth_fdir_flex_conf flex_conf;
 };
 
+/**
+ * @internal
+ * Check if the ethdev is a representor port.
+ *
+ * @param dev
+ *  Pointer to struct rte_eth_dev.
+ *
+ * @return
+ *  false the ethdev is not a representor port.
+ *  true  the ethdev is a representor port.
+ */
+static inline bool
+rte_eth_dev_is_repr(const struct rte_eth_dev *dev)
+{
+	return ((dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR) != 0);
+}
+
 #ifdef __cplusplus
 }
 #endif