1387259bdSDeclan Doherty /*- 2387259bdSDeclan Doherty * BSD LICENSE 3387259bdSDeclan Doherty * 41bd407faSFiona Trahe * Copyright(c) 2015-2016 Intel Corporation. All rights reserved. 5387259bdSDeclan Doherty * All rights reserved. 6387259bdSDeclan Doherty * 7387259bdSDeclan Doherty * Redistribution and use in source and binary forms, with or without 8387259bdSDeclan Doherty * modification, are permitted provided that the following conditions 9387259bdSDeclan Doherty * are met: 10387259bdSDeclan Doherty * 11387259bdSDeclan Doherty * * Redistributions of source code must retain the above copyright 12387259bdSDeclan Doherty * notice, this list of conditions and the following disclaimer. 13387259bdSDeclan Doherty * * Redistributions in binary form must reproduce the above copyright 14387259bdSDeclan Doherty * notice, this list of conditions and the following disclaimer in 15387259bdSDeclan Doherty * the documentation and/or other materials provided with the 16387259bdSDeclan Doherty * distribution. 17387259bdSDeclan Doherty * * Neither the name of Intel Corporation nor the names of its 18387259bdSDeclan Doherty * contributors may be used to endorse or promote products derived 19387259bdSDeclan Doherty * from this software without specific prior written permission. 20387259bdSDeclan Doherty * 21387259bdSDeclan Doherty * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22387259bdSDeclan Doherty * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23387259bdSDeclan Doherty * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24387259bdSDeclan Doherty * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25387259bdSDeclan Doherty * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26387259bdSDeclan Doherty * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27387259bdSDeclan Doherty * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28387259bdSDeclan Doherty * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29387259bdSDeclan Doherty * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30387259bdSDeclan Doherty * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31387259bdSDeclan Doherty * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32387259bdSDeclan Doherty */ 33387259bdSDeclan Doherty 34387259bdSDeclan Doherty #include <time.h> 35387259bdSDeclan Doherty #include <stdio.h> 36387259bdSDeclan Doherty #include <stdlib.h> 37387259bdSDeclan Doherty #include <string.h> 38387259bdSDeclan Doherty #include <stdint.h> 39387259bdSDeclan Doherty #include <inttypes.h> 40387259bdSDeclan Doherty #include <sys/types.h> 41387259bdSDeclan Doherty #include <sys/queue.h> 42387259bdSDeclan Doherty #include <netinet/in.h> 43387259bdSDeclan Doherty #include <setjmp.h> 44387259bdSDeclan Doherty #include <stdarg.h> 45387259bdSDeclan Doherty #include <ctype.h> 46387259bdSDeclan Doherty #include <errno.h> 47387259bdSDeclan Doherty #include <getopt.h> 48387259bdSDeclan Doherty 49387259bdSDeclan Doherty #include <rte_atomic.h> 50387259bdSDeclan Doherty #include <rte_branch_prediction.h> 51387259bdSDeclan Doherty #include <rte_common.h> 52387259bdSDeclan Doherty #include <rte_cryptodev.h> 53387259bdSDeclan Doherty #include <rte_cycles.h> 54387259bdSDeclan Doherty #include <rte_debug.h> 55387259bdSDeclan Doherty #include <rte_eal.h> 56387259bdSDeclan Doherty #include <rte_ether.h> 57387259bdSDeclan Doherty #include <rte_ethdev.h> 58387259bdSDeclan Doherty #include <rte_interrupts.h> 59387259bdSDeclan Doherty #include <rte_ip.h> 60387259bdSDeclan Doherty #include <rte_launch.h> 61387259bdSDeclan Doherty #include <rte_lcore.h> 62387259bdSDeclan Doherty #include <rte_log.h> 63387259bdSDeclan Doherty #include <rte_malloc.h> 64387259bdSDeclan Doherty #include <rte_mbuf.h> 65387259bdSDeclan Doherty #include <rte_mbuf_offload.h> 66387259bdSDeclan Doherty #include <rte_memcpy.h> 67387259bdSDeclan Doherty #include <rte_memory.h> 68387259bdSDeclan Doherty #include <rte_mempool.h> 69387259bdSDeclan Doherty #include <rte_memzone.h> 70387259bdSDeclan Doherty #include <rte_pci.h> 71387259bdSDeclan Doherty #include <rte_per_lcore.h> 72387259bdSDeclan Doherty #include <rte_prefetch.h> 73387259bdSDeclan Doherty #include <rte_random.h> 74387259bdSDeclan Doherty #include <rte_ring.h> 75387259bdSDeclan Doherty 76387259bdSDeclan Doherty #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1 77387259bdSDeclan Doherty 78387259bdSDeclan Doherty #define NB_MBUF 8192 79387259bdSDeclan Doherty 80387259bdSDeclan Doherty #define MAX_PKT_BURST 32 81387259bdSDeclan Doherty #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */ 82387259bdSDeclan Doherty 83387259bdSDeclan Doherty /* 84387259bdSDeclan Doherty * Configurable number of RX/TX ring descriptors 85387259bdSDeclan Doherty */ 86387259bdSDeclan Doherty #define RTE_TEST_RX_DESC_DEFAULT 128 87387259bdSDeclan Doherty #define RTE_TEST_TX_DESC_DEFAULT 512 88387259bdSDeclan Doherty static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; 89387259bdSDeclan Doherty static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; 90387259bdSDeclan Doherty 91387259bdSDeclan Doherty /* ethernet addresses of ports */ 92387259bdSDeclan Doherty static struct ether_addr l2fwd_ports_eth_addr[RTE_MAX_ETHPORTS]; 93387259bdSDeclan Doherty 94387259bdSDeclan Doherty /* mask of enabled ports */ 95387259bdSDeclan Doherty static uint64_t l2fwd_enabled_port_mask; 96387259bdSDeclan Doherty static uint64_t l2fwd_enabled_crypto_mask; 97387259bdSDeclan Doherty 98387259bdSDeclan Doherty /* list of enabled ports */ 99387259bdSDeclan Doherty static uint32_t l2fwd_dst_ports[RTE_MAX_ETHPORTS]; 100387259bdSDeclan Doherty 101387259bdSDeclan Doherty 102387259bdSDeclan Doherty struct pkt_buffer { 103387259bdSDeclan Doherty unsigned len; 104387259bdSDeclan Doherty struct rte_mbuf *buffer[MAX_PKT_BURST]; 105387259bdSDeclan Doherty }; 106387259bdSDeclan Doherty 107387259bdSDeclan Doherty #define MAX_RX_QUEUE_PER_LCORE 16 108387259bdSDeclan Doherty #define MAX_TX_QUEUE_PER_PORT 16 109387259bdSDeclan Doherty 110387259bdSDeclan Doherty enum l2fwd_crypto_xform_chain { 111387259bdSDeclan Doherty L2FWD_CRYPTO_CIPHER_HASH, 112387259bdSDeclan Doherty L2FWD_CRYPTO_HASH_CIPHER 113387259bdSDeclan Doherty }; 114387259bdSDeclan Doherty 115*a7f4562bSFiona Trahe struct l2fwd_key { 116*a7f4562bSFiona Trahe uint8_t *data; 117*a7f4562bSFiona Trahe uint32_t length; 118*a7f4562bSFiona Trahe phys_addr_t phys_addr; 119*a7f4562bSFiona Trahe }; 120*a7f4562bSFiona Trahe 121387259bdSDeclan Doherty /** l2fwd crypto application command line options */ 122387259bdSDeclan Doherty struct l2fwd_crypto_options { 123387259bdSDeclan Doherty unsigned portmask; 124387259bdSDeclan Doherty unsigned nb_ports_per_lcore; 125387259bdSDeclan Doherty unsigned refresh_period; 126387259bdSDeclan Doherty unsigned single_lcore:1; 127387259bdSDeclan Doherty 128387259bdSDeclan Doherty enum rte_cryptodev_type cdev_type; 129387259bdSDeclan Doherty unsigned sessionless:1; 130387259bdSDeclan Doherty 131387259bdSDeclan Doherty enum l2fwd_crypto_xform_chain xform_chain; 132387259bdSDeclan Doherty 1331bd407faSFiona Trahe struct rte_crypto_sym_xform cipher_xform; 134387259bdSDeclan Doherty uint8_t ckey_data[32]; 135387259bdSDeclan Doherty 136*a7f4562bSFiona Trahe struct l2fwd_key iv_key; 137387259bdSDeclan Doherty uint8_t ivkey_data[16]; 138387259bdSDeclan Doherty 1391bd407faSFiona Trahe struct rte_crypto_sym_xform auth_xform; 140387259bdSDeclan Doherty uint8_t akey_data[128]; 141387259bdSDeclan Doherty }; 142387259bdSDeclan Doherty 143387259bdSDeclan Doherty /** l2fwd crypto lcore params */ 144387259bdSDeclan Doherty struct l2fwd_crypto_params { 145387259bdSDeclan Doherty uint8_t dev_id; 146387259bdSDeclan Doherty uint8_t qp_id; 147387259bdSDeclan Doherty 148387259bdSDeclan Doherty unsigned digest_length; 149387259bdSDeclan Doherty unsigned block_size; 150*a7f4562bSFiona Trahe struct l2fwd_key iv_key; 1511bd407faSFiona Trahe struct rte_cryptodev_sym_session *session; 152387259bdSDeclan Doherty }; 153387259bdSDeclan Doherty 154387259bdSDeclan Doherty /** lcore configuration */ 155387259bdSDeclan Doherty struct lcore_queue_conf { 156387259bdSDeclan Doherty unsigned nb_rx_ports; 157387259bdSDeclan Doherty unsigned rx_port_list[MAX_RX_QUEUE_PER_LCORE]; 158387259bdSDeclan Doherty 159387259bdSDeclan Doherty unsigned nb_crypto_devs; 160387259bdSDeclan Doherty unsigned cryptodev_list[MAX_RX_QUEUE_PER_LCORE]; 161387259bdSDeclan Doherty 162387259bdSDeclan Doherty struct pkt_buffer crypto_pkt_buf[RTE_MAX_ETHPORTS]; 163387259bdSDeclan Doherty struct pkt_buffer tx_pkt_buf[RTE_MAX_ETHPORTS]; 164387259bdSDeclan Doherty } __rte_cache_aligned; 165387259bdSDeclan Doherty 166387259bdSDeclan Doherty struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE]; 167387259bdSDeclan Doherty 168387259bdSDeclan Doherty static const struct rte_eth_conf port_conf = { 169387259bdSDeclan Doherty .rxmode = { 170387259bdSDeclan Doherty .split_hdr_size = 0, 171387259bdSDeclan Doherty .header_split = 0, /**< Header Split disabled */ 172387259bdSDeclan Doherty .hw_ip_checksum = 0, /**< IP checksum offload disabled */ 173387259bdSDeclan Doherty .hw_vlan_filter = 0, /**< VLAN filtering disabled */ 174387259bdSDeclan Doherty .jumbo_frame = 0, /**< Jumbo Frame Support disabled */ 175387259bdSDeclan Doherty .hw_strip_crc = 0, /**< CRC stripped by hardware */ 176387259bdSDeclan Doherty }, 177387259bdSDeclan Doherty .txmode = { 178387259bdSDeclan Doherty .mq_mode = ETH_MQ_TX_NONE, 179387259bdSDeclan Doherty }, 180387259bdSDeclan Doherty }; 181387259bdSDeclan Doherty 182387259bdSDeclan Doherty struct rte_mempool *l2fwd_pktmbuf_pool; 183387259bdSDeclan Doherty struct rte_mempool *l2fwd_mbuf_ol_pool; 184387259bdSDeclan Doherty 185387259bdSDeclan Doherty /* Per-port statistics struct */ 186387259bdSDeclan Doherty struct l2fwd_port_statistics { 187387259bdSDeclan Doherty uint64_t tx; 188387259bdSDeclan Doherty uint64_t rx; 189387259bdSDeclan Doherty 190387259bdSDeclan Doherty uint64_t crypto_enqueued; 191387259bdSDeclan Doherty uint64_t crypto_dequeued; 192387259bdSDeclan Doherty 193387259bdSDeclan Doherty uint64_t dropped; 194387259bdSDeclan Doherty } __rte_cache_aligned; 195387259bdSDeclan Doherty 196387259bdSDeclan Doherty struct l2fwd_crypto_statistics { 197387259bdSDeclan Doherty uint64_t enqueued; 198387259bdSDeclan Doherty uint64_t dequeued; 199387259bdSDeclan Doherty 200387259bdSDeclan Doherty uint64_t errors; 201387259bdSDeclan Doherty } __rte_cache_aligned; 202387259bdSDeclan Doherty 203387259bdSDeclan Doherty struct l2fwd_port_statistics port_statistics[RTE_MAX_ETHPORTS]; 204387259bdSDeclan Doherty struct l2fwd_crypto_statistics crypto_statistics[RTE_MAX_ETHPORTS]; 205387259bdSDeclan Doherty 206387259bdSDeclan Doherty /* A tsc-based timer responsible for triggering statistics printout */ 207387259bdSDeclan Doherty #define TIMER_MILLISECOND 2000000ULL /* around 1ms at 2 Ghz */ 208387259bdSDeclan Doherty #define MAX_TIMER_PERIOD 86400 /* 1 day max */ 209387259bdSDeclan Doherty 210387259bdSDeclan Doherty /* default period is 10 seconds */ 211387259bdSDeclan Doherty static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; 212387259bdSDeclan Doherty 213387259bdSDeclan Doherty /* Print out statistics on packets dropped */ 214387259bdSDeclan Doherty static void 215387259bdSDeclan Doherty print_stats(void) 216387259bdSDeclan Doherty { 21728523d9aSPablo de Lara uint64_t total_packets_dropped, total_packets_tx, total_packets_rx; 21828523d9aSPablo de Lara uint64_t total_packets_enqueued, total_packets_dequeued, 21928523d9aSPablo de Lara total_packets_errors; 220387259bdSDeclan Doherty unsigned portid; 221387259bdSDeclan Doherty uint64_t cdevid; 222387259bdSDeclan Doherty 22328523d9aSPablo de Lara total_packets_dropped = 0; 22428523d9aSPablo de Lara total_packets_tx = 0; 22528523d9aSPablo de Lara total_packets_rx = 0; 22628523d9aSPablo de Lara total_packets_enqueued = 0; 22728523d9aSPablo de Lara total_packets_dequeued = 0; 22828523d9aSPablo de Lara total_packets_errors = 0; 229387259bdSDeclan Doherty 230387259bdSDeclan Doherty const char clr[] = { 27, '[', '2', 'J', '\0' }; 231387259bdSDeclan Doherty const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' }; 232387259bdSDeclan Doherty 233387259bdSDeclan Doherty /* Clear screen and move to top left */ 234387259bdSDeclan Doherty printf("%s%s", clr, topLeft); 235387259bdSDeclan Doherty 236387259bdSDeclan Doherty printf("\nPort statistics ===================================="); 237387259bdSDeclan Doherty 238387259bdSDeclan Doherty for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { 239387259bdSDeclan Doherty /* skip disabled ports */ 240387259bdSDeclan Doherty if ((l2fwd_enabled_port_mask & (1 << portid)) == 0) 241387259bdSDeclan Doherty continue; 242387259bdSDeclan Doherty printf("\nStatistics for port %u ------------------------------" 243387259bdSDeclan Doherty "\nPackets sent: %32"PRIu64 244387259bdSDeclan Doherty "\nPackets received: %28"PRIu64 245387259bdSDeclan Doherty "\nPackets dropped: %29"PRIu64, 246387259bdSDeclan Doherty portid, 247387259bdSDeclan Doherty port_statistics[portid].tx, 248387259bdSDeclan Doherty port_statistics[portid].rx, 249387259bdSDeclan Doherty port_statistics[portid].dropped); 250387259bdSDeclan Doherty 251387259bdSDeclan Doherty total_packets_dropped += port_statistics[portid].dropped; 252387259bdSDeclan Doherty total_packets_tx += port_statistics[portid].tx; 253387259bdSDeclan Doherty total_packets_rx += port_statistics[portid].rx; 254387259bdSDeclan Doherty } 255387259bdSDeclan Doherty printf("\nCrypto statistics =================================="); 256387259bdSDeclan Doherty 257387259bdSDeclan Doherty for (cdevid = 0; cdevid < RTE_CRYPTO_MAX_DEVS; cdevid++) { 258387259bdSDeclan Doherty /* skip disabled ports */ 259387259bdSDeclan Doherty if ((l2fwd_enabled_crypto_mask & (1lu << cdevid)) == 0) 260387259bdSDeclan Doherty continue; 261387259bdSDeclan Doherty printf("\nStatistics for cryptodev %"PRIu64 262387259bdSDeclan Doherty " -------------------------" 263387259bdSDeclan Doherty "\nPackets enqueued: %28"PRIu64 264387259bdSDeclan Doherty "\nPackets dequeued: %28"PRIu64 265387259bdSDeclan Doherty "\nPackets errors: %30"PRIu64, 266387259bdSDeclan Doherty cdevid, 267387259bdSDeclan Doherty crypto_statistics[cdevid].enqueued, 268387259bdSDeclan Doherty crypto_statistics[cdevid].dequeued, 269387259bdSDeclan Doherty crypto_statistics[cdevid].errors); 270387259bdSDeclan Doherty 271387259bdSDeclan Doherty total_packets_enqueued += crypto_statistics[cdevid].enqueued; 272387259bdSDeclan Doherty total_packets_dequeued += crypto_statistics[cdevid].dequeued; 273387259bdSDeclan Doherty total_packets_errors += crypto_statistics[cdevid].errors; 274387259bdSDeclan Doherty } 275387259bdSDeclan Doherty printf("\nAggregate statistics ===============================" 276387259bdSDeclan Doherty "\nTotal packets received: %22"PRIu64 277387259bdSDeclan Doherty "\nTotal packets enqueued: %22"PRIu64 278387259bdSDeclan Doherty "\nTotal packets dequeued: %22"PRIu64 279387259bdSDeclan Doherty "\nTotal packets sent: %26"PRIu64 280387259bdSDeclan Doherty "\nTotal packets dropped: %23"PRIu64 281387259bdSDeclan Doherty "\nTotal packets crypto errors: %17"PRIu64, 282387259bdSDeclan Doherty total_packets_rx, 283387259bdSDeclan Doherty total_packets_enqueued, 284387259bdSDeclan Doherty total_packets_dequeued, 285387259bdSDeclan Doherty total_packets_tx, 286387259bdSDeclan Doherty total_packets_dropped, 287387259bdSDeclan Doherty total_packets_errors); 288387259bdSDeclan Doherty printf("\n====================================================\n"); 289387259bdSDeclan Doherty } 290387259bdSDeclan Doherty 291387259bdSDeclan Doherty 292387259bdSDeclan Doherty 293387259bdSDeclan Doherty static int 294387259bdSDeclan Doherty l2fwd_crypto_send_burst(struct lcore_queue_conf *qconf, unsigned n, 295387259bdSDeclan Doherty struct l2fwd_crypto_params *cparams) 296387259bdSDeclan Doherty { 297387259bdSDeclan Doherty struct rte_mbuf **pkt_buffer; 298387259bdSDeclan Doherty unsigned ret; 299387259bdSDeclan Doherty 300387259bdSDeclan Doherty pkt_buffer = (struct rte_mbuf **) 301387259bdSDeclan Doherty qconf->crypto_pkt_buf[cparams->dev_id].buffer; 302387259bdSDeclan Doherty 303387259bdSDeclan Doherty ret = rte_cryptodev_enqueue_burst(cparams->dev_id, cparams->qp_id, 304387259bdSDeclan Doherty pkt_buffer, (uint16_t) n); 305387259bdSDeclan Doherty crypto_statistics[cparams->dev_id].enqueued += ret; 306387259bdSDeclan Doherty if (unlikely(ret < n)) { 307387259bdSDeclan Doherty crypto_statistics[cparams->dev_id].errors += (n - ret); 308387259bdSDeclan Doherty do { 309387259bdSDeclan Doherty rte_pktmbuf_offload_free(pkt_buffer[ret]->offload_ops); 310387259bdSDeclan Doherty rte_pktmbuf_free(pkt_buffer[ret]); 311387259bdSDeclan Doherty } while (++ret < n); 312387259bdSDeclan Doherty } 313387259bdSDeclan Doherty 314387259bdSDeclan Doherty return 0; 315387259bdSDeclan Doherty } 316387259bdSDeclan Doherty 317387259bdSDeclan Doherty static int 318387259bdSDeclan Doherty l2fwd_crypto_enqueue(struct rte_mbuf *m, struct l2fwd_crypto_params *cparams) 319387259bdSDeclan Doherty { 320387259bdSDeclan Doherty unsigned lcore_id, len; 321387259bdSDeclan Doherty struct lcore_queue_conf *qconf; 322387259bdSDeclan Doherty 323387259bdSDeclan Doherty lcore_id = rte_lcore_id(); 324387259bdSDeclan Doherty 325387259bdSDeclan Doherty qconf = &lcore_queue_conf[lcore_id]; 326387259bdSDeclan Doherty len = qconf->crypto_pkt_buf[cparams->dev_id].len; 327387259bdSDeclan Doherty qconf->crypto_pkt_buf[cparams->dev_id].buffer[len] = m; 328387259bdSDeclan Doherty len++; 329387259bdSDeclan Doherty 330387259bdSDeclan Doherty /* enough pkts to be sent */ 331387259bdSDeclan Doherty if (len == MAX_PKT_BURST) { 332387259bdSDeclan Doherty l2fwd_crypto_send_burst(qconf, MAX_PKT_BURST, cparams); 333387259bdSDeclan Doherty len = 0; 334387259bdSDeclan Doherty } 335387259bdSDeclan Doherty 336387259bdSDeclan Doherty qconf->crypto_pkt_buf[cparams->dev_id].len = len; 337387259bdSDeclan Doherty return 0; 338387259bdSDeclan Doherty } 339387259bdSDeclan Doherty 340387259bdSDeclan Doherty static int 341387259bdSDeclan Doherty l2fwd_simple_crypto_enqueue(struct rte_mbuf *m, 342387259bdSDeclan Doherty struct rte_mbuf_offload *ol, 343387259bdSDeclan Doherty struct l2fwd_crypto_params *cparams) 344387259bdSDeclan Doherty { 345387259bdSDeclan Doherty struct ether_hdr *eth_hdr; 346387259bdSDeclan Doherty struct ipv4_hdr *ip_hdr; 347387259bdSDeclan Doherty 348387259bdSDeclan Doherty unsigned ipdata_offset, pad_len, data_len; 349387259bdSDeclan Doherty char *padding; 350387259bdSDeclan Doherty 351387259bdSDeclan Doherty eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *); 352387259bdSDeclan Doherty 353387259bdSDeclan Doherty if (eth_hdr->ether_type != rte_cpu_to_be_16(ETHER_TYPE_IPv4)) 354387259bdSDeclan Doherty return -1; 355387259bdSDeclan Doherty 356387259bdSDeclan Doherty ipdata_offset = sizeof(struct ether_hdr); 357387259bdSDeclan Doherty 358387259bdSDeclan Doherty ip_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(m, char *) + 359387259bdSDeclan Doherty ipdata_offset); 360387259bdSDeclan Doherty 361387259bdSDeclan Doherty ipdata_offset += (ip_hdr->version_ihl & IPV4_HDR_IHL_MASK) 362387259bdSDeclan Doherty * IPV4_IHL_MULTIPLIER; 363387259bdSDeclan Doherty 364387259bdSDeclan Doherty 365387259bdSDeclan Doherty /* Zero pad data to be crypto'd so it is block aligned */ 366387259bdSDeclan Doherty data_len = rte_pktmbuf_data_len(m) - ipdata_offset; 367387259bdSDeclan Doherty pad_len = data_len % cparams->block_size ? cparams->block_size - 368387259bdSDeclan Doherty (data_len % cparams->block_size) : 0; 369387259bdSDeclan Doherty 370387259bdSDeclan Doherty if (pad_len) { 371387259bdSDeclan Doherty padding = rte_pktmbuf_append(m, pad_len); 372387259bdSDeclan Doherty if (unlikely(!padding)) 373387259bdSDeclan Doherty return -1; 374387259bdSDeclan Doherty 375387259bdSDeclan Doherty data_len += pad_len; 376387259bdSDeclan Doherty memset(padding, 0, pad_len); 377387259bdSDeclan Doherty } 378387259bdSDeclan Doherty 379387259bdSDeclan Doherty /* Set crypto operation data parameters */ 3801bd407faSFiona Trahe rte_crypto_sym_op_attach_session(&ol->op.crypto, cparams->session); 381387259bdSDeclan Doherty 382387259bdSDeclan Doherty /* Append space for digest to end of packet */ 383387259bdSDeclan Doherty ol->op.crypto.digest.data = (uint8_t *)rte_pktmbuf_append(m, 384387259bdSDeclan Doherty cparams->digest_length); 385387259bdSDeclan Doherty ol->op.crypto.digest.phys_addr = rte_pktmbuf_mtophys_offset(m, 386387259bdSDeclan Doherty rte_pktmbuf_pkt_len(m) - cparams->digest_length); 387387259bdSDeclan Doherty ol->op.crypto.digest.length = cparams->digest_length; 388387259bdSDeclan Doherty 389387259bdSDeclan Doherty ol->op.crypto.iv.data = cparams->iv_key.data; 390387259bdSDeclan Doherty ol->op.crypto.iv.phys_addr = cparams->iv_key.phys_addr; 391387259bdSDeclan Doherty ol->op.crypto.iv.length = cparams->iv_key.length; 392387259bdSDeclan Doherty 393387259bdSDeclan Doherty ol->op.crypto.data.to_cipher.offset = ipdata_offset; 394387259bdSDeclan Doherty ol->op.crypto.data.to_cipher.length = data_len; 395387259bdSDeclan Doherty 396387259bdSDeclan Doherty ol->op.crypto.data.to_hash.offset = ipdata_offset; 397387259bdSDeclan Doherty ol->op.crypto.data.to_hash.length = data_len; 398387259bdSDeclan Doherty 399387259bdSDeclan Doherty rte_pktmbuf_offload_attach(m, ol); 400387259bdSDeclan Doherty 401387259bdSDeclan Doherty return l2fwd_crypto_enqueue(m, cparams); 402387259bdSDeclan Doherty } 403387259bdSDeclan Doherty 404387259bdSDeclan Doherty 405387259bdSDeclan Doherty /* Send the burst of packets on an output interface */ 406387259bdSDeclan Doherty static int 407387259bdSDeclan Doherty l2fwd_send_burst(struct lcore_queue_conf *qconf, unsigned n, uint8_t port) 408387259bdSDeclan Doherty { 409387259bdSDeclan Doherty struct rte_mbuf **pkt_buffer; 410387259bdSDeclan Doherty unsigned ret; 411387259bdSDeclan Doherty unsigned queueid = 0; 412387259bdSDeclan Doherty 413387259bdSDeclan Doherty pkt_buffer = (struct rte_mbuf **)qconf->tx_pkt_buf[port].buffer; 414387259bdSDeclan Doherty 415387259bdSDeclan Doherty ret = rte_eth_tx_burst(port, (uint16_t) queueid, pkt_buffer, 416387259bdSDeclan Doherty (uint16_t)n); 417387259bdSDeclan Doherty port_statistics[port].tx += ret; 418387259bdSDeclan Doherty if (unlikely(ret < n)) { 419387259bdSDeclan Doherty port_statistics[port].dropped += (n - ret); 420387259bdSDeclan Doherty do { 421387259bdSDeclan Doherty rte_pktmbuf_free(pkt_buffer[ret]); 422387259bdSDeclan Doherty } while (++ret < n); 423387259bdSDeclan Doherty } 424387259bdSDeclan Doherty 425387259bdSDeclan Doherty return 0; 426387259bdSDeclan Doherty } 427387259bdSDeclan Doherty 428387259bdSDeclan Doherty /* Enqueue packets for TX and prepare them to be sent */ 429387259bdSDeclan Doherty static int 430387259bdSDeclan Doherty l2fwd_send_packet(struct rte_mbuf *m, uint8_t port) 431387259bdSDeclan Doherty { 432387259bdSDeclan Doherty unsigned lcore_id, len; 433387259bdSDeclan Doherty struct lcore_queue_conf *qconf; 434387259bdSDeclan Doherty 435387259bdSDeclan Doherty lcore_id = rte_lcore_id(); 436387259bdSDeclan Doherty 437387259bdSDeclan Doherty qconf = &lcore_queue_conf[lcore_id]; 438387259bdSDeclan Doherty len = qconf->tx_pkt_buf[port].len; 439387259bdSDeclan Doherty qconf->tx_pkt_buf[port].buffer[len] = m; 440387259bdSDeclan Doherty len++; 441387259bdSDeclan Doherty 442387259bdSDeclan Doherty /* enough pkts to be sent */ 443387259bdSDeclan Doherty if (unlikely(len == MAX_PKT_BURST)) { 444387259bdSDeclan Doherty l2fwd_send_burst(qconf, MAX_PKT_BURST, port); 445387259bdSDeclan Doherty len = 0; 446387259bdSDeclan Doherty } 447387259bdSDeclan Doherty 448387259bdSDeclan Doherty qconf->tx_pkt_buf[port].len = len; 449387259bdSDeclan Doherty return 0; 450387259bdSDeclan Doherty } 451387259bdSDeclan Doherty 452387259bdSDeclan Doherty static void 453387259bdSDeclan Doherty l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid) 454387259bdSDeclan Doherty { 455387259bdSDeclan Doherty struct ether_hdr *eth; 456387259bdSDeclan Doherty void *tmp; 457387259bdSDeclan Doherty unsigned dst_port; 458387259bdSDeclan Doherty 459387259bdSDeclan Doherty dst_port = l2fwd_dst_ports[portid]; 460387259bdSDeclan Doherty eth = rte_pktmbuf_mtod(m, struct ether_hdr *); 461387259bdSDeclan Doherty 462387259bdSDeclan Doherty /* 02:00:00:00:00:xx */ 463387259bdSDeclan Doherty tmp = ð->d_addr.addr_bytes[0]; 464387259bdSDeclan Doherty *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dst_port << 40); 465387259bdSDeclan Doherty 466387259bdSDeclan Doherty /* src addr */ 467387259bdSDeclan Doherty ether_addr_copy(&l2fwd_ports_eth_addr[dst_port], ð->s_addr); 468387259bdSDeclan Doherty 469387259bdSDeclan Doherty l2fwd_send_packet(m, (uint8_t) dst_port); 470387259bdSDeclan Doherty } 471387259bdSDeclan Doherty 472387259bdSDeclan Doherty /** Generate random key */ 473387259bdSDeclan Doherty static void 474387259bdSDeclan Doherty generate_random_key(uint8_t *key, unsigned length) 475387259bdSDeclan Doherty { 476387259bdSDeclan Doherty unsigned i; 477387259bdSDeclan Doherty 478387259bdSDeclan Doherty for (i = 0; i < length; i++) 479387259bdSDeclan Doherty key[i] = rand() % 0xff; 480387259bdSDeclan Doherty } 481387259bdSDeclan Doherty 4821bd407faSFiona Trahe static struct rte_cryptodev_sym_session * 483387259bdSDeclan Doherty initialize_crypto_session(struct l2fwd_crypto_options *options, 484387259bdSDeclan Doherty uint8_t cdev_id) 485387259bdSDeclan Doherty { 4861bd407faSFiona Trahe struct rte_crypto_sym_xform *first_xform; 487387259bdSDeclan Doherty 488387259bdSDeclan Doherty if (options->xform_chain == L2FWD_CRYPTO_CIPHER_HASH) { 489387259bdSDeclan Doherty first_xform = &options->cipher_xform; 490387259bdSDeclan Doherty first_xform->next = &options->auth_xform; 491387259bdSDeclan Doherty } else { 492387259bdSDeclan Doherty first_xform = &options->auth_xform; 493387259bdSDeclan Doherty first_xform->next = &options->cipher_xform; 494387259bdSDeclan Doherty } 495387259bdSDeclan Doherty 496387259bdSDeclan Doherty /* Setup Cipher Parameters */ 4971bd407faSFiona Trahe return rte_cryptodev_sym_session_create(cdev_id, first_xform); 498387259bdSDeclan Doherty } 499387259bdSDeclan Doherty 500387259bdSDeclan Doherty static void 501387259bdSDeclan Doherty l2fwd_crypto_options_print(struct l2fwd_crypto_options *options); 502387259bdSDeclan Doherty 503387259bdSDeclan Doherty /* main processing loop */ 504387259bdSDeclan Doherty static void 505387259bdSDeclan Doherty l2fwd_main_loop(struct l2fwd_crypto_options *options) 506387259bdSDeclan Doherty { 507387259bdSDeclan Doherty struct rte_mbuf *m, *pkts_burst[MAX_PKT_BURST]; 508387259bdSDeclan Doherty unsigned lcore_id = rte_lcore_id(); 509387259bdSDeclan Doherty uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0; 510387259bdSDeclan Doherty unsigned i, j, portid, nb_rx; 511387259bdSDeclan Doherty struct lcore_queue_conf *qconf = &lcore_queue_conf[lcore_id]; 512387259bdSDeclan Doherty const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / 513387259bdSDeclan Doherty US_PER_S * BURST_TX_DRAIN_US; 514387259bdSDeclan Doherty struct l2fwd_crypto_params *cparams; 515387259bdSDeclan Doherty struct l2fwd_crypto_params port_cparams[qconf->nb_crypto_devs]; 516387259bdSDeclan Doherty 517387259bdSDeclan Doherty if (qconf->nb_rx_ports == 0) { 518387259bdSDeclan Doherty RTE_LOG(INFO, L2FWD, "lcore %u has nothing to do\n", lcore_id); 519387259bdSDeclan Doherty return; 520387259bdSDeclan Doherty } 521387259bdSDeclan Doherty 522387259bdSDeclan Doherty RTE_LOG(INFO, L2FWD, "entering main loop on lcore %u\n", lcore_id); 523387259bdSDeclan Doherty 524387259bdSDeclan Doherty l2fwd_crypto_options_print(options); 525387259bdSDeclan Doherty 526387259bdSDeclan Doherty for (i = 0; i < qconf->nb_rx_ports; i++) { 527387259bdSDeclan Doherty 528387259bdSDeclan Doherty portid = qconf->rx_port_list[i]; 529387259bdSDeclan Doherty RTE_LOG(INFO, L2FWD, " -- lcoreid=%u portid=%u\n", lcore_id, 530387259bdSDeclan Doherty portid); 531387259bdSDeclan Doherty } 532387259bdSDeclan Doherty 533387259bdSDeclan Doherty for (i = 0; i < qconf->nb_crypto_devs; i++) { 534387259bdSDeclan Doherty port_cparams[i].dev_id = qconf->cryptodev_list[i]; 535387259bdSDeclan Doherty port_cparams[i].qp_id = 0; 536387259bdSDeclan Doherty 537387259bdSDeclan Doherty port_cparams[i].block_size = 64; 538387259bdSDeclan Doherty port_cparams[i].digest_length = 20; 539387259bdSDeclan Doherty 540387259bdSDeclan Doherty port_cparams[i].iv_key.data = 541387259bdSDeclan Doherty (uint8_t *)rte_malloc(NULL, 16, 8); 542387259bdSDeclan Doherty port_cparams[i].iv_key.length = 16; 543387259bdSDeclan Doherty port_cparams[i].iv_key.phys_addr = rte_malloc_virt2phy( 544387259bdSDeclan Doherty (void *)port_cparams[i].iv_key.data); 545387259bdSDeclan Doherty generate_random_key(port_cparams[i].iv_key.data, 546387259bdSDeclan Doherty sizeof(cparams[i].iv_key.length)); 547387259bdSDeclan Doherty 548387259bdSDeclan Doherty port_cparams[i].session = initialize_crypto_session(options, 549387259bdSDeclan Doherty port_cparams[i].dev_id); 550387259bdSDeclan Doherty 551387259bdSDeclan Doherty if (port_cparams[i].session == NULL) 552387259bdSDeclan Doherty return; 553387259bdSDeclan Doherty RTE_LOG(INFO, L2FWD, " -- lcoreid=%u cryptoid=%u\n", lcore_id, 554387259bdSDeclan Doherty port_cparams[i].dev_id); 555387259bdSDeclan Doherty } 556387259bdSDeclan Doherty 557387259bdSDeclan Doherty while (1) { 558387259bdSDeclan Doherty 559387259bdSDeclan Doherty cur_tsc = rte_rdtsc(); 560387259bdSDeclan Doherty 561387259bdSDeclan Doherty /* 562387259bdSDeclan Doherty * TX burst queue drain 563387259bdSDeclan Doherty */ 564387259bdSDeclan Doherty diff_tsc = cur_tsc - prev_tsc; 565387259bdSDeclan Doherty if (unlikely(diff_tsc > drain_tsc)) { 566387259bdSDeclan Doherty 567387259bdSDeclan Doherty for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { 568387259bdSDeclan Doherty if (qconf->tx_pkt_buf[portid].len == 0) 569387259bdSDeclan Doherty continue; 570387259bdSDeclan Doherty l2fwd_send_burst(&lcore_queue_conf[lcore_id], 571387259bdSDeclan Doherty qconf->tx_pkt_buf[portid].len, 572387259bdSDeclan Doherty (uint8_t) portid); 573387259bdSDeclan Doherty qconf->tx_pkt_buf[portid].len = 0; 574387259bdSDeclan Doherty } 575387259bdSDeclan Doherty 576387259bdSDeclan Doherty /* if timer is enabled */ 577387259bdSDeclan Doherty if (timer_period > 0) { 578387259bdSDeclan Doherty 579387259bdSDeclan Doherty /* advance the timer */ 580387259bdSDeclan Doherty timer_tsc += diff_tsc; 581387259bdSDeclan Doherty 582387259bdSDeclan Doherty /* if timer has reached its timeout */ 583387259bdSDeclan Doherty if (unlikely(timer_tsc >= 584387259bdSDeclan Doherty (uint64_t)timer_period)) { 585387259bdSDeclan Doherty 586387259bdSDeclan Doherty /* do this only on master core */ 587ad509b4aSDeclan Doherty if (lcore_id == rte_get_master_lcore() 588ad509b4aSDeclan Doherty && options->refresh_period) { 589387259bdSDeclan Doherty print_stats(); 590387259bdSDeclan Doherty timer_tsc = 0; 591387259bdSDeclan Doherty } 592387259bdSDeclan Doherty } 593387259bdSDeclan Doherty } 594387259bdSDeclan Doherty 595387259bdSDeclan Doherty prev_tsc = cur_tsc; 596387259bdSDeclan Doherty } 597387259bdSDeclan Doherty 598387259bdSDeclan Doherty /* 599387259bdSDeclan Doherty * Read packet from RX queues 600387259bdSDeclan Doherty */ 601387259bdSDeclan Doherty for (i = 0; i < qconf->nb_rx_ports; i++) { 602387259bdSDeclan Doherty struct rte_mbuf_offload *ol; 603387259bdSDeclan Doherty 604387259bdSDeclan Doherty portid = qconf->rx_port_list[i]; 605387259bdSDeclan Doherty 606387259bdSDeclan Doherty cparams = &port_cparams[i]; 607387259bdSDeclan Doherty 608387259bdSDeclan Doherty nb_rx = rte_eth_rx_burst((uint8_t) portid, 0, 609387259bdSDeclan Doherty pkts_burst, MAX_PKT_BURST); 610387259bdSDeclan Doherty 611387259bdSDeclan Doherty port_statistics[portid].rx += nb_rx; 612387259bdSDeclan Doherty 613387259bdSDeclan Doherty /* Enqueue packets from Crypto device*/ 614387259bdSDeclan Doherty for (j = 0; j < nb_rx; j++) { 615387259bdSDeclan Doherty m = pkts_burst[j]; 616387259bdSDeclan Doherty ol = rte_pktmbuf_offload_alloc( 617387259bdSDeclan Doherty l2fwd_mbuf_ol_pool, 6181bd407faSFiona Trahe RTE_PKTMBUF_OL_CRYPTO_SYM); 619387259bdSDeclan Doherty /* 620387259bdSDeclan Doherty * If we can't allocate a offload, then drop 621387259bdSDeclan Doherty * the rest of the burst and dequeue and 622387259bdSDeclan Doherty * process the packets to free offload structs 623387259bdSDeclan Doherty */ 624387259bdSDeclan Doherty if (unlikely(ol == NULL)) { 625387259bdSDeclan Doherty for (; j < nb_rx; j++) { 626387259bdSDeclan Doherty rte_pktmbuf_free(pkts_burst[j]); 627387259bdSDeclan Doherty port_statistics[portid].dropped++; 628387259bdSDeclan Doherty } 629387259bdSDeclan Doherty break; 630387259bdSDeclan Doherty } 631387259bdSDeclan Doherty 632387259bdSDeclan Doherty rte_prefetch0(rte_pktmbuf_mtod(m, void *)); 633387259bdSDeclan Doherty rte_prefetch0((void *)ol); 634387259bdSDeclan Doherty 635387259bdSDeclan Doherty l2fwd_simple_crypto_enqueue(m, ol, cparams); 636387259bdSDeclan Doherty } 637387259bdSDeclan Doherty 638387259bdSDeclan Doherty /* Dequeue packets from Crypto device */ 639387259bdSDeclan Doherty nb_rx = rte_cryptodev_dequeue_burst( 640387259bdSDeclan Doherty cparams->dev_id, cparams->qp_id, 641387259bdSDeclan Doherty pkts_burst, MAX_PKT_BURST); 642387259bdSDeclan Doherty crypto_statistics[cparams->dev_id].dequeued += nb_rx; 643387259bdSDeclan Doherty 644387259bdSDeclan Doherty /* Forward crypto'd packets */ 645387259bdSDeclan Doherty for (j = 0; j < nb_rx; j++) { 646387259bdSDeclan Doherty m = pkts_burst[j]; 647387259bdSDeclan Doherty rte_pktmbuf_offload_free(m->offload_ops); 648387259bdSDeclan Doherty rte_prefetch0(rte_pktmbuf_mtod(m, void *)); 649387259bdSDeclan Doherty l2fwd_simple_forward(m, portid); 650387259bdSDeclan Doherty } 651387259bdSDeclan Doherty } 652387259bdSDeclan Doherty } 653387259bdSDeclan Doherty } 654387259bdSDeclan Doherty 655387259bdSDeclan Doherty static int 656387259bdSDeclan Doherty l2fwd_launch_one_lcore(void *arg) 657387259bdSDeclan Doherty { 658387259bdSDeclan Doherty l2fwd_main_loop((struct l2fwd_crypto_options *)arg); 659387259bdSDeclan Doherty return 0; 660387259bdSDeclan Doherty } 661387259bdSDeclan Doherty 662387259bdSDeclan Doherty /* Display command line arguments usage */ 663387259bdSDeclan Doherty static void 664387259bdSDeclan Doherty l2fwd_crypto_usage(const char *prgname) 665387259bdSDeclan Doherty { 666387259bdSDeclan Doherty printf("%s [EAL options] -- --cdev TYPE [optional parameters]\n" 667387259bdSDeclan Doherty " -p PORTMASK: hexadecimal bitmask of ports to configure\n" 668387259bdSDeclan Doherty " -q NQ: number of queue (=ports) per lcore (default is 1)\n" 669387259bdSDeclan Doherty " -s manage all ports from single lcore" 670387259bdSDeclan Doherty " -t PERIOD: statistics will be refreshed each PERIOD seconds" 671387259bdSDeclan Doherty " (0 to disable, 10 default, 86400 maximum)\n" 672387259bdSDeclan Doherty 673387259bdSDeclan Doherty " --cdev AESNI_MB / QAT\n" 674387259bdSDeclan Doherty " --chain HASH_CIPHER / CIPHER_HASH\n" 675387259bdSDeclan Doherty 676387259bdSDeclan Doherty " --cipher_algo ALGO\n" 677387259bdSDeclan Doherty " --cipher_op ENCRYPT / DECRYPT\n" 678387259bdSDeclan Doherty " --cipher_key KEY\n" 6793b98cbaaSPablo de Lara " --iv IV\n" 680387259bdSDeclan Doherty 6813b98cbaaSPablo de Lara " --auth_algo ALGO\n" 682387259bdSDeclan Doherty " --auth_op GENERATE / VERIFY\n" 683387259bdSDeclan Doherty " --auth_key KEY\n" 684387259bdSDeclan Doherty 685387259bdSDeclan Doherty " --sessionless\n", 686387259bdSDeclan Doherty prgname); 687387259bdSDeclan Doherty } 688387259bdSDeclan Doherty 689387259bdSDeclan Doherty /** Parse crypto device type command line argument */ 690387259bdSDeclan Doherty static int 691387259bdSDeclan Doherty parse_cryptodev_type(enum rte_cryptodev_type *type, char *optarg) 692387259bdSDeclan Doherty { 693387259bdSDeclan Doherty if (strcmp("AESNI_MB", optarg) == 0) { 694387259bdSDeclan Doherty *type = RTE_CRYPTODEV_AESNI_MB_PMD; 695387259bdSDeclan Doherty return 0; 696387259bdSDeclan Doherty } else if (strcmp("QAT", optarg) == 0) { 6971bd407faSFiona Trahe *type = RTE_CRYPTODEV_QAT_SYM_PMD; 698387259bdSDeclan Doherty return 0; 699387259bdSDeclan Doherty } 700387259bdSDeclan Doherty 701387259bdSDeclan Doherty return -1; 702387259bdSDeclan Doherty } 703387259bdSDeclan Doherty 704387259bdSDeclan Doherty /** Parse crypto chain xform command line argument */ 705387259bdSDeclan Doherty static int 706387259bdSDeclan Doherty parse_crypto_opt_chain(struct l2fwd_crypto_options *options, char *optarg) 707387259bdSDeclan Doherty { 708387259bdSDeclan Doherty if (strcmp("CIPHER_HASH", optarg) == 0) { 709387259bdSDeclan Doherty options->xform_chain = L2FWD_CRYPTO_CIPHER_HASH; 710387259bdSDeclan Doherty return 0; 711387259bdSDeclan Doherty } else if (strcmp("HASH_CIPHER", optarg) == 0) { 712387259bdSDeclan Doherty options->xform_chain = L2FWD_CRYPTO_HASH_CIPHER; 713387259bdSDeclan Doherty return 0; 714387259bdSDeclan Doherty } 715387259bdSDeclan Doherty 716387259bdSDeclan Doherty return -1; 717387259bdSDeclan Doherty } 718387259bdSDeclan Doherty 719387259bdSDeclan Doherty /** Parse crypto cipher algo option command line argument */ 720387259bdSDeclan Doherty static int 721387259bdSDeclan Doherty parse_cipher_algo(enum rte_crypto_cipher_algorithm *algo, char *optarg) 722387259bdSDeclan Doherty { 723387259bdSDeclan Doherty if (strcmp("AES_CBC", optarg) == 0) { 724387259bdSDeclan Doherty *algo = RTE_CRYPTO_CIPHER_AES_CBC; 725387259bdSDeclan Doherty return 0; 726387259bdSDeclan Doherty } else if (strcmp("AES_GCM", optarg) == 0) { 727387259bdSDeclan Doherty *algo = RTE_CRYPTO_CIPHER_AES_GCM; 728387259bdSDeclan Doherty return 0; 729387259bdSDeclan Doherty } 730387259bdSDeclan Doherty 731387259bdSDeclan Doherty printf("Cipher algorithm not supported!\n"); 732387259bdSDeclan Doherty return -1; 733387259bdSDeclan Doherty } 734387259bdSDeclan Doherty 735387259bdSDeclan Doherty /** Parse crypto cipher operation command line argument */ 736387259bdSDeclan Doherty static int 737387259bdSDeclan Doherty parse_cipher_op(enum rte_crypto_cipher_operation *op, char *optarg) 738387259bdSDeclan Doherty { 739387259bdSDeclan Doherty if (strcmp("ENCRYPT", optarg) == 0) { 740387259bdSDeclan Doherty *op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 741387259bdSDeclan Doherty return 0; 742387259bdSDeclan Doherty } else if (strcmp("DECRYPT", optarg) == 0) { 743387259bdSDeclan Doherty *op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 744387259bdSDeclan Doherty return 0; 745387259bdSDeclan Doherty } 746387259bdSDeclan Doherty 747387259bdSDeclan Doherty printf("Cipher operation not supported!\n"); 748387259bdSDeclan Doherty return -1; 749387259bdSDeclan Doherty } 750387259bdSDeclan Doherty 751387259bdSDeclan Doherty /** Parse crypto key command line argument */ 752387259bdSDeclan Doherty static int 753*a7f4562bSFiona Trahe parse_key(struct l2fwd_key *key __rte_unused, 754387259bdSDeclan Doherty unsigned length __rte_unused, char *arg __rte_unused) 755387259bdSDeclan Doherty { 756387259bdSDeclan Doherty printf("Currently an unsupported argument!\n"); 757387259bdSDeclan Doherty return -1; 758387259bdSDeclan Doherty } 759387259bdSDeclan Doherty 760387259bdSDeclan Doherty /** Parse crypto cipher operation command line argument */ 761387259bdSDeclan Doherty static int 762387259bdSDeclan Doherty parse_auth_algo(enum rte_crypto_auth_algorithm *algo, char *optarg) 763387259bdSDeclan Doherty { 764387259bdSDeclan Doherty if (strcmp("SHA1", optarg) == 0) { 765387259bdSDeclan Doherty *algo = RTE_CRYPTO_AUTH_SHA1; 766387259bdSDeclan Doherty return 0; 767387259bdSDeclan Doherty } else if (strcmp("SHA1_HMAC", optarg) == 0) { 768387259bdSDeclan Doherty *algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 769387259bdSDeclan Doherty return 0; 770387259bdSDeclan Doherty } else if (strcmp("SHA224", optarg) == 0) { 771387259bdSDeclan Doherty *algo = RTE_CRYPTO_AUTH_SHA224; 772387259bdSDeclan Doherty return 0; 773387259bdSDeclan Doherty } else if (strcmp("SHA224_HMAC", optarg) == 0) { 774387259bdSDeclan Doherty *algo = RTE_CRYPTO_AUTH_SHA224_HMAC; 775387259bdSDeclan Doherty return 0; 776387259bdSDeclan Doherty } else if (strcmp("SHA256", optarg) == 0) { 777387259bdSDeclan Doherty *algo = RTE_CRYPTO_AUTH_SHA256; 778387259bdSDeclan Doherty return 0; 779387259bdSDeclan Doherty } else if (strcmp("SHA256_HMAC", optarg) == 0) { 780387259bdSDeclan Doherty *algo = RTE_CRYPTO_AUTH_SHA256_HMAC; 781387259bdSDeclan Doherty return 0; 782387259bdSDeclan Doherty } else if (strcmp("SHA512", optarg) == 0) { 783387259bdSDeclan Doherty *algo = RTE_CRYPTO_AUTH_SHA256; 784387259bdSDeclan Doherty return 0; 785387259bdSDeclan Doherty } else if (strcmp("SHA512_HMAC", optarg) == 0) { 786387259bdSDeclan Doherty *algo = RTE_CRYPTO_AUTH_SHA256_HMAC; 787387259bdSDeclan Doherty return 0; 788387259bdSDeclan Doherty } 789387259bdSDeclan Doherty 790387259bdSDeclan Doherty printf("Authentication algorithm specified not supported!\n"); 791387259bdSDeclan Doherty return -1; 792387259bdSDeclan Doherty } 793387259bdSDeclan Doherty 794387259bdSDeclan Doherty static int 795387259bdSDeclan Doherty parse_auth_op(enum rte_crypto_auth_operation *op, char *optarg) 796387259bdSDeclan Doherty { 797387259bdSDeclan Doherty if (strcmp("VERIFY", optarg) == 0) { 798387259bdSDeclan Doherty *op = RTE_CRYPTO_AUTH_OP_VERIFY; 799387259bdSDeclan Doherty return 0; 800387259bdSDeclan Doherty } else if (strcmp("GENERATE", optarg) == 0) { 80172169087SPablo de Lara *op = RTE_CRYPTO_AUTH_OP_GENERATE; 802387259bdSDeclan Doherty return 0; 803387259bdSDeclan Doherty } 804387259bdSDeclan Doherty 805387259bdSDeclan Doherty printf("Authentication operation specified not supported!\n"); 806387259bdSDeclan Doherty return -1; 807387259bdSDeclan Doherty } 808387259bdSDeclan Doherty 809387259bdSDeclan Doherty /** Parse long options */ 810387259bdSDeclan Doherty static int 811387259bdSDeclan Doherty l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, 812387259bdSDeclan Doherty struct option *lgopts, int option_index) 813387259bdSDeclan Doherty { 814387259bdSDeclan Doherty if (strcmp(lgopts[option_index].name, "cdev_type") == 0) 815387259bdSDeclan Doherty return parse_cryptodev_type(&options->cdev_type, optarg); 816387259bdSDeclan Doherty 817387259bdSDeclan Doherty else if (strcmp(lgopts[option_index].name, "chain") == 0) 818387259bdSDeclan Doherty return parse_crypto_opt_chain(options, optarg); 819387259bdSDeclan Doherty 820387259bdSDeclan Doherty /* Cipher options */ 821387259bdSDeclan Doherty else if (strcmp(lgopts[option_index].name, "cipher_algo") == 0) 822387259bdSDeclan Doherty return parse_cipher_algo(&options->cipher_xform.cipher.algo, 823387259bdSDeclan Doherty optarg); 824387259bdSDeclan Doherty 825387259bdSDeclan Doherty else if (strcmp(lgopts[option_index].name, "cipher_op") == 0) 826387259bdSDeclan Doherty return parse_cipher_op(&options->cipher_xform.cipher.op, 827387259bdSDeclan Doherty optarg); 828387259bdSDeclan Doherty 829*a7f4562bSFiona Trahe else if (strcmp(lgopts[option_index].name, "cipher_key") == 0) { 830*a7f4562bSFiona Trahe struct l2fwd_key key = { 0 }; 831*a7f4562bSFiona Trahe int retval = 0; 832387259bdSDeclan Doherty 833*a7f4562bSFiona Trahe retval = parse_key(&key, sizeof(options->ckey_data), optarg); 834*a7f4562bSFiona Trahe 835*a7f4562bSFiona Trahe options->cipher_xform.cipher.key.data = key.data; 836*a7f4562bSFiona Trahe options->cipher_xform.cipher.key.length = key.length; 837*a7f4562bSFiona Trahe 838*a7f4562bSFiona Trahe return retval; 839*a7f4562bSFiona Trahe 840*a7f4562bSFiona Trahe } else if (strcmp(lgopts[option_index].name, "iv") == 0) 841387259bdSDeclan Doherty return parse_key(&options->iv_key, sizeof(options->ivkey_data), 842387259bdSDeclan Doherty optarg); 843387259bdSDeclan Doherty 844387259bdSDeclan Doherty /* Authentication options */ 845387259bdSDeclan Doherty else if (strcmp(lgopts[option_index].name, "auth_algo") == 0) 84672169087SPablo de Lara return parse_auth_algo(&options->auth_xform.auth.algo, 847387259bdSDeclan Doherty optarg); 848387259bdSDeclan Doherty 849387259bdSDeclan Doherty else if (strcmp(lgopts[option_index].name, "auth_op") == 0) 85072169087SPablo de Lara return parse_auth_op(&options->auth_xform.auth.op, 851387259bdSDeclan Doherty optarg); 852387259bdSDeclan Doherty 853*a7f4562bSFiona Trahe else if (strcmp(lgopts[option_index].name, "auth_key") == 0) { 854*a7f4562bSFiona Trahe struct l2fwd_key key = { 0 }; 855*a7f4562bSFiona Trahe int retval = 0; 856387259bdSDeclan Doherty 857*a7f4562bSFiona Trahe retval = parse_key(&key, sizeof(options->akey_data), optarg); 858*a7f4562bSFiona Trahe 859*a7f4562bSFiona Trahe options->auth_xform.auth.key.data = key.data; 860*a7f4562bSFiona Trahe options->auth_xform.auth.key.length = key.length; 861*a7f4562bSFiona Trahe 862*a7f4562bSFiona Trahe return retval; 863*a7f4562bSFiona Trahe 864*a7f4562bSFiona Trahe } else if (strcmp(lgopts[option_index].name, "sessionless") == 0) { 865387259bdSDeclan Doherty options->sessionless = 1; 866387259bdSDeclan Doherty return 0; 867387259bdSDeclan Doherty } 868387259bdSDeclan Doherty 869387259bdSDeclan Doherty return -1; 870387259bdSDeclan Doherty } 871387259bdSDeclan Doherty 872387259bdSDeclan Doherty /** Parse port mask */ 873387259bdSDeclan Doherty static int 874387259bdSDeclan Doherty l2fwd_crypto_parse_portmask(struct l2fwd_crypto_options *options, 875387259bdSDeclan Doherty const char *q_arg) 876387259bdSDeclan Doherty { 877387259bdSDeclan Doherty char *end = NULL; 878387259bdSDeclan Doherty unsigned long pm; 879387259bdSDeclan Doherty 880387259bdSDeclan Doherty /* parse hexadecimal string */ 881387259bdSDeclan Doherty pm = strtoul(q_arg, &end, 16); 882387259bdSDeclan Doherty if ((pm == '\0') || (end == NULL) || (*end != '\0')) 883387259bdSDeclan Doherty pm = 0; 884387259bdSDeclan Doherty 885387259bdSDeclan Doherty options->portmask = pm; 886387259bdSDeclan Doherty if (options->portmask == 0) { 887387259bdSDeclan Doherty printf("invalid portmask specified\n"); 888387259bdSDeclan Doherty return -1; 889387259bdSDeclan Doherty } 890387259bdSDeclan Doherty 891387259bdSDeclan Doherty return pm; 892387259bdSDeclan Doherty } 893387259bdSDeclan Doherty 894387259bdSDeclan Doherty /** Parse number of queues */ 895387259bdSDeclan Doherty static int 896387259bdSDeclan Doherty l2fwd_crypto_parse_nqueue(struct l2fwd_crypto_options *options, 897387259bdSDeclan Doherty const char *q_arg) 898387259bdSDeclan Doherty { 899387259bdSDeclan Doherty char *end = NULL; 900387259bdSDeclan Doherty unsigned long n; 901387259bdSDeclan Doherty 902387259bdSDeclan Doherty /* parse hexadecimal string */ 903387259bdSDeclan Doherty n = strtoul(q_arg, &end, 10); 904387259bdSDeclan Doherty if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0')) 905387259bdSDeclan Doherty n = 0; 906387259bdSDeclan Doherty else if (n >= MAX_RX_QUEUE_PER_LCORE) 907387259bdSDeclan Doherty n = 0; 908387259bdSDeclan Doherty 909387259bdSDeclan Doherty options->nb_ports_per_lcore = n; 910387259bdSDeclan Doherty if (options->nb_ports_per_lcore == 0) { 911387259bdSDeclan Doherty printf("invalid number of ports selected\n"); 912387259bdSDeclan Doherty return -1; 913387259bdSDeclan Doherty } 914387259bdSDeclan Doherty 915387259bdSDeclan Doherty return 0; 916387259bdSDeclan Doherty } 917387259bdSDeclan Doherty 918387259bdSDeclan Doherty /** Parse timer period */ 919387259bdSDeclan Doherty static int 920387259bdSDeclan Doherty l2fwd_crypto_parse_timer_period(struct l2fwd_crypto_options *options, 921387259bdSDeclan Doherty const char *q_arg) 922387259bdSDeclan Doherty { 923387259bdSDeclan Doherty char *end = NULL; 924ad509b4aSDeclan Doherty long int n; 925387259bdSDeclan Doherty 926387259bdSDeclan Doherty /* parse number string */ 927387259bdSDeclan Doherty n = strtol(q_arg, &end, 10); 928387259bdSDeclan Doherty if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0')) 929387259bdSDeclan Doherty n = 0; 930387259bdSDeclan Doherty 931ad509b4aSDeclan Doherty if (n >= MAX_TIMER_PERIOD) { 932ad509b4aSDeclan Doherty printf("Warning refresh period specified %ld is greater than " 933ad509b4aSDeclan Doherty "max value %d! using max value", 934ad509b4aSDeclan Doherty n, MAX_TIMER_PERIOD); 935ad509b4aSDeclan Doherty n = MAX_TIMER_PERIOD; 936ad509b4aSDeclan Doherty } 937387259bdSDeclan Doherty 938387259bdSDeclan Doherty options->refresh_period = n * 1000 * TIMER_MILLISECOND; 939387259bdSDeclan Doherty 940387259bdSDeclan Doherty return 0; 941387259bdSDeclan Doherty } 942387259bdSDeclan Doherty 943387259bdSDeclan Doherty /** Generate default options for application */ 944387259bdSDeclan Doherty static void 945387259bdSDeclan Doherty l2fwd_crypto_default_options(struct l2fwd_crypto_options *options) 946387259bdSDeclan Doherty { 947387259bdSDeclan Doherty srand(time(NULL)); 948387259bdSDeclan Doherty 949387259bdSDeclan Doherty options->portmask = 0xffffffff; 950387259bdSDeclan Doherty options->nb_ports_per_lcore = 1; 951387259bdSDeclan Doherty options->refresh_period = 10000; 952387259bdSDeclan Doherty options->single_lcore = 0; 953387259bdSDeclan Doherty 954387259bdSDeclan Doherty options->cdev_type = RTE_CRYPTODEV_AESNI_MB_PMD; 955387259bdSDeclan Doherty options->sessionless = 0; 956387259bdSDeclan Doherty options->xform_chain = L2FWD_CRYPTO_CIPHER_HASH; 957387259bdSDeclan Doherty 958387259bdSDeclan Doherty /* Cipher Data */ 9591bd407faSFiona Trahe options->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 960387259bdSDeclan Doherty options->cipher_xform.next = NULL; 961387259bdSDeclan Doherty 962387259bdSDeclan Doherty options->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 963387259bdSDeclan Doherty options->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 964387259bdSDeclan Doherty 965387259bdSDeclan Doherty generate_random_key(options->ckey_data, sizeof(options->ckey_data)); 966387259bdSDeclan Doherty 967387259bdSDeclan Doherty options->cipher_xform.cipher.key.data = options->ckey_data; 968387259bdSDeclan Doherty options->cipher_xform.cipher.key.length = 16; 969387259bdSDeclan Doherty 970387259bdSDeclan Doherty 971387259bdSDeclan Doherty /* Authentication Data */ 9721bd407faSFiona Trahe options->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 973387259bdSDeclan Doherty options->auth_xform.next = NULL; 974387259bdSDeclan Doherty 975387259bdSDeclan Doherty options->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 976387259bdSDeclan Doherty options->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 977387259bdSDeclan Doherty 978387259bdSDeclan Doherty options->auth_xform.auth.add_auth_data_length = 0; 979387259bdSDeclan Doherty options->auth_xform.auth.digest_length = 20; 980387259bdSDeclan Doherty 981387259bdSDeclan Doherty generate_random_key(options->akey_data, sizeof(options->akey_data)); 982387259bdSDeclan Doherty 983387259bdSDeclan Doherty options->auth_xform.auth.key.data = options->akey_data; 984387259bdSDeclan Doherty options->auth_xform.auth.key.length = 20; 985387259bdSDeclan Doherty } 986387259bdSDeclan Doherty 987387259bdSDeclan Doherty static void 988387259bdSDeclan Doherty l2fwd_crypto_options_print(struct l2fwd_crypto_options *options) 989387259bdSDeclan Doherty { 990387259bdSDeclan Doherty printf("Options:-\nn"); 991387259bdSDeclan Doherty printf("portmask: %x\n", options->portmask); 992387259bdSDeclan Doherty printf("ports per lcore: %u\n", options->nb_ports_per_lcore); 993387259bdSDeclan Doherty printf("refresh period : %u\n", options->refresh_period); 994387259bdSDeclan Doherty printf("single lcore mode: %s\n", 995387259bdSDeclan Doherty options->single_lcore ? "enabled" : "disabled"); 996387259bdSDeclan Doherty printf("stats_printing: %s\n", 997ad509b4aSDeclan Doherty options->refresh_period == 0 ? "disabled" : "enabled"); 998387259bdSDeclan Doherty 999387259bdSDeclan Doherty switch (options->cdev_type) { 1000387259bdSDeclan Doherty case RTE_CRYPTODEV_AESNI_MB_PMD: 1001e57dcc38SPablo de Lara printf("cryptodev type: AES-NI MB PMD\n"); break; 10021bd407faSFiona Trahe case RTE_CRYPTODEV_QAT_SYM_PMD: 1003e57dcc38SPablo de Lara printf("cryptodev type: QAT PMD\n"); break; 1004387259bdSDeclan Doherty default: 1005387259bdSDeclan Doherty break; 1006387259bdSDeclan Doherty } 1007387259bdSDeclan Doherty 1008387259bdSDeclan Doherty printf("sessionless crypto: %s\n", 1009387259bdSDeclan Doherty options->sessionless ? "enabled" : "disabled"); 1010387259bdSDeclan Doherty #if 0 1011387259bdSDeclan Doherty options->xform_chain = L2FWD_CRYPTO_CIPHER_HASH; 1012387259bdSDeclan Doherty 1013387259bdSDeclan Doherty /* Cipher Data */ 1014387259bdSDeclan Doherty options->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER; 1015387259bdSDeclan Doherty options->cipher_xform.next = NULL; 1016387259bdSDeclan Doherty 1017387259bdSDeclan Doherty options->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1018387259bdSDeclan Doherty options->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 1019387259bdSDeclan Doherty 1020387259bdSDeclan Doherty generate_random_key(options->ckey_data, sizeof(options->ckey_data)); 1021387259bdSDeclan Doherty 1022387259bdSDeclan Doherty options->cipher_xform.cipher.key.data = options->ckey_data; 1023387259bdSDeclan Doherty options->cipher_xform.cipher.key.phys_addr = 0; 1024387259bdSDeclan Doherty options->cipher_xform.cipher.key.length = 16; 1025387259bdSDeclan Doherty 1026387259bdSDeclan Doherty 1027387259bdSDeclan Doherty /* Authentication Data */ 1028387259bdSDeclan Doherty options->auth_xform.type = RTE_CRYPTO_XFORM_AUTH; 1029387259bdSDeclan Doherty options->auth_xform.next = NULL; 1030387259bdSDeclan Doherty 1031387259bdSDeclan Doherty options->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 1032387259bdSDeclan Doherty options->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 1033387259bdSDeclan Doherty 1034387259bdSDeclan Doherty options->auth_xform.auth.add_auth_data_length = 0; 1035387259bdSDeclan Doherty options->auth_xform.auth.digest_length = 20; 1036387259bdSDeclan Doherty 1037387259bdSDeclan Doherty generate_random_key(options->akey_data, sizeof(options->akey_data)); 1038387259bdSDeclan Doherty 1039387259bdSDeclan Doherty options->auth_xform.auth.key.data = options->akey_data; 1040387259bdSDeclan Doherty options->auth_xform.auth.key.phys_addr = 0; 1041387259bdSDeclan Doherty options->auth_xform.auth.key.length = 20; 1042387259bdSDeclan Doherty #endif 1043387259bdSDeclan Doherty } 1044387259bdSDeclan Doherty 1045387259bdSDeclan Doherty /* Parse the argument given in the command line of the application */ 1046387259bdSDeclan Doherty static int 1047387259bdSDeclan Doherty l2fwd_crypto_parse_args(struct l2fwd_crypto_options *options, 1048387259bdSDeclan Doherty int argc, char **argv) 1049387259bdSDeclan Doherty { 1050387259bdSDeclan Doherty int opt, retval, option_index; 1051387259bdSDeclan Doherty char **argvopt = argv, *prgname = argv[0]; 1052387259bdSDeclan Doherty 1053387259bdSDeclan Doherty static struct option lgopts[] = { 1054387259bdSDeclan Doherty { "sessionless", no_argument, 0, 0 }, 1055387259bdSDeclan Doherty 1056387259bdSDeclan Doherty { "cdev_type", required_argument, 0, 0 }, 1057387259bdSDeclan Doherty { "chain", required_argument, 0, 0 }, 1058387259bdSDeclan Doherty 1059387259bdSDeclan Doherty { "cipher_algo", required_argument, 0, 0 }, 1060387259bdSDeclan Doherty { "cipher_op", required_argument, 0, 0 }, 1061387259bdSDeclan Doherty { "cipher_key", required_argument, 0, 0 }, 1062387259bdSDeclan Doherty 1063387259bdSDeclan Doherty { "auth_algo", required_argument, 0, 0 }, 1064387259bdSDeclan Doherty { "auth_op", required_argument, 0, 0 }, 1065387259bdSDeclan Doherty { "auth_key", required_argument, 0, 0 }, 1066387259bdSDeclan Doherty 1067387259bdSDeclan Doherty { "iv", required_argument, 0, 0 }, 1068387259bdSDeclan Doherty 1069387259bdSDeclan Doherty { "sessionless", no_argument, 0, 0 }, 1070387259bdSDeclan Doherty { NULL, 0, 0, 0 } 1071387259bdSDeclan Doherty }; 1072387259bdSDeclan Doherty 1073387259bdSDeclan Doherty l2fwd_crypto_default_options(options); 1074387259bdSDeclan Doherty 1075387259bdSDeclan Doherty while ((opt = getopt_long(argc, argvopt, "p:q:st:", lgopts, 1076387259bdSDeclan Doherty &option_index)) != EOF) { 1077387259bdSDeclan Doherty switch (opt) { 1078387259bdSDeclan Doherty /* long options */ 1079387259bdSDeclan Doherty case 0: 1080387259bdSDeclan Doherty retval = l2fwd_crypto_parse_args_long_options(options, 1081387259bdSDeclan Doherty lgopts, option_index); 1082387259bdSDeclan Doherty if (retval < 0) { 1083387259bdSDeclan Doherty l2fwd_crypto_usage(prgname); 1084387259bdSDeclan Doherty return -1; 1085387259bdSDeclan Doherty } 1086387259bdSDeclan Doherty break; 1087387259bdSDeclan Doherty 1088387259bdSDeclan Doherty /* portmask */ 1089387259bdSDeclan Doherty case 'p': 1090387259bdSDeclan Doherty retval = l2fwd_crypto_parse_portmask(options, optarg); 1091387259bdSDeclan Doherty if (retval < 0) { 1092387259bdSDeclan Doherty l2fwd_crypto_usage(prgname); 1093387259bdSDeclan Doherty return -1; 1094387259bdSDeclan Doherty } 1095387259bdSDeclan Doherty break; 1096387259bdSDeclan Doherty 1097387259bdSDeclan Doherty /* nqueue */ 1098387259bdSDeclan Doherty case 'q': 1099387259bdSDeclan Doherty retval = l2fwd_crypto_parse_nqueue(options, optarg); 1100387259bdSDeclan Doherty if (retval < 0) { 1101387259bdSDeclan Doherty l2fwd_crypto_usage(prgname); 1102387259bdSDeclan Doherty return -1; 1103387259bdSDeclan Doherty } 1104387259bdSDeclan Doherty break; 1105387259bdSDeclan Doherty 1106387259bdSDeclan Doherty /* single */ 1107387259bdSDeclan Doherty case 's': 1108387259bdSDeclan Doherty options->single_lcore = 1; 1109387259bdSDeclan Doherty 1110387259bdSDeclan Doherty break; 1111387259bdSDeclan Doherty 1112387259bdSDeclan Doherty /* timer period */ 1113387259bdSDeclan Doherty case 't': 1114387259bdSDeclan Doherty retval = l2fwd_crypto_parse_timer_period(options, 1115387259bdSDeclan Doherty optarg); 1116387259bdSDeclan Doherty if (retval < 0) { 1117387259bdSDeclan Doherty l2fwd_crypto_usage(prgname); 1118387259bdSDeclan Doherty return -1; 1119387259bdSDeclan Doherty } 1120387259bdSDeclan Doherty break; 1121387259bdSDeclan Doherty 1122387259bdSDeclan Doherty default: 1123387259bdSDeclan Doherty l2fwd_crypto_usage(prgname); 1124387259bdSDeclan Doherty return -1; 1125387259bdSDeclan Doherty } 1126387259bdSDeclan Doherty } 1127387259bdSDeclan Doherty 1128387259bdSDeclan Doherty 1129387259bdSDeclan Doherty if (optind >= 0) 1130387259bdSDeclan Doherty argv[optind-1] = prgname; 1131387259bdSDeclan Doherty 1132387259bdSDeclan Doherty retval = optind-1; 1133387259bdSDeclan Doherty optind = 0; /* reset getopt lib */ 1134387259bdSDeclan Doherty 1135387259bdSDeclan Doherty return retval; 1136387259bdSDeclan Doherty } 1137387259bdSDeclan Doherty 1138387259bdSDeclan Doherty /* Check the link status of all ports in up to 9s, and print them finally */ 1139387259bdSDeclan Doherty static void 1140387259bdSDeclan Doherty check_all_ports_link_status(uint8_t port_num, uint32_t port_mask) 1141387259bdSDeclan Doherty { 1142387259bdSDeclan Doherty #define CHECK_INTERVAL 100 /* 100ms */ 1143387259bdSDeclan Doherty #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */ 1144387259bdSDeclan Doherty uint8_t portid, count, all_ports_up, print_flag = 0; 1145387259bdSDeclan Doherty struct rte_eth_link link; 1146387259bdSDeclan Doherty 1147387259bdSDeclan Doherty printf("\nChecking link status"); 1148387259bdSDeclan Doherty fflush(stdout); 1149387259bdSDeclan Doherty for (count = 0; count <= MAX_CHECK_TIME; count++) { 1150387259bdSDeclan Doherty all_ports_up = 1; 1151387259bdSDeclan Doherty for (portid = 0; portid < port_num; portid++) { 1152387259bdSDeclan Doherty if ((port_mask & (1 << portid)) == 0) 1153387259bdSDeclan Doherty continue; 1154387259bdSDeclan Doherty memset(&link, 0, sizeof(link)); 1155387259bdSDeclan Doherty rte_eth_link_get_nowait(portid, &link); 1156387259bdSDeclan Doherty /* print link status if flag set */ 1157387259bdSDeclan Doherty if (print_flag == 1) { 1158387259bdSDeclan Doherty if (link.link_status) 1159387259bdSDeclan Doherty printf("Port %d Link Up - speed %u " 1160387259bdSDeclan Doherty "Mbps - %s\n", (uint8_t)portid, 1161387259bdSDeclan Doherty (unsigned)link.link_speed, 1162387259bdSDeclan Doherty (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? 1163387259bdSDeclan Doherty ("full-duplex") : ("half-duplex\n")); 1164387259bdSDeclan Doherty else 1165387259bdSDeclan Doherty printf("Port %d Link Down\n", 1166387259bdSDeclan Doherty (uint8_t)portid); 1167387259bdSDeclan Doherty continue; 1168387259bdSDeclan Doherty } 1169387259bdSDeclan Doherty /* clear all_ports_up flag if any link down */ 1170387259bdSDeclan Doherty if (link.link_status == 0) { 1171387259bdSDeclan Doherty all_ports_up = 0; 1172387259bdSDeclan Doherty break; 1173387259bdSDeclan Doherty } 1174387259bdSDeclan Doherty } 1175387259bdSDeclan Doherty /* after finally printing all link status, get out */ 1176387259bdSDeclan Doherty if (print_flag == 1) 1177387259bdSDeclan Doherty break; 1178387259bdSDeclan Doherty 1179387259bdSDeclan Doherty if (all_ports_up == 0) { 1180387259bdSDeclan Doherty printf("."); 1181387259bdSDeclan Doherty fflush(stdout); 1182387259bdSDeclan Doherty rte_delay_ms(CHECK_INTERVAL); 1183387259bdSDeclan Doherty } 1184387259bdSDeclan Doherty 1185387259bdSDeclan Doherty /* set the print_flag if all ports up or timeout */ 1186387259bdSDeclan Doherty if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { 1187387259bdSDeclan Doherty print_flag = 1; 1188387259bdSDeclan Doherty printf("done\n"); 1189387259bdSDeclan Doherty } 1190387259bdSDeclan Doherty } 1191387259bdSDeclan Doherty } 1192387259bdSDeclan Doherty 1193387259bdSDeclan Doherty static int 1194387259bdSDeclan Doherty initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports) 1195387259bdSDeclan Doherty { 1196387259bdSDeclan Doherty unsigned i, cdev_id, cdev_count, enabled_cdev_count = 0; 1197387259bdSDeclan Doherty int retval; 1198387259bdSDeclan Doherty 11991bd407faSFiona Trahe if (options->cdev_type == RTE_CRYPTODEV_QAT_SYM_PMD) { 1200387259bdSDeclan Doherty if (rte_cryptodev_count() < nb_ports) 1201387259bdSDeclan Doherty return -1; 1202387259bdSDeclan Doherty } else if (options->cdev_type == RTE_CRYPTODEV_AESNI_MB_PMD) { 1203387259bdSDeclan Doherty for (i = 0; i < nb_ports; i++) { 1204a324c45aSPablo de Lara int retval = rte_eal_vdev_init(CRYPTODEV_NAME_AESNI_MB_PMD, 1205387259bdSDeclan Doherty NULL); 1206a324c45aSPablo de Lara if (retval < 0) 1207387259bdSDeclan Doherty return -1; 1208387259bdSDeclan Doherty } 1209387259bdSDeclan Doherty } 1210387259bdSDeclan Doherty 1211387259bdSDeclan Doherty cdev_count = rte_cryptodev_count(); 1212387259bdSDeclan Doherty for (cdev_id = 0; 1213387259bdSDeclan Doherty cdev_id < cdev_count && enabled_cdev_count < nb_ports; 1214387259bdSDeclan Doherty cdev_id++) { 1215387259bdSDeclan Doherty struct rte_cryptodev_qp_conf qp_conf; 1216387259bdSDeclan Doherty struct rte_cryptodev_info dev_info; 1217387259bdSDeclan Doherty 1218387259bdSDeclan Doherty struct rte_cryptodev_config conf = { 1219387259bdSDeclan Doherty .nb_queue_pairs = 1, 1220387259bdSDeclan Doherty .socket_id = SOCKET_ID_ANY, 1221387259bdSDeclan Doherty .session_mp = { 1222387259bdSDeclan Doherty .nb_objs = 2048, 1223387259bdSDeclan Doherty .cache_size = 64 1224387259bdSDeclan Doherty } 1225387259bdSDeclan Doherty }; 1226387259bdSDeclan Doherty 1227387259bdSDeclan Doherty rte_cryptodev_info_get(cdev_id, &dev_info); 1228387259bdSDeclan Doherty 1229387259bdSDeclan Doherty if (dev_info.dev_type != options->cdev_type) 1230387259bdSDeclan Doherty continue; 1231387259bdSDeclan Doherty 1232387259bdSDeclan Doherty 1233387259bdSDeclan Doherty retval = rte_cryptodev_configure(cdev_id, &conf); 1234387259bdSDeclan Doherty if (retval < 0) { 1235387259bdSDeclan Doherty printf("Failed to configure cryptodev %u", cdev_id); 1236387259bdSDeclan Doherty return -1; 1237387259bdSDeclan Doherty } 1238387259bdSDeclan Doherty 1239387259bdSDeclan Doherty qp_conf.nb_descriptors = 2048; 1240387259bdSDeclan Doherty 1241387259bdSDeclan Doherty retval = rte_cryptodev_queue_pair_setup(cdev_id, 0, &qp_conf, 1242387259bdSDeclan Doherty SOCKET_ID_ANY); 1243387259bdSDeclan Doherty if (retval < 0) { 1244387259bdSDeclan Doherty printf("Failed to setup queue pair %u on cryptodev %u", 1245387259bdSDeclan Doherty 0, cdev_id); 1246387259bdSDeclan Doherty return -1; 1247387259bdSDeclan Doherty } 1248387259bdSDeclan Doherty 1249387259bdSDeclan Doherty l2fwd_enabled_crypto_mask |= (1 << cdev_id); 1250387259bdSDeclan Doherty 1251387259bdSDeclan Doherty enabled_cdev_count++; 1252387259bdSDeclan Doherty } 1253387259bdSDeclan Doherty 1254387259bdSDeclan Doherty return enabled_cdev_count; 1255387259bdSDeclan Doherty } 1256387259bdSDeclan Doherty 1257387259bdSDeclan Doherty static int 1258387259bdSDeclan Doherty initialize_ports(struct l2fwd_crypto_options *options) 1259387259bdSDeclan Doherty { 1260387259bdSDeclan Doherty uint8_t last_portid, portid; 1261387259bdSDeclan Doherty unsigned enabled_portcount = 0; 1262387259bdSDeclan Doherty unsigned nb_ports = rte_eth_dev_count(); 1263387259bdSDeclan Doherty 1264387259bdSDeclan Doherty if (nb_ports == 0) { 1265387259bdSDeclan Doherty printf("No Ethernet ports - bye\n"); 1266387259bdSDeclan Doherty return -1; 1267387259bdSDeclan Doherty } 1268387259bdSDeclan Doherty 1269387259bdSDeclan Doherty if (nb_ports > RTE_MAX_ETHPORTS) 1270387259bdSDeclan Doherty nb_ports = RTE_MAX_ETHPORTS; 1271387259bdSDeclan Doherty 1272387259bdSDeclan Doherty /* Reset l2fwd_dst_ports */ 1273387259bdSDeclan Doherty for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) 1274387259bdSDeclan Doherty l2fwd_dst_ports[portid] = 0; 1275387259bdSDeclan Doherty 1276387259bdSDeclan Doherty for (last_portid = 0, portid = 0; portid < nb_ports; portid++) { 1277387259bdSDeclan Doherty int retval; 1278387259bdSDeclan Doherty 1279387259bdSDeclan Doherty /* Skip ports that are not enabled */ 1280387259bdSDeclan Doherty if ((options->portmask & (1 << portid)) == 0) 1281387259bdSDeclan Doherty continue; 1282387259bdSDeclan Doherty 1283387259bdSDeclan Doherty /* init port */ 1284387259bdSDeclan Doherty printf("Initializing port %u... ", (unsigned) portid); 1285387259bdSDeclan Doherty fflush(stdout); 1286387259bdSDeclan Doherty retval = rte_eth_dev_configure(portid, 1, 1, &port_conf); 1287387259bdSDeclan Doherty if (retval < 0) { 1288387259bdSDeclan Doherty printf("Cannot configure device: err=%d, port=%u\n", 1289387259bdSDeclan Doherty retval, (unsigned) portid); 1290387259bdSDeclan Doherty return -1; 1291387259bdSDeclan Doherty } 1292387259bdSDeclan Doherty 1293387259bdSDeclan Doherty /* init one RX queue */ 1294387259bdSDeclan Doherty fflush(stdout); 1295387259bdSDeclan Doherty retval = rte_eth_rx_queue_setup(portid, 0, nb_rxd, 1296387259bdSDeclan Doherty rte_eth_dev_socket_id(portid), 1297387259bdSDeclan Doherty NULL, l2fwd_pktmbuf_pool); 1298387259bdSDeclan Doherty if (retval < 0) { 1299387259bdSDeclan Doherty printf("rte_eth_rx_queue_setup:err=%d, port=%u\n", 1300387259bdSDeclan Doherty retval, (unsigned) portid); 1301387259bdSDeclan Doherty return -1; 1302387259bdSDeclan Doherty } 1303387259bdSDeclan Doherty 1304387259bdSDeclan Doherty /* init one TX queue on each port */ 1305387259bdSDeclan Doherty fflush(stdout); 1306387259bdSDeclan Doherty retval = rte_eth_tx_queue_setup(portid, 0, nb_txd, 1307387259bdSDeclan Doherty rte_eth_dev_socket_id(portid), 1308387259bdSDeclan Doherty NULL); 1309387259bdSDeclan Doherty if (retval < 0) { 1310387259bdSDeclan Doherty printf("rte_eth_tx_queue_setup:err=%d, port=%u\n", 1311387259bdSDeclan Doherty retval, (unsigned) portid); 1312387259bdSDeclan Doherty 1313387259bdSDeclan Doherty return -1; 1314387259bdSDeclan Doherty } 1315387259bdSDeclan Doherty 1316387259bdSDeclan Doherty /* Start device */ 1317387259bdSDeclan Doherty retval = rte_eth_dev_start(portid); 1318387259bdSDeclan Doherty if (retval < 0) { 1319387259bdSDeclan Doherty printf("rte_eth_dev_start:err=%d, port=%u\n", 1320387259bdSDeclan Doherty retval, (unsigned) portid); 1321387259bdSDeclan Doherty return -1; 1322387259bdSDeclan Doherty } 1323387259bdSDeclan Doherty 1324387259bdSDeclan Doherty rte_eth_promiscuous_enable(portid); 1325387259bdSDeclan Doherty 1326387259bdSDeclan Doherty rte_eth_macaddr_get(portid, &l2fwd_ports_eth_addr[portid]); 1327387259bdSDeclan Doherty 1328387259bdSDeclan Doherty printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n", 1329387259bdSDeclan Doherty (unsigned) portid, 1330387259bdSDeclan Doherty l2fwd_ports_eth_addr[portid].addr_bytes[0], 1331387259bdSDeclan Doherty l2fwd_ports_eth_addr[portid].addr_bytes[1], 1332387259bdSDeclan Doherty l2fwd_ports_eth_addr[portid].addr_bytes[2], 1333387259bdSDeclan Doherty l2fwd_ports_eth_addr[portid].addr_bytes[3], 1334387259bdSDeclan Doherty l2fwd_ports_eth_addr[portid].addr_bytes[4], 1335387259bdSDeclan Doherty l2fwd_ports_eth_addr[portid].addr_bytes[5]); 1336387259bdSDeclan Doherty 1337387259bdSDeclan Doherty /* initialize port stats */ 1338387259bdSDeclan Doherty memset(&port_statistics, 0, sizeof(port_statistics)); 1339387259bdSDeclan Doherty 1340387259bdSDeclan Doherty /* Setup port forwarding table */ 1341387259bdSDeclan Doherty if (enabled_portcount % 2) { 1342387259bdSDeclan Doherty l2fwd_dst_ports[portid] = last_portid; 1343387259bdSDeclan Doherty l2fwd_dst_ports[last_portid] = portid; 1344387259bdSDeclan Doherty } else { 1345387259bdSDeclan Doherty last_portid = portid; 1346387259bdSDeclan Doherty } 1347387259bdSDeclan Doherty 1348387259bdSDeclan Doherty l2fwd_enabled_port_mask |= (1 << portid); 1349387259bdSDeclan Doherty enabled_portcount++; 1350387259bdSDeclan Doherty } 1351387259bdSDeclan Doherty 1352387259bdSDeclan Doherty if (enabled_portcount == 1) { 1353387259bdSDeclan Doherty l2fwd_dst_ports[last_portid] = last_portid; 1354387259bdSDeclan Doherty } else if (enabled_portcount % 2) { 1355387259bdSDeclan Doherty printf("odd number of ports in portmask- bye\n"); 1356387259bdSDeclan Doherty return -1; 1357387259bdSDeclan Doherty } 1358387259bdSDeclan Doherty 1359387259bdSDeclan Doherty check_all_ports_link_status(nb_ports, l2fwd_enabled_port_mask); 1360387259bdSDeclan Doherty 1361387259bdSDeclan Doherty return enabled_portcount; 1362387259bdSDeclan Doherty } 1363387259bdSDeclan Doherty 1364387259bdSDeclan Doherty int 1365387259bdSDeclan Doherty main(int argc, char **argv) 1366387259bdSDeclan Doherty { 1367387259bdSDeclan Doherty struct lcore_queue_conf *qconf; 1368387259bdSDeclan Doherty struct l2fwd_crypto_options options; 1369387259bdSDeclan Doherty 1370387259bdSDeclan Doherty uint8_t nb_ports, nb_cryptodevs, portid, cdev_id; 1371387259bdSDeclan Doherty unsigned lcore_id, rx_lcore_id; 1372387259bdSDeclan Doherty int ret, enabled_cdevcount, enabled_portcount; 1373387259bdSDeclan Doherty 1374387259bdSDeclan Doherty /* init EAL */ 1375387259bdSDeclan Doherty ret = rte_eal_init(argc, argv); 1376387259bdSDeclan Doherty if (ret < 0) 1377387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n"); 1378387259bdSDeclan Doherty argc -= ret; 1379387259bdSDeclan Doherty argv += ret; 1380387259bdSDeclan Doherty 1381387259bdSDeclan Doherty /* parse application arguments (after the EAL ones) */ 1382387259bdSDeclan Doherty ret = l2fwd_crypto_parse_args(&options, argc, argv); 1383387259bdSDeclan Doherty if (ret < 0) 1384387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, "Invalid L2FWD-CRYPTO arguments\n"); 1385387259bdSDeclan Doherty 1386387259bdSDeclan Doherty /* create the mbuf pool */ 1387387259bdSDeclan Doherty l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 128, 1388387259bdSDeclan Doherty 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); 1389387259bdSDeclan Doherty if (l2fwd_pktmbuf_pool == NULL) 1390387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n"); 1391387259bdSDeclan Doherty 1392387259bdSDeclan Doherty /* create crypto op pool */ 1393387259bdSDeclan Doherty l2fwd_mbuf_ol_pool = rte_pktmbuf_offload_pool_create( 1394387259bdSDeclan Doherty "mbuf_offload_pool", NB_MBUF, 128, 0, rte_socket_id()); 1395387259bdSDeclan Doherty if (l2fwd_mbuf_ol_pool == NULL) 1396387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, "Cannot create crypto op pool\n"); 1397387259bdSDeclan Doherty 1398387259bdSDeclan Doherty /* Enable Ethernet ports */ 1399387259bdSDeclan Doherty enabled_portcount = initialize_ports(&options); 1400387259bdSDeclan Doherty if (enabled_portcount < 1) 1401387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, "Failed to initial Ethernet ports\n"); 1402387259bdSDeclan Doherty 1403387259bdSDeclan Doherty nb_ports = rte_eth_dev_count(); 1404387259bdSDeclan Doherty /* Initialize the port/queue configuration of each logical core */ 1405387259bdSDeclan Doherty for (rx_lcore_id = 0, qconf = NULL, portid = 0; 1406387259bdSDeclan Doherty portid < nb_ports; portid++) { 1407387259bdSDeclan Doherty 1408387259bdSDeclan Doherty /* skip ports that are not enabled */ 1409387259bdSDeclan Doherty if ((options.portmask & (1 << portid)) == 0) 1410387259bdSDeclan Doherty continue; 1411387259bdSDeclan Doherty 1412387259bdSDeclan Doherty if (options.single_lcore && qconf == NULL) { 1413387259bdSDeclan Doherty while (rte_lcore_is_enabled(rx_lcore_id) == 0) { 1414387259bdSDeclan Doherty rx_lcore_id++; 1415387259bdSDeclan Doherty if (rx_lcore_id >= RTE_MAX_LCORE) 1416387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, 1417387259bdSDeclan Doherty "Not enough cores\n"); 1418387259bdSDeclan Doherty } 1419387259bdSDeclan Doherty } else if (!options.single_lcore) { 1420387259bdSDeclan Doherty /* get the lcore_id for this port */ 1421387259bdSDeclan Doherty while (rte_lcore_is_enabled(rx_lcore_id) == 0 || 1422387259bdSDeclan Doherty lcore_queue_conf[rx_lcore_id].nb_rx_ports == 1423387259bdSDeclan Doherty options.nb_ports_per_lcore) { 1424387259bdSDeclan Doherty rx_lcore_id++; 1425387259bdSDeclan Doherty if (rx_lcore_id >= RTE_MAX_LCORE) 1426387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, 1427387259bdSDeclan Doherty "Not enough cores\n"); 1428387259bdSDeclan Doherty } 1429387259bdSDeclan Doherty } 1430387259bdSDeclan Doherty 1431387259bdSDeclan Doherty /* Assigned a new logical core in the loop above. */ 1432387259bdSDeclan Doherty if (qconf != &lcore_queue_conf[rx_lcore_id]) 1433387259bdSDeclan Doherty qconf = &lcore_queue_conf[rx_lcore_id]; 1434387259bdSDeclan Doherty 1435387259bdSDeclan Doherty qconf->rx_port_list[qconf->nb_rx_ports] = portid; 1436387259bdSDeclan Doherty qconf->nb_rx_ports++; 1437387259bdSDeclan Doherty 1438387259bdSDeclan Doherty printf("Lcore %u: RX port %u\n", rx_lcore_id, (unsigned)portid); 1439387259bdSDeclan Doherty } 1440387259bdSDeclan Doherty 1441387259bdSDeclan Doherty 1442387259bdSDeclan Doherty /* Enable Crypto devices */ 1443387259bdSDeclan Doherty enabled_cdevcount = initialize_cryptodevs(&options, enabled_portcount); 1444387259bdSDeclan Doherty if (enabled_cdevcount < 1) 1445387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, "Failed to initial crypto devices\n"); 1446387259bdSDeclan Doherty 1447387259bdSDeclan Doherty nb_cryptodevs = rte_cryptodev_count(); 1448387259bdSDeclan Doherty /* Initialize the port/queue configuration of each logical core */ 1449387259bdSDeclan Doherty for (rx_lcore_id = 0, qconf = NULL, cdev_id = 0; 1450387259bdSDeclan Doherty cdev_id < nb_cryptodevs && enabled_cdevcount; 1451387259bdSDeclan Doherty cdev_id++) { 1452387259bdSDeclan Doherty struct rte_cryptodev_info info; 1453387259bdSDeclan Doherty 1454387259bdSDeclan Doherty rte_cryptodev_info_get(cdev_id, &info); 1455387259bdSDeclan Doherty 1456387259bdSDeclan Doherty /* skip devices of the wrong type */ 1457387259bdSDeclan Doherty if (options.cdev_type != info.dev_type) 1458387259bdSDeclan Doherty continue; 1459387259bdSDeclan Doherty 1460387259bdSDeclan Doherty if (options.single_lcore && qconf == NULL) { 1461387259bdSDeclan Doherty while (rte_lcore_is_enabled(rx_lcore_id) == 0) { 1462387259bdSDeclan Doherty rx_lcore_id++; 1463387259bdSDeclan Doherty if (rx_lcore_id >= RTE_MAX_LCORE) 1464387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, 1465387259bdSDeclan Doherty "Not enough cores\n"); 1466387259bdSDeclan Doherty } 1467387259bdSDeclan Doherty } else if (!options.single_lcore) { 1468387259bdSDeclan Doherty /* get the lcore_id for this port */ 1469387259bdSDeclan Doherty while (rte_lcore_is_enabled(rx_lcore_id) == 0 || 1470387259bdSDeclan Doherty lcore_queue_conf[rx_lcore_id].nb_crypto_devs == 1471387259bdSDeclan Doherty options.nb_ports_per_lcore) { 1472387259bdSDeclan Doherty rx_lcore_id++; 1473387259bdSDeclan Doherty if (rx_lcore_id >= RTE_MAX_LCORE) 1474387259bdSDeclan Doherty rte_exit(EXIT_FAILURE, 1475387259bdSDeclan Doherty "Not enough cores\n"); 1476387259bdSDeclan Doherty } 1477387259bdSDeclan Doherty } 1478387259bdSDeclan Doherty 1479387259bdSDeclan Doherty /* Assigned a new logical core in the loop above. */ 1480387259bdSDeclan Doherty if (qconf != &lcore_queue_conf[rx_lcore_id]) 1481387259bdSDeclan Doherty qconf = &lcore_queue_conf[rx_lcore_id]; 1482387259bdSDeclan Doherty 1483387259bdSDeclan Doherty qconf->cryptodev_list[qconf->nb_crypto_devs] = cdev_id; 1484387259bdSDeclan Doherty qconf->nb_crypto_devs++; 1485387259bdSDeclan Doherty 1486387259bdSDeclan Doherty enabled_cdevcount--; 1487387259bdSDeclan Doherty 1488387259bdSDeclan Doherty printf("Lcore %u: cryptodev %u\n", rx_lcore_id, 1489387259bdSDeclan Doherty (unsigned)cdev_id); 1490387259bdSDeclan Doherty } 1491387259bdSDeclan Doherty 1492387259bdSDeclan Doherty 1493387259bdSDeclan Doherty 1494387259bdSDeclan Doherty /* launch per-lcore init on every lcore */ 1495387259bdSDeclan Doherty rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, (void *)&options, 1496387259bdSDeclan Doherty CALL_MASTER); 1497387259bdSDeclan Doherty RTE_LCORE_FOREACH_SLAVE(lcore_id) { 1498387259bdSDeclan Doherty if (rte_eal_wait_lcore(lcore_id) < 0) 1499387259bdSDeclan Doherty return -1; 1500387259bdSDeclan Doherty } 1501387259bdSDeclan Doherty 1502387259bdSDeclan Doherty return 0; 1503387259bdSDeclan Doherty } 1504