From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5683AA00C3; Mon, 19 Sep 2022 08:05:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F1768410D0; Mon, 19 Sep 2022 08:05:24 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id E506B40E0F; Mon, 19 Sep 2022 08:05:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663567523; x=1695103523; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=XArHfCb4LkGfVDNu4ddWIANX1V+3Uy/Ub+EVdZeDqfo=; b=O0Z383ERyWQuoN1tED0AYY0tAD/MMvhDTrWD4YPqsuf9fQobDHtbMQ2R ic1uhx0gs5J8ceNec8Fyy1+C0T0n81gL9k+1Gci9TjTIRQvN2w/2hCema VO/zUbhAfEhxyrsowqFJwRI7JKjHL0wL+N/1KQvNa/zjA4dYPUXmczs5j 8r6hQj5eHq9XTHnOkh5asNosIhYmEd0AZByyg1NHdkFBg8P7pF7xpE8TM 0whcHp/wu797WTUbR1tLqL7FqkbNI039WLHFNBATAYIi624FrczIDCiaE AVa9fu8CyvEbs/4rBOTA6srUQfLs1xIP1VUxHCosPheqeYDc44fX0yFgp A==; X-IronPort-AV: E=McAfee;i="6500,9779,10474"; a="296904635" X-IronPort-AV: E=Sophos;i="5.93,327,1654585200"; d="scan'208";a="296904635" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2022 23:04:52 -0700 X-IronPort-AV: E=Sophos;i="5.93,327,1654585200"; d="scan'208";a="618354128" Received: from unknown (HELO dpdkserver..) ([10.239.252.174]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2022 23:04:49 -0700 From: Yiding Zhou To: dev@dpdk.org Cc: jingjing.wu@intel.com, beilei.xing@intel.com, Yiding Zhou , stable@dpdk.org Subject: [PATCH] net/iavf: fix error of virtchnl command Date: Mon, 19 Sep 2022 14:06:54 +0800 Message-Id: <20220919060654.1092715-1-yidingx.zhou@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When the device is bonded, bond pmd will register callback for LSC event. This callback will execute some virtchnl commands in eal-intr-thread to reinitialize the device with interrupts disabled. In this case, responses to all commands not be received. This commit starts a thread to handle all events to fix this issue. Fixes: 48de41ca11f0 ("net/avf: enable link status update") CC: stable@dpdk.org Signed-off-by: Yiding Zhou --- drivers/net/iavf/iavf.h | 2 + drivers/net/iavf/iavf_ethdev.c | 5 ++ drivers/net/iavf/iavf_vchnl.c | 130 ++++++++++++++++++++++++++++++++- 3 files changed, 136 insertions(+), 1 deletion(-) diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h index 025ab3ff60..7c215e1797 100644 --- a/drivers/net/iavf/iavf.h +++ b/drivers/net/iavf/iavf.h @@ -417,6 +417,8 @@ _atomic_set_async_response_cmd(struct iavf_info *vf, enum virtchnl_ops ops) } int iavf_check_api_version(struct iavf_adapter *adapter); int iavf_get_vf_resource(struct iavf_adapter *adapter); +void iavf_dev_event_handler_fini(void); +int iavf_dev_event_handler_init(void); void iavf_handle_virtchnl_msg(struct rte_eth_dev *dev); int iavf_enable_vlan_strip(struct iavf_adapter *adapter); int iavf_disable_vlan_strip(struct iavf_adapter *adapter); diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c index 506fcff6e3..a584b8918d 100644 --- a/drivers/net/iavf/iavf_ethdev.c +++ b/drivers/net/iavf/iavf_ethdev.c @@ -2629,6 +2629,9 @@ iavf_dev_init(struct rte_eth_dev *eth_dev) rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]); + if (iavf_dev_event_handler_init()) + goto init_vf_err; + if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) { /* register callback func to eal lib */ rte_intr_callback_register(pci_dev->intr_handle, @@ -2783,6 +2786,8 @@ iavf_dev_uninit(struct rte_eth_dev *dev) iavf_dev_close(dev); + iavf_dev_event_handler_fini(); + return 0; } diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index 21bd1e2193..5f3dd8779e 100644 --- a/drivers/net/iavf/iavf_vchnl.c +++ b/drivers/net/iavf/iavf_vchnl.c @@ -2,6 +2,8 @@ * Copyright(c) 2017 Intel Corporation */ +#include +#include #include #include #include @@ -27,6 +29,132 @@ #define MAX_TRY_TIMES 2000 #define ASQ_DELAY_MS 1 +struct iavf_arq_event_element { + TAILQ_ENTRY(iavf_arq_event_element) next; + struct rte_eth_dev *dev; + enum rte_eth_event_type event; + void *param; +}; + +struct iavf_event_handler { + rte_atomic32_t ndev; + pthread_t tid; + int fd[2]; + pthread_mutex_t lock; + TAILQ_HEAD(event_lsit, iavf_arq_event_element) pending; +}; + +static struct iavf_event_handler event_handler = { + .fd = {-1, -1}, +}; + +#ifndef TAILQ_FOREACH_SAFE +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) +#endif + +static void * +iavf_dev_event_handle(void *param __rte_unused) +{ + struct iavf_event_handler *handler = &event_handler; + TAILQ_HEAD(event_list, iavf_arq_event_element) pending; + + while (true) { + char unused; + int nr = read(handler->fd[0], &unused, 1); + if (nr <= 0) + break; + + TAILQ_INIT(&pending); + pthread_mutex_lock(&handler->lock); + TAILQ_CONCAT(&pending, &handler->pending, next); + pthread_mutex_unlock(&handler->lock); + + struct iavf_arq_event_element *pos, *save_next; + TAILQ_FOREACH_SAFE(pos, &pending, next, save_next) { + TAILQ_REMOVE(&pending, pos, next); + rte_eth_dev_callback_process(pos->dev, pos->event, pos->param); + rte_free(pos); + } + } + return NULL; +} + +static void +iavf_dev_event_post(struct rte_eth_dev *dev, + enum rte_eth_event_type event, + void *param) +{ + struct iavf_event_handler *handler = &event_handler; + char notify_byte; + struct iavf_arq_event_element *elem = rte_malloc(NULL, sizeof(*elem), 0); + if (!elem) + return; + + elem->dev = dev; + elem->event = event; + elem->param = param; + + pthread_mutex_lock(&handler->lock); + TAILQ_INSERT_TAIL(&handler->pending, elem, next); + pthread_mutex_unlock(&handler->lock); + + write(handler->fd[1], ¬ify_byte, 1); +} + +int +iavf_dev_event_handler_init(void) +{ + struct iavf_event_handler *handler = &event_handler; + + if (rte_atomic32_add_return(&handler->ndev, 1) != 1) + return 0; + + if (pipe(handler->fd)) { + rte_atomic32_dec(&handler->ndev); + return -1; + } + + TAILQ_INIT(&handler->pending); + pthread_mutex_init(&handler->lock, NULL); + + int flags = fcntl(handler->fd[1], F_GETFL); + fcntl(handler->fd[1], F_SETFL, flags | O_NONBLOCK); + if (rte_ctrl_thread_create(&handler->tid, "iavf-event-thread", + NULL, iavf_dev_event_handle, NULL)) { + rte_atomic32_dec(&handler->ndev); + return -1; + } + + return 0; +} + +void +iavf_dev_event_handler_fini(void) +{ + struct iavf_event_handler *handler = &event_handler; + + if (!rte_atomic32_dec_and_test(&handler->ndev)) + return; + + pthread_cancel(handler->tid); + close(handler->fd[0]); + close(handler->fd[1]); + handler->fd[0] = -1; + handler->fd[1] = -1; + + pthread_join(handler->tid, NULL); + pthread_mutex_destroy(&handler->lock); + + struct iavf_arq_event_element *pos, *save_next; + TAILQ_FOREACH_SAFE(pos, &handler->pending, next, save_next) { + TAILQ_REMOVE(&handler->pending, pos, next); + rte_free(pos); + } +} + static uint32_t iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed) { @@ -293,7 +421,7 @@ iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg, vf->link_speed = iavf_convert_link_speed(speed); } iavf_dev_link_update(dev, 0); - rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL); + iavf_dev_event_post(dev, RTE_ETH_EVENT_INTR_LSC, NULL); break; case VIRTCHNL_EVENT_PF_DRIVER_CLOSE: PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event"); -- 2.34.1