Skip to content

Commit

Permalink
net/ice: track DCF state of PF
Browse files Browse the repository at this point in the history
[ upstream commit 285f63f ]

When VF is reset, PF will change DCF state from ON to other state, if
flow creation, destroy, or redirect command is sent to DCF at this
time, it will fail.

This patch tracks DCF state and returns try-again error to caller when
DCF state is not ON.

Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
Acked-by: Haiyue Wang <haiyue.wang@intel.com>
  • Loading branch information
yudapengx authored and bluca committed Feb 14, 2022
1 parent f7b02e1 commit 8577641
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
12 changes: 12 additions & 0 deletions drivers/net/ice/ice_dcf_ethdev.c
Expand Up @@ -870,6 +870,13 @@ ice_dcf_dev_close(struct rte_eth_dev *dev)
return 0;
}

bool
ice_dcf_adminq_need_retry(struct ice_adapter *ad)
{
return ad->hw.dcf_enabled &&
!__atomic_load_n(&ad->dcf_state_on, __ATOMIC_RELAXED);
}

static int
ice_dcf_link_update(__rte_unused struct rte_eth_dev *dev,
__rte_unused int wait_to_complete)
Expand Down Expand Up @@ -905,6 +912,7 @@ static int
ice_dcf_dev_init(struct rte_eth_dev *eth_dev)
{
struct ice_dcf_adapter *adapter = eth_dev->data->dev_private;
struct ice_adapter *parent_adapter = &adapter->parent;

eth_dev->dev_ops = &ice_dcf_eth_dev_ops;
eth_dev->rx_pkt_burst = ice_dcf_recv_pkts;
Expand All @@ -916,9 +924,13 @@ ice_dcf_dev_init(struct rte_eth_dev *eth_dev)
adapter->real_hw.vc_event_msg_cb = ice_dcf_handle_pf_event_msg;
if (ice_dcf_init_hw(eth_dev, &adapter->real_hw) != 0) {
PMD_INIT_LOG(ERR, "Failed to init DCF hardware");
__atomic_store_n(&parent_adapter->dcf_state_on, false,
__ATOMIC_RELAXED);
return -1;
}

__atomic_store_n(&parent_adapter->dcf_state_on, true, __ATOMIC_RELAXED);

if (ice_dcf_init_parent_adapter(eth_dev) != 0) {
PMD_INIT_LOG(ERR, "Failed to init DCF parent adapter");
ice_dcf_uninit_hw(eth_dev, &adapter->real_hw);
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ice/ice_dcf_ethdev.h
Expand Up @@ -26,5 +26,6 @@ void ice_dcf_handle_pf_event_msg(struct ice_dcf_hw *dcf_hw,
uint8_t *msg, uint16_t msglen);
int ice_dcf_init_parent_adapter(struct rte_eth_dev *eth_dev);
void ice_dcf_uninit_parent_adapter(struct rte_eth_dev *eth_dev);
bool ice_dcf_adminq_need_retry(struct ice_adapter *ad);

#endif /* _ICE_DCF_ETHDEV_H_ */
10 changes: 10 additions & 0 deletions drivers/net/ice/ice_dcf_parent.c
Expand Up @@ -111,6 +111,9 @@ static void*
ice_dcf_vsi_update_service_handler(void *param)
{
struct ice_dcf_hw *hw = param;
struct ice_dcf_adapter *adapter =
container_of(hw, struct ice_dcf_adapter, real_hw);
struct ice_adapter *parent_adapter = &adapter->parent;

pthread_detach(pthread_self());
usleep(ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL);
Expand All @@ -122,6 +125,8 @@ ice_dcf_vsi_update_service_handler(void *param)
struct ice_dcf_adapter *dcf_ad =
container_of(hw, struct ice_dcf_adapter, real_hw);

__atomic_store_n(&parent_adapter->dcf_state_on, true,
__ATOMIC_RELAXED);
ice_dcf_update_vf_vsi_map(&dcf_ad->parent.hw,
hw->num_vfs, hw->vf_vsi_map);
}
Expand All @@ -137,6 +142,9 @@ ice_dcf_handle_pf_event_msg(struct ice_dcf_hw *dcf_hw,
{
struct virtchnl_pf_event *pf_msg = (struct virtchnl_pf_event *)msg;
pthread_t thread;
struct ice_dcf_adapter *adapter =
container_of(dcf_hw, struct ice_dcf_adapter, real_hw);
struct ice_adapter *parent_adapter = &adapter->parent;

if (msglen < sizeof(struct virtchnl_pf_event)) {
PMD_DRV_LOG(DEBUG, "Invalid event message length : %u", msglen);
Expand All @@ -161,6 +169,8 @@ ice_dcf_handle_pf_event_msg(struct ice_dcf_hw *dcf_hw,
pf_msg->event_data.vf_vsi_map.vsi_id);
pthread_create(&thread, NULL,
ice_dcf_vsi_update_service_handler, dcf_hw);
__atomic_store_n(&parent_adapter->dcf_state_on, false,
__ATOMIC_RELAXED);
break;
default:
PMD_DRV_LOG(ERR, "Unknown event received %u", pf_msg->event);
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ice/ice_ethdev.h
Expand Up @@ -478,6 +478,8 @@ struct ice_adapter {
struct ice_devargs devargs;
enum ice_pkg_type active_pkg_type; /* loaded ddp package type */
uint16_t fdir_ref_cnt;
/* True if DCF state of the associated PF is on */
bool dcf_state_on;
#ifdef RTE_ARCH_X86
bool rx_use_avx2;
bool rx_use_avx512;
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/ice/ice_generic_flow.c
Expand Up @@ -2323,7 +2323,9 @@ ice_flow_flush(struct rte_eth_dev *dev,
ret = ice_flow_destroy(dev, p_flow, error);
if (ret) {
PMD_DRV_LOG(ERR, "Failed to flush flows");
return -EINVAL;
if (ret != -EAGAIN)
ret = -EINVAL;
return ret;
}
}

Expand Down
45 changes: 43 additions & 2 deletions drivers/net/ice/ice_switch_filter.c
Expand Up @@ -438,6 +438,14 @@ ice_switch_create(struct ice_adapter *ad,
"lookup list should not be NULL");
goto error;
}

if (ice_dcf_adminq_need_retry(ad)) {
rte_flow_error_set(error, EAGAIN,
RTE_FLOW_ERROR_TYPE_ITEM, NULL,
"DCF is not on");
goto error;
}

ret = ice_add_adv_rule(hw, list, lkups_cnt, rule_info, &rule_added);
if (!ret) {
filter_conf_ptr = rte_zmalloc("ice_switch_filter",
Expand All @@ -461,7 +469,12 @@ ice_switch_create(struct ice_adapter *ad,

flow->rule = filter_conf_ptr;
} else {
rte_flow_error_set(error, EINVAL,
if (ice_dcf_adminq_need_retry(ad))
ret = -EAGAIN;
else
ret = -EINVAL;

rte_flow_error_set(error, -ret,
RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
"switch filter create flow fail");
goto error;
Expand Down Expand Up @@ -513,9 +526,21 @@ ice_switch_destroy(struct ice_adapter *ad,
return -rte_errno;
}

if (ice_dcf_adminq_need_retry(ad)) {
rte_flow_error_set(error, EAGAIN,
RTE_FLOW_ERROR_TYPE_ITEM, NULL,
"DCF is not on");
return -rte_errno;
}

ret = ice_rem_adv_rule_by_id(hw, &filter_conf_ptr->sw_query_data);
if (ret) {
rte_flow_error_set(error, EINVAL,
if (ice_dcf_adminq_need_retry(ad))
ret = -EAGAIN;
else
ret = -EINVAL;

rte_flow_error_set(error, -ret,
RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
"fail to destroy switch filter rule");
return -rte_errno;
Expand Down Expand Up @@ -1904,6 +1929,12 @@ ice_switch_redirect(struct ice_adapter *ad,
}

rmv_rule:
if (ice_dcf_adminq_need_retry(ad)) {
PMD_DRV_LOG(WARNING, "DCF is not on");
ret = -EAGAIN;
goto out;
}

/* Remove the old rule */
ret = ice_rem_adv_rule(hw, lkups_ref, lkups_cnt, &rinfo);
if (ret) {
Expand All @@ -1916,6 +1947,12 @@ ice_switch_redirect(struct ice_adapter *ad,
}

add_rule:
if (ice_dcf_adminq_need_retry(ad)) {
PMD_DRV_LOG(WARNING, "DCF is not on");
ret = -EAGAIN;
goto out;
}

/* Update VSI context */
hw->vsi_ctx[rd->vsi_handle]->vsi_num = rd->new_vsi_num;

Expand All @@ -1935,6 +1972,10 @@ ice_switch_redirect(struct ice_adapter *ad,
}

out:
if (ret == -EINVAL)
if (ice_dcf_adminq_need_retry(ad))
ret = -EAGAIN;

ice_free(hw, lkups_dp);
return ret;
}
Expand Down

0 comments on commit 8577641

Please sign in to comment.