1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2018 NXP 3 */ 4 5 #include <string.h> 6 #include <rte_eal.h> 7 #include <rte_mbuf.h> 8 #include <rte_errno.h> 9 #include <rte_mbuf_pool_ops.h> 10 11 int 12 rte_mbuf_set_platform_mempool_ops(const char *ops_name) 13 { 14 const struct rte_memzone *mz; 15 16 size_t len = strnlen(ops_name, RTE_MEMPOOL_OPS_NAMESIZE); 17 if (len == 0) 18 return -EINVAL; 19 if (len == RTE_MEMPOOL_OPS_NAMESIZE) 20 return -ENAMETOOLONG; 21 22 mz = rte_memzone_lookup("mbuf_platform_pool_ops"); 23 if (mz == NULL) { 24 mz = rte_memzone_reserve("mbuf_platform_pool_ops", 25 RTE_MEMPOOL_OPS_NAMESIZE, SOCKET_ID_ANY, 0); 26 if (mz == NULL) 27 return -rte_errno; 28 strcpy(mz->addr, ops_name); 29 return 0; 30 } else if (strcmp(mz->addr, ops_name) == 0) { 31 return 0; 32 } 33 34 RTE_LOG(ERR, MBUF, 35 "%s is already registered as platform mbuf pool ops\n", 36 (char *)mz->addr); 37 return -EEXIST; 38 } 39 40 const char * 41 rte_mbuf_platform_mempool_ops(void) 42 { 43 const struct rte_memzone *mz; 44 45 mz = rte_memzone_lookup("mbuf_platform_pool_ops"); 46 if (mz == NULL) 47 return NULL; 48 return mz->addr; 49 } 50 51 int 52 rte_mbuf_set_user_mempool_ops(const char *ops_name) 53 { 54 const struct rte_memzone *mz; 55 56 size_t len = strnlen(ops_name, RTE_MEMPOOL_OPS_NAMESIZE); 57 if (len == 0) 58 return -EINVAL; 59 if (len == RTE_MEMPOOL_OPS_NAMESIZE) 60 return -ENAMETOOLONG; 61 62 mz = rte_memzone_lookup("mbuf_user_pool_ops"); 63 if (mz == NULL) { 64 mz = rte_memzone_reserve("mbuf_user_pool_ops", 65 RTE_MEMPOOL_OPS_NAMESIZE, SOCKET_ID_ANY, 0); 66 if (mz == NULL) 67 return -rte_errno; 68 } 69 70 strcpy(mz->addr, ops_name); 71 return 0; 72 73 } 74 75 const char * 76 rte_mbuf_user_mempool_ops(void) 77 { 78 const struct rte_memzone *mz; 79 80 mz = rte_memzone_lookup("mbuf_user_pool_ops"); 81 if (mz == NULL) 82 return rte_eal_mbuf_user_pool_ops(); 83 return mz->addr; 84 } 85 86 /* Return mbuf pool ops name */ 87 const char * 88 rte_mbuf_best_mempool_ops(void) 89 { 90 /* User defined mempool ops takes the priority */ 91 const char *best_ops = rte_mbuf_user_mempool_ops(); 92 if (best_ops) 93 return best_ops; 94 95 /* Next choice is platform configured mempool ops */ 96 best_ops = rte_mbuf_platform_mempool_ops(); 97 if (best_ops) 98 return best_ops; 99 100 /* Last choice is to use the compile time config pool */ 101 return RTE_MBUF_DEFAULT_MEMPOOL_OPS; 102 } 103