diff mbox series

[2.0,v2,2/3] linux-gen: pktio: add IO interface operations data allocate/free API

Message ID 1510938009-12495-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [2.0,v2,1/3] linux-gen: pktio: add IO interface operation data pool | expand

Commit Message

Github ODP bot Nov. 17, 2017, 5 p.m. UTC
From: Bogdan Pricope <bogdan.pricope@linaro.org>


Pktios may use added macros to alloc/free operation data buffers

Signed-off-by: Bogdan Pricope <bogdan.pricope@linaro.org>

---
/** Email created from pull request 297 (bogdanPricope:2_0_ops_alloc_pr)
 ** https://github.com/Linaro/odp/pull/297
 ** Patch: https://github.com/Linaro/odp/pull/297.patch
 ** Base sha: 6cd43041e55bd73a02ca202f835e590b3ad5c354
 ** Merge commit sha: c785d2a3749494734a049a6e261df1b741ea22e0
 **/
 .../include/odp_pktio_ops_subsystem.h              | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h
index cb107fed2..42cb6d2c5 100644
--- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h
+++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h
@@ -15,7 +15,9 @@  extern "C" {
 #endif
 
 #include <odp_module.h>
+#include <odp/api/align.h>
 #include <odp/api/packet_io.h>
+#include <odp/drv/shm.h>
 
 /* ODP packet IO operations subsystem declaration */
 ODP_SUBSYSTEM_DECLARE(pktio_ops);
@@ -92,6 +94,32 @@  typedef ODP_MODULE_CLASS(pktio_ops) {
 #define odp_ops_data(_p, _mod) \
 	((pktio_ops_ ## _mod ## _data_t *)(uintptr_t)_p->s.ops_data)
 
+#define odp_ops_data_alloc(_p, _size)					\
+({									\
+	odpdrv_shm_pool_t _pool;					\
+									\
+	_p->s.ops_data = NULL;						\
+	_pool = odpdrv_shm_pool_lookup(ODP_PKTIO_OPS_DATA_POOL_NAME);	\
+	if (_pool != ODPDRV_SHM_POOL_INVALID)				\
+		_p->s.ops_data = odpdrv_shm_pool_alloc(_pool,		\
+			ROUNDUP_CACHE_LINE(_size));			\
+									\
+	_p->s.ops_data;							\
+})
+
+#define odp_ops_data_free(_p)						\
+({									\
+	odpdrv_shm_pool_t _pool;					\
+	int _result = -1;						\
+									\
+	_pool = odpdrv_shm_pool_lookup(ODP_PKTIO_OPS_DATA_POOL_NAME);	\
+	if (_pool != ODPDRV_SHM_POOL_INVALID) {				\
+		odpdrv_shm_pool_free(_pool, _p->s.ops_data);		\
+		_result = 0;						\
+	}								\
+	_result;							\
+})
+
 #ifdef __cplusplus
 }
 #endif