|
| 1 | +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
| 2 | +/* Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ |
| 3 | + |
| 4 | +#include "dr_ste_v1.h" |
| 5 | +#include "dr_ste_v2.h" |
| 6 | + |
| 7 | +static void dr_ste_v3_set_encap(u8 *hw_ste_p, u8 *d_action, |
| 8 | + u32 reformat_id, int size) |
| 9 | +{ |
| 10 | + MLX5_SET(ste_double_action_insert_with_ptr_v3, d_action, action_id, |
| 11 | + DR_STE_V1_ACTION_ID_INSERT_POINTER); |
| 12 | + /* The hardware expects here size in words (2 byte) */ |
| 13 | + MLX5_SET(ste_double_action_insert_with_ptr_v3, d_action, size, size / 2); |
| 14 | + MLX5_SET(ste_double_action_insert_with_ptr_v3, d_action, pointer, reformat_id); |
| 15 | + MLX5_SET(ste_double_action_insert_with_ptr_v3, d_action, attributes, |
| 16 | + DR_STE_V1_ACTION_INSERT_PTR_ATTR_ENCAP); |
| 17 | + dr_ste_v1_set_reparse(hw_ste_p); |
| 18 | +} |
| 19 | + |
| 20 | +static void dr_ste_v3_set_push_vlan(u8 *ste, u8 *d_action, |
| 21 | + u32 vlan_hdr) |
| 22 | +{ |
| 23 | + MLX5_SET(ste_double_action_insert_with_inline_v3, d_action, action_id, |
| 24 | + DR_STE_V1_ACTION_ID_INSERT_INLINE); |
| 25 | + /* The hardware expects here offset to vlan header in words (2 byte) */ |
| 26 | + MLX5_SET(ste_double_action_insert_with_inline_v3, d_action, start_offset, |
| 27 | + HDR_LEN_L2_MACS >> 1); |
| 28 | + MLX5_SET(ste_double_action_insert_with_inline_v3, d_action, inline_data, vlan_hdr); |
| 29 | + dr_ste_v1_set_reparse(ste); |
| 30 | +} |
| 31 | + |
| 32 | +static void dr_ste_v3_set_pop_vlan(u8 *hw_ste_p, u8 *s_action, |
| 33 | + u8 vlans_num) |
| 34 | +{ |
| 35 | + MLX5_SET(ste_single_action_remove_header_size_v3, s_action, |
| 36 | + action_id, DR_STE_V1_ACTION_ID_REMOVE_BY_SIZE); |
| 37 | + MLX5_SET(ste_single_action_remove_header_size_v3, s_action, |
| 38 | + start_anchor, DR_STE_HEADER_ANCHOR_1ST_VLAN); |
| 39 | + /* The hardware expects here size in words (2 byte) */ |
| 40 | + MLX5_SET(ste_single_action_remove_header_size_v3, s_action, |
| 41 | + remove_size, (HDR_LEN_L2_VLAN >> 1) * vlans_num); |
| 42 | + |
| 43 | + dr_ste_v1_set_reparse(hw_ste_p); |
| 44 | +} |
| 45 | + |
| 46 | +static void dr_ste_v3_set_encap_l3(u8 *hw_ste_p, |
| 47 | + u8 *frst_s_action, |
| 48 | + u8 *scnd_d_action, |
| 49 | + u32 reformat_id, |
| 50 | + int size) |
| 51 | +{ |
| 52 | + /* Remove L2 headers */ |
| 53 | + MLX5_SET(ste_single_action_remove_header_v3, frst_s_action, action_id, |
| 54 | + DR_STE_V1_ACTION_ID_REMOVE_HEADER_TO_HEADER); |
| 55 | + MLX5_SET(ste_single_action_remove_header_v3, frst_s_action, end_anchor, |
| 56 | + DR_STE_HEADER_ANCHOR_IPV6_IPV4); |
| 57 | + |
| 58 | + /* Encapsulate with given reformat ID */ |
| 59 | + MLX5_SET(ste_double_action_insert_with_ptr_v3, scnd_d_action, action_id, |
| 60 | + DR_STE_V1_ACTION_ID_INSERT_POINTER); |
| 61 | + /* The hardware expects here size in words (2 byte) */ |
| 62 | + MLX5_SET(ste_double_action_insert_with_ptr_v3, scnd_d_action, size, size / 2); |
| 63 | + MLX5_SET(ste_double_action_insert_with_ptr_v3, scnd_d_action, pointer, reformat_id); |
| 64 | + MLX5_SET(ste_double_action_insert_with_ptr_v3, scnd_d_action, attributes, |
| 65 | + DR_STE_V1_ACTION_INSERT_PTR_ATTR_ENCAP); |
| 66 | + |
| 67 | + dr_ste_v1_set_reparse(hw_ste_p); |
| 68 | +} |
| 69 | + |
| 70 | +static void dr_ste_v3_set_rx_decap(u8 *hw_ste_p, u8 *s_action) |
| 71 | +{ |
| 72 | + MLX5_SET(ste_single_action_remove_header_v3, s_action, action_id, |
| 73 | + DR_STE_V1_ACTION_ID_REMOVE_HEADER_TO_HEADER); |
| 74 | + MLX5_SET(ste_single_action_remove_header_v3, s_action, decap, 1); |
| 75 | + MLX5_SET(ste_single_action_remove_header_v3, s_action, vni_to_cqe, 1); |
| 76 | + MLX5_SET(ste_single_action_remove_header_v3, s_action, end_anchor, |
| 77 | + DR_STE_HEADER_ANCHOR_INNER_MAC); |
| 78 | + |
| 79 | + dr_ste_v1_set_reparse(hw_ste_p); |
| 80 | +} |
| 81 | + |
| 82 | +static int |
| 83 | +dr_ste_v3_set_action_decap_l3_list(void *data, u32 data_sz, |
| 84 | + u8 *hw_action, u32 hw_action_sz, |
| 85 | + uint16_t *used_hw_action_num) |
| 86 | +{ |
| 87 | + u8 padded_data[DR_STE_L2_HDR_MAX_SZ] = {}; |
| 88 | + void *data_ptr = padded_data; |
| 89 | + u16 used_actions = 0; |
| 90 | + u32 inline_data_sz; |
| 91 | + u32 i; |
| 92 | + |
| 93 | + if (hw_action_sz / DR_STE_ACTION_DOUBLE_SZ < DR_STE_DECAP_L3_ACTION_NUM) |
| 94 | + return -EINVAL; |
| 95 | + |
| 96 | + inline_data_sz = |
| 97 | + MLX5_FLD_SZ_BYTES(ste_double_action_insert_with_inline_v3, inline_data); |
| 98 | + |
| 99 | + /* Add an alignment padding */ |
| 100 | + memcpy(padded_data + data_sz % inline_data_sz, data, data_sz); |
| 101 | + |
| 102 | + /* Remove L2L3 outer headers */ |
| 103 | + MLX5_SET(ste_single_action_remove_header_v3, hw_action, action_id, |
| 104 | + DR_STE_V1_ACTION_ID_REMOVE_HEADER_TO_HEADER); |
| 105 | + MLX5_SET(ste_single_action_remove_header_v3, hw_action, decap, 1); |
| 106 | + MLX5_SET(ste_single_action_remove_header_v3, hw_action, vni_to_cqe, 1); |
| 107 | + MLX5_SET(ste_single_action_remove_header_v3, hw_action, end_anchor, |
| 108 | + DR_STE_HEADER_ANCHOR_INNER_IPV6_IPV4); |
| 109 | + hw_action += DR_STE_ACTION_DOUBLE_SZ; |
| 110 | + used_actions++; /* Remove and NOP are a single double action */ |
| 111 | + |
| 112 | + /* Point to the last dword of the header */ |
| 113 | + data_ptr += (data_sz / inline_data_sz) * inline_data_sz; |
| 114 | + |
| 115 | + /* Add the new header using inline action 4Byte at a time, the header |
| 116 | + * is added in reversed order to the beginning of the packet to avoid |
| 117 | + * incorrect parsing by the HW. Since header is 14B or 18B an extra |
| 118 | + * two bytes are padded and later removed. |
| 119 | + */ |
| 120 | + for (i = 0; i < data_sz / inline_data_sz + 1; i++) { |
| 121 | + void *addr_inline; |
| 122 | + |
| 123 | + MLX5_SET(ste_double_action_insert_with_inline_v3, hw_action, action_id, |
| 124 | + DR_STE_V1_ACTION_ID_INSERT_INLINE); |
| 125 | + /* The hardware expects here offset to words (2 bytes) */ |
| 126 | + MLX5_SET(ste_double_action_insert_with_inline_v3, hw_action, start_offset, 0); |
| 127 | + |
| 128 | + /* Copy bytes one by one to avoid endianness problem */ |
| 129 | + addr_inline = MLX5_ADDR_OF(ste_double_action_insert_with_inline_v3, |
| 130 | + hw_action, inline_data); |
| 131 | + memcpy(addr_inline, data_ptr - i * inline_data_sz, inline_data_sz); |
| 132 | + hw_action += DR_STE_ACTION_DOUBLE_SZ; |
| 133 | + used_actions++; |
| 134 | + } |
| 135 | + |
| 136 | + /* Remove first 2 extra bytes */ |
| 137 | + MLX5_SET(ste_single_action_remove_header_size_v3, hw_action, action_id, |
| 138 | + DR_STE_V1_ACTION_ID_REMOVE_BY_SIZE); |
| 139 | + MLX5_SET(ste_single_action_remove_header_size_v3, hw_action, start_offset, 0); |
| 140 | + /* The hardware expects here size in words (2 bytes) */ |
| 141 | + MLX5_SET(ste_single_action_remove_header_size_v3, hw_action, remove_size, 1); |
| 142 | + used_actions++; |
| 143 | + |
| 144 | + *used_hw_action_num = used_actions; |
| 145 | + |
| 146 | + return 0; |
| 147 | +} |
| 148 | + |
| 149 | +static struct mlx5dr_ste_ctx ste_ctx_v3 = { |
| 150 | + /* Builders */ |
| 151 | + .build_eth_l2_src_dst_init = &dr_ste_v1_build_eth_l2_src_dst_init, |
| 152 | + .build_eth_l3_ipv6_src_init = &dr_ste_v1_build_eth_l3_ipv6_src_init, |
| 153 | + .build_eth_l3_ipv6_dst_init = &dr_ste_v1_build_eth_l3_ipv6_dst_init, |
| 154 | + .build_eth_l3_ipv4_5_tuple_init = &dr_ste_v1_build_eth_l3_ipv4_5_tuple_init, |
| 155 | + .build_eth_l2_src_init = &dr_ste_v1_build_eth_l2_src_init, |
| 156 | + .build_eth_l2_dst_init = &dr_ste_v1_build_eth_l2_dst_init, |
| 157 | + .build_eth_l2_tnl_init = &dr_ste_v1_build_eth_l2_tnl_init, |
| 158 | + .build_eth_l3_ipv4_misc_init = &dr_ste_v1_build_eth_l3_ipv4_misc_init, |
| 159 | + .build_eth_ipv6_l3_l4_init = &dr_ste_v1_build_eth_ipv6_l3_l4_init, |
| 160 | + .build_mpls_init = &dr_ste_v1_build_mpls_init, |
| 161 | + .build_tnl_gre_init = &dr_ste_v1_build_tnl_gre_init, |
| 162 | + .build_tnl_mpls_init = &dr_ste_v1_build_tnl_mpls_init, |
| 163 | + .build_tnl_mpls_over_udp_init = &dr_ste_v1_build_tnl_mpls_over_udp_init, |
| 164 | + .build_tnl_mpls_over_gre_init = &dr_ste_v1_build_tnl_mpls_over_gre_init, |
| 165 | + .build_icmp_init = &dr_ste_v1_build_icmp_init, |
| 166 | + .build_general_purpose_init = &dr_ste_v1_build_general_purpose_init, |
| 167 | + .build_eth_l4_misc_init = &dr_ste_v1_build_eth_l4_misc_init, |
| 168 | + .build_tnl_vxlan_gpe_init = &dr_ste_v1_build_flex_parser_tnl_vxlan_gpe_init, |
| 169 | + .build_tnl_geneve_init = &dr_ste_v1_build_flex_parser_tnl_geneve_init, |
| 170 | + .build_tnl_geneve_tlv_opt_init = &dr_ste_v1_build_flex_parser_tnl_geneve_tlv_opt_init, |
| 171 | + .build_tnl_geneve_tlv_opt_exist_init = |
| 172 | + &dr_ste_v1_build_flex_parser_tnl_geneve_tlv_opt_exist_init, |
| 173 | + .build_register_0_init = &dr_ste_v1_build_register_0_init, |
| 174 | + .build_register_1_init = &dr_ste_v1_build_register_1_init, |
| 175 | + .build_src_gvmi_qpn_init = &dr_ste_v1_build_src_gvmi_qpn_init, |
| 176 | + .build_flex_parser_0_init = &dr_ste_v1_build_flex_parser_0_init, |
| 177 | + .build_flex_parser_1_init = &dr_ste_v1_build_flex_parser_1_init, |
| 178 | + .build_tnl_gtpu_init = &dr_ste_v1_build_flex_parser_tnl_gtpu_init, |
| 179 | + .build_tnl_header_0_1_init = &dr_ste_v1_build_tnl_header_0_1_init, |
| 180 | + .build_tnl_gtpu_flex_parser_0_init = &dr_ste_v1_build_tnl_gtpu_flex_parser_0_init, |
| 181 | + .build_tnl_gtpu_flex_parser_1_init = &dr_ste_v1_build_tnl_gtpu_flex_parser_1_init, |
| 182 | + |
| 183 | + /* Getters and Setters */ |
| 184 | + .ste_init = &dr_ste_v1_init, |
| 185 | + .set_next_lu_type = &dr_ste_v1_set_next_lu_type, |
| 186 | + .get_next_lu_type = &dr_ste_v1_get_next_lu_type, |
| 187 | + .is_miss_addr_set = &dr_ste_v1_is_miss_addr_set, |
| 188 | + .set_miss_addr = &dr_ste_v1_set_miss_addr, |
| 189 | + .get_miss_addr = &dr_ste_v1_get_miss_addr, |
| 190 | + .set_hit_addr = &dr_ste_v1_set_hit_addr, |
| 191 | + .set_byte_mask = &dr_ste_v1_set_byte_mask, |
| 192 | + .get_byte_mask = &dr_ste_v1_get_byte_mask, |
| 193 | + |
| 194 | + /* Actions */ |
| 195 | + .actions_caps = DR_STE_CTX_ACTION_CAP_TX_POP | |
| 196 | + DR_STE_CTX_ACTION_CAP_RX_PUSH | |
| 197 | + DR_STE_CTX_ACTION_CAP_RX_ENCAP, |
| 198 | + .set_actions_rx = &dr_ste_v1_set_actions_rx, |
| 199 | + .set_actions_tx = &dr_ste_v1_set_actions_tx, |
| 200 | + .modify_field_arr_sz = ARRAY_SIZE(dr_ste_v2_action_modify_field_arr), |
| 201 | + .modify_field_arr = dr_ste_v2_action_modify_field_arr, |
| 202 | + .set_action_set = &dr_ste_v1_set_action_set, |
| 203 | + .set_action_add = &dr_ste_v1_set_action_add, |
| 204 | + .set_action_copy = &dr_ste_v1_set_action_copy, |
| 205 | + .set_action_decap_l3_list = &dr_ste_v3_set_action_decap_l3_list, |
| 206 | + .alloc_modify_hdr_chunk = &dr_ste_v1_alloc_modify_hdr_ptrn_arg, |
| 207 | + .dealloc_modify_hdr_chunk = &dr_ste_v1_free_modify_hdr_ptrn_arg, |
| 208 | + /* Actions bit set */ |
| 209 | + .set_encap = &dr_ste_v3_set_encap, |
| 210 | + .set_push_vlan = &dr_ste_v3_set_push_vlan, |
| 211 | + .set_pop_vlan = &dr_ste_v3_set_pop_vlan, |
| 212 | + .set_rx_decap = &dr_ste_v3_set_rx_decap, |
| 213 | + .set_encap_l3 = &dr_ste_v3_set_encap_l3, |
| 214 | + /* Send */ |
| 215 | + .prepare_for_postsend = &dr_ste_v1_prepare_for_postsend, |
| 216 | +}; |
| 217 | + |
| 218 | +struct mlx5dr_ste_ctx *mlx5dr_ste_get_ctx_v3(void) |
| 219 | +{ |
| 220 | + return &ste_ctx_v3; |
| 221 | +} |
0 commit comments