@@ -598,29 +598,20 @@ static int
nfp_flower_enable_services(struct nfp_app_fw_flower *app_fw_flower)
{
int ret;
- uint32_t service_id;
+ struct nfp_service_info info;
const struct rte_service_spec flower_service = {
.name = "flower_ctrl_vnic_service",
.callback = nfp_flower_ctrl_vnic_service,
.callback_userdata = (void *)app_fw_flower,
};
- /* Register the flower services */
- ret = rte_service_component_register(&flower_service, &service_id);
+ ret = nfp_service_enable(&flower_service, &info);
if (ret != 0) {
- PMD_INIT_LOG(ERR, "Could not register %s", flower_service.name);
- return -EINVAL;
+ PMD_INIT_LOG(ERR, "Could not enable service %s", flower_service.name);
+ return ret;
}
- app_fw_flower->ctrl_vnic_id = service_id;
- PMD_INIT_LOG(INFO, "%s registered", flower_service.name);
-
- /* Map them to available service cores */
- ret = nfp_map_service(service_id);
- if (ret != 0) {
- PMD_INIT_LOG(ERR, "Could not map %s", flower_service.name);
- return -EINVAL;
- }
+ app_fw_flower->ctrl_vnic_id = info.id;
return 0;
}
@@ -396,6 +396,9 @@ nfp_flower_repr_dev_close(struct rte_eth_dev *dev)
if (app_fw_flower->pf_repr != NULL)
return 0;
+ /* Disable cpp service */
+ nfp_service_disable(&pf_dev->cpp_service_info);
+
/* Now it is safe to free all PF resources */
nfp_uninit_app_fw_flower(pf_dev);
nfp_pf_uninit(pf_dev);
@@ -40,6 +40,7 @@ sources = files(
'nfp_net_ctrl.c',
'nfp_net_flow.c',
'nfp_rxtx.c',
+ 'nfp_service.c',
)
deps += ['hash', 'security', 'common_nfp']
@@ -8,10 +8,9 @@
#include <unistd.h>
#include <sys/ioctl.h>
-#include <rte_service_component.h>
-
#include "nfpcore/nfp_cpp.h"
#include "nfp_logs.h"
+#include "nfp_service.h"
#define NFP_CPP_MEMIO_BOUNDARY (1 << 20)
#define NFP_BRIDGE_OP_READ 20
@@ -24,82 +23,23 @@
/* Prototypes */
static int nfp_cpp_bridge_service_func(void *args);
-int
-nfp_map_service(uint32_t service_id)
-{
- int32_t ret;
- uint32_t slcore = 0;
- int32_t slcore_count;
- uint8_t service_count;
- const char *service_name;
- uint32_t slcore_array[RTE_MAX_LCORE];
- uint8_t min_service_count = UINT8_MAX;
-
- slcore_count = rte_service_lcore_list(slcore_array, RTE_MAX_LCORE);
- if (slcore_count <= 0) {
- PMD_INIT_LOG(DEBUG, "No service cores found");
- return -ENOENT;
- }
-
- /*
- * Find a service core with the least number of services already
- * registered to it.
- */
- while (slcore_count--) {
- service_count = rte_service_lcore_count_services(slcore_array[slcore_count]);
- if (service_count < min_service_count) {
- slcore = slcore_array[slcore_count];
- min_service_count = service_count;
- }
- }
-
- service_name = rte_service_get_name(service_id);
- PMD_INIT_LOG(INFO, "Mapping service %s to core %u", service_name, slcore);
-
- ret = rte_service_map_lcore_set(service_id, slcore, 1);
- if (ret != 0) {
- PMD_INIT_LOG(DEBUG, "Could not map flower service");
- return -ENOENT;
- }
-
- rte_service_runstate_set(service_id, 1);
- rte_service_component_runstate_set(service_id, 1);
- rte_service_lcore_start(slcore);
- if (rte_service_may_be_active(slcore) != 0)
- PMD_INIT_LOG(INFO, "The service %s is running", service_name);
- else
- PMD_INIT_LOG(ERR, "The service %s is not running", service_name);
-
- return 0;
-}
-
int
nfp_enable_cpp_service(struct nfp_pf_dev *pf_dev)
{
int ret;
- uint32_t service_id = 0;
+ const char *pci_name;
struct rte_service_spec cpp_service = {
- .name = "nfp_cpp_service",
- .callback = nfp_cpp_bridge_service_func,
+ .callback = nfp_cpp_bridge_service_func,
+ .callback_userdata = (void *)pf_dev,
};
- cpp_service.callback_userdata = (void *)pf_dev;
+ pci_name = strchr(pf_dev->pci_dev->name, ':') + 1;
+ snprintf(cpp_service.name, sizeof(cpp_service.name), "%s_cpp_service", pci_name);
- /* Register the cpp service */
- ret = rte_service_component_register(&cpp_service, &service_id);
+ ret = nfp_service_enable(&cpp_service, &pf_dev->cpp_service_info);
if (ret != 0) {
- PMD_INIT_LOG(WARNING, "Could not register nfp cpp service");
- return -EINVAL;
- }
-
- pf_dev->cpp_bridge_id = service_id;
- PMD_INIT_LOG(INFO, "NFP cpp service registered");
-
- /* Map it to available service core */
- ret = nfp_map_service(service_id);
- if (ret != 0) {
- PMD_INIT_LOG(DEBUG, "Could not map nfp cpp service");
- return -EINVAL;
+ PMD_INIT_LOG(DEBUG, "Could not enable service %s", cpp_service.name);
+ return ret;
}
return 0;
@@ -387,12 +327,18 @@ nfp_cpp_bridge_service_func(void *args)
int sockfd;
int datafd;
struct nfp_cpp *cpp;
+ const char *pci_name;
+ char socket_handle[14];
struct sockaddr address;
struct nfp_pf_dev *pf_dev;
struct timeval timeout = {1, 0};
- unlink("/tmp/nfp_cpp");
+ pf_dev = args;
+
+ pci_name = strchr(pf_dev->pci_dev->name, ':') + 1;
+ snprintf(socket_handle, sizeof(socket_handle), "/tmp/%s", pci_name);
+ unlink(socket_handle);
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sockfd < 0) {
PMD_CPP_LOG(ERR, "socket creation error. Service failed");
@@ -404,7 +350,7 @@ nfp_cpp_bridge_service_func(void *args)
memset(&address, 0, sizeof(struct sockaddr));
address.sa_family = AF_UNIX;
- strcpy(address.sa_data, "/tmp/nfp_cpp");
+ strcpy(address.sa_data, socket_handle);
ret = bind(sockfd, (const struct sockaddr *)&address,
sizeof(struct sockaddr));
@@ -421,9 +367,8 @@ nfp_cpp_bridge_service_func(void *args)
return ret;
}
- pf_dev = args;
cpp = pf_dev->cpp;
- while (rte_service_runstate_get(pf_dev->cpp_bridge_id) != 0) {
+ while (rte_service_runstate_get(pf_dev->cpp_service_info.id) != 0) {
datafd = accept(sockfd, NULL, NULL);
if (datafd < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK)
@@ -9,6 +9,5 @@
#include "nfp_net_common.h"
int nfp_enable_cpp_service(struct nfp_pf_dev *pf_dev);
-int nfp_map_service(uint32_t service_id);
#endif /* __NFP_CPP_BRIDGE_H__ */
@@ -14,6 +14,7 @@
#include "nfpcore/nfp_sync.h"
#include "nfp_net_ctrl.h"
+#include "nfp_service.h"
/* Interrupt definitions */
#define NFP_NET_IRQ_LSC_IDX 0
@@ -102,8 +103,8 @@ struct nfp_pf_dev {
struct nfp_hwinfo *hwinfo;
struct nfp_rtsym_table *sym_tbl;
- /** Service id of cpp bridge service */
- uint32_t cpp_bridge_id;
+ /** Service info of cpp bridge service */
+ struct nfp_service_info cpp_service_info;
/** Multiple PF configuration */
struct nfp_multi_pf multi_pf;
new file mode 100644
@@ -0,0 +1,117 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Corigine, Inc.
+ * All rights reserved.
+ */
+
+#include "nfp_service.h"
+
+#include "nfpcore/nfp_cpp.h"
+#include "nfp_logs.h"
+
+/* Disable service and try to get service status */
+#define NFP_SERVICE_DISABLE_WAIT_COUNT 3000
+
+static int
+nfp_map_service(struct nfp_service_info *info)
+{
+ int32_t ret;
+ uint32_t slcore = 0;
+ int32_t slcore_count;
+ uint8_t service_count;
+ const char *service_name;
+ uint32_t slcore_array[RTE_MAX_LCORE];
+ uint8_t min_service_count = UINT8_MAX;
+
+ slcore_count = rte_service_lcore_list(slcore_array, RTE_MAX_LCORE);
+ if (slcore_count <= 0) {
+ PMD_DRV_LOG(DEBUG, "No service cores found");
+ return -ENOENT;
+ }
+
+ /*
+ * Find a service core with the least number of services already
+ * registered to it
+ */
+ while (slcore_count--) {
+ service_count = rte_service_lcore_count_services(slcore_array[slcore_count]);
+ if (service_count < min_service_count) {
+ slcore = slcore_array[slcore_count];
+ min_service_count = service_count;
+ }
+ }
+
+ service_name = rte_service_get_name(info->id);
+ PMD_INIT_LOG(INFO, "Mapping service %s to core %u", service_name, slcore);
+
+ ret = rte_service_map_lcore_set(info->id, slcore, 1);
+ if (ret != 0) {
+ PMD_DRV_LOG(DEBUG, "Could not map flower service");
+ return -ENOENT;
+ }
+
+ rte_service_runstate_set(info->id, 1);
+ rte_service_component_runstate_set(info->id, 1);
+ rte_service_lcore_start(slcore);
+ if (rte_service_may_be_active(slcore))
+ PMD_DRV_LOG(INFO, "The service %s is running", service_name);
+ else
+ PMD_DRV_LOG(ERR, "The service %s is not running", service_name);
+
+ info->lcore = slcore;
+
+ return 0;
+}
+
+int
+nfp_service_enable(const struct rte_service_spec *service_spec,
+ struct nfp_service_info *info)
+{
+ int ret;
+
+ /* Register the service */
+ ret = rte_service_component_register(service_spec, &info->id);
+ if (ret != 0) {
+ PMD_DRV_LOG(DEBUG, "Could not register %s", service_spec->name);
+ return -EINVAL;
+ }
+
+ /* Map it to available service core */
+ ret = nfp_map_service(info);
+ if (ret != 0) {
+ PMD_DRV_LOG(DEBUG, "Could not map %s", service_spec->name);
+ return -EINVAL;
+ }
+
+ PMD_DRV_LOG(DEBUG, "Enable service %s successfully", service_spec->name);
+
+ return 0;
+}
+
+int
+nfp_service_disable(struct nfp_service_info *info)
+{
+ uint32_t i;
+ const char *service_name;
+
+ service_name = rte_service_get_name(info->id);
+ if (service_name == NULL) {
+ PMD_DRV_LOG(ERR, "Could not find service %u", info->id);
+ return -EINVAL;
+ }
+
+ rte_service_runstate_set(info->id, 0);
+ rte_service_component_runstate_set(info->id, 0);
+
+ for (i = 0; i < NFP_SERVICE_DISABLE_WAIT_COUNT; i++) {
+ if (rte_service_may_be_active(info->id) == 0)
+ break;
+ rte_delay_ms(1);
+ }
+ if (i == NFP_SERVICE_DISABLE_WAIT_COUNT)
+ PMD_DRV_LOG(ERR, "Could not stop service %s", service_name);
+
+ rte_service_map_lcore_set(info->id, info->lcore, 0);
+ rte_service_component_unregister(info->id);
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Corigine, Inc.
+ * All rights reserved.
+ */
+
+#ifndef __NFP_SERVICE_H__
+#define __NFP_SERVICE_H__
+
+#include <rte_service_component.h>
+
+struct nfp_service_info {
+ uint32_t id;
+ uint32_t lcore;
+};
+
+int nfp_service_disable(struct nfp_service_info *info);
+int nfp_service_enable(const struct rte_service_spec *service_spec,
+ struct nfp_service_info *info);
+
+#endif /* __NFP_SERVICE_H__ */