From: Beilei Xing <beilei.xing@intel.com>
Add link update ops for representor.
Signed-off-by: Jingjing Wu <jingjing.wu@intel.com>
Signed-off-by: Beilei Xing <beilei.xing@intel.com>
---
drivers/net/cpfl/cpfl_ethdev.h | 1 +
drivers/net/cpfl/cpfl_representor.c | 89 +++++++++++++++++++++++------
2 files changed, 71 insertions(+), 19 deletions(-)
@@ -162,6 +162,7 @@ struct cpfl_repr {
struct cpfl_repr_id repr_id;
struct rte_ether_addr mac_addr;
struct cpfl_vport_info *vport_info;
+ bool func_up; /* If the represented function is up */
};
struct cpfl_adapter_ext {
@@ -308,6 +308,72 @@ cpfl_repr_tx_queue_setup(__rte_unused struct rte_eth_dev *dev,
return 0;
}
+static int
+cpfl_func_id_get(uint8_t host_id, uint8_t pf_id)
+{
+ if ((host_id != CPFL_HOST_ID_HOST &&
+ host_id != CPFL_HOST_ID_ACC) ||
+ (pf_id != CPFL_PF_TYPE_APF &&
+ pf_id != CPFL_PF_TYPE_CPF))
+ return -EINVAL;
+
+ static const uint32_t func_id_map[CPFL_HOST_ID_NUM][CPFL_PF_TYPE_NUM] = {
+ [CPFL_HOST_ID_HOST][CPFL_PF_TYPE_APF] = CPFL_HOST0_APF,
+ [CPFL_HOST_ID_HOST][CPFL_PF_TYPE_CPF] = CPFL_HOST0_CPF_ID,
+ [CPFL_HOST_ID_ACC][CPFL_PF_TYPE_APF] = CPFL_ACC_APF_ID,
+ [CPFL_HOST_ID_ACC][CPFL_PF_TYPE_CPF] = CPFL_ACC_CPF_ID,
+ };
+
+ return func_id_map[host_id][pf_id];
+}
+
+static int
+cpfl_repr_link_update(struct rte_eth_dev *ethdev,
+ int wait_to_complete)
+{
+ struct cpfl_repr *repr = CPFL_DEV_TO_REPR(ethdev);
+ struct rte_eth_link *dev_link = ðdev->data->dev_link;
+ struct cpfl_adapter_ext *adapter = repr->itf.adapter;
+ struct cpchnl2_get_vport_info_response response;
+ struct cpfl_vport_id vi;
+ int ret;
+
+ if (!(ethdev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)) {
+ PMD_INIT_LOG(ERR, "This ethdev is not representor.");
+ return -EINVAL;
+ }
+
+ if (wait_to_complete) {
+ if (repr->repr_id.type == RTE_ETH_REPRESENTOR_PF) {
+ /* PF */
+ vi.func_type = CPCHNL2_FUNC_TYPE_PF;
+ vi.pf_id = cpfl_func_id_get(repr->repr_id.host_id, repr->repr_id.pf_id);
+ vi.vf_id = 0;
+ } else {
+ /* VF */
+ vi.func_type = CPCHNL2_FUNC_TYPE_SRIOV;
+ vi.pf_id = CPFL_HOST0_APF;
+ vi.vf_id = repr->repr_id.vf_id;
+ }
+ ret = cpfl_cc_vport_info_get(adapter, &repr->vport_info->vport.vport,
+ &vi, &response);
+ if (ret < 0) {
+ PMD_INIT_LOG(ERR, "Fail to get vport info.");
+ return ret;
+ }
+
+ if (response.info.vport_status == CPCHNL2_VPORT_STATUS_ENABLED)
+ repr->func_up = true;
+ else
+ repr->func_up = false;
+ }
+
+ dev_link->link_status = repr->func_up ?
+ RTE_ETH_LINK_UP : RTE_ETH_LINK_DOWN;
+
+ return 0;
+}
+
static const struct eth_dev_ops cpfl_repr_dev_ops = {
.dev_start = cpfl_repr_dev_start,
.dev_stop = cpfl_repr_dev_stop,
@@ -317,6 +383,8 @@ static const struct eth_dev_ops cpfl_repr_dev_ops = {
.rx_queue_setup = cpfl_repr_rx_queue_setup,
.tx_queue_setup = cpfl_repr_tx_queue_setup,
+
+ .link_update = cpfl_repr_link_update,
};
static int
@@ -331,6 +399,8 @@ cpfl_repr_init(struct rte_eth_dev *eth_dev, void *init_param)
repr->itf.type = CPFL_ITF_TYPE_REPRESENTOR;
repr->itf.adapter = adapter;
repr->itf.data = eth_dev->data;
+ if (repr->vport_info->vport.info.vport_status == CPCHNL2_VPORT_STATUS_ENABLED)
+ repr->func_up = true;
eth_dev->dev_ops = &cpfl_repr_dev_ops;
@@ -349,25 +419,6 @@ cpfl_repr_init(struct rte_eth_dev *eth_dev, void *init_param)
return cpfl_repr_allowlist_update(adapter, &repr->repr_id, eth_dev);
}
-static int
-cpfl_func_id_get(uint8_t host_id, uint8_t pf_id)
-{
- if ((host_id != CPFL_HOST_ID_HOST &&
- host_id != CPFL_HOST_ID_ACC) ||
- (pf_id != CPFL_PF_TYPE_APF &&
- pf_id != CPFL_PF_TYPE_CPF))
- return -EINVAL;
-
- static const uint32_t func_id_map[CPFL_HOST_ID_NUM][CPFL_PF_TYPE_NUM] = {
- [CPFL_HOST_ID_HOST][CPFL_PF_TYPE_APF] = CPFL_HOST0_APF,
- [CPFL_HOST_ID_HOST][CPFL_PF_TYPE_CPF] = CPFL_HOST0_CPF_ID,
- [CPFL_HOST_ID_ACC][CPFL_PF_TYPE_APF] = CPFL_ACC_APF_ID,
- [CPFL_HOST_ID_ACC][CPFL_PF_TYPE_CPF] = CPFL_ACC_CPF_ID,
- };
-
- return func_id_map[host_id][pf_id];
-}
-
static bool
cpfl_match_repr_with_vport(const struct cpfl_repr_id *repr_id,
struct cpchnl2_vport_info *info)