#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/queue.h>
#include <netinet/in.h>
#include <setjmp.h>
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1
#define NB_MBUF 8192
#define MAX_PKT_BURST 32
#define BURST_TX_DRAIN_US 100
#define RTE_TEST_RX_DESC_DEFAULT 128
#define RTE_TEST_TX_DESC_DEFAULT 512
static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
static struct ether_addr l2fwd_ports_eth_addr[RTE_MAX_ETHPORTS];
static uint64_t l2fwd_enabled_port_mask;
static uint64_t l2fwd_enabled_crypto_mask;
static uint32_t l2fwd_dst_ports[RTE_MAX_ETHPORTS];
struct pkt_buffer {
unsigned len;
};
#define MAX_RX_QUEUE_PER_LCORE 16
#define MAX_TX_QUEUE_PER_PORT 16
enum l2fwd_crypto_xform_chain {
L2FWD_CRYPTO_CIPHER_HASH,
L2FWD_CRYPTO_HASH_CIPHER
};
struct l2fwd_crypto_options {
unsigned portmask;
unsigned nb_ports_per_lcore;
unsigned refresh_period;
unsigned single_lcore:1;
unsigned sessionless:1;
enum l2fwd_crypto_xform_chain xform_chain;
uint8_t ckey_data[32];
uint8_t ivkey_data[16];
uint8_t akey_data[128];
};
struct l2fwd_crypto_params {
uint8_t dev_id;
uint8_t qp_id;
unsigned digest_length;
unsigned block_size;
struct rte_cryptodev_session *session;
};
struct lcore_queue_conf {
unsigned nb_rx_ports;
unsigned rx_port_list[MAX_RX_QUEUE_PER_LCORE];
unsigned nb_crypto_devs;
unsigned cryptodev_list[MAX_RX_QUEUE_PER_LCORE];
struct pkt_buffer crypto_pkt_buf[RTE_MAX_ETHPORTS];
struct pkt_buffer tx_pkt_buf[RTE_MAX_ETHPORTS];
struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE];
.header_split = 0,
.hw_ip_checksum = 0,
.hw_vlan_filter = 0,
.jumbo_frame = 0,
.hw_strip_crc = 0,
},
.txmode = {
},
};
struct l2fwd_port_statistics {
uint64_t tx;
uint64_t rx;
uint64_t crypto_enqueued;
uint64_t crypto_dequeued;
uint64_t dropped;
struct l2fwd_crypto_statistics {
uint64_t enqueued;
uint64_t dequeued;
uint64_t errors;
struct l2fwd_port_statistics port_statistics[RTE_MAX_ETHPORTS];
struct l2fwd_crypto_statistics crypto_statistics[RTE_MAX_ETHPORTS];
#define TIMER_MILLISECOND 2000000ULL
#define MAX_TIMER_PERIOD 86400
static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000;
uint64_t total_packets_dropped = 0, total_packets_tx = 0, total_packets_rx = 0,
total_packets_enqueued = 0, total_packets_dequeued = 0,
total_packets_errors = 0;
static void
print_stats(void)
{
unsigned portid;
uint64_t cdevid;
const char clr[] = { 27, '[', '2', 'J', '\0' };
const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' };
printf("%s%s", clr, topLeft);
printf("\nPort statistics ====================================");
for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
if ((l2fwd_enabled_port_mask & (1 << portid)) == 0)
continue;
printf("\nStatistics for port %u ------------------------------"
"\nPackets sent: %32"PRIu64
"\nPackets received: %28"PRIu64
"\nPackets dropped: %29"PRIu64,
portid,
port_statistics[portid].tx,
port_statistics[portid].rx,
port_statistics[portid].dropped);
total_packets_dropped += port_statistics[portid].dropped;
total_packets_tx += port_statistics[portid].tx;
total_packets_rx += port_statistics[portid].rx;
}
printf("\nCrypto statistics ==================================");
for (cdevid = 0; cdevid < RTE_CRYPTO_MAX_DEVS; cdevid++) {
if ((l2fwd_enabled_crypto_mask & (1lu << cdevid)) == 0)
continue;
printf("\nStatistics for cryptodev %"PRIu64
" -------------------------"
"\nPackets enqueued: %28"PRIu64
"\nPackets dequeued: %28"PRIu64
"\nPackets errors: %30"PRIu64,
cdevid,
crypto_statistics[cdevid].enqueued,
crypto_statistics[cdevid].dequeued,
crypto_statistics[cdevid].errors);
total_packets_enqueued += crypto_statistics[cdevid].enqueued;
total_packets_dequeued += crypto_statistics[cdevid].dequeued;
total_packets_errors += crypto_statistics[cdevid].errors;
}
printf("\nAggregate statistics ==============================="
"\nTotal packets received: %22"PRIu64
"\nTotal packets enqueued: %22"PRIu64
"\nTotal packets dequeued: %22"PRIu64
"\nTotal packets sent: %26"PRIu64
"\nTotal packets dropped: %23"PRIu64
"\nTotal packets crypto errors: %17"PRIu64,
total_packets_rx,
total_packets_enqueued,
total_packets_dequeued,
total_packets_tx,
total_packets_dropped,
total_packets_errors);
printf("\n====================================================\n");
}
static int
l2fwd_crypto_send_burst(struct lcore_queue_conf *qconf, unsigned n,
struct l2fwd_crypto_params *cparams)
{
unsigned ret;
qconf->crypto_pkt_buf[cparams->dev_id].buffer;
pkt_buffer, (uint16_t) n);
crypto_statistics[cparams->dev_id].enqueued += ret;
crypto_statistics[cparams->dev_id].errors += (n - ret);
do {
} while (++ret < n);
}
return 0;
}
static int
l2fwd_crypto_enqueue(
struct rte_mbuf *m,
struct l2fwd_crypto_params *cparams)
{
unsigned lcore_id, len;
struct lcore_queue_conf *qconf;
qconf = &lcore_queue_conf[lcore_id];
len = qconf->crypto_pkt_buf[cparams->dev_id].len;
qconf->crypto_pkt_buf[cparams->dev_id].buffer[len] = m;
len++;
if (len == MAX_PKT_BURST) {
l2fwd_crypto_send_burst(qconf, MAX_PKT_BURST, cparams);
len = 0;
}
qconf->crypto_pkt_buf[cparams->dev_id].len = len;
return 0;
}
static int
l2fwd_simple_crypto_enqueue(
struct rte_mbuf *m,
struct l2fwd_crypto_params *cparams)
{
unsigned ipdata_offset, pad_len, data_len;
char *padding;
return -1;
ipdata_offset);
pad_len = data_len % cparams->block_size ? cparams->block_size -
(data_len % cparams->block_size) : 0;
if (pad_len) {
return -1;
data_len += pad_len;
memset(padding, 0, pad_len);
}
cparams->digest_length);
return l2fwd_crypto_enqueue(m, cparams);
}
static int
l2fwd_send_burst(
struct lcore_queue_conf *qconf,
unsigned n, uint8_t
port)
{
unsigned ret;
unsigned queueid = 0;
pkt_buffer = (
struct rte_mbuf **)qconf->tx_pkt_buf[port].buffer;
(uint16_t)n);
port_statistics[
port].tx += ret;
port_statistics[
port].dropped += (n - ret);
do {
} while (++ret < n);
}
return 0;
}
static int
l2fwd_send_packet(
struct rte_mbuf *m, uint8_t port)
{
unsigned lcore_id, len;
struct lcore_queue_conf *qconf;
qconf = &lcore_queue_conf[lcore_id];
len = qconf->tx_pkt_buf[port].len;
qconf->tx_pkt_buf[port].buffer[len] = m;
len++;
l2fwd_send_burst(qconf, MAX_PKT_BURST, port);
len = 0;
}
qconf->tx_pkt_buf[port].len = len;
return 0;
}
static void
l2fwd_simple_forward(
struct rte_mbuf *m,
unsigned portid)
{
void *tmp;
unsigned dst_port;
dst_port = l2fwd_dst_ports[portid];
*((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dst_port << 40);
l2fwd_send_packet(m, (uint8_t) dst_port);
}
static void
generate_random_key(uint8_t *key, unsigned length)
{
unsigned i;
for (i = 0; i < length; i++)
key[i] = rand() % 0xff;
}
static struct rte_cryptodev_session *
initialize_crypto_session(struct l2fwd_crypto_options *options,
uint8_t cdev_id)
{
if (options->xform_chain == L2FWD_CRYPTO_CIPHER_HASH) {
first_xform = &options->cipher_xform;
first_xform->
next = &options->auth_xform;
} else {
first_xform = &options->auth_xform;
first_xform->
next = &options->cipher_xform;
}
}
static void
l2fwd_crypto_options_print(struct l2fwd_crypto_options *options);
static void
l2fwd_main_loop(struct l2fwd_crypto_options *options)
{
struct rte_mbuf *m, *pkts_burst[MAX_PKT_BURST];
uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
unsigned i, j, portid, nb_rx;
struct lcore_queue_conf *qconf = &lcore_queue_conf[lcore_id];
US_PER_S * BURST_TX_DRAIN_US;
struct l2fwd_crypto_params *cparams;
struct l2fwd_crypto_params port_cparams[qconf->nb_crypto_devs];
if (qconf->nb_rx_ports == 0) {
RTE_LOG(INFO, L2FWD,
"lcore %u has nothing to do\n", lcore_id);
return;
}
RTE_LOG(INFO, L2FWD,
"entering main loop on lcore %u\n", lcore_id);
l2fwd_crypto_options_print(options);
for (i = 0; i < qconf->nb_rx_ports; i++) {
portid = qconf->rx_port_list[i];
RTE_LOG(INFO, L2FWD,
" -- lcoreid=%u portid=%u\n", lcore_id,
portid);
}
for (i = 0; i < qconf->nb_crypto_devs; i++) {
port_cparams[i].dev_id = qconf->cryptodev_list[i];
port_cparams[i].qp_id = 0;
port_cparams[i].block_size = 64;
port_cparams[i].digest_length = 20;
port_cparams[i].iv_key.data =
port_cparams[i].iv_key.length = 16;
(void *)port_cparams[i].iv_key.data);
generate_random_key(port_cparams[i].iv_key.data,
sizeof(cparams[i].iv_key.length));
port_cparams[i].session = initialize_crypto_session(options,
port_cparams[i].dev_id);
if (port_cparams[i].session == NULL)
return;
RTE_LOG(INFO, L2FWD,
" -- lcoreid=%u cryptoid=%u\n", lcore_id,
port_cparams[i].dev_id);
}
while (1) {
cur_tsc = rte_rdtsc();
diff_tsc = cur_tsc - prev_tsc;
for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
if (qconf->tx_pkt_buf[portid].len == 0)
continue;
l2fwd_send_burst(&lcore_queue_conf[lcore_id],
qconf->tx_pkt_buf[portid].len,
(uint8_t) portid);
qconf->tx_pkt_buf[portid].len = 0;
}
if (timer_period > 0) {
timer_tsc += diff_tsc;
(uint64_t)timer_period)) {
&& options->refresh_period) {
print_stats();
timer_tsc = 0;
}
}
}
prev_tsc = cur_tsc;
}
for (i = 0; i < qconf->nb_rx_ports; i++) {
portid = qconf->rx_port_list[i];
cparams = &port_cparams[i];
pkts_burst, MAX_PKT_BURST);
port_statistics[portid].rx += nb_rx;
for (j = 0; j < nb_rx; j++) {
m = pkts_burst[j];
l2fwd_mbuf_ol_pool,
for (; j < nb_rx; j++) {
port_statistics[portid].dropped++;
}
break;
}
l2fwd_simple_crypto_enqueue(m, ol, cparams);
}
cparams->dev_id, cparams->qp_id,
pkts_burst, MAX_PKT_BURST);
crypto_statistics[cparams->dev_id].dequeued += nb_rx;
for (j = 0; j < nb_rx; j++) {
m = pkts_burst[j];
l2fwd_simple_forward(m, portid);
}
}
}
}
static int
l2fwd_launch_one_lcore(void *arg)
{
l2fwd_main_loop((struct l2fwd_crypto_options *)arg);
return 0;
}
static void
l2fwd_crypto_usage(const char *prgname)
{
printf("%s [EAL options] -- --cdev TYPE [optional parameters]\n"
" -p PORTMASK: hexadecimal bitmask of ports to configure\n"
" -q NQ: number of queue (=ports) per lcore (default is 1)\n"
" -s manage all ports from single lcore"
" -t PERIOD: statistics will be refreshed each PERIOD seconds"
" (0 to disable, 10 default, 86400 maximum)\n"
" --cdev AESNI_MB / QAT\n"
" --chain HASH_CIPHER / CIPHER_HASH\n"
" --cipher_algo ALGO\n"
" --cipher_op ENCRYPT / DECRYPT\n"
" --cipher_key KEY\n"
" --auth ALGO\n"
" --auth_op GENERATE / VERIFY\n"
" --auth_key KEY\n"
" --sessionless\n",
prgname);
}
static int
{
if (strcmp("AESNI_MB", optarg) == 0) {
return 0;
} else if (strcmp("QAT", optarg) == 0) {
return 0;
}
return -1;
}
static int
parse_crypto_opt_chain(struct l2fwd_crypto_options *options, char *optarg)
{
if (strcmp("CIPHER_HASH", optarg) == 0) {
options->xform_chain = L2FWD_CRYPTO_CIPHER_HASH;
return 0;
} else if (strcmp("HASH_CIPHER", optarg) == 0) {
options->xform_chain = L2FWD_CRYPTO_HASH_CIPHER;
return 0;
}
return -1;
}
static int
{
if (strcmp("AES_CBC", optarg) == 0) {
return 0;
} else if (strcmp("AES_GCM", optarg) == 0) {
return 0;
}
printf("Cipher algorithm not supported!\n");
return -1;
}
static int
{
if (strcmp("ENCRYPT", optarg) == 0) {
return 0;
} else if (strcmp("DECRYPT", optarg) == 0) {
return 0;
}
printf("Cipher operation not supported!\n");
return -1;
}
static int
unsigned length __rte_unused, char *arg __rte_unused)
{
printf("Currently an unsupported argument!\n");
return -1;
}
static int
{
if (strcmp("SHA1", optarg) == 0) {
return 0;
} else if (strcmp("SHA1_HMAC", optarg) == 0) {
return 0;
} else if (strcmp("SHA224", optarg) == 0) {
return 0;
} else if (strcmp("SHA224_HMAC", optarg) == 0) {
return 0;
} else if (strcmp("SHA256", optarg) == 0) {
return 0;
} else if (strcmp("SHA256_HMAC", optarg) == 0) {
return 0;
} else if (strcmp("SHA512", optarg) == 0) {
return 0;
} else if (strcmp("SHA512_HMAC", optarg) == 0) {
return 0;
}
printf("Authentication algorithm specified not supported!\n");
return -1;
}
static int
{
if (strcmp("VERIFY", optarg) == 0) {
return 0;
} else if (strcmp("GENERATE", optarg) == 0) {
return 0;
}
printf("Authentication operation specified not supported!\n");
return -1;
}
static int
l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options,
struct option *lgopts, int option_index)
{
if (strcmp(lgopts[option_index].name, "cdev_type") == 0)
return parse_cryptodev_type(&options->cdev_type, optarg);
else if (strcmp(lgopts[option_index].name, "chain") == 0)
return parse_crypto_opt_chain(options, optarg);
else if (strcmp(lgopts[option_index].name, "cipher_algo") == 0)
return parse_cipher_algo(&options->cipher_xform.cipher.algo,
optarg);
else if (strcmp(lgopts[option_index].name, "cipher_op") == 0)
return parse_cipher_op(&options->cipher_xform.cipher.op,
optarg);
else if (strcmp(lgopts[option_index].name, "cipher_key") == 0)
return parse_key(&options->cipher_xform.cipher.key,
sizeof(options->ckey_data), optarg);
else if (strcmp(lgopts[option_index].name, "iv") == 0)
return parse_key(&options->iv_key, sizeof(options->ivkey_data),
optarg);
else if (strcmp(lgopts[option_index].name, "auth_algo") == 0)
return parse_auth_algo(&options->cipher_xform.auth.algo,
optarg);
else if (strcmp(lgopts[option_index].name, "auth_op") == 0)
return parse_auth_op(&options->cipher_xform.auth.op,
optarg);
else if (strcmp(lgopts[option_index].name, "auth_key") == 0)
return parse_key(&options->auth_xform.auth.key,
sizeof(options->akey_data), optarg);
else if (strcmp(lgopts[option_index].name, "sessionless") == 0) {
options->sessionless = 1;
return 0;
}
return -1;
}
static int
l2fwd_crypto_parse_portmask(struct l2fwd_crypto_options *options,
const char *q_arg)
{
char *end = NULL;
unsigned long pm;
pm = strtoul(q_arg, &end, 16);
if ((pm == '\0') || (end == NULL) || (*end != '\0'))
pm = 0;
options->portmask = pm;
if (options->portmask == 0) {
printf("invalid portmask specified\n");
return -1;
}
return pm;
}
static int
l2fwd_crypto_parse_nqueue(struct l2fwd_crypto_options *options,
const char *q_arg)
{
char *end = NULL;
unsigned long n;
n = strtoul(q_arg, &end, 10);
if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0'))
n = 0;
else if (n >= MAX_RX_QUEUE_PER_LCORE)
n = 0;
options->nb_ports_per_lcore = n;
if (options->nb_ports_per_lcore == 0) {
printf("invalid number of ports selected\n");
return -1;
}
return 0;
}
static int
l2fwd_crypto_parse_timer_period(struct l2fwd_crypto_options *options,
const char *q_arg)
{
char *end = NULL;
long int n;
n = strtol(q_arg, &end, 10);
if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0'))
n = 0;
if (n >= MAX_TIMER_PERIOD) {
printf("Warning refresh period specified %ld is greater than "
"max value %d! using max value",
n, MAX_TIMER_PERIOD);
n = MAX_TIMER_PERIOD;
}
options->refresh_period = n * 1000 * TIMER_MILLISECOND;
return 0;
}
static void
l2fwd_crypto_default_options(struct l2fwd_crypto_options *options)
{
srand(time(NULL));
options->portmask = 0xffffffff;
options->nb_ports_per_lcore = 1;
options->refresh_period = 10000;
options->single_lcore = 0;
options->sessionless = 0;
options->xform_chain = L2FWD_CRYPTO_CIPHER_HASH;
options->cipher_xform.next = NULL;
generate_random_key(options->ckey_data, sizeof(options->ckey_data));
options->cipher_xform.cipher.key.data = options->ckey_data;
options->cipher_xform.cipher.key.phys_addr = 0;
options->cipher_xform.cipher.key.length = 16;
options->auth_xform.next = NULL;
options->auth_xform.auth.add_auth_data_length = 0;
options->auth_xform.auth.digest_length = 20;
generate_random_key(options->akey_data, sizeof(options->akey_data));
options->auth_xform.auth.key.data = options->akey_data;
options->auth_xform.auth.key.phys_addr = 0;
options->auth_xform.auth.key.length = 20;
}
static void
l2fwd_crypto_options_print(struct l2fwd_crypto_options *options)
{
printf("Options:-\nn");
printf("portmask: %x\n", options->portmask);
printf("ports per lcore: %u\n", options->nb_ports_per_lcore);
printf("refresh period : %u\n", options->refresh_period);
printf("single lcore mode: %s\n",
options->single_lcore ? "enabled" : "disabled");
printf("stats_printing: %s\n",
options->refresh_period == 0 ? "disabled" : "enabled");
switch (options->cdev_type) {
printf("crytpodev type: AES-NI MB PMD\n"); break;
printf("crytpodev type: QAT PMD\n"); break;
default:
break;
}
printf("sessionless crypto: %s\n",
options->sessionless ? "enabled" : "disabled");
#if 0
options->xform_chain = L2FWD_CRYPTO_CIPHER_HASH;
options->cipher_xform.next = NULL;
generate_random_key(options->ckey_data, sizeof(options->ckey_data));
options->cipher_xform.cipher.key.data = options->ckey_data;
options->cipher_xform.cipher.key.phys_addr = 0;
options->cipher_xform.cipher.key.length = 16;
options->auth_xform.next = NULL;
options->auth_xform.auth.add_auth_data_length = 0;
options->auth_xform.auth.digest_length = 20;
generate_random_key(options->akey_data, sizeof(options->akey_data));
options->auth_xform.auth.key.data = options->akey_data;
options->auth_xform.auth.key.phys_addr = 0;
options->auth_xform.auth.key.length = 20;
#endif
}
static int
l2fwd_crypto_parse_args(struct l2fwd_crypto_options *options,
int argc, char **argv)
{
int opt, retval, option_index;
char **argvopt = argv, *prgname = argv[0];
static struct option lgopts[] = {
{ "sessionless", no_argument, 0, 0 },
{ "cdev_type", required_argument, 0, 0 },
{ "chain", required_argument, 0, 0 },
{ "cipher_algo", required_argument, 0, 0 },
{ "cipher_op", required_argument, 0, 0 },
{ "cipher_key", required_argument, 0, 0 },
{ "auth_algo", required_argument, 0, 0 },
{ "auth_op", required_argument, 0, 0 },
{ "auth_key", required_argument, 0, 0 },
{ "iv", required_argument, 0, 0 },
{ "sessionless", no_argument, 0, 0 },
{ NULL, 0, 0, 0 }
};
l2fwd_crypto_default_options(options);
while ((opt = getopt_long(argc, argvopt, "p:q:st:", lgopts,
&option_index)) != EOF) {
switch (opt) {
case 0:
retval = l2fwd_crypto_parse_args_long_options(options,
lgopts, option_index);
if (retval < 0) {
l2fwd_crypto_usage(prgname);
return -1;
}
break;
case 'p':
retval = l2fwd_crypto_parse_portmask(options, optarg);
if (retval < 0) {
l2fwd_crypto_usage(prgname);
return -1;
}
break;
case 'q':
retval = l2fwd_crypto_parse_nqueue(options, optarg);
if (retval < 0) {
l2fwd_crypto_usage(prgname);
return -1;
}
break;
case 's':
options->single_lcore = 1;
break;
case 't':
retval = l2fwd_crypto_parse_timer_period(options,
optarg);
if (retval < 0) {
l2fwd_crypto_usage(prgname);
return -1;
}
break;
default:
l2fwd_crypto_usage(prgname);
return -1;
}
}
if (optind >= 0)
argv[optind-1] = prgname;
retval = optind-1;
optind = 0;
return retval;
}
static void
check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)
{
#define CHECK_INTERVAL 100
#define MAX_CHECK_TIME 90
uint8_t portid, count, all_ports_up, print_flag = 0;
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 << portid)) == 0)
continue;
memset(&link, 0, sizeof(link));
if (print_flag == 1) {
if (link.link_status)
printf("Port %d Link Up - speed %u "
"Mbps - %s\n", (uint8_t)portid,
(unsigned)link.link_speed,
("full-duplex") : ("half-duplex\n"));
else
printf("Port %d Link Down\n",
(uint8_t)portid);
continue;
}
if (link.link_status == 0) {
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");
}
}
}
static int
initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports)
{
unsigned i, cdev_id, cdev_count, enabled_cdev_count = 0;
int retval;
return -1;
for (i = 0; i < nb_ports; i++) {
NULL);
if (id < 0)
return -1;
}
}
for (cdev_id = 0;
cdev_id < cdev_count && enabled_cdev_count < nb_ports;
cdev_id++) {
.session_mp = {
.nb_objs = 2048,
.cache_size = 64
}
};
if (dev_info.dev_type != options->cdev_type)
continue;
if (retval < 0) {
printf("Failed to configure cryptodev %u", cdev_id);
return -1;
}
qp_conf.nb_descriptors = 2048;
if (retval < 0) {
printf("Failed to setup queue pair %u on cryptodev %u",
0, cdev_id);
return -1;
}
l2fwd_enabled_crypto_mask |= (1 << cdev_id);
enabled_cdev_count++;
}
return enabled_cdev_count;
}
static int
initialize_ports(struct l2fwd_crypto_options *options)
{
uint8_t last_portid, portid;
unsigned enabled_portcount = 0;
if (nb_ports == 0) {
printf("No Ethernet ports - bye\n");
return -1;
}
if (nb_ports > RTE_MAX_ETHPORTS)
nb_ports = RTE_MAX_ETHPORTS;
for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++)
l2fwd_dst_ports[portid] = 0;
for (last_portid = 0, portid = 0; portid < nb_ports; portid++) {
int retval;
if ((options->portmask & (1 << portid)) == 0)
continue;
printf("Initializing port %u... ", (unsigned) portid);
fflush(stdout);
if (retval < 0) {
printf("Cannot configure device: err=%d, port=%u\n",
retval, (unsigned) portid);
return -1;
}
fflush(stdout);
rte_eth_dev_socket_id(portid),
NULL, l2fwd_pktmbuf_pool);
if (retval < 0) {
printf("rte_eth_rx_queue_setup:err=%d, port=%u\n",
retval, (unsigned) portid);
return -1;
}
fflush(stdout);
rte_eth_dev_socket_id(portid),
NULL);
if (retval < 0) {
printf("rte_eth_tx_queue_setup:err=%d, port=%u\n",
retval, (unsigned) portid);
return -1;
}
if (retval < 0) {
printf("rte_eth_dev_start:err=%d, port=%u\n",
retval, (unsigned) portid);
return -1;
}
printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
(unsigned) portid,
l2fwd_ports_eth_addr[portid].addr_bytes[0],
l2fwd_ports_eth_addr[portid].addr_bytes[1],
l2fwd_ports_eth_addr[portid].addr_bytes[2],
l2fwd_ports_eth_addr[portid].addr_bytes[3],
l2fwd_ports_eth_addr[portid].addr_bytes[4],
l2fwd_ports_eth_addr[portid].addr_bytes[5]);
memset(&port_statistics, 0, sizeof(port_statistics));
if (enabled_portcount % 2) {
l2fwd_dst_ports[portid] = last_portid;
l2fwd_dst_ports[last_portid] = portid;
} else {
last_portid = portid;
}
l2fwd_enabled_port_mask |= (1 << portid);
enabled_portcount++;
}
if (enabled_portcount == 1) {
l2fwd_dst_ports[last_portid] = last_portid;
} else if (enabled_portcount % 2) {
printf("odd number of ports in portmask- bye\n");
return -1;
}
check_all_ports_link_status(nb_ports, l2fwd_enabled_port_mask);
return enabled_portcount;
}
int
main(int argc, char **argv)
{
struct lcore_queue_conf *qconf;
struct l2fwd_crypto_options options;
uint8_t nb_ports, nb_cryptodevs, portid, cdev_id;
unsigned lcore_id, rx_lcore_id;
int ret, enabled_cdevcount, enabled_portcount;
if (ret < 0)
rte_exit(EXIT_FAILURE,
"Invalid EAL arguments\n");
argc -= ret;
argv += ret;
ret = l2fwd_crypto_parse_args(&options, argc, argv);
if (ret < 0)
rte_exit(EXIT_FAILURE,
"Invalid L2FWD-CRYPTO arguments\n");
if (l2fwd_pktmbuf_pool == NULL)
rte_exit(EXIT_FAILURE,
"Cannot create mbuf pool\n");
if (l2fwd_mbuf_ol_pool == NULL)
rte_exit(EXIT_FAILURE,
"Cannot create crypto op pool\n");
enabled_portcount = initialize_ports(&options);
if (enabled_portcount < 1)
rte_exit(EXIT_FAILURE,
"Failed to initial Ethernet ports\n");
for (rx_lcore_id = 0, qconf = NULL, portid = 0;
portid < nb_ports; portid++) {
if ((options.portmask & (1 << portid)) == 0)
continue;
if (options.single_lcore && qconf == NULL) {
rx_lcore_id++;
if (rx_lcore_id >= RTE_MAX_LCORE)
"Not enough cores\n");
}
} else if (!options.single_lcore) {
lcore_queue_conf[rx_lcore_id].nb_rx_ports ==
options.nb_ports_per_lcore) {
rx_lcore_id++;
if (rx_lcore_id >= RTE_MAX_LCORE)
"Not enough cores\n");
}
}
if (qconf != &lcore_queue_conf[rx_lcore_id])
qconf = &lcore_queue_conf[rx_lcore_id];
qconf->rx_port_list[qconf->nb_rx_ports] = portid;
qconf->nb_rx_ports++;
printf("Lcore %u: RX port %u\n", rx_lcore_id, (unsigned)portid);
}
enabled_cdevcount = initialize_cryptodevs(&options, enabled_portcount);
if (enabled_cdevcount < 1)
rte_exit(EXIT_FAILURE,
"Failed to initial crypto devices\n");
for (rx_lcore_id = 0, qconf = NULL, cdev_id = 0;
cdev_id < nb_cryptodevs && enabled_cdevcount;
cdev_id++) {
if (options.cdev_type != info.dev_type)
continue;
if (options.single_lcore && qconf == NULL) {
rx_lcore_id++;
if (rx_lcore_id >= RTE_MAX_LCORE)
"Not enough cores\n");
}
} else if (!options.single_lcore) {
lcore_queue_conf[rx_lcore_id].nb_crypto_devs ==
options.nb_ports_per_lcore) {
rx_lcore_id++;
if (rx_lcore_id >= RTE_MAX_LCORE)
"Not enough cores\n");
}
}
if (qconf != &lcore_queue_conf[rx_lcore_id])
qconf = &lcore_queue_conf[rx_lcore_id];
qconf->cryptodev_list[qconf->nb_crypto_devs] = cdev_id;
qconf->nb_crypto_devs++;
enabled_cdevcount--;
printf("Lcore %u: cryptodev %u\n", rx_lcore_id,
(unsigned)cdev_id);
}
return -1;
}
return 0;
}