Add the related data structure and functions, prepare for the encap action of IPv4 tunnel.
Signed-off-by: Chaoyong He <chaoyong...@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderl...@corigine.com> --- drivers/net/nfp/flower/nfp_flower_cmsg.c | 29 ++++++++++ drivers/net/nfp/flower/nfp_flower_cmsg.h | 93 ++++++++++++++++++++++++++++++++ drivers/net/nfp/nfp_flow.c | 88 ++++++++++++++++++++++++++++++ drivers/net/nfp/nfp_flow.h | 27 ++++++++++ 4 files changed, 237 insertions(+) diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.c b/drivers/net/nfp/flower/nfp_flower_cmsg.c index 15d8381..7021d1f 100644 --- a/drivers/net/nfp/flower/nfp_flower_cmsg.c +++ b/drivers/net/nfp/flower/nfp_flower_cmsg.c @@ -246,3 +246,32 @@ return 0; } + +int +nfp_flower_cmsg_tun_neigh_v4_rule(struct nfp_app_fw_flower *app_fw_flower, + struct nfp_flower_cmsg_tun_neigh_v4 *payload) +{ + uint16_t cnt; + size_t msg_len; + struct rte_mbuf *mbuf; + struct nfp_flower_cmsg_tun_neigh_v4 *msg; + + mbuf = rte_pktmbuf_alloc(app_fw_flower->ctrl_pktmbuf_pool); + if (mbuf == NULL) { + PMD_DRV_LOG(DEBUG, "Failed to alloc mbuf for v4 tun neigh"); + return -ENOMEM; + } + + msg_len = sizeof(struct nfp_flower_cmsg_tun_neigh_v4); + msg = nfp_flower_cmsg_init(mbuf, NFP_FLOWER_CMSG_TYPE_TUN_NEIGH, msg_len); + memcpy(msg, payload, msg_len); + + cnt = nfp_flower_ctrl_vnic_xmit(app_fw_flower, mbuf); + if (cnt == 0) { + PMD_DRV_LOG(ERR, "Send cmsg through ctrl vnic failed."); + rte_pktmbuf_free(mbuf); + return -EIO; + } + + return 0; +} diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.h b/drivers/net/nfp/flower/nfp_flower_cmsg.h index 996ba3b..e44e311 100644 --- a/drivers/net/nfp/flower/nfp_flower_cmsg.h +++ b/drivers/net/nfp/flower/nfp_flower_cmsg.h @@ -129,6 +129,36 @@ struct nfp_flower_cmsg_port_mod { rte_be16_t mtu; }; +struct nfp_flower_tun_neigh { + uint8_t dst_mac[RTE_ETHER_ADDR_LEN]; + uint8_t src_mac[RTE_ETHER_ADDR_LEN]; + rte_be32_t port_id; +}; + +/* + * NFP_FLOWER_CMSG_TYPE_TUN_NEIGH_V4 + * Bit 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 + * -----\ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +---------------------------------------------------------------+ + * 0 | DST_IPV4 | + * +---------------------------------------------------------------+ + * 1 | SRC_IPV4 | + * +---------------------------------------------------------------+ + * 2 | DST_MAC_B5_B4_B3_B2 | + * +-------------------------------+-------------------------------+ + * 3 | DST_MAC_B1_B0 | SRC_MAC_B5_B4 | + * +-------------------------------+-------------------------------+ + * 4 | SRC_MAC_B3_B2_B1_B0 | + * +---------------------------------------------------------------+ + * 5 | Egress Port (NFP internal) | + * +---------------------------------------------------------------+ + */ +struct nfp_flower_cmsg_tun_neigh_v4 { + rte_be32_t dst_ipv4; + rte_be32_t src_ipv4; + struct nfp_flower_tun_neigh common; +}; + /* * NFP_FLOWER_CMSG_TYPE_FLOW_STATS * Bit 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 @@ -574,6 +604,67 @@ struct nfp_fl_act_set_tport { rte_be16_t dst_port; }; +/* + * Pre-tunnel + * 3 2 1 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | - | opcode | |jump_id| - |M| - |V| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | ipv6_daddr_127_96 / ipv4_daddr | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | ipv6_daddr_95_64 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | ipv6_daddr_63_32 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | ipv6_daddr_31_0 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +struct nfp_fl_act_pre_tun { + struct nfp_fl_act_head head; + rte_be16_t flags; + union { + rte_be32_t ipv4_dst; + uint8_t ipv6_dst[16]; + }; +}; + +/* + * Set tunnel + * 3 2 1 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | res | opcode | res | len_lw| reserved | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | tun_id0 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | tun_id1 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | reserved | type |r| idx | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | ipv4_flags | ttl | tos | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | reserved_cvs1 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | reserved_cvs2 | reserved_cvs3 | + * | var_flags | var_np | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +struct nfp_fl_act_set_tun { + struct nfp_fl_act_head head; + rte_be16_t reserved; + rte_be64_t tun_id; + rte_be32_t tun_type_index; + rte_be16_t tun_flags; + uint8_t ttl; + uint8_t tos; + rte_be16_t outer_vlan_tpid; + rte_be16_t outer_vlan_tci; + uint8_t tun_len; /* Only valid for NFP_FL_TUNNEL_GENEVE */ + uint8_t reserved2; + rte_be16_t tun_proto; /* Only valid for NFP_FL_TUNNEL_GENEVE */ +} __rte_packed; + int nfp_flower_cmsg_mac_repr(struct nfp_app_fw_flower *app_fw_flower); int nfp_flower_cmsg_repr_reify(struct nfp_app_fw_flower *app_fw_flower, struct nfp_flower_representor *repr); @@ -583,5 +674,7 @@ int nfp_flower_cmsg_flow_delete(struct nfp_app_fw_flower *app_fw_flower, struct rte_flow *flow); int nfp_flower_cmsg_flow_add(struct nfp_app_fw_flower *app_fw_flower, struct rte_flow *flow); +int nfp_flower_cmsg_tun_neigh_v4_rule(struct nfp_app_fw_flower *app_fw_flower, + struct nfp_flower_cmsg_tun_neigh_v4 *payload); #endif /* _NFP_CMSG_H_ */ diff --git a/drivers/net/nfp/nfp_flow.c b/drivers/net/nfp/nfp_flow.c index bbd9dba..f71f8b1 100644 --- a/drivers/net/nfp/nfp_flow.c +++ b/drivers/net/nfp/nfp_flow.c @@ -1772,6 +1772,91 @@ struct nfp_mask_id_entry { tc_hl->reserved = 0; } +__rte_unused static void +nfp_flow_pre_tun_v4_process(struct nfp_fl_act_pre_tun *pre_tun, + rte_be32_t ipv4_dst) +{ + pre_tun->head.jump_id = NFP_FL_ACTION_OPCODE_PRE_TUNNEL; + pre_tun->head.len_lw = sizeof(struct nfp_fl_act_pre_tun) >> NFP_FL_LW_SIZ; + pre_tun->ipv4_dst = ipv4_dst; +} + +__rte_unused static void +nfp_flow_set_tun_process(struct nfp_fl_act_set_tun *set_tun, + enum nfp_flower_tun_type tun_type, + uint64_t tun_id, + uint8_t ttl, + uint8_t tos) +{ + /* Currently only support one pre-tunnel, so index is always 0. */ + uint8_t pretun_idx = 0; + uint32_t tun_type_index; + + tun_type_index = ((tun_type << 4) & 0xf0) | (pretun_idx & 0x07); + + set_tun->head.jump_id = NFP_FL_ACTION_OPCODE_SET_TUNNEL; + set_tun->head.len_lw = sizeof(struct nfp_fl_act_set_tun) >> NFP_FL_LW_SIZ; + set_tun->tun_type_index = rte_cpu_to_be_32(tun_type_index); + set_tun->tun_id = rte_cpu_to_be_64(tun_id); + set_tun->ttl = ttl; + set_tun->tos = tos; +} + +__rte_unused static int +nfp_flower_add_tun_neigh_v4_encap(struct nfp_app_fw_flower *app_fw_flower, + struct nfp_fl_rule_metadata *nfp_flow_meta, + struct nfp_fl_tun *tun, + const struct rte_ether_hdr *eth, + const struct rte_flow_item_ipv4 *ipv4) +{ + struct nfp_fl_tun *tmp; + struct nfp_flow_priv *priv; + struct nfp_flower_in_port *port; + struct nfp_flower_cmsg_tun_neigh_v4 payload; + + tun->payload.v6_flag = 0; + tun->payload.dst.dst_ipv4 = ipv4->hdr.dst_addr; + tun->payload.src.src_ipv4 = ipv4->hdr.src_addr; + memcpy(tun->payload.dst_addr, eth->dst_addr.addr_bytes, RTE_ETHER_ADDR_LEN); + memcpy(tun->payload.src_addr, eth->src_addr.addr_bytes, RTE_ETHER_ADDR_LEN); + + tun->ref_cnt = 1; + priv = app_fw_flower->flow_priv; + LIST_FOREACH(tmp, &priv->nn_list, next) { + if (memcmp(&tmp->payload, &tun->payload, sizeof(struct nfp_fl_tun_entry)) == 0) { + tmp->ref_cnt++; + return 0; + } + } + + LIST_INSERT_HEAD(&priv->nn_list, tun, next); + + port = (struct nfp_flower_in_port *)((char *)nfp_flow_meta + + sizeof(struct nfp_fl_rule_metadata) + + sizeof(struct nfp_flower_meta_tci)); + + memset(&payload, 0, sizeof(struct nfp_flower_cmsg_tun_neigh_v4)); + payload.dst_ipv4 = ipv4->hdr.dst_addr; + payload.src_ipv4 = ipv4->hdr.src_addr; + memcpy(payload.common.dst_mac, eth->dst_addr.addr_bytes, RTE_ETHER_ADDR_LEN); + memcpy(payload.common.src_mac, eth->src_addr.addr_bytes, RTE_ETHER_ADDR_LEN); + payload.common.port_id = port->in_port; + + return nfp_flower_cmsg_tun_neigh_v4_rule(app_fw_flower, &payload); +} + +__rte_unused static int +nfp_flower_del_tun_neigh_v4(struct nfp_app_fw_flower *app_fw_flower, + rte_be32_t ipv4) +{ + struct nfp_flower_cmsg_tun_neigh_v4 payload; + + memset(&payload, 0, sizeof(struct nfp_flower_cmsg_tun_neigh_v4)); + payload.dst_ipv4 = ipv4; + + return nfp_flower_cmsg_tun_neigh_v4_rule(app_fw_flower, &payload); +} + static int nfp_flow_compile_action(__rte_unused struct nfp_flower_representor *representor, const struct rte_flow_action actions[], @@ -2487,6 +2572,9 @@ struct nfp_mask_id_entry { goto free_mask_table; } + /* neighbor next list */ + LIST_INIT(&priv->nn_list); + return 0; free_mask_table: diff --git a/drivers/net/nfp/nfp_flow.h b/drivers/net/nfp/nfp_flow.h index 0ad89e5..892dbc0 100644 --- a/drivers/net/nfp/nfp_flow.h +++ b/drivers/net/nfp/nfp_flow.h @@ -90,6 +90,11 @@ enum nfp_flower_tun_type { NFP_FL_TUN_GENEVE = 4, }; +enum nfp_flow_type { + NFP_FLOW_COMMON, + NFP_FLOW_ENCAP, +}; + struct nfp_fl_key_ls { uint32_t key_layer_two; uint8_t key_layer; @@ -118,6 +123,24 @@ struct nfp_fl_payload { char *action_data; }; +struct nfp_fl_tun { + LIST_ENTRY(nfp_fl_tun) next; + uint8_t ref_cnt; + struct nfp_fl_tun_entry { + uint8_t v6_flag; + uint8_t dst_addr[RTE_ETHER_ADDR_LEN]; + uint8_t src_addr[RTE_ETHER_ADDR_LEN]; + union { + rte_be32_t dst_ipv4; + uint8_t dst_ipv6[16]; + } dst; + union { + rte_be32_t src_ipv4; + uint8_t src_ipv6[16]; + } src; + } payload; +}; + #define CIRC_CNT(head, tail, size) (((head) - (tail)) & ((size) - 1)) #define CIRC_SPACE(head, tail, size) CIRC_CNT((tail), ((head) + 1), (size)) struct circ_buf { @@ -161,13 +184,17 @@ struct nfp_flow_priv { struct nfp_fl_stats_id stats_ids; /**< The stats id ring. */ struct nfp_fl_stats *stats; /**< Store stats of flow. */ rte_spinlock_t stats_lock; /** < Lock the update of 'stats' field. */ + /* neighbor next */ + LIST_HEAD(, nfp_fl_tun)nn_list; /**< Store nn entry */ }; struct rte_flow { struct nfp_fl_payload payload; + struct nfp_fl_tun tun; size_t length; uint32_t hash_key; bool install_flag; + enum nfp_flow_type type; }; int nfp_flow_priv_init(struct nfp_pf_dev *pf_dev); -- 1.8.3.1