199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson * Copyright(c) 2010-2014 Intel Corporation
399a2dd95SBruce Richardson */
499a2dd95SBruce Richardson
599a2dd95SBruce Richardson #include <string.h>
699a2dd95SBruce Richardson
799a2dd95SBruce Richardson #include <rte_malloc.h>
899a2dd95SBruce Richardson
999a2dd95SBruce Richardson #include "rte_table_stub.h"
1099a2dd95SBruce Richardson
11*ae67895bSDavid Marchand #include "table_log.h"
12*ae67895bSDavid Marchand
1399a2dd95SBruce Richardson #ifdef RTE_TABLE_STATS_COLLECT
1499a2dd95SBruce Richardson
1599a2dd95SBruce Richardson #define RTE_TABLE_LPM_STATS_PKTS_IN_ADD(table, val) \
1699a2dd95SBruce Richardson table->stats.n_pkts_in += val
1799a2dd95SBruce Richardson #define RTE_TABLE_LPM_STATS_PKTS_LOOKUP_MISS(table, val) \
1899a2dd95SBruce Richardson table->stats.n_pkts_lookup_miss += val
1999a2dd95SBruce Richardson
2099a2dd95SBruce Richardson #else
2199a2dd95SBruce Richardson
2299a2dd95SBruce Richardson #define RTE_TABLE_LPM_STATS_PKTS_IN_ADD(table, val)
2399a2dd95SBruce Richardson #define RTE_TABLE_LPM_STATS_PKTS_LOOKUP_MISS(table, val)
2499a2dd95SBruce Richardson
2599a2dd95SBruce Richardson #endif
2699a2dd95SBruce Richardson
2799a2dd95SBruce Richardson struct rte_table_stub {
2899a2dd95SBruce Richardson struct rte_table_stats stats;
2999a2dd95SBruce Richardson };
3099a2dd95SBruce Richardson
3199a2dd95SBruce Richardson static void *
rte_table_stub_create(__rte_unused void * params,__rte_unused int socket_id,__rte_unused uint32_t entry_size)3299a2dd95SBruce Richardson rte_table_stub_create(__rte_unused void *params,
3399a2dd95SBruce Richardson __rte_unused int socket_id,
3499a2dd95SBruce Richardson __rte_unused uint32_t entry_size)
3599a2dd95SBruce Richardson {
3699a2dd95SBruce Richardson struct rte_table_stub *stub;
3799a2dd95SBruce Richardson uint32_t size;
3899a2dd95SBruce Richardson
3999a2dd95SBruce Richardson size = sizeof(struct rte_table_stub);
4099a2dd95SBruce Richardson stub = rte_zmalloc_socket("TABLE", size, RTE_CACHE_LINE_SIZE,
4199a2dd95SBruce Richardson socket_id);
4299a2dd95SBruce Richardson if (stub == NULL) {
43*ae67895bSDavid Marchand TABLE_LOG(ERR,
44*ae67895bSDavid Marchand "%s: Cannot allocate %u bytes for stub table",
4599a2dd95SBruce Richardson __func__, size);
4699a2dd95SBruce Richardson return NULL;
4799a2dd95SBruce Richardson }
4899a2dd95SBruce Richardson
4999a2dd95SBruce Richardson return stub;
5099a2dd95SBruce Richardson }
5199a2dd95SBruce Richardson
5299a2dd95SBruce Richardson static int
rte_table_stub_lookup(__rte_unused void * table,__rte_unused struct rte_mbuf ** pkts,__rte_unused uint64_t pkts_mask,uint64_t * lookup_hit_mask,__rte_unused void ** entries)5399a2dd95SBruce Richardson rte_table_stub_lookup(
5499a2dd95SBruce Richardson __rte_unused void *table,
5599a2dd95SBruce Richardson __rte_unused struct rte_mbuf **pkts,
5699a2dd95SBruce Richardson __rte_unused uint64_t pkts_mask,
5799a2dd95SBruce Richardson uint64_t *lookup_hit_mask,
5899a2dd95SBruce Richardson __rte_unused void **entries)
5999a2dd95SBruce Richardson {
6099a2dd95SBruce Richardson __rte_unused struct rte_table_stub *stub = (struct rte_table_stub *) table;
613d4e27fdSDavid Marchand __rte_unused uint32_t n_pkts_in = rte_popcount64(pkts_mask);
6299a2dd95SBruce Richardson
6399a2dd95SBruce Richardson RTE_TABLE_LPM_STATS_PKTS_IN_ADD(stub, n_pkts_in);
6499a2dd95SBruce Richardson *lookup_hit_mask = 0;
6599a2dd95SBruce Richardson RTE_TABLE_LPM_STATS_PKTS_LOOKUP_MISS(stub, n_pkts_in);
6699a2dd95SBruce Richardson
6799a2dd95SBruce Richardson return 0;
6899a2dd95SBruce Richardson }
6999a2dd95SBruce Richardson
7099a2dd95SBruce Richardson static int
rte_table_stub_stats_read(void * table,struct rte_table_stats * stats,int clear)7199a2dd95SBruce Richardson rte_table_stub_stats_read(void *table, struct rte_table_stats *stats, int clear)
7299a2dd95SBruce Richardson {
7399a2dd95SBruce Richardson struct rte_table_stub *t = table;
7499a2dd95SBruce Richardson
7599a2dd95SBruce Richardson if (stats != NULL)
7699a2dd95SBruce Richardson memcpy(stats, &t->stats, sizeof(t->stats));
7799a2dd95SBruce Richardson
7899a2dd95SBruce Richardson if (clear)
7999a2dd95SBruce Richardson memset(&t->stats, 0, sizeof(t->stats));
8099a2dd95SBruce Richardson
8199a2dd95SBruce Richardson return 0;
8299a2dd95SBruce Richardson }
8399a2dd95SBruce Richardson
8499a2dd95SBruce Richardson struct rte_table_ops rte_table_stub_ops = {
8599a2dd95SBruce Richardson .f_create = rte_table_stub_create,
8699a2dd95SBruce Richardson .f_free = NULL,
8799a2dd95SBruce Richardson .f_add = NULL,
8899a2dd95SBruce Richardson .f_delete = NULL,
8999a2dd95SBruce Richardson .f_add_bulk = NULL,
9099a2dd95SBruce Richardson .f_delete_bulk = NULL,
9199a2dd95SBruce Richardson .f_lookup = rte_table_stub_lookup,
9299a2dd95SBruce Richardson .f_stats = rte_table_stub_stats_read,
9399a2dd95SBruce Richardson };
94