Skip to content

Commit 7d18af7

Browse files
hechaoyongferruhy
authored andcommitted
net/nfp: support merged flows and conntrack stats
Adjust the original logic to make it valid for both normal flow and merged flow. Add the logic to update conntrack flow stats. Add the support of conntrack action. Signed-off-by: Chaoyong He <[email protected]>
1 parent b4ae16e commit 7d18af7

File tree

4 files changed

+126
-17
lines changed

4 files changed

+126
-17
lines changed

drivers/net/nfp/flower/nfp_conntrack.c

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct nfp_ct_flow_entry {
3939
struct nfp_flower_representor *repr;
4040
struct nfp_ct_zone_entry *ze;
4141
struct nfp_initial_flow rule;
42+
struct nfp_fl_stats stats;
4243
};
4344

4445
struct nfp_ct_map_entry {
@@ -56,6 +57,7 @@ struct nfp_ct_zone_entry {
5657

5758
struct nfp_ct_merge_entry {
5859
uint64_t cookie[2];
60+
uint32_t ctx_id;
5961
LIST_ENTRY(nfp_ct_merge_entry) pre_ct_list;
6062
LIST_ENTRY(nfp_ct_merge_entry) post_ct_list;
6163
struct nfp_initial_flow rule;
@@ -990,12 +992,14 @@ nfp_ct_offload_add(struct nfp_flower_representor *repr,
990992
cookie = rte_rand();
991993
items = merge_entry->rule.items;
992994
actions = merge_entry->rule.actions;
993-
nfp_flow = nfp_flow_process(repr, items, actions, false, cookie, true);
995+
nfp_flow = nfp_flow_process(repr, items, actions, false, cookie, true, true);
994996
if (nfp_flow == NULL) {
995997
PMD_DRV_LOG(ERR, "Process the merged flow rule failed.");
996998
return -EINVAL;
997999
}
9981000

1001+
merge_entry->ctx_id = rte_be_to_cpu_32(nfp_flow->payload.meta->host_ctx_id);
1002+
9991003
/* Add the flow to hardware */
10001004
priv = repr->app_fw_flower->flow_priv;
10011005
ret = nfp_flower_cmsg_flow_add(repr->app_fw_flower, nfp_flow);
@@ -1005,7 +1009,7 @@ nfp_ct_offload_add(struct nfp_flower_representor *repr,
10051009
}
10061010

10071011
/* Add the flow to flow hash table */
1008-
ret = nfp_flow_table_add(priv, nfp_flow);
1012+
ret = nfp_flow_table_add_merge(priv, nfp_flow);
10091013
if (ret != 0) {
10101014
PMD_DRV_LOG(ERR, "Add the merged flow to flow table failed.");
10111015
goto flow_teardown;
@@ -1693,14 +1697,14 @@ nfp_ct_flow_setup(struct nfp_flower_representor *representor,
16931697

16941698
if (is_ct_commit_flow(ct)) {
16951699
return nfp_flow_process(representor, &items[1], actions,
1696-
validate_flag, cookie, false);
1700+
validate_flag, cookie, false, false);
16971701
}
16981702

16991703
if (is_post_ct_flow(ct)) {
17001704
if (nfp_flow_handle_post_ct(ct_item, representor, &items[1],
17011705
actions, cookie)) {
17021706
return nfp_flow_process(representor, &items[1], actions,
1703-
validate_flag, cookie, false);
1707+
validate_flag, cookie, false, false);
17041708
}
17051709

17061710
PMD_DRV_LOG(ERR, "Handle nfp post ct flow failed.");
@@ -1711,7 +1715,7 @@ nfp_ct_flow_setup(struct nfp_flower_representor *representor,
17111715
if (nfp_flow_handle_pre_ct(ct_item, representor, &items[1],
17121716
actions, cookie)) {
17131717
return nfp_flow_process(representor, &items[1], actions,
1714-
validate_flag, cookie, false);
1718+
validate_flag, cookie, false, false);
17151719
}
17161720

17171721
PMD_DRV_LOG(ERR, "Handle nfp pre ct flow failed.");
@@ -1721,3 +1725,43 @@ nfp_ct_flow_setup(struct nfp_flower_representor *representor,
17211725
PMD_DRV_LOG(ERR, "Unsupported ct flow type.");
17221726
return NULL;
17231727
}
1728+
1729+
static inline void
1730+
nfp_ct_flow_stats_update(struct nfp_flow_priv *priv,
1731+
struct nfp_ct_merge_entry *m_ent)
1732+
{
1733+
uint32_t ctx_id;
1734+
struct nfp_fl_stats *merge_stats;
1735+
1736+
ctx_id = m_ent->ctx_id;
1737+
merge_stats = &priv->stats[ctx_id];
1738+
1739+
m_ent->pre_ct_parent->stats.bytes += merge_stats->bytes;
1740+
m_ent->pre_ct_parent->stats.pkts += merge_stats->pkts;
1741+
m_ent->post_ct_parent->stats.bytes += merge_stats->bytes;
1742+
m_ent->post_ct_parent->stats.pkts += merge_stats->pkts;
1743+
1744+
merge_stats->bytes = 0;
1745+
merge_stats->pkts = 0;
1746+
}
1747+
1748+
struct nfp_fl_stats *
1749+
nfp_ct_flow_stats_get(struct nfp_flow_priv *priv,
1750+
struct nfp_ct_map_entry *me)
1751+
{
1752+
struct nfp_ct_merge_entry *m_ent;
1753+
1754+
rte_spinlock_lock(&priv->stats_lock);
1755+
1756+
if (me->fe->type == CT_TYPE_PRE_CT) {
1757+
LIST_FOREACH(m_ent, &me->fe->children, pre_ct_list)
1758+
nfp_ct_flow_stats_update(priv, m_ent);
1759+
} else {
1760+
LIST_FOREACH(m_ent, &me->fe->children, post_ct_list)
1761+
nfp_ct_flow_stats_update(priv, m_ent);
1762+
}
1763+
1764+
rte_spinlock_unlock(&priv->stats_lock);
1765+
1766+
return &me->fe->stats;
1767+
}

drivers/net/nfp/flower/nfp_conntrack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ struct rte_flow *nfp_ct_flow_setup(struct nfp_flower_representor *representor,
3434
bool validate_flag,
3535
uint64_t cookie);
3636

37+
struct nfp_fl_stats *nfp_ct_flow_stats_get(struct nfp_flow_priv *priv,
38+
struct nfp_ct_map_entry *me);
39+
3740
#endif /* __NFP_CONNTRACK_H__ */

drivers/net/nfp/nfp_flow.c

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,14 @@ nfp_check_mask_add(struct nfp_flow_priv *priv,
310310
ret = nfp_mask_table_add(priv, mask_data, mask_len, mask_id);
311311
if (ret != 0)
312312
return false;
313-
314-
*meta_flags |= NFP_FL_META_FLAG_MANAGE_MASK;
315313
} else {
316314
/* mask entry already exist */
317315
mask_entry->ref_cnt++;
318316
*mask_id = mask_entry->mask_id;
319317
}
320318

319+
*meta_flags |= NFP_FL_META_FLAG_MANAGE_MASK;
320+
321321
return true;
322322
}
323323

@@ -349,7 +349,7 @@ nfp_check_mask_remove(struct nfp_flow_priv *priv,
349349
return true;
350350
}
351351

352-
int
352+
static int
353353
nfp_flow_table_add(struct nfp_flow_priv *priv,
354354
struct rte_flow *nfp_flow)
355355
{
@@ -396,6 +396,48 @@ nfp_flow_table_search(struct nfp_flow_priv *priv,
396396
return flow_find;
397397
}
398398

399+
int
400+
nfp_flow_table_add_merge(struct nfp_flow_priv *priv,
401+
struct rte_flow *nfp_flow)
402+
{
403+
struct rte_flow *flow_find;
404+
405+
flow_find = nfp_flow_table_search(priv, nfp_flow);
406+
if (flow_find != NULL) {
407+
if (nfp_flow->merge_flag || flow_find->merge_flag) {
408+
flow_find->merge_flag = true;
409+
flow_find->ref_cnt++;
410+
return 0;
411+
}
412+
413+
PMD_DRV_LOG(ERR, "Add to flow table failed.");
414+
return -EINVAL;
415+
}
416+
417+
return nfp_flow_table_add(priv, nfp_flow);
418+
}
419+
420+
static int
421+
nfp_flow_table_delete_merge(struct nfp_flow_priv *priv,
422+
struct rte_flow *nfp_flow)
423+
{
424+
struct rte_flow *flow_find;
425+
426+
flow_find = nfp_flow_table_search(priv, nfp_flow);
427+
if (flow_find == NULL) {
428+
PMD_DRV_LOG(ERR, "Can't delete a non-existing flow.");
429+
return -EINVAL;
430+
}
431+
432+
if (nfp_flow->merge_flag || flow_find->merge_flag) {
433+
flow_find->ref_cnt--;
434+
if (flow_find->ref_cnt > 0)
435+
return 0;
436+
}
437+
438+
return nfp_flow_table_delete(priv, nfp_flow);
439+
}
440+
399441
static struct rte_flow *
400442
nfp_flow_alloc(struct nfp_fl_key_ls *key_layer, uint32_t port_id)
401443
{
@@ -1082,6 +1124,9 @@ nfp_flow_key_layers_calculate_actions(const struct rte_flow_action actions[],
10821124
return -ENOTSUP;
10831125
}
10841126
break;
1127+
case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1128+
PMD_DRV_LOG(DEBUG, "RTE_FLOW_ACTION_TYPE_CONNTRACK detected");
1129+
break;
10851130
default:
10861131
PMD_DRV_LOG(ERR, "Action type %d not supported.", action->type);
10871132
return -ENOTSUP;
@@ -3626,6 +3671,9 @@ nfp_flow_compile_action(struct nfp_flower_representor *representor,
36263671
return -EINVAL;
36273672
position += sizeof(struct nfp_fl_act_meter);
36283673
break;
3674+
case RTE_FLOW_ACTION_TYPE_CONNTRACK:
3675+
PMD_DRV_LOG(DEBUG, "Process RTE_FLOW_ACTION_TYPE_CONNTRACK");
3676+
break;
36293677
default:
36303678
PMD_DRV_LOG(ERR, "Unsupported action type: %d", action->type);
36313679
return -ENOTSUP;
@@ -3647,7 +3695,8 @@ nfp_flow_process(struct nfp_flower_representor *representor,
36473695
const struct rte_flow_action actions[],
36483696
bool validate_flag,
36493697
uint64_t cookie,
3650-
bool install_flag)
3698+
bool install_flag,
3699+
bool merge_flag)
36513700
{
36523701
int ret;
36533702
char *hash_data;
@@ -3684,6 +3733,7 @@ nfp_flow_process(struct nfp_flower_representor *representor,
36843733
}
36853734

36863735
nfp_flow->install_flag = install_flag;
3736+
nfp_flow->merge_flag = merge_flag;
36873737

36883738
nfp_flow_compile_metadata(priv, nfp_flow, &key_layer, stats_ctx, cookie);
36893739

@@ -3717,7 +3767,7 @@ nfp_flow_process(struct nfp_flower_representor *representor,
37173767

37183768
/* Find the flow in hash table */
37193769
flow_find = nfp_flow_table_search(priv, nfp_flow);
3720-
if (flow_find != NULL) {
3770+
if (flow_find != NULL && !nfp_flow->merge_flag && !flow_find->merge_flag) {
37213771
PMD_DRV_LOG(ERR, "This flow is already exist.");
37223772
if (!nfp_check_mask_remove(priv, mask_data, mask_len,
37233773
&nfp_flow_meta->flags)) {
@@ -3774,7 +3824,7 @@ nfp_flow_setup(struct nfp_flower_representor *representor,
37743824
return nfp_ct_flow_setup(representor, items, actions,
37753825
ct_item, validate_flag, cookie);
37763826

3777-
return nfp_flow_process(representor, items, actions, validate_flag, cookie, true);
3827+
return nfp_flow_process(representor, items, actions, validate_flag, cookie, true, false);
37783828
}
37793829

37803830
int
@@ -3877,7 +3927,7 @@ nfp_flow_create(struct rte_eth_dev *dev,
38773927
}
38783928

38793929
/* Add the flow to flow hash table */
3880-
ret = nfp_flow_table_add(priv, nfp_flow);
3930+
ret = nfp_flow_table_add_merge(priv, nfp_flow);
38813931
if (ret != 0) {
38823932
rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
38833933
NULL, "Add flow to the flow table failed.");
@@ -3988,7 +4038,7 @@ nfp_flow_destroy(struct rte_eth_dev *dev,
39884038
}
39894039

39904040
/* Delete the flow from flow hash table */
3991-
ret = nfp_flow_table_delete(priv, nfp_flow);
4041+
ret = nfp_flow_table_delete_merge(priv, nfp_flow);
39924042
if (ret != 0) {
39934043
rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
39944044
NULL, "Delete flow from the flow table failed.");
@@ -4047,10 +4097,12 @@ nfp_flow_stats_get(struct rte_eth_dev *dev,
40474097
void *data)
40484098
{
40494099
bool reset;
4100+
uint64_t cookie;
40504101
uint32_t ctx_id;
40514102
struct rte_flow *flow;
40524103
struct nfp_flow_priv *priv;
40534104
struct nfp_fl_stats *stats;
4105+
struct nfp_ct_map_entry *me;
40544106
struct rte_flow_query_count *query;
40554107

40564108
priv = nfp_flow_dev_to_priv(dev);
@@ -4064,8 +4116,15 @@ nfp_flow_stats_get(struct rte_eth_dev *dev,
40644116
reset = query->reset;
40654117
memset(query, 0, sizeof(*query));
40664118

4067-
ctx_id = rte_be_to_cpu_32(nfp_flow->payload.meta->host_ctx_id);
4068-
stats = &priv->stats[ctx_id];
4119+
/* Find the flow in ct_map_table */
4120+
cookie = rte_be_to_cpu_64(nfp_flow->payload.meta->host_cookie);
4121+
me = nfp_ct_map_table_search(priv, (char *)&cookie, sizeof(uint64_t));
4122+
if (me != NULL) {
4123+
stats = nfp_ct_flow_stats_get(priv, me);
4124+
} else {
4125+
ctx_id = rte_be_to_cpu_32(nfp_flow->payload.meta->host_ctx_id);
4126+
stats = &priv->stats[ctx_id];
4127+
}
40694128

40704129
rte_spinlock_lock(&priv->stats_lock);
40714130
if (stats->pkts != 0 && stats->bytes != 0) {

drivers/net/nfp/nfp_flow.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ struct rte_flow {
165165
uint32_t port_id;
166166
bool install_flag;
167167
bool tcp_flag; /**< Used in the SET_TP_* action */
168+
bool merge_flag;
168169
enum nfp_flow_type type;
170+
uint16_t ref_cnt;
169171
};
170172

171173
/* Forward declaration */
@@ -181,8 +183,9 @@ struct rte_flow *nfp_flow_process(struct nfp_flower_representor *representor,
181183
const struct rte_flow_action actions[],
182184
bool validate_flag,
183185
uint64_t cookie,
184-
bool install_flag);
185-
int nfp_flow_table_add(struct nfp_flow_priv *priv,
186+
bool install_flag,
187+
bool merge_flag);
188+
int nfp_flow_table_add_merge(struct nfp_flow_priv *priv,
186189
struct rte_flow *nfp_flow);
187190
int nfp_flow_teardown(struct nfp_flow_priv *priv,
188191
struct rte_flow *nfp_flow,

0 commit comments

Comments
 (0)