Skip to content

Commit dfa6257

Browse files
wulong2022ferruhy
authored andcommitted
net/nfp: enhance flower service framework
Some DPDK applications may not have the service core which can be used for the NFP flower service, so enhance the flower service framework by adding an alarm for this situation. Signed-off-by: Long Wu <[email protected]> Reviewed-by: Chaoyong He <[email protected]>
1 parent ad88999 commit dfa6257

File tree

1 file changed

+65
-5
lines changed

1 file changed

+65
-5
lines changed

drivers/net/nfp/flower/nfp_flower_service.c

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "nfp_flower_service.h"
77

8+
#include <rte_alarm.h>
89
#include <rte_spinlock.h>
910

1011
#include "nfp_flower_ctrl.h"
@@ -16,9 +17,13 @@
1617
/* Driver limitation, PMD can enlarge it if need. */
1718
#define MAX_FLOWER_SERVICE_SLOT 8
1819

20+
#define FLOWER_ALARM_INTERVAL 3000
21+
1922
struct nfp_flower_service {
2023
/** Flower service is enabled */
2124
bool service_enabled;
25+
/** Flower alarm is enabled */
26+
bool alarm_enabled;
2227
/** Flower service info */
2328
struct nfp_service_info info;
2429
/** Store flower cards' information */
@@ -33,6 +38,52 @@ nfp_flower_service_handle_get(struct nfp_net_hw_priv *hw_priv)
3338
return hw_priv->pf_dev->process_share.fl_service;
3439
}
3540

41+
static void
42+
nfp_flower_service_alarm_func(void *arg)
43+
{
44+
int ret;
45+
uint16_t slot;
46+
struct nfp_net_hw_priv *hw_priv;
47+
struct nfp_flower_service *service_handle;
48+
49+
service_handle = arg;
50+
if (!service_handle->alarm_enabled)
51+
goto alarm_set;
52+
53+
rte_spinlock_lock(&service_handle->spinlock);
54+
for (slot = 0; slot < MAX_FLOWER_SERVICE_SLOT; slot++) {
55+
hw_priv = service_handle->slots[slot];
56+
if (hw_priv == NULL)
57+
continue;
58+
59+
nfp_flower_ctrl_vnic_process(hw_priv);
60+
}
61+
rte_spinlock_unlock(&service_handle->spinlock);
62+
63+
alarm_set:
64+
ret = rte_eal_alarm_set(FLOWER_ALARM_INTERVAL, nfp_flower_service_alarm_func, arg);
65+
if (ret < 0)
66+
PMD_DRV_LOG(ERR, "Set flower service alarm failed.");
67+
}
68+
69+
static int
70+
nfp_flower_service_alarm_enable(struct nfp_flower_service *service_handle)
71+
{
72+
int ret;
73+
74+
ret = rte_eal_alarm_set(FLOWER_ALARM_INTERVAL, nfp_flower_service_alarm_func,
75+
(void *)service_handle);
76+
if (ret < 0) {
77+
PMD_DRV_LOG(ERR, "Flower service alarm initialization failed.");
78+
return ret;
79+
}
80+
81+
rte_spinlock_init(&service_handle->spinlock);
82+
service_handle->alarm_enabled = true;
83+
84+
return 0;
85+
}
86+
3687
static int
3788
nfp_flower_service_func(void *arg)
3889
{
@@ -109,11 +160,15 @@ nfp_flower_service_start(struct nfp_net_hw_priv *hw_priv)
109160
}
110161

111162
/* Enable flower service when driver initializes the first NIC */
112-
if (!service_handle->service_enabled) {
163+
if (!service_handle->service_enabled && !service_handle->alarm_enabled) {
113164
ret = nfp_flower_service_enable(service_handle);
114165
if (ret != 0) {
115-
PMD_DRV_LOG(ERR, "Could not enable flower service");
116-
return -ESRCH;
166+
PMD_DRV_LOG(INFO, "Could not enable flower service.");
167+
ret = nfp_flower_service_alarm_enable(service_handle);
168+
if (ret != 0) {
169+
PMD_DRV_LOG(ERR, "Could not set flower service alarm.");
170+
return ret;
171+
}
117172
}
118173
}
119174

@@ -157,8 +212,13 @@ nfp_flower_service_stop(struct nfp_net_hw_priv *hw_priv)
157212
if (count > 1)
158213
return;
159214

160-
if (nfp_service_disable(&service_handle->info) != 0)
161-
PMD_DRV_LOG(ERR, "Could not disable service");
215+
if (service_handle->service_enabled) {
216+
if (nfp_service_disable(&service_handle->info) != 0)
217+
PMD_DRV_LOG(ERR, "Could not disable service.");
218+
} else if (service_handle->alarm_enabled) {
219+
rte_eal_alarm_cancel(nfp_flower_service_alarm_func,
220+
(void *)service_handle);
221+
}
162222
}
163223

164224
int

0 commit comments

Comments
 (0)