#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/queue.h>
#include <errno.h>
#include <stdarg.h>
#include <inttypes.h>
#include "common.h"
#include "args.h"
#include "init.h"
#define MBUFS_PER_NODE 1536
#define MBUFS_PER_PORT 1536
#define MBUF_CACHE_SIZE 512
#define RTE_MP_RX_DESC_DEFAULT 512
#define RTE_MP_TX_DESC_DEFAULT 512
#define NODE_QUEUE_RINGSIZE 128
#define NO_FLAGS 0
struct node *nodes;
struct rte_efd_table *efd_table;
struct shared_info *info;
static int
init_mbuf_pools(void)
{
const unsigned int num_mbufs = (num_nodes * MBUFS_PER_NODE) +
(info->num_ports * MBUFS_PER_PORT);
printf("Creating mbuf pool '%s' [%u mbufs] ...\n",
PKTMBUF_POOL_NAME, num_mbufs);
return pktmbuf_pool == NULL;
}
static int
init_port(uint16_t port_num)
{
},
};
const uint16_t rx_rings = 1, tx_rings = num_nodes;
uint16_t rx_ring_size = RTE_MP_RX_DESC_DEFAULT;
uint16_t tx_ring_size = RTE_MP_TX_DESC_DEFAULT;
uint16_t q;
int retval;
printf("Port %u init ... ", port_num);
fflush(stdout);
if (retval != 0)
return retval;
if (retval != 0)
return retval;
&tx_ring_size);
if (retval != 0)
return retval;
for (q = 0; q < rx_rings; q++) {
NULL, pktmbuf_pool);
if (retval < 0)
return retval;
}
txconf = dev_info.default_txconf;
for (q = 0; q < tx_rings; q++) {
&txconf);
if (retval < 0)
return retval;
}
if (retval != 0)
return retval;
if (retval < 0)
return retval;
printf("done:\n");
return 0;
}
static int
init_shm_rings(void)
{
unsigned int i;
unsigned int socket_id;
const char *q_name;
const unsigned int ringsize = NODE_QUEUE_RINGSIZE;
sizeof(*nodes) * num_nodes, 0);
if (nodes == NULL)
rte_exit(EXIT_FAILURE,
"Cannot allocate memory for "
"node program details\n");
for (i = 0; i < num_nodes; i++) {
q_name = get_rx_queue_name(i);
ringsize, socket_id,
if (nodes[i].rx_q == NULL)
rte_exit(EXIT_FAILURE,
"Cannot create rx ring queue "
"for node %u\n", i);
}
return 0;
}
static void
create_efd_table(void)
{
efd_table =
rte_efd_create(
"flow table", num_flows * 2,
sizeof(uint32_t),
1 << socket_id, socket_id);
if (efd_table == NULL)
rte_exit(EXIT_FAILURE,
"Problem creating the flow table\n");
}
static void
populate_efd_table(void)
{
unsigned int i;
int32_t ret;
uint32_t ip_dst;
uint64_t node_id;
for (i = 0; i < num_flows; i++) {
node_id = i % num_nodes;
(void *)&ip_dst, (efd_value_t)node_id);
if (ret < 0)
rte_exit(EXIT_FAILURE,
"Unable to add entry %u in "
"EFD table\n", i);
}
printf("EFD table: Adding 0x%x keys\n", num_flows);
}
static void
check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
{
#define CHECK_INTERVAL 100
#define MAX_CHECK_TIME 90
uint8_t count, all_ports_up, print_flag = 0;
uint16_t portid;
int ret;
printf("\nChecking link status");
fflush(stdout);
for (count = 0; count <= MAX_CHECK_TIME; count++) {
all_ports_up = 1;
for (portid = 0; portid < port_num; portid++) {
if ((port_mask & (1 << info->id[portid])) == 0)
continue;
memset(&link, 0, sizeof(link));
if (ret < 0) {
all_ports_up = 0;
if (print_flag == 1)
printf("Port %u link get failed: %s\n",
continue;
}
if (print_flag == 1) {
sizeof(link_status_text), &link);
printf("Port %d %s\n", info->id[portid],
link_status_text);
continue;
}
all_ports_up = 0;
break;
}
}
if (print_flag == 1)
break;
if (all_ports_up == 0) {
printf(".");
fflush(stdout);
}
if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
print_flag = 1;
printf("done\n");
}
}
}
int
init(int argc, char *argv[])
{
int retval;
uint8_t i, total_ports;
if (retval < 0)
return -1;
argc -= retval;
argv += retval;
if (mz == NULL)
rte_exit(EXIT_FAILURE,
"Cannot reserve memory zone "
"for port information\n");
memset(mz->
addr, 0,
sizeof(*info));
retval = parse_app_args(total_ports, argc, argv);
if (retval != 0)
return -1;
retval = init_mbuf_pools();
if (retval != 0)
rte_exit(EXIT_FAILURE,
"Cannot create needed mbuf pools\n");
for (i = 0; i < info->num_ports; i++) {
retval = init_port(info->id[i]);
if (retval != 0)
rte_exit(EXIT_FAILURE,
"Cannot initialise port %u\n",
(unsigned int) i);
}
check_all_ports_link_status(info->num_ports, (~0x0));
init_shm_rings();
create_efd_table();
populate_efd_table();
info->num_nodes = num_nodes;
info->num_flows = num_flows;
return 0;
}
static rte_be32_t rte_cpu_to_be_32(uint32_t x)
__rte_noreturn void rte_exit(int exit_code, const char *format,...) __rte_format_printf(2
static void rte_delay_ms(unsigned ms)
int rte_eal_init(int argc, char **argv)
struct rte_efd_table * rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len, uint64_t online_cpu_socket_bitmask, uint8_t offline_cpu_socket)
int rte_efd_update(struct rte_efd_table *table, unsigned int socket_id, const void *key, efd_value_t value)
const char * rte_strerror(int errnum)
int rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_queue, uint16_t nb_tx_queue, const struct rte_eth_conf *eth_conf)
#define RTE_ETH_LINK_DOWN
int rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id, uint16_t nb_rx_desc, unsigned int socket_id, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mb_pool)
#define RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
int rte_eth_promiscuous_enable(uint16_t port_id)
__rte_experimental int rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link)
int rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
int rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id, uint16_t nb_tx_desc, unsigned int socket_id, const struct rte_eth_txconf *tx_conf)
#define RTE_ETH_LINK_MAX_STR_LEN
uint16_t rte_eth_dev_count_avail(void)
int rte_eth_dev_socket_id(uint16_t port_id)
int rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *link)
int rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id, uint16_t *nb_rx_desc, uint16_t *nb_tx_desc)
int rte_eth_dev_start(uint16_t port_id)
unsigned int rte_socket_id(void)
void * rte_malloc(const char *type, size_t size, unsigned align) __rte_alloc_size(2)
struct rte_mempool * rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id)
const struct rte_memzone * rte_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags)
struct rte_ring * rte_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags)
struct rte_eth_txmode txmode
struct rte_eth_rxmode rxmode
enum rte_eth_rx_mq_mode mq_mode