Skip to content

Commit b4ae16e

Browse files
hechaoyongferruhy
authored andcommitted
net/nfp: support to add and delete flows to firmware
Add the offload call to add and delete the flows to the firmware. Signed-off-by: Chaoyong He <[email protected]>
1 parent 8e55349 commit b4ae16e

File tree

3 files changed

+122
-3
lines changed

3 files changed

+122
-3
lines changed

drivers/net/nfp/flower/nfp_conntrack.c

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <rte_hash.h>
1010
#include <rte_jhash.h>
1111

12-
#include "../nfp_flow.h"
1312
#include "../nfp_logs.h"
13+
#include "nfp_flower_cmsg.h"
1414
#include "nfp_flower_representor.h"
1515

1616
struct ct_data {
@@ -59,6 +59,7 @@ struct nfp_ct_merge_entry {
5959
LIST_ENTRY(nfp_ct_merge_entry) pre_ct_list;
6060
LIST_ENTRY(nfp_ct_merge_entry) post_ct_list;
6161
struct nfp_initial_flow rule;
62+
struct rte_flow *compiled_rule;
6263
struct nfp_ct_zone_entry *ze;
6364
struct nfp_ct_flow_entry *pre_ct_parent;
6465
struct nfp_ct_flow_entry *post_ct_parent;
@@ -975,6 +976,102 @@ nfp_ct_zone_entry_free(struct nfp_ct_zone_entry *ze,
975976
}
976977
}
977978

979+
static int
980+
nfp_ct_offload_add(struct nfp_flower_representor *repr,
981+
struct nfp_ct_merge_entry *merge_entry)
982+
{
983+
int ret;
984+
uint64_t cookie;
985+
struct rte_flow *nfp_flow;
986+
struct nfp_flow_priv *priv;
987+
const struct rte_flow_item *items;
988+
const struct rte_flow_action *actions;
989+
990+
cookie = rte_rand();
991+
items = merge_entry->rule.items;
992+
actions = merge_entry->rule.actions;
993+
nfp_flow = nfp_flow_process(repr, items, actions, false, cookie, true);
994+
if (nfp_flow == NULL) {
995+
PMD_DRV_LOG(ERR, "Process the merged flow rule failed.");
996+
return -EINVAL;
997+
}
998+
999+
/* Add the flow to hardware */
1000+
priv = repr->app_fw_flower->flow_priv;
1001+
ret = nfp_flower_cmsg_flow_add(repr->app_fw_flower, nfp_flow);
1002+
if (ret != 0) {
1003+
PMD_DRV_LOG(ERR, "Add the merged flow to firmware failed.");
1004+
goto flow_teardown;
1005+
}
1006+
1007+
/* Add the flow to flow hash table */
1008+
ret = nfp_flow_table_add(priv, nfp_flow);
1009+
if (ret != 0) {
1010+
PMD_DRV_LOG(ERR, "Add the merged flow to flow table failed.");
1011+
goto flow_teardown;
1012+
}
1013+
1014+
merge_entry->compiled_rule = nfp_flow;
1015+
1016+
return 0;
1017+
1018+
flow_teardown:
1019+
nfp_flow_teardown(priv, nfp_flow, false);
1020+
nfp_flow_free(nfp_flow);
1021+
1022+
return ret;
1023+
}
1024+
1025+
int
1026+
nfp_ct_offload_del(struct rte_eth_dev *dev,
1027+
struct nfp_ct_map_entry *me,
1028+
struct rte_flow_error *error)
1029+
{
1030+
int ret;
1031+
struct nfp_ct_flow_entry *fe;
1032+
struct nfp_ct_merge_entry *m_ent;
1033+
1034+
fe = me->fe;
1035+
1036+
if (fe->type == CT_TYPE_PRE_CT) {
1037+
LIST_FOREACH(m_ent, &fe->children, pre_ct_list) {
1038+
if (m_ent->compiled_rule != NULL) {
1039+
ret = nfp_flow_destroy(dev, m_ent->compiled_rule, error);
1040+
if (ret != 0) {
1041+
PMD_DRV_LOG(ERR, "Could not alloc ct_flow_item");
1042+
return -EINVAL;
1043+
}
1044+
m_ent->compiled_rule = NULL;
1045+
}
1046+
1047+
m_ent->pre_ct_parent = NULL;
1048+
LIST_REMOVE(m_ent, pre_ct_list);
1049+
if (m_ent->post_ct_parent == NULL)
1050+
nfp_ct_merge_entry_destroy(m_ent);
1051+
}
1052+
} else {
1053+
LIST_FOREACH(m_ent, &fe->children, post_ct_list) {
1054+
if (m_ent->compiled_rule != NULL) {
1055+
ret = nfp_flow_destroy(dev, m_ent->compiled_rule, error);
1056+
if (ret != 0) {
1057+
PMD_DRV_LOG(ERR, "Could not alloc ct_flow_item");
1058+
return -EINVAL;
1059+
}
1060+
m_ent->compiled_rule = NULL;
1061+
}
1062+
1063+
m_ent->post_ct_parent = NULL;
1064+
LIST_REMOVE(m_ent, post_ct_list);
1065+
if (m_ent->pre_ct_parent == NULL)
1066+
nfp_ct_merge_entry_destroy(m_ent);
1067+
}
1068+
}
1069+
1070+
nfp_ct_flow_entry_destroy_partly(fe);
1071+
1072+
return 0;
1073+
}
1074+
9781075
static inline bool
9791076
is_item_check_pass(const struct rte_flow_item *item1,
9801077
const struct rte_flow_item *item2,
@@ -1402,8 +1499,17 @@ nfp_ct_do_flow_merge(struct nfp_ct_zone_entry *ze,
14021499
goto free_actions;
14031500
}
14041501

1502+
/* Send to firmware */
1503+
ret = nfp_ct_offload_add(pre_ct_entry->repr, merge_entry);
1504+
if (ret != 0) {
1505+
PMD_DRV_LOG(ERR, "Send the merged flow to firmware failed");
1506+
goto merge_table_del;
1507+
}
1508+
14051509
return true;
14061510

1511+
merge_table_del:
1512+
nfp_ct_merge_table_delete(ze, merge_entry);
14071513
free_actions:
14081514
rte_free(merge_entry->rule.actions);
14091515
free_items:
@@ -1490,7 +1596,7 @@ nfp_flow_handle_pre_ct(const struct rte_flow_item *ct_item,
14901596
}
14911597
}
14921598

1493-
/* The real offload logic comes in next commit, so here just return false for now */
1599+
return true;
14941600

14951601
ct_flow_entry_free:
14961602
nfp_ct_flow_entry_destroy(fe);
@@ -1559,7 +1665,7 @@ nfp_flow_handle_post_ct(const struct rte_flow_item *ct_item,
15591665
if (!ret)
15601666
goto ct_flow_entry_free;
15611667

1562-
/* The real offload logic comes in next commit, so here just return false for now */
1668+
return true;
15631669

15641670
ct_flow_entry_free:
15651671
nfp_ct_flow_entry_destroy(fe);

drivers/net/nfp/flower/nfp_conntrack.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <stdbool.h>
1010

11+
#include <ethdev_driver.h>
1112
#include <rte_flow.h>
1213

1314
#include "../nfp_flow.h"
@@ -22,6 +23,10 @@ struct nfp_ct_map_entry *nfp_ct_map_table_search(struct nfp_flow_priv *priv,
2223
char *hash_data,
2324
uint32_t hash_len);
2425

26+
int nfp_ct_offload_del(struct rte_eth_dev *dev,
27+
struct nfp_ct_map_entry *me,
28+
struct rte_flow_error *error);
29+
2530
struct rte_flow *nfp_ct_flow_setup(struct nfp_flower_representor *representor,
2631
const struct rte_flow_item items[],
2732
const struct rte_flow_action actions[],

drivers/net/nfp/nfp_flow.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,15 +3911,23 @@ nfp_flow_destroy(struct rte_eth_dev *dev,
39113911
struct rte_flow_error *error)
39123912
{
39133913
int ret;
3914+
uint64_t cookie;
39143915
struct rte_flow *flow_find;
39153916
struct nfp_flow_priv *priv;
3917+
struct nfp_ct_map_entry *me;
39163918
struct nfp_app_fw_flower *app_fw_flower;
39173919
struct nfp_flower_representor *representor;
39183920

39193921
representor = dev->data->dev_private;
39203922
app_fw_flower = representor->app_fw_flower;
39213923
priv = app_fw_flower->flow_priv;
39223924

3925+
/* Find the flow in ct_map_table */
3926+
cookie = rte_be_to_cpu_64(nfp_flow->payload.meta->host_cookie);
3927+
me = nfp_ct_map_table_search(priv, (char *)&cookie, sizeof(uint64_t));
3928+
if (me != NULL)
3929+
return nfp_ct_offload_del(dev, me, error);
3930+
39233931
/* Find the flow in flow hash table */
39243932
flow_find = nfp_flow_table_search(priv, nfp_flow);
39253933
if (flow_find == NULL) {

0 commit comments

Comments
 (0)