@@ -85,13 +85,47 @@ struct flow_nic_dev {
enum flow_nic_err_msg_e {
ERR_SUCCESS = 0,
ERR_FAILED = 1,
+ ERR_MEMORY = 2,
ERR_OUTPUT_TOO_MANY = 3,
+ ERR_RSS_TOO_MANY_QUEUES = 4,
+ ERR_VLAN_TYPE_NOT_SUPPORTED = 5,
+ ERR_VXLAN_HEADER_NOT_ACCEPTED = 6,
+ ERR_VXLAN_POP_INVALID_RECIRC_PORT = 7,
+ ERR_VXLAN_POP_FAILED_CREATING_VTEP = 8,
+ ERR_MATCH_VLAN_TOO_MANY = 9,
+ ERR_MATCH_INVALID_IPV6_HDR = 10,
+ ERR_MATCH_TOO_MANY_TUNNEL_PORTS = 11,
ERR_MATCH_INVALID_OR_UNSUPPORTED_ELEM = 12,
+ ERR_MATCH_FAILED_BY_HW_LIMITS = 13,
ERR_MATCH_RESOURCE_EXHAUSTION = 14,
+ ERR_MATCH_FAILED_TOO_COMPLEX = 15,
+ ERR_ACTION_REPLICATION_FAILED = 16,
+ ERR_ACTION_OUTPUT_RESOURCE_EXHAUSTION = 17,
+ ERR_ACTION_TUNNEL_HEADER_PUSH_OUTPUT_LIMIT = 18,
+ ERR_ACTION_INLINE_MOD_RESOURCE_EXHAUSTION = 19,
+ ERR_ACTION_RETRANSMIT_RESOURCE_EXHAUSTION = 20,
+ ERR_ACTION_FLOW_COUNTER_EXHAUSTION = 21,
+ ERR_ACTION_INTERNAL_RESOURCE_EXHAUSTION = 22,
+ ERR_INTERNAL_QSL_COMPARE_FAILED = 23,
+ ERR_INTERNAL_CAT_FUNC_REUSE_FAILED = 24,
+ ERR_MATCH_ENTROPHY_FAILED = 25,
+ ERR_MATCH_CAM_EXHAUSTED = 26,
+ ERR_INTERNAL_VIRTUAL_PORT_CREATION_FAILED = 27,
ERR_ACTION_UNSUPPORTED = 28,
ERR_REMOVE_FLOW_FAILED = 29,
+ ERR_ACTION_NO_OUTPUT_DEFINED_USE_DEFAULT = 30,
+ ERR_ACTION_NO_OUTPUT_QUEUE_FOUND = 31,
+ ERR_MATCH_UNSUPPORTED_ETHER_TYPE = 32,
ERR_OUTPUT_INVALID = 33,
+ ERR_MATCH_PARTIAL_OFFLOAD_NOT_SUPPORTED = 34,
+ ERR_MATCH_CAT_CAM_EXHAUSTED = 35,
+ ERR_MATCH_KCC_KEY_CLASH = 36,
+ ERR_MATCH_CAT_CAM_FAILED = 37,
+ ERR_PARTIAL_FLOW_MARK_TOO_BIG = 38,
+ ERR_FLOW_PRIORITY_VALUE_INVALID = 39,
ERR_ACTION_MULTIPLE_PORT_ID_UNSUPPORTED = 40,
+ ERR_RSS_TOO_LONG_KEY = 41,
+ ERR_ACTION_AGE_UNSUPPORTED_GROUP_0 = 42,
ERR_MSG_NO_MSG
};
@@ -54,6 +54,30 @@ enum res_type_e {
#define MAX_CPY_WRITERS_SUPPORTED 8
+#define MAX_MATCH_FIELDS 16
+
+struct match_elem_s {
+ int masked_for_tcam; /* if potentially selected for TCAM */
+ uint32_t e_word[4];
+ uint32_t e_mask[4];
+
+ int extr_start_offs_id;
+ int8_t rel_offs;
+ uint32_t word_len;
+};
+
+struct km_flow_def_s {
+ struct flow_api_backend_s *be;
+
+ /* For collect flow elements and sorting */
+ struct match_elem_s match[MAX_MATCH_FIELDS];
+ int num_ftype_elem;
+
+ /* Flow information */
+ /* HW input port ID needed for compare. In port must be identical on flow types */
+ uint32_t port_id;
+};
+
enum flow_port_type_e {
PORT_NONE, /* not defined or drop */
PORT_INTERNAL, /* no queues attached */
@@ -99,6 +123,25 @@ struct nic_flow_def {
uint32_t jump_to_group;
int full_offload;
+
+ /*
+ * Modify field
+ */
+ struct {
+ uint32_t select;
+ union {
+ uint8_t value8[16];
+ uint16_t value16[8];
+ uint32_t value32[4];
+ };
+ } modify_field[MAX_CPY_WRITERS_SUPPORTED];
+
+ uint32_t modify_field_count;
+
+ /*
+ * Key Matcher flow definitions
+ */
+ struct km_flow_def_s km;
};
enum flow_handle_type {
@@ -159,6 +202,9 @@ struct flow_handle {
void km_free_ndev_resource_management(void **handle);
+int km_add_match_elem(struct km_flow_def_s *km, uint32_t e_word[4], uint32_t e_mask[4],
+ uint32_t word_len, enum frame_offs_e start, int8_t offset);
+
void kcc_free_ndev_resource_management(void **handle);
/*
@@ -120,6 +120,17 @@ enum {
} \
} while (0)
+enum frame_offs_e {
+ DYN_L2 = 1,
+ DYN_L3 = 4,
+ DYN_L4 = 7,
+ DYN_L4_PAYLOAD = 8,
+ DYN_TUN_L3 = 13,
+ DYN_TUN_L4 = 16,
+};
+
+/* Sideband info bit indicator */
+
enum km_flm_if_select_e {
KM_FLM_IF_FIRST = 0,
KM_FLM_IF_SECOND = 1
@@ -133,6 +144,39 @@ enum km_flm_if_select_e {
unsigned int alloced_size; \
int debug
+enum {
+ PROT_OTHER = 0,
+ PROT_L2_ETH2 = 1,
+};
+
+enum {
+ PROT_L3_IPV4 = 1,
+};
+
+enum {
+ PROT_L4_ICMP = 4
+};
+
+enum {
+ PROT_TUN_L3_OTHER = 0,
+ PROT_TUN_L3_IPV4 = 1,
+};
+
+enum {
+ PROT_TUN_L4_OTHER = 0,
+ PROT_TUN_L4_ICMP = 4
+};
+
+
+enum {
+ CPY_SELECT_DSCP_IPV4 = 0,
+ CPY_SELECT_DSCP_IPV6 = 1,
+ CPY_SELECT_RQI_QFI = 2,
+ CPY_SELECT_IPV4 = 3,
+ CPY_SELECT_PORT = 4,
+ CPY_SELECT_TEID = 5,
+};
+
struct common_func_s {
COMMON_FUNC_INFO_S;
};
@@ -3,10 +3,38 @@
* Copyright(c) 2023 Napatech A/S
*/
+#include <assert.h>
#include <stdlib.h>
#include "hw_mod_backend.h"
#include "flow_api_engine.h"
+#include "nt_util.h"
+
+#define NUM_CAM_MASKS (ARRAY_SIZE(cam_masks))
+
+static const struct cam_match_masks_s {
+ uint32_t word_len;
+ uint32_t key_mask[4];
+} cam_masks[] = {
+ { 4, { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff } }, /* IP6_SRC, IP6_DST */
+ { 4, { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 } }, /* DMAC,SMAC,ethtype */
+ { 4, { 0xffffffff, 0xffff0000, 0x00000000, 0xffff0000 } }, /* DMAC,ethtype */
+ { 4, { 0x00000000, 0x0000ffff, 0xffffffff, 0xffff0000 } }, /* SMAC,ethtype */
+ { 4, { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 } }, /* ETH_128 */
+ { 2, { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 } }, /* IP4_COMBINED */
+ /*
+ * ETH_TYPE, IP4_TTL_PROTO, IP4_SRC, IP4_DST, IP6_FLOW_TC,
+ * IP6_NEXT_HDR_HOP, TP_PORT_COMBINED, SIDEBAND_VNI
+ */
+ { 1, { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 } },
+ /* IP4_IHL_TOS, TP_PORT_SRC32_OR_ICMP, TCP_CTRL */
+ { 1, { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 } },
+ { 1, { 0x0000ffff, 0x00000000, 0x00000000, 0x00000000 } }, /* TP_PORT_DST32 */
+ /* IPv4 TOS mask bits used often by OVS */
+ { 1, { 0x00030000, 0x00000000, 0x00000000, 0x00000000 } },
+ /* IPv6 TOS mask bits used often by OVS */
+ { 1, { 0x00300000, 0x00000000, 0x00000000, 0x00000000 } },
+};
void km_free_ndev_resource_management(void **handle)
{
@@ -17,3 +45,56 @@ void km_free_ndev_resource_management(void **handle)
*handle = NULL;
}
+
+int km_add_match_elem(struct km_flow_def_s *km, uint32_t e_word[4], uint32_t e_mask[4],
+ uint32_t word_len, enum frame_offs_e start_id, int8_t offset)
+{
+ /* valid word_len 1,2,4 */
+ if (word_len == 3) {
+ word_len = 4;
+ e_word[3] = 0;
+ e_mask[3] = 0;
+ }
+
+ if (word_len < 1 || word_len > 4) {
+ assert(0);
+ return -1;
+ }
+
+ for (unsigned int i = 0; i < word_len; i++) {
+ km->match[km->num_ftype_elem].e_word[i] = e_word[i];
+ km->match[km->num_ftype_elem].e_mask[i] = e_mask[i];
+ }
+
+ km->match[km->num_ftype_elem].word_len = word_len;
+ km->match[km->num_ftype_elem].rel_offs = offset;
+ km->match[km->num_ftype_elem].extr_start_offs_id = start_id;
+
+ /*
+ * Determine here if this flow may better be put into TCAM
+ * Otherwise it will go into CAM
+ * This is dependent on a cam_masks list defined above
+ */
+ km->match[km->num_ftype_elem].masked_for_tcam = 1;
+
+ for (unsigned int msk = 0; msk < NUM_CAM_MASKS; msk++) {
+ if (word_len == cam_masks[msk].word_len) {
+ int match = 1;
+
+ for (unsigned int wd = 0; wd < word_len; wd++) {
+ if (e_mask[wd] != cam_masks[msk].key_mask[wd]) {
+ match = 0;
+ break;
+ }
+ }
+
+ if (match) {
+ /* Can go into CAM */
+ km->match[km->num_ftype_elem].masked_for_tcam = 0;
+ }
+ }
+ }
+
+ km->num_ftype_elem++;
+ return 0;
+}
@@ -416,10 +416,67 @@ static int interpret_flow_elements(const struct flow_eth_dev *dev,
return 0;
}
-static int convert_fh_to_fh_flm(struct flow_handle *fh, const uint32_t *packet_data __rte_unused,
- uint32_t flm_key_id __rte_unused, uint32_t flm_ft __rte_unused,
- uint16_t rpl_ext_ptr __rte_unused, uint32_t flm_scrub __rte_unused,
- uint32_t priority __rte_unused)
+static void copy_fd_to_fh_flm(struct flow_handle *fh, const struct nic_flow_def *fd,
+ const uint32_t *packet_data, uint32_t flm_key_id, uint32_t flm_ft,
+ uint16_t rpl_ext_ptr, uint32_t flm_scrub __rte_unused, uint32_t priority)
+{
+ switch (fd->l4_prot) {
+ case PROT_L4_ICMP:
+ fh->flm_prot = fd->ip_prot;
+ break;
+
+ default:
+ switch (fd->tunnel_l4_prot) {
+ case PROT_TUN_L4_ICMP:
+ fh->flm_prot = fd->tunnel_ip_prot;
+ break;
+
+ default:
+ fh->flm_prot = 0;
+ break;
+ }
+
+ break;
+ }
+
+ memcpy(fh->flm_data, packet_data, sizeof(uint32_t) * 10);
+
+ fh->flm_kid = flm_key_id;
+ fh->flm_rpl_ext_ptr = rpl_ext_ptr;
+ fh->flm_prio = (uint8_t)priority;
+ fh->flm_ft = (uint8_t)flm_ft;
+
+ for (unsigned int i = 0; i < fd->modify_field_count; ++i) {
+ switch (fd->modify_field[i].select) {
+ case CPY_SELECT_DSCP_IPV4:
+ case CPY_SELECT_RQI_QFI:
+ fh->flm_rqi = (fd->modify_field[i].value8[0] >> 6) & 0x1;
+ fh->flm_qfi = fd->modify_field[i].value8[0] & 0x3f;
+ break;
+
+ case CPY_SELECT_IPV4:
+ fh->flm_nat_ipv4 = ntohl(fd->modify_field[i].value32[0]);
+ break;
+
+ case CPY_SELECT_PORT:
+ fh->flm_nat_port = ntohs(fd->modify_field[i].value16[0]);
+ break;
+
+ case CPY_SELECT_TEID:
+ fh->flm_teid = ntohl(fd->modify_field[i].value32[0]);
+ break;
+
+ default:
+ NT_LOG(DBG, FILTER, "Unknown modify field: %d",
+ fd->modify_field[i].select);
+ break;
+ }
+ }
+}
+
+static int convert_fh_to_fh_flm(struct flow_handle *fh, const uint32_t *packet_data,
+ uint32_t flm_key_id, uint32_t flm_ft, uint16_t rpl_ext_ptr,
+ uint32_t flm_scrub, uint32_t priority)
{
struct nic_flow_def *fd;
struct flow_handle fh_copy;
@@ -443,6 +500,9 @@ static int convert_fh_to_fh_flm(struct flow_handle *fh, const uint32_t *packet_d
for (int i = 0; i < RES_COUNT; ++i)
fh->flm_db_idxs[i] = fh_copy.db_idxs[i];
+ copy_fd_to_fh_flm(fh, fd, packet_data, flm_key_id, flm_ft, rpl_ext_ptr, flm_scrub,
+ priority);
+
free(fd);
return 0;