#include <stdint.h>
#include <stdio.h>
#include <stdlib.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 MBUF_CACHE_SIZE 512
#define RTE_MP_RX_DESC_DEFAULT 1024
#define RTE_MP_TX_DESC_DEFAULT 1024
#define CLIENT_QUEUE_RINGSIZE 128
#define NO_FLAGS 0
struct client *clients = NULL;
struct port_info *ports;
static int
init_mbuf_pools(void)
{
const unsigned int num_mbufs_server =
RTE_MP_RX_DESC_DEFAULT * ports->num_ports;
const unsigned int num_mbufs_client =
num_clients * (CLIENT_QUEUE_RINGSIZE +
RTE_MP_TX_DESC_DEFAULT * ports->num_ports);
const unsigned int num_mbufs_mp_cache =
(num_clients + 1) * MBUF_CACHE_SIZE;
const unsigned int num_mbufs =
num_mbufs_server + num_mbufs_client + num_mbufs_mp_cache;
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_clients;
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);
&port_conf)) != 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;
}
for ( q = 0; q < tx_rings; q ++ ) {
NULL);
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 i;
unsigned socket_id;
const char * q_name;
const unsigned ringsize = CLIENT_QUEUE_RINGSIZE;
sizeof(*clients) * num_clients, 0);
if (clients == NULL)
rte_exit(EXIT_FAILURE,
"Cannot allocate memory for client program details\n");
for (i = 0; i < num_clients; i++) {
q_name = get_rx_queue_name(i);
ringsize, socket_id,
if (clients[i].rx_q == NULL)
rte_exit(EXIT_FAILURE,
"Cannot create rx ring queue for client %u\n", i);
}
return 0;
}
static void
check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
{
#define CHECK_INTERVAL 100
#define MAX_CHECK_TIME 90
uint16_t portid;
uint8_t count, all_ports_up, print_flag = 0;
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 << ports->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",
ports->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;
uint16_t i;
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(*ports));
retval = parse_app_args(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 < ports->num_ports; i++) {
retval = init_port(ports->id[i]);
if (retval != 0)
rte_exit(EXIT_FAILURE,
"Cannot initialise port %u\n",
(unsigned)i);
}
check_all_ports_link_status(ports->num_ports, (~0x0));
init_shm_rings();
return 0;
}
__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)
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)
int rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *link) __rte_warn_unused_result
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_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
int rte_eth_dev_socket_id(uint16_t port_id)
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) __rte_alloc_align(3) __rte_malloc __rte_dealloc_free
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_rxmode rxmode
enum rte_eth_rx_mq_mode mq_mode