2018-01-29 08:10:45 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright 2018 NXP
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2018-01-22 01:48:06 +00:00
|
|
|
#include <rte_compat.h>
|
2018-01-29 08:10:45 +00:00
|
|
|
#include <rte_eal.h>
|
|
|
|
#include <rte_mbuf.h>
|
|
|
|
#include <rte_errno.h>
|
|
|
|
#include <rte_mbuf_pool_ops.h>
|
|
|
|
|
2018-06-05 06:24:11 +00:00
|
|
|
int
|
2018-01-29 08:10:45 +00:00
|
|
|
rte_mbuf_set_platform_mempool_ops(const char *ops_name)
|
|
|
|
{
|
|
|
|
const struct rte_memzone *mz;
|
|
|
|
|
|
|
|
if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
|
|
|
mz = rte_memzone_lookup("mbuf_platform_pool_ops");
|
|
|
|
if (mz == NULL) {
|
|
|
|
mz = rte_memzone_reserve("mbuf_platform_pool_ops",
|
|
|
|
RTE_MEMPOOL_OPS_NAMESIZE, SOCKET_ID_ANY, 0);
|
|
|
|
if (mz == NULL)
|
|
|
|
return -rte_errno;
|
2018-03-29 17:05:30 +00:00
|
|
|
strcpy(mz->addr, ops_name);
|
2018-01-29 08:10:45 +00:00
|
|
|
return 0;
|
|
|
|
} else if (strcmp(mz->addr, ops_name) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTE_LOG(ERR, MBUF,
|
|
|
|
"%s is already registered as platform mbuf pool ops\n",
|
|
|
|
(char *)mz->addr);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
2018-06-05 06:24:11 +00:00
|
|
|
const char *
|
2018-01-29 08:10:45 +00:00
|
|
|
rte_mbuf_platform_mempool_ops(void)
|
|
|
|
{
|
|
|
|
const struct rte_memzone *mz;
|
|
|
|
|
|
|
|
mz = rte_memzone_lookup("mbuf_platform_pool_ops");
|
|
|
|
if (mz == NULL)
|
|
|
|
return NULL;
|
|
|
|
return mz->addr;
|
|
|
|
}
|
|
|
|
|
2018-06-05 06:24:11 +00:00
|
|
|
int
|
2018-01-29 08:10:45 +00:00
|
|
|
rte_mbuf_set_user_mempool_ops(const char *ops_name)
|
|
|
|
{
|
|
|
|
const struct rte_memzone *mz;
|
|
|
|
|
|
|
|
if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
|
|
|
mz = rte_memzone_lookup("mbuf_user_pool_ops");
|
|
|
|
if (mz == NULL) {
|
|
|
|
mz = rte_memzone_reserve("mbuf_user_pool_ops",
|
|
|
|
RTE_MEMPOOL_OPS_NAMESIZE, SOCKET_ID_ANY, 0);
|
|
|
|
if (mz == NULL)
|
|
|
|
return -rte_errno;
|
|
|
|
}
|
|
|
|
|
2018-03-29 17:05:30 +00:00
|
|
|
strcpy(mz->addr, ops_name);
|
2018-01-29 08:10:45 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-05 06:24:11 +00:00
|
|
|
const char *
|
2018-01-29 08:10:45 +00:00
|
|
|
rte_mbuf_user_mempool_ops(void)
|
|
|
|
{
|
|
|
|
const struct rte_memzone *mz;
|
|
|
|
|
|
|
|
mz = rte_memzone_lookup("mbuf_user_pool_ops");
|
|
|
|
if (mz == NULL)
|
2018-02-02 08:03:01 +00:00
|
|
|
return rte_eal_mbuf_user_pool_ops();
|
2018-01-29 08:10:45 +00:00
|
|
|
return mz->addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return mbuf pool ops name */
|
2018-06-05 06:24:11 +00:00
|
|
|
const char *
|
2018-01-29 08:10:45 +00:00
|
|
|
rte_mbuf_best_mempool_ops(void)
|
|
|
|
{
|
|
|
|
/* User defined mempool ops takes the priority */
|
|
|
|
const char *best_ops = rte_mbuf_user_mempool_ops();
|
|
|
|
if (best_ops)
|
|
|
|
return best_ops;
|
|
|
|
|
|
|
|
/* Next choice is platform configured mempool ops */
|
|
|
|
best_ops = rte_mbuf_platform_mempool_ops();
|
|
|
|
if (best_ops)
|
|
|
|
return best_ops;
|
|
|
|
|
|
|
|
/* Last choice is to use the compile time config pool */
|
|
|
|
return RTE_MBUF_DEFAULT_MEMPOOL_OPS;
|
|
|
|
}
|