#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 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) {
printf("Port %d Link Up - speed %u "
"Mbps - %s\n", ports->id[portid],
("full-duplex") : ("half-duplex"));
else
printf("Port %d Link Down\n",
(uint8_t)ports->id[portid]);
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;
}