From 2a0db471858d1143b12ace6a062d37ea509612f7 Mon Sep 17 00:00:00 2001 From: nanger Date: Mon, 20 Aug 2018 11:23:31 +0800 Subject: Feat: HAL decoupling with DPDK Change-Id: I62c60117e63e75793c1348b6852eed6753915077 Signed-off-by: nanger --- src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c | 2 ++ src/framework/hal/hal.c | 6 ++---- src/framework/hal/hal.h | 6 +++--- src/framework/include/hal_api.h | 13 ++++++------- src/nSocket/nstack/nstack.c | 4 +--- stacks/lwip_stack/lwip_src/netif/spl_hal.c | 6 ++++-- stacks/lwip_stack/src/io_adpt/dpdk.c | 10 +++++++--- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c index 5af828f..08ad4cd 100644 --- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c +++ b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c @@ -37,8 +37,10 @@ #define NSFW_SHMEM_PID (get_sys_pid()) #define NSFW_SHMEM_FLAG (g_shmem_localdata->enflag) +/* app_mode 1: simple stack with APP*/ extern u8 app_mode; u8 app_mode = 0; + nsfw_mem_localdata *g_shmem_localdata = NULL; /*check g_mem_localdata*/ diff --git a/src/framework/hal/hal.c b/src/framework/hal/hal.c index 1adf274..545c759 100644 --- a/src/framework/hal/hal.c +++ b/src/framework/hal/hal.c @@ -31,8 +31,6 @@ static char* hal_invalid_str_script[] = {"&&", "||", ">>", "${", ";;", "/./", "/ static char* hal_invalid_str_script_begin[] = {"./", "../"}; -extern const netif_ops_t dpdk_netif_ops; - static hal_hdl_t hal_invaldi_hdl = {.id = -1}; static const netif_ops_t* netif_ops_table[HAL_DRV_MAX]; @@ -598,7 +596,7 @@ hal_get_capability (hal_hdl_t hdl, hal_netif_capa_t * info) *****************************************************************************/ uint16_t hal_recv_packet (hal_hdl_t hdl, uint16_t queue_id, - struct common_mem_mbuf **rx_pkts, uint16_t nb_pkts) + hal_mbuf_t ** rx_pkts, uint16_t nb_pkts) { netif_inst_t *inst; @@ -627,7 +625,7 @@ hal_recv_packet (hal_hdl_t hdl, uint16_t queue_id, *****************************************************************************/ uint16_t hal_send_packet (hal_hdl_t hdl, uint16_t queue_id, - struct common_mem_mbuf ** tx_pkts, uint16_t nb_pkts) + hal_mbuf_t ** tx_pkts, uint16_t nb_pkts) { netif_inst_t *inst; diff --git a/src/framework/hal/hal.h b/src/framework/hal/hal.h index 2f66914..36ad79d 100644 --- a/src/framework/hal/hal.h +++ b/src/framework/hal/hal.h @@ -59,7 +59,7 @@ typedef struct dpdk_if uint32_t rx_queue_num; uint32_t rx_ring_size[HAL_ETH_MAX_QUEUE_NUM]; - struct rte_mempool *rx_pool[HAL_ETH_MAX_QUEUE_NUM]; + hal_mempool_t *rx_pool[HAL_ETH_MAX_QUEUE_NUM]; uint32_t tx_queue_num; uint32_t tx_ring_size[HAL_ETH_MAX_QUEUE_NUM]; @@ -103,9 +103,9 @@ typedef struct netif_ops int (*macaddr) (netif_inst_t * inst, void *mac_addr); int (*capability) (netif_inst_t * inst, hal_netif_capa_t * info); uint16_t (*recv) (netif_inst_t * inst, uint16_t queue_id, - struct common_mem_mbuf ** rx_pkts, uint16_t nb_pkts); + hal_mbuf_t ** rx_pkts, uint16_t nb_pkts); uint16_t (*send) (netif_inst_t * inst, uint16_t queue_id, - struct common_mem_mbuf ** tx_pkts, uint16_t nb_pkts); + hal_mbuf_t ** tx_pkts, uint16_t nb_pkts); uint32_t (*link_status) (netif_inst_t * inst); int (*stats) (netif_inst_t * inst, hal_netif_stats_t * stats); int (*stats_reset) (netif_inst_t * inst); diff --git a/src/framework/include/hal_api.h b/src/framework/include/hal_api.h index 24ed779..90c3100 100644 --- a/src/framework/include/hal_api.h +++ b/src/framework/include/hal_api.h @@ -17,16 +17,15 @@ #ifndef _HAL_API_H_ #define _HAL_API_H_ -#include "common_mem_mbuf.h" -#include "common_mem_mempool.h" -#include "common_func.h" - #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif +typedef void hal_mempool_t; +typedef void hal_mbuf_t; + #define HAL_ETH_MAX_QUEUE_NUM 4 #define HAL_ETH_QUEUE_STAT_CNTRS 16 @@ -98,7 +97,7 @@ typedef struct hal_netif_config { uint32_t queue_num; uint32_t ring_size[HAL_ETH_MAX_QUEUE_NUM]; - struct common_mem_mempool *ring_pool[HAL_ETH_MAX_QUEUE_NUM]; + hal_mempool_t *ring_pool[HAL_ETH_MAX_QUEUE_NUM]; } rx; struct @@ -125,9 +124,9 @@ uint32_t hal_get_mtu (hal_hdl_t hdl); void hal_get_macaddr (hal_hdl_t hdl, void *mac_addr); void hal_get_capability (hal_hdl_t hdl, hal_netif_capa_t * info); uint16_t hal_recv_packet (hal_hdl_t hdl, uint16_t queue_id, - struct common_mem_mbuf **rx_pkts, uint16_t nb_pkts); + hal_mbuf_t ** rx_pkts, uint16_t nb_pkts); uint16_t hal_send_packet (hal_hdl_t hdl, uint16_t queue_id, - struct common_mem_mbuf **tx_pkts, uint16_t nb_pkts); + hal_mbuf_t ** tx_pkts, uint16_t nb_pkts); uint32_t hal_link_status (hal_hdl_t hdl); int hal_stats (hal_hdl_t hdl, hal_netif_stats_t * stats); void hal_stats_reset (hal_hdl_t hdl); diff --git a/src/nSocket/nstack/nstack.c b/src/nSocket/nstack/nstack.c index 4b01961..707cb49 100644 --- a/src/nSocket/nstack/nstack.c +++ b/src/nSocket/nstack/nstack.c @@ -56,9 +56,7 @@ nStack_info_t g_nStackInfo = { /*if this flag was set, maybe all socket interface called during initializing*/ __thread int g_tloadflag = 0; -/* app_mode 1: simple stack with APP*/ -u8 app_mode=0; - +extern u8 app_mode; /*check init stack*/ #define NSTACK_INIT_STATE_CHECK_RET(state) do {\ diff --git a/stacks/lwip_stack/lwip_src/netif/spl_hal.c b/stacks/lwip_stack/lwip_src/netif/spl_hal.c index 5f69a9d..c7cfca1 100644 --- a/stacks/lwip_stack/lwip_src/netif/spl_hal.c +++ b/stacks/lwip_stack/lwip_src/netif/spl_hal.c @@ -1470,7 +1470,8 @@ spl_hal_send (struct netif *pnetif) do { sent += - hal_send_packet (pnetifExt->hdl, 0, &(tx_ptks[sent]), tx_num - sent); + hal_send_packet (pnetifExt->hdl, 0, (hal_mbuf_t **) & (tx_ptks[sent]), + tx_num - sent); _retry++; if (_retry > SPL_HAL_SEND_TRY) @@ -1514,7 +1515,8 @@ spl_hal_recv (struct netif *pnetif, u8_t id) return 0; rx_c = - hal_recv_packet (pnetifExt->hdl, 0, spl_hal_pkts[netif_id].rx.pkts, + hal_recv_packet (pnetifExt->hdl, 0, + (hal_mbuf_t **) spl_hal_pkts[netif_id].rx.pkts, PKT_BURST); if (rx_c <= 0) diff --git a/stacks/lwip_stack/src/io_adpt/dpdk.c b/stacks/lwip_stack/src/io_adpt/dpdk.c index 63ffde1..da2cfb6 100644 --- a/stacks/lwip_stack/src/io_adpt/dpdk.c +++ b/stacks/lwip_stack/src/io_adpt/dpdk.c @@ -35,6 +35,9 @@ #include #include #include "nsfw_init.h" +#include "common_mem_mbuf.h" +#include "common_mem_mempool.h" +#include "common_func.h" #include "hal.h" #include "nstack_securec.h" #include @@ -1524,7 +1527,8 @@ dpdk_setup_port (netif_inst_t * inst) struct rte_eth_txconf *tx_conf; uint8_t port_id = inst->data.dpdk_if.port_id; - struct rte_mempool **mp = inst->data.dpdk_if.rx_pool; + struct rte_mempool **mp = + (struct rte_mempool **) inst->data.dpdk_if.rx_pool; uint32_t *rx_ring_size = inst->data.dpdk_if.rx_ring_size; uint32_t *tx_ring_size = inst->data.dpdk_if.tx_ring_size; uint32_t rx_queue_num = inst->data.dpdk_if.rx_queue_num; @@ -1797,7 +1801,7 @@ dpdk_get_capability (netif_inst_t * inst, hal_netif_capa_t * capa) *****************************************************************************/ NSTACK_STATIC uint16_t dpdk_recv (netif_inst_t * inst, uint16_t queue_id, - struct common_mem_mbuf ** rx_pkts, uint16_t nb_pkts) + hal_mbuf_t ** rx_pkts, uint16_t nb_pkts) { return hal_rte_eth_rx_burst (inst->data.dpdk_if.port_id, queue_id, (struct rte_mbuf **) rx_pkts, nb_pkts); @@ -1818,7 +1822,7 @@ dpdk_recv (netif_inst_t * inst, uint16_t queue_id, *****************************************************************************/ NSTACK_STATIC uint16_t dpdk_send (netif_inst_t * inst, uint16_t queue_id, - struct common_mem_mbuf **tx_pkts, uint16_t nb_pkts) + hal_mbuf_t ** tx_pkts, uint16_t nb_pkts) { return hal_rte_eth_tx_burst (inst->data.dpdk_if.port_id, queue_id, (struct rte_mbuf **) tx_pkts, nb_pkts); -- cgit 1.2.3-korg