1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
9 #include <rte_string_fns.h>
11 #include "rte_eth_softnic_internals.h"
13 #define BUFFER_SIZE_MIN (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
16 softnic_mempool_init(struct pmd_internals *p)
18 TAILQ_INIT(&p->mempool_list);
24 softnic_mempool_free(struct pmd_internals *p)
27 struct softnic_mempool *mempool;
29 mempool = TAILQ_FIRST(&p->mempool_list);
33 TAILQ_REMOVE(&p->mempool_list, mempool, node);
34 rte_mempool_free(mempool->m);
39 struct softnic_mempool *
40 softnic_mempool_find(struct pmd_internals *p,
43 struct softnic_mempool *mempool;
48 TAILQ_FOREACH(mempool, &p->mempool_list, node)
49 if (strcmp(mempool->name, name) == 0)
55 struct softnic_mempool *
56 softnic_mempool_create(struct pmd_internals *p,
58 struct softnic_mempool_params *params)
60 char mempool_name[NAME_SIZE];
61 struct softnic_mempool *mempool;
62 struct rte_mempool *m;
64 /* Check input params */
66 softnic_mempool_find(p, name) ||
68 params->buffer_size < BUFFER_SIZE_MIN ||
69 params->pool_size == 0)
73 snprintf(mempool_name, sizeof(mempool_name), "%s_%s",
77 m = rte_pktmbuf_pool_create(mempool_name,
81 params->buffer_size - sizeof(struct rte_mbuf),
88 mempool = calloc(1, sizeof(struct softnic_mempool));
89 if (mempool == NULL) {
95 strlcpy(mempool->name, name, sizeof(mempool->name));
97 mempool->buffer_size = params->buffer_size;
99 /* Node add to list */
100 TAILQ_INSERT_TAIL(&p->mempool_list, mempool, node);