From: Long Wu <long...@corigine.com> After bonding port notification and firmware created the bonding port, NFP rte_flow rule adds support for destination port to bonding port.
Signed-off-by: Long Wu <long...@corigine.com> Reviewed-by: Peng Zhang <peng.zh...@corigine.com> Reviewed-by: Chaoyong He <chaoyong...@corigine.com> --- drivers/net/nfp/flower/nfp_flower_bond.c | 22 +++ drivers/net/nfp/flower/nfp_flower_bond.h | 6 + drivers/net/nfp/flower/nfp_flower_cmsg.h | 9 + drivers/net/nfp/flower/nfp_flower_flow.c | 232 +++++++++++++++++++++-- 4 files changed, 252 insertions(+), 17 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower_bond.c b/drivers/net/nfp/flower/nfp_flower_bond.c index c809465ffc..6e4d60659a 100644 --- a/drivers/net/nfp/flower/nfp_flower_bond.c +++ b/drivers/net/nfp/flower/nfp_flower_bond.c @@ -667,3 +667,25 @@ nfp_flower_bond_fw_create_get(struct rte_eth_dev *bond_dev, return ret; } + +int +nfp_flower_bond_get_output_id(struct nfp_flower_bond *nfp_bond, + const struct rte_eth_dev *bond_dev, + uint32_t *group_id) +{ + struct nfp_bond_group *group; + + pthread_mutex_lock(&nfp_bond->mutex); + + group = nfp_flower_bond_find_group(nfp_bond, bond_dev); + if (group == NULL) { + pthread_mutex_unlock(&nfp_bond->mutex); + return -ENOENT; + } + + *group_id = group->group_id; + + pthread_mutex_unlock(&nfp_bond->mutex); + + return 0; +} diff --git a/drivers/net/nfp/flower/nfp_flower_bond.h b/drivers/net/nfp/flower/nfp_flower_bond.h index 91d7d88b8c..6debe32549 100644 --- a/drivers/net/nfp/flower/nfp_flower_bond.h +++ b/drivers/net/nfp/flower/nfp_flower_bond.h @@ -44,6 +44,9 @@ /** We store 100(101-1) mbufs but queue needs 101 */ #define NFP_FL_BOND_RETRANS_LIMIT 101 +/* Flow output action of bonding port */ +#define NFP_FL_BOND_OUT 0xC0DE0000 + enum nfp_flower_bond_batch { NFP_FLOWER_BOND_BATCH_FIRST, NFP_FLOWER_BOND_BATCH_MEMBER, @@ -155,5 +158,8 @@ int nfp_fl_bond_put_unprocessed(struct nfp_flower_bond *nfp_bond, struct rte_mbuf *mbuf); int nfp_flower_bond_fw_create_get(struct rte_eth_dev *bond_dev, struct rte_eth_dev *nfp_dev); +int nfp_flower_bond_get_output_id(struct nfp_flower_bond *nfp_bond, + const struct rte_eth_dev *bond_dev, + uint32_t *group_id); #endif /* __NFP_FLOWER_BOND_H__ */ diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.h b/drivers/net/nfp/flower/nfp_flower_cmsg.h index 60ab58a3b1..17ef943855 100644 --- a/drivers/net/nfp/flower/nfp_flower_cmsg.h +++ b/drivers/net/nfp/flower/nfp_flower_cmsg.h @@ -712,6 +712,15 @@ struct nfp_fl_act_head { uint8_t len_lw; }; +#define NFP_FL_PRE_BOND_VER_OFF 8 + +struct nfp_fl_pre_bond { + struct nfp_fl_act_head head; + rte_be16_t group_id; + uint8_t lag_version[3]; + uint8_t instance; +}; + struct nfp_fl_act_output { struct nfp_fl_act_head head; rte_be16_t flags; diff --git a/drivers/net/nfp/flower/nfp_flower_flow.c b/drivers/net/nfp/flower/nfp_flower_flow.c index e26be30d18..6e21ad8c26 100644 --- a/drivers/net/nfp/flower/nfp_flower_flow.c +++ b/drivers/net/nfp/flower/nfp_flower_flow.c @@ -5,12 +5,14 @@ #include "nfp_flower_flow.h" +#include <rte_eth_bond.h> #include <rte_flow_driver.h> #include <rte_hash.h> #include <rte_jhash.h> #include <rte_malloc.h> #include "flower/nfp_conntrack.h" +#include "flower/nfp_flower_bond.h" #include "flower/nfp_flower_representor.h" #include "nfpcore/nfp_rtsym.h" #include "nfp_logs.h" @@ -969,9 +971,23 @@ nfp_flow_key_layers_calculate_items(const struct rte_flow_item items[], return 0; } +static bool +nfp_flow_check_bond_action(struct nfp_flower_representor *representor, + uint32_t port_id) +{ + struct rte_eth_dev *bond_dev = &rte_eth_devices[port_id]; + + if (nfp_flower_support_bond_offload(representor->app_fw_flower) || + !nfp_flower_bond_all_member_are_phyrepr(bond_dev)) + return false; + + return true; +} + static int nfp_flow_key_layers_calculate_actions(const struct rte_flow_action actions[], - struct nfp_fl_key_ls *key_ls) + struct nfp_fl_key_ls *key_ls, + struct nfp_flower_representor *representor) { int ret = 0; bool meter_flag = false; @@ -981,6 +997,8 @@ nfp_flow_key_layers_calculate_actions(const struct rte_flow_action actions[], bool mac_set_flag = false; bool ttl_tos_flag = false; const struct rte_flow_action *action; + const struct rte_flow_action_port_id *port_id; + const struct rte_flow_action_ethdev *action_ethdev; for (action = actions; action->type != RTE_FLOW_ACTION_TYPE_END; ++action) { /* Make sure actions length no longer than NFP_FL_MAX_A_SIZ */ @@ -1006,10 +1024,36 @@ nfp_flow_key_layers_calculate_actions(const struct rte_flow_action actions[], case RTE_FLOW_ACTION_TYPE_PORT_ID: PMD_DRV_LOG(DEBUG, "RTE_FLOW_ACTION_TYPE_PORT_ID detected"); key_ls->act_size += sizeof(struct nfp_fl_act_output); + + port_id = action->conf; + if (port_id == NULL) + return -ERANGE; + + if (!rte_eth_bond_is_valid_port(port_id->id)) + break; + + if (!nfp_flow_check_bond_action(representor, port_id->id)) + return -ENOTSUP; + + /* We only add when all checks have passed */ + key_ls->act_size += sizeof(struct nfp_fl_pre_bond); break; case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: PMD_DRV_LOG(DEBUG, "RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT detected"); key_ls->act_size += sizeof(struct nfp_fl_act_output); + + action_ethdev = action->conf; + if (action_ethdev == NULL) + return -ERANGE; + + if (!rte_eth_bond_is_valid_port(action_ethdev->port_id)) + break; + + if (!nfp_flow_check_bond_action(representor, action_ethdev->port_id)) + return -ENOTSUP; + + /* We only add when all checks have passed */ + key_ls->act_size += sizeof(struct nfp_fl_pre_bond); break; case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC: PMD_DRV_LOG(DEBUG, "RTE_FLOW_ACTION_TYPE_SET_MAC_SRC detected"); @@ -1150,7 +1194,8 @@ nfp_flow_key_layers_calculate_actions(const struct rte_flow_action actions[], static int nfp_flow_key_layers_calculate(const struct rte_flow_item items[], const struct rte_flow_action actions[], - struct nfp_fl_key_ls *key_ls) + struct nfp_fl_key_ls *key_ls, + struct nfp_flower_representor *representor) { int ret = 0; @@ -1164,7 +1209,7 @@ nfp_flow_key_layers_calculate(const struct rte_flow_item items[], key_ls->tun_type = NFP_FL_TUN_NONE; ret |= nfp_flow_key_layers_calculate_items(items, key_ls); - ret |= nfp_flow_key_layers_calculate_actions(actions, key_ls); + ret |= nfp_flow_key_layers_calculate_actions(actions, key_ls, representor); return ret; } @@ -2160,12 +2205,45 @@ nfp_flow_compile_items(struct nfp_flower_representor *representor, return 0; } +static int +nfp_flower_bond_populate_pre_action(struct nfp_flower_representor *repr, + struct rte_eth_dev *bond_dev, + struct nfp_fl_pre_bond *pre_bond) +{ + rte_be32_t version; + struct nfp_bond_group *group; + struct nfp_flower_bond *nfp_bond; + + nfp_bond = repr->app_fw_flower->nfp_bond; + + pthread_mutex_lock(&nfp_bond->mutex); + + group = nfp_flower_bond_find_group(nfp_bond, bond_dev); + if (group == NULL) { + pthread_mutex_unlock(&nfp_bond->mutex); + PMD_DRV_LOG(ERR, "Invalid entry: group does not exist for bond action"); + return -ENOENT; + } + + pre_bond->group_id = rte_cpu_to_be_16(group->group_id); + version = rte_cpu_to_be_32(nfp_bond->batch_ver << NFP_FL_PRE_BOND_VER_OFF); + memcpy(pre_bond->lag_version, &version, 3); + pre_bond->instance = group->group_inst; + + pthread_mutex_unlock(&nfp_bond->mutex); + + return 0; +} + static int nfp_flow_action_output(char *act_data, const struct rte_flow_action *action, struct nfp_fl_rule_metadata *nfp_flow_meta, - uint32_t output_cnt) + uint32_t output_cnt, + struct nfp_flower_bond *nfp_bond, + bool *bonding_port) { + uint32_t gid; size_t act_size; struct rte_eth_dev *ethdev; struct nfp_fl_act_output *output; @@ -2177,18 +2255,31 @@ nfp_flow_action_output(char *act_data, return -ERANGE; ethdev = &rte_eth_devices[port_id->id]; - representor = ethdev->data->dev_private; + output = (struct nfp_fl_act_output *)act_data; + if (rte_eth_bond_is_valid_port(port_id->id)) { + /* Output port is bonding port */ + if (nfp_flower_bond_get_output_id(nfp_bond, ethdev, &gid) != 0) { + PMD_DRV_LOG(ERR, "Cannot find group id for bond action"); + return -EINVAL; + } + + output->port = rte_cpu_to_be_32(NFP_FL_BOND_OUT | gid); + nfp_flow_meta->shortcut = rte_cpu_to_be_32(NFP_FL_SC_ACT_NULL); + *bonding_port = true; + } else { + representor = ethdev->data->dev_private; + + output->port = rte_cpu_to_be_32(representor->port_id); + nfp_flow_meta->shortcut = rte_cpu_to_be_32(representor->port_id); + } + act_size = sizeof(struct nfp_fl_act_output); - output = (struct nfp_fl_act_output *)act_data; output->head.jump_id = NFP_FL_ACTION_OPCODE_OUTPUT; output->head.len_lw = act_size >> NFP_FL_LW_SIZ; - output->port = rte_cpu_to_be_32(representor->port_id); if (output_cnt == 0) output->flags = rte_cpu_to_be_16(NFP_FL_OUT_FLAGS_LAST); - nfp_flow_meta->shortcut = rte_cpu_to_be_32(representor->port_id); - return 0; } @@ -2196,8 +2287,11 @@ static int nfp_flow_action_output_stage(char *act_data, const struct rte_flow_action *action, struct nfp_fl_rule_metadata *nfp_flow_meta, - uint32_t output_cnt) + uint32_t output_cnt, + struct nfp_flower_bond *nfp_bond, + bool *bonding_port) { + uint32_t gid; size_t act_size; struct rte_eth_dev *ethdev; struct nfp_fl_act_output *output; @@ -2209,17 +2303,70 @@ nfp_flow_action_output_stage(char *act_data, return -ERANGE; ethdev = &rte_eth_devices[action_ethdev->port_id]; - representor = ethdev->data->dev_private; + output = (struct nfp_fl_act_output *)act_data; + if (rte_eth_bond_is_valid_port(action_ethdev->port_id)) { + /* Output port is bonding port */ + if (nfp_flower_bond_get_output_id(nfp_bond, ethdev, &gid) != 0) { + PMD_DRV_LOG(ERR, "Cannot find group id for bond action"); + return -EINVAL; + } + + output->port = rte_cpu_to_be_32(NFP_FL_BOND_OUT | gid); + nfp_flow_meta->shortcut = rte_cpu_to_be_32(NFP_FL_SC_ACT_NULL); + *bonding_port = true; + } else { + representor = ethdev->data->dev_private; + + output->port = rte_cpu_to_be_32(representor->port_id); + nfp_flow_meta->shortcut = rte_cpu_to_be_32(representor->port_id); + } + act_size = sizeof(struct nfp_fl_act_output); - output = (struct nfp_fl_act_output *)act_data; output->head.jump_id = NFP_FL_ACTION_OPCODE_OUTPUT; output->head.len_lw = act_size >> NFP_FL_LW_SIZ; - output->port = rte_cpu_to_be_32(representor->port_id); if (output_cnt == 0) output->flags = rte_cpu_to_be_16(NFP_FL_OUT_FLAGS_LAST); - nfp_flow_meta->shortcut = rte_cpu_to_be_32(representor->port_id); + return 0; +} + +static int +nfp_flow_pre_bond(struct nfp_flower_representor *representor, + char *act_data, + char *actions, + const struct rte_flow_action *action) +{ + int err; + int act_len; + uint32_t port_id; + struct rte_eth_dev *ethdev; + struct nfp_fl_pre_bond *pre_bond; + uint32_t pre_bond_size = sizeof(struct nfp_fl_pre_bond); + + act_len = act_data - actions; + + if (act_len + pre_bond_size > NFP_FL_MAX_A_SIZ) { + PMD_DRV_LOG(ERR, "Maximum allowed action list size exceeded at bond action"); + return -EOPNOTSUPP; + } + + if (act_len != 0) + memmove(actions + pre_bond_size, actions, act_len); + + if (action->type == RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT) + port_id = ((const struct rte_flow_action_ethdev *)action->conf)->port_id; + else + port_id = ((const struct rte_flow_action_port_id *)action->conf)->id; + + ethdev = &rte_eth_devices[port_id]; + pre_bond = (struct nfp_fl_pre_bond *)actions; + err = nfp_flower_bond_populate_pre_action(representor, ethdev, pre_bond); + if (err != 0) + return err; + + pre_bond->head.jump_id = NFP_FL_ACTION_OPCODE_PRE_LAG; + pre_bond->head.len_lw = pre_bond_size >> NFP_FL_LW_SIZ; return 0; } @@ -3502,6 +3649,13 @@ nfp_flow_count_output(const struct rte_flow_action actions[]) return count; } +static bool +nfp_flow_check_action_first(const struct rte_flow_action actions[], + uint32_t count) +{ + return ((nfp_flow_count_output(actions) - count) == 1); +} + static int nfp_flow_compile_action(struct nfp_flower_representor *representor, const struct rte_flow_action actions[], @@ -3517,7 +3671,9 @@ nfp_flow_compile_action(struct nfp_flower_representor *representor, bool tp_set_flag = false; bool mac_set_flag = false; bool ttl_tos_flag = false; + bool bonding_port = false; uint32_t total_actions = 0; + struct nfp_flower_bond *nfp_bond; const struct rte_flow_action *action; struct nfp_flower_meta_tci *meta_tci; struct nfp_fl_rule_metadata *nfp_flow_meta; @@ -3546,7 +3702,10 @@ nfp_flow_compile_action(struct nfp_flower_representor *representor, case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: PMD_DRV_LOG(DEBUG, "Process RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT"); count--; - ret = nfp_flow_action_output_stage(position, action, nfp_flow_meta, count); + + nfp_bond = representor->app_fw_flower->nfp_bond; + ret = nfp_flow_action_output_stage(position, action, + nfp_flow_meta, count, nfp_bond, &bonding_port); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed when process" " RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT"); @@ -3554,11 +3713,32 @@ nfp_flow_compile_action(struct nfp_flower_representor *representor, } position += sizeof(struct nfp_fl_act_output); + + /* Output port is not a bonding port */ + if (!bonding_port) + break; + + if (!nfp_flow_check_action_first(actions, count)) { + PMD_DRV_LOG(ERR, "Bond action should be first"); + return -EOPNOTSUPP; + } + + ret = nfp_flow_pre_bond(representor, position, + action_data, action); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Bond action special move failed"); + return ret; + } + + position += sizeof(struct nfp_fl_pre_bond); break; case RTE_FLOW_ACTION_TYPE_PORT_ID: PMD_DRV_LOG(DEBUG, "Process RTE_FLOW_ACTION_TYPE_PORT_ID"); count--; - ret = nfp_flow_action_output(position, action, nfp_flow_meta, count); + + nfp_bond = representor->app_fw_flower->nfp_bond; + ret = nfp_flow_action_output(position, action, + nfp_flow_meta, count, nfp_bond, &bonding_port); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed when process" " RTE_FLOW_ACTION_TYPE_PORT_ID"); @@ -3566,6 +3746,24 @@ nfp_flow_compile_action(struct nfp_flower_representor *representor, } position += sizeof(struct nfp_fl_act_output); + + /* Output port is not a bonding port */ + if (!bonding_port) + break; + + if (!nfp_flow_check_action_first(actions, count)) { + PMD_DRV_LOG(ERR, "Bond action should be first"); + return -EOPNOTSUPP; + } + + ret = nfp_flow_pre_bond(representor, position, + action_data, action); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Bond action special move failed"); + return ret; + } + + position += sizeof(struct nfp_fl_pre_bond); break; case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC: PMD_DRV_LOG(DEBUG, "Process RTE_FLOW_ACTION_TYPE_SET_MAC_SRC"); @@ -3770,7 +3968,7 @@ nfp_flow_process(struct nfp_flower_representor *representor, struct nfp_fl_key_ls key_layer; struct nfp_fl_rule_metadata *nfp_flow_meta; - ret = nfp_flow_key_layers_calculate(items, actions, &key_layer); + ret = nfp_flow_key_layers_calculate(items, actions, &key_layer, representor); if (ret != 0) { PMD_DRV_LOG(ERR, "Key layers calculate failed."); return NULL; -- 2.39.1