This commit adds the FLM update service to the NTNIC PMD. The service is responsible for handling creating/destroying flows.
Signed-off-by: Serhii Iliushyk <sil-...@napatech.com> --- drivers/net/ntnic/include/ntdrv_4ga.h | 1 - drivers/net/ntnic/ntnic_ethdev.c | 67 ++++++++++++------- drivers/net/ntnic/ntnic_filter/ntnic_filter.c | 17 +++++ drivers/net/ntnic/ntutil/nt_service.c | 4 +- drivers/net/ntnic/rte_pmd_ntnic.h | 3 +- 5 files changed, 62 insertions(+), 30 deletions(-) diff --git a/drivers/net/ntnic/include/ntdrv_4ga.h b/drivers/net/ntnic/include/ntdrv_4ga.h index 78cf10368a..35afcd546c 100644 --- a/drivers/net/ntnic/include/ntdrv_4ga.h +++ b/drivers/net/ntnic/include/ntdrv_4ga.h @@ -15,7 +15,6 @@ typedef struct ntdrv_4ga_s { char *p_drv_name; volatile bool b_shutdown; - rte_thread_t flm_thread; rte_spinlock_t stat_lck; rte_thread_t stat_thread; rte_thread_t port_event_thread; diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c index 79ef9e7e7c..c114017db8 100644 --- a/drivers/net/ntnic/ntnic_ethdev.c +++ b/drivers/net/ntnic/ntnic_ethdev.c @@ -31,6 +31,7 @@ #include "profile_inline/flm_age_queue.h" #include "profile_inline/flm_evt_queue.h" #include "rte_pmd_ntnic.h" +#include "nt_service.h" const rte_thread_attr_t thread_attr = { .priority = RTE_THREAD_PRIORITY_NORMAL }; #define THREAD_CREATE(a, b, c) rte_thread_create(a, &thread_attr, b, c) @@ -1546,7 +1547,7 @@ drv_deinit(struct drv_s *p_drv) THREAD_JOIN(p_nt_drv->stat_thread); if (fpga_info->profile == FPGA_INFO_PROFILE_INLINE) { - THREAD_JOIN(p_nt_drv->flm_thread); + nthw_service_del(RTE_NTNIC_SERVICE_FLM_UPDATE); profile_inline_ops->flm_free_queues(); THREAD_JOIN(p_nt_drv->port_event_thread); /* Free all local flm event queues */ @@ -1980,40 +1981,46 @@ THREAD_FUNC port_event_thread_fn(void *context) } /* - * Adapter flm stat thread + * Adapter flm update service */ -THREAD_FUNC adapter_flm_update_thread_fn(void *context) +static int adapter_flm_update_service(void *context) { - const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops(); + static struct flow_eth_dev *dev; + static const struct profile_inline_ops *profile_inline_ops; - if (profile_inline_ops == NULL) { - NT_LOG(ERR, NTNIC, "%s: profile_inline module uninitialized", __func__); - return THREAD_RETURN; - } + struct nt_service *flm_update_srv = nthw_service_get_info(RTE_NTNIC_SERVICE_FLM_UPDATE); + RTE_ASSERT(flm_update_srv != NULL); - struct drv_s *p_drv = context; + if (!NT_SERVICE_GET_STATE(flm_update_srv)) { + struct drv_s *p_drv = context; + RTE_ASSERT(p_drv != NULL); - struct ntdrv_4ga_s *p_nt_drv = &p_drv->ntdrv; - struct adapter_info_s *p_adapter_info = &p_nt_drv->adapter_info; - struct nt4ga_filter_s *p_nt4ga_filter = &p_adapter_info->nt4ga_filter; - struct flow_nic_dev *p_flow_nic_dev = p_nt4ga_filter->mp_flow_device; + struct ntdrv_4ga_s *p_nt_drv = &p_drv->ntdrv; + struct adapter_info_s *p_adapter_info = &p_nt_drv->adapter_info; + struct nt4ga_filter_s *p_nt4ga_filter = &p_adapter_info->nt4ga_filter; + struct flow_nic_dev *p_flow_nic_dev = p_nt4ga_filter->mp_flow_device; - NT_LOG(DBG, NTNIC, "%s: %s: waiting for port configuration", - p_adapter_info->mp_adapter_id_str, __func__); + NT_LOG(DBG, NTNIC, "%s: %s: waiting for port configuration", + p_adapter_info->mp_adapter_id_str, __func__); - while (p_flow_nic_dev->eth_base == NULL) - nt_os_wait_usec(1 * 1000 * 1000); + if (p_flow_nic_dev->eth_base == NULL) + return -1; - struct flow_eth_dev *dev = p_flow_nic_dev->eth_base; + dev = p_flow_nic_dev->eth_base; - NT_LOG(DBG, NTNIC, "%s: %s: begin", p_adapter_info->mp_adapter_id_str, __func__); + profile_inline_ops = get_profile_inline_ops(); + RTE_ASSERT(profile_inline_ops != NULL); - while (!p_drv->ntdrv.b_shutdown) - if (profile_inline_ops->flm_update(dev) == 0) - nt_os_wait_usec(10); + NT_LOG(INF, NTNIC, "flm update service started on lcore %i", rte_lcore_id()); + flm_update_srv->lcore = rte_lcore_id(); + NT_SERVICE_SET_STATE(flm_update_srv, true); + return 0; + } - NT_LOG(DBG, NTNIC, "%s: %s: end", p_adapter_info->mp_adapter_id_str, __func__); - return THREAD_RETURN; + if (profile_inline_ops->flm_update(dev) == 0) + nt_os_wait_usec(10); + + return 0; } /* @@ -2346,8 +2353,16 @@ nthw_pci_dev_init(struct rte_pci_device *pci_dev) if (profile_inline_ops != NULL && fpga_info->profile == FPGA_INFO_PROFILE_INLINE) { profile_inline_ops->flm_setup_queues(); - res = THREAD_CTRL_CREATE(&p_nt_drv->flm_thread, "ntnic-nt_flm_update_thr", - adapter_flm_update_thread_fn, (void *)p_drv); + + struct rte_service_spec flm_update_spec = { + .name = "ntnic-flm_update_service", + .callback = adapter_flm_update_service, + .socket_id = SOCKET_ID_ANY, + .capabilities = RTE_SERVICE_CAP_MT_SAFE, + .callback_userdata = p_drv + }; + + res = nthw_service_add(&flm_update_spec, RTE_NTNIC_SERVICE_FLM_UPDATE); if (res) { NT_LOG_DBGX(ERR, NTNIC, "%s: error=%d", diff --git a/drivers/net/ntnic/ntnic_filter/ntnic_filter.c b/drivers/net/ntnic/ntnic_filter/ntnic_filter.c index fc06cf12c3..c6c448312f 100644 --- a/drivers/net/ntnic/ntnic_filter/ntnic_filter.c +++ b/drivers/net/ntnic/ntnic_filter/ntnic_filter.c @@ -6,6 +6,7 @@ #include <rte_flow_driver.h> #include <rte_pci.h> #include <rte_version.h> +#include <rte_pmd_ntnic.h> #include "ntlog.h" #include "nt_util.h" @@ -13,6 +14,8 @@ #include "ntnic_mod_reg.h" #include "ntos_system.h" #include "ntos_drv.h" +#include "nt_service.h" +#include "rte_service.h" #define MAX_RTE_FLOWS 8192 @@ -543,6 +546,13 @@ eth_flow_destroy(struct rte_eth_dev *eth_dev, struct rte_flow *flow, struct rte_ return -1; } + struct nt_service *srv = nthw_service_get_info(RTE_NTNIC_SERVICE_FLM_UPDATE); + + if (!srv || !NT_SERVICE_GET_STATE(srv) || !rte_service_runstate_get(srv->id)) { + NT_LOG(ERR, FILTER, "flm update service is not started. Flow cannot be destroyed"); + return -1; + } + struct pmd_internals *internals = eth_dev->data->dev_private; error->type = RTE_FLOW_ERROR_TYPE_NONE; @@ -580,6 +590,13 @@ static struct rte_flow *eth_flow_create(struct rte_eth_dev *eth_dev, return NULL; } + struct nt_service *srv = nthw_service_get_info(RTE_NTNIC_SERVICE_FLM_UPDATE); + + if (!srv || !NT_SERVICE_GET_STATE(srv) || !rte_service_runstate_get(srv->id)) { + NT_LOG(ERR, FILTER, "flm update service is not started. Flow cannot be created"); + return NULL; + } + struct pmd_internals *internals = eth_dev->data->dev_private; struct fpga_info_s *fpga_info = &internals->p_drv->ntdrv.adapter_info.fpga_info; diff --git a/drivers/net/ntnic/ntutil/nt_service.c b/drivers/net/ntnic/ntutil/nt_service.c index 4ef1233f12..86f709e401 100644 --- a/drivers/net/ntnic/ntutil/nt_service.c +++ b/drivers/net/ntnic/ntutil/nt_service.c @@ -12,8 +12,8 @@ #define NT_SERVICE_UNKNOWN_ID (-1) static struct nt_service g_nt_services[RTE_NTNIC_SERVICE_MAX] = { - [0] = { - .tag = RTE_NTNIC_SERVICE_MAX, + [RTE_NTNIC_SERVICE_FLM_UPDATE] = { + .tag = RTE_NTNIC_SERVICE_FLM_UPDATE, .id = NT_SERVICE_UNKNOWN_ID, .lcore = RTE_MAX_LCORE, .initialized = false, diff --git a/drivers/net/ntnic/rte_pmd_ntnic.h b/drivers/net/ntnic/rte_pmd_ntnic.h index 7a491319fa..d6236dae32 100644 --- a/drivers/net/ntnic/rte_pmd_ntnic.h +++ b/drivers/net/ntnic/rte_pmd_ntnic.h @@ -41,7 +41,8 @@ enum rte_ntnic_event_type { }; enum rte_ntnic_service_tag { - RTE_NTNIC_SERVICE_MAX = 1 + RTE_NTNIC_SERVICE_FLM_UPDATE = 0, + RTE_NTNIC_SERVICE_MAX }; /** -- 2.45.0