> -----Original Message----- > From: Xing, Beilei <beilei.x...@intel.com> > Sent: Wednesday, August 16, 2023 11:06 PM > To: Wu, Jingjing <jingjing...@intel.com> > Cc: dev@dpdk.org; Liu, Mingxia <mingxia....@intel.com>; Xing, Beilei > <beilei.x...@intel.com> > Subject: [PATCH v2 09/12] net/cpfl: update vport info before creating > representor > > From: Beilei Xing <beilei.x...@intel.com> > > Get port representor's vport list and update vport_map_hash before creating > the > port representor. > > Signed-off-by: Beilei Xing <beilei.x...@intel.com> > --- > drivers/net/cpfl/cpfl_ethdev.c | 2 +- > drivers/net/cpfl/cpfl_ethdev.h | 3 + > drivers/net/cpfl/cpfl_representor.c | 124 ++++++++++++++++++++++++++++ > 3 files changed, 128 insertions(+), 1 deletion(-) > int > cpfl_repr_create(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext > *adapter) { @@ -375,8 +455,14 @@ cpfl_repr_create(struct rte_pci_device > *pci_dev, struct cpfl_adapter_ext *adapte > uint32_t iter = 0; > const struct cpfl_repr_id *repr_id; > const struct cpfl_vport_id *vp_id; > + struct cpchnl2_get_vport_list_response *vlist_resp; > + struct cpchnl2_get_vport_info_response vinfo_resp; > int ret; > > + vlist_resp = rte_zmalloc(NULL, IDPF_DFLT_MBX_BUF_SIZE, 0); > + if (vlist_resp == NULL) > + return -ENOMEM; > + > rte_spinlock_lock(&adapter->repr_lock); > > while (rte_hash_iterate(adapter->repr_allowlist_hash, > @@ -385,6 +471,7 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct > cpfl_adapter_ext *adapte > char name[RTE_ETH_NAME_MAX_LEN]; > uint32_t iter_iter = 0; > bool matched; > + int i; > > /* skip representor already be created */ > if (dev != NULL) > @@ -402,6 +489,41 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct > cpfl_adapter_ext *adapte > repr_id->host_id, > repr_id->pf_id); > > + /* get vport list for the port representor */ > + ret = cpfl_repr_vport_list_query(adapter, repr_id, vlist_resp); > + if (ret != 0) { > + PMD_INIT_LOG(ERR, "Failed to get host%d pf%d vf%d's > vport list", > + repr_id->host_id, repr_id->pf_id, repr_id- > >vf_id); > + rte_spinlock_unlock(&adapter->repr_lock); > + rte_free(vlist_resp); > + return ret; > + } > + > + /* get all vport info for the port representor */ > + for (i = 0; i < vlist_resp->nof_vports; i++) { > + ret = cpfl_repr_vport_info_query(adapter, repr_id, > + &vlist_resp->vports[i], > &vinfo_resp); > + if (ret != 0) { > + PMD_INIT_LOG(ERR, "Failed to get host%d > pf%d vf%d vport[%d]'s info", > + repr_id->host_id, repr_id->pf_id, > repr_id->vf_id, > + vlist_resp->vports[i].vport_id); > + rte_spinlock_unlock(&adapter->repr_lock); > + rte_free(vlist_resp); > + return ret; > + } > + > + ret = cpfl_repr_vport_map_update(adapter, repr_id, > + vlist_resp->vports[i].vport_id, > &vinfo_resp); > + if (ret != 0) { > + PMD_INIT_LOG(ERR, "Failed to update host%d > pf%d vf%d vport[%d]'s info to vport_map_hash", > + repr_id->host_id, repr_id->pf_id, > repr_id->vf_id, > + vlist_resp->vports[i].vport_id); > + rte_spinlock_unlock(&adapter->repr_lock); > + rte_free(vlist_resp); > + return ret; > + } > + } > + > /* find a matched vport */ > rte_spinlock_lock(&adapter->vport_map_lock); > > @@ -428,6 +550,7 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct > cpfl_adapter_ext *adapte > PMD_INIT_LOG(ERR, "Failed to create > representor %s", name); > rte_spinlock_unlock(&adapter- > >vport_map_lock); > rte_spinlock_unlock(&adapter->repr_lock); > + rte_free(vlist_resp); > return ret; > } > break; > @@ -443,6 +566,7 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct > cpfl_adapter_ext *adapte > } > > rte_spinlock_unlock(&adapter->repr_lock); > + rte_free(vlist_resp); > [Liu, Mingxia] There are several exit point that do the common clean work rte_spinlock_unlock(&adapter->repr_lock); rte_free(vlist_resp); return ret; how about using goto ? > return 0; > } > -- > 2.34.1