1474572d2SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2474572d2SBruce Richardson * Copyright(c) 2010-2016 Intel Corporation 3474572d2SBruce Richardson */ 4474572d2SBruce Richardson 5474572d2SBruce Richardson #include <stdio.h> 6474572d2SBruce Richardson #include <stdlib.h> 7474572d2SBruce Richardson #include <stdint.h> 8474572d2SBruce Richardson 9474572d2SBruce Richardson #include <rte_log.h> 10474572d2SBruce Richardson #include <rte_ethdev.h> 11474572d2SBruce Richardson #include <rte_ether.h> 12474572d2SBruce Richardson #include <rte_ip.h> 13474572d2SBruce Richardson #include <rte_byteorder.h> 14474572d2SBruce Richardson 15474572d2SBruce Richardson #include <rte_port_ring.h> 16474572d2SBruce Richardson #include <rte_table_hash.h> 17474572d2SBruce Richardson #include <rte_hash.h> 18474572d2SBruce Richardson #include <rte_table_hash_cuckoo.h> 19474572d2SBruce Richardson #include <rte_pipeline.h> 20474572d2SBruce Richardson 21474572d2SBruce Richardson #include "main.h" 22474572d2SBruce Richardson 23474572d2SBruce Richardson static void 24474572d2SBruce Richardson translate_options(uint32_t *special, uint32_t *ext, uint32_t *key_size) 25474572d2SBruce Richardson { 26474572d2SBruce Richardson switch (app.pipeline_type) { 27474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY8_EXT: 28474572d2SBruce Richardson *special = 0; *ext = 1; *key_size = 8; return; 29474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY8_LRU: 30474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 8; return; 31474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY16_EXT: 32474572d2SBruce Richardson *special = 0; *ext = 1; *key_size = 16; return; 33474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY16_LRU: 34474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 16; return; 35474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY32_EXT: 36474572d2SBruce Richardson *special = 0; *ext = 1; *key_size = 32; return; 37474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY32_LRU: 38474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 32; return; 39474572d2SBruce Richardson 40474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY8_EXT: 41474572d2SBruce Richardson *special = 1; *ext = 1; *key_size = 8; return; 42474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY8_LRU: 43474572d2SBruce Richardson *special = 1; *ext = 0; *key_size = 8; return; 44474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT: 45474572d2SBruce Richardson *special = 1; *ext = 1; *key_size = 16; return; 46474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU: 47474572d2SBruce Richardson *special = 1; *ext = 0; *key_size = 16; return; 48474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY32_EXT: 49474572d2SBruce Richardson *special = 1; *ext = 1; *key_size = 32; return; 50474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU: 51474572d2SBruce Richardson *special = 1; *ext = 0; *key_size = 32; return; 52474572d2SBruce Richardson 53474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY8: 54474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 8; return; 55474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY16: 56474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 16; return; 57474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY32: 58474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 32; return; 59474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY48: 60474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 48; return; 61474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY64: 62474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 64; return; 63474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY80: 64474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 80; return; 65474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY96: 66474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 96; return; 67474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY112: 68474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 112; return; 69474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY128: 70474572d2SBruce Richardson *special = 0; *ext = 0; *key_size = 128; return; 71474572d2SBruce Richardson 72474572d2SBruce Richardson default: 73474572d2SBruce Richardson rte_panic("Invalid hash table type or key size\n"); 74474572d2SBruce Richardson } 75474572d2SBruce Richardson } 76474572d2SBruce Richardson void 77474572d2SBruce Richardson app_main_loop_worker_pipeline_hash(void) { 78474572d2SBruce Richardson struct rte_pipeline_params pipeline_params = { 79474572d2SBruce Richardson .name = "pipeline", 80474572d2SBruce Richardson .socket_id = rte_socket_id(), 81474572d2SBruce Richardson }; 82474572d2SBruce Richardson 83474572d2SBruce Richardson struct rte_pipeline *p; 84474572d2SBruce Richardson uint32_t port_in_id[APP_MAX_PORTS]; 85474572d2SBruce Richardson uint32_t port_out_id[APP_MAX_PORTS]; 86474572d2SBruce Richardson uint32_t table_id; 87474572d2SBruce Richardson uint32_t i; 88474572d2SBruce Richardson uint32_t special, ext, key_size; 89474572d2SBruce Richardson 90474572d2SBruce Richardson translate_options(&special, &ext, &key_size); 91474572d2SBruce Richardson 92474572d2SBruce Richardson RTE_LOG(INFO, USER1, "Core %u is doing work " 93474572d2SBruce Richardson "(pipeline with hash table, %s, %s, %d-byte key)\n", 94474572d2SBruce Richardson rte_lcore_id(), 95474572d2SBruce Richardson special ? "specialized" : "non-specialized", 96474572d2SBruce Richardson ext ? "extendible bucket" : "LRU", 97474572d2SBruce Richardson key_size); 98474572d2SBruce Richardson 99474572d2SBruce Richardson /* Pipeline configuration */ 100474572d2SBruce Richardson p = rte_pipeline_create(&pipeline_params); 101474572d2SBruce Richardson if (p == NULL) 102474572d2SBruce Richardson rte_panic("Unable to configure the pipeline\n"); 103474572d2SBruce Richardson 104474572d2SBruce Richardson /* Input port configuration */ 105474572d2SBruce Richardson for (i = 0; i < app.n_ports; i++) { 106474572d2SBruce Richardson struct rte_port_ring_reader_params port_ring_params = { 107474572d2SBruce Richardson .ring = app.rings_rx[i], 108474572d2SBruce Richardson }; 109474572d2SBruce Richardson 110474572d2SBruce Richardson struct rte_pipeline_port_in_params port_params = { 111474572d2SBruce Richardson .ops = &rte_port_ring_reader_ops, 112474572d2SBruce Richardson .arg_create = (void *) &port_ring_params, 113474572d2SBruce Richardson .f_action = NULL, 114474572d2SBruce Richardson .arg_ah = NULL, 115474572d2SBruce Richardson .burst_size = app.burst_size_worker_read, 116474572d2SBruce Richardson }; 117474572d2SBruce Richardson 118474572d2SBruce Richardson if (rte_pipeline_port_in_create(p, &port_params, 119474572d2SBruce Richardson &port_in_id[i])) 120474572d2SBruce Richardson rte_panic("Unable to configure input port for " 121474572d2SBruce Richardson "ring %d\n", i); 122474572d2SBruce Richardson } 123474572d2SBruce Richardson 124474572d2SBruce Richardson /* Output port configuration */ 125474572d2SBruce Richardson for (i = 0; i < app.n_ports; i++) { 126474572d2SBruce Richardson struct rte_port_ring_writer_params port_ring_params = { 127474572d2SBruce Richardson .ring = app.rings_tx[i], 128474572d2SBruce Richardson .tx_burst_sz = app.burst_size_worker_write, 129474572d2SBruce Richardson }; 130474572d2SBruce Richardson 131474572d2SBruce Richardson struct rte_pipeline_port_out_params port_params = { 132474572d2SBruce Richardson .ops = &rte_port_ring_writer_ops, 133474572d2SBruce Richardson .arg_create = (void *) &port_ring_params, 134474572d2SBruce Richardson .f_action = NULL, 135474572d2SBruce Richardson .arg_ah = NULL, 136474572d2SBruce Richardson }; 137474572d2SBruce Richardson 138474572d2SBruce Richardson if (rte_pipeline_port_out_create(p, &port_params, 139474572d2SBruce Richardson &port_out_id[i])) 140474572d2SBruce Richardson rte_panic("Unable to configure output port for " 141474572d2SBruce Richardson "ring %d\n", i); 142474572d2SBruce Richardson } 143474572d2SBruce Richardson 144474572d2SBruce Richardson struct rte_table_hash_params table_hash_params = { 145474572d2SBruce Richardson .name = "TABLE", 146474572d2SBruce Richardson .key_size = key_size, 147474572d2SBruce Richardson .key_offset = APP_METADATA_OFFSET(32), 148474572d2SBruce Richardson .key_mask = NULL, 149474572d2SBruce Richardson .n_keys = 1 << 24, 150474572d2SBruce Richardson .n_buckets = 1 << 22, 151474572d2SBruce Richardson .f_hash = test_hash, 152474572d2SBruce Richardson .seed = 0, 153474572d2SBruce Richardson }; 154474572d2SBruce Richardson 155474572d2SBruce Richardson struct rte_table_hash_cuckoo_params table_hash_cuckoo_params = { 156474572d2SBruce Richardson .name = "TABLE", 157474572d2SBruce Richardson .key_size = key_size, 158474572d2SBruce Richardson .key_offset = APP_METADATA_OFFSET(32), 159474572d2SBruce Richardson .key_mask = NULL, 160474572d2SBruce Richardson .n_keys = 1 << 24, 161474572d2SBruce Richardson .n_buckets = 1 << 22, 162474572d2SBruce Richardson .f_hash = test_hash_cuckoo, 163474572d2SBruce Richardson .seed = 0, 164474572d2SBruce Richardson }; 165474572d2SBruce Richardson 166474572d2SBruce Richardson /* Table configuration */ 167474572d2SBruce Richardson switch (app.pipeline_type) { 168474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY8_EXT: 169474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY16_EXT: 170474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY32_EXT: 171474572d2SBruce Richardson { 172474572d2SBruce Richardson struct rte_pipeline_table_params table_params = { 173474572d2SBruce Richardson .ops = &rte_table_hash_ext_ops, 174474572d2SBruce Richardson .arg_create = &table_hash_params, 175474572d2SBruce Richardson .f_action_hit = NULL, 176474572d2SBruce Richardson .f_action_miss = NULL, 177474572d2SBruce Richardson .arg_ah = NULL, 178474572d2SBruce Richardson .action_data_size = 0, 179474572d2SBruce Richardson }; 180474572d2SBruce Richardson 181474572d2SBruce Richardson if (rte_pipeline_table_create(p, &table_params, &table_id)) 182474572d2SBruce Richardson rte_panic("Unable to configure the hash table\n"); 183474572d2SBruce Richardson } 184474572d2SBruce Richardson break; 185474572d2SBruce Richardson 186474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY8_LRU: 187474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY16_LRU: 188474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY32_LRU: 189474572d2SBruce Richardson { 190474572d2SBruce Richardson struct rte_pipeline_table_params table_params = { 191474572d2SBruce Richardson .ops = &rte_table_hash_lru_ops, 192474572d2SBruce Richardson .arg_create = &table_hash_params, 193474572d2SBruce Richardson .f_action_hit = NULL, 194474572d2SBruce Richardson .f_action_miss = NULL, 195474572d2SBruce Richardson .arg_ah = NULL, 196474572d2SBruce Richardson .action_data_size = 0, 197474572d2SBruce Richardson }; 198474572d2SBruce Richardson 199474572d2SBruce Richardson if (rte_pipeline_table_create(p, &table_params, &table_id)) 200474572d2SBruce Richardson rte_panic("Unable to configure the hash table\n"); 201474572d2SBruce Richardson } 202474572d2SBruce Richardson break; 203474572d2SBruce Richardson 204474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY8_EXT: 205474572d2SBruce Richardson { 206474572d2SBruce Richardson struct rte_pipeline_table_params table_params = { 207474572d2SBruce Richardson .ops = &rte_table_hash_key8_ext_ops, 208474572d2SBruce Richardson .arg_create = &table_hash_params, 209474572d2SBruce Richardson .f_action_hit = NULL, 210474572d2SBruce Richardson .f_action_miss = NULL, 211474572d2SBruce Richardson .arg_ah = NULL, 212474572d2SBruce Richardson .action_data_size = 0, 213474572d2SBruce Richardson }; 214474572d2SBruce Richardson 215474572d2SBruce Richardson if (rte_pipeline_table_create(p, &table_params, &table_id)) 216474572d2SBruce Richardson rte_panic("Unable to configure the hash table\n"); 217474572d2SBruce Richardson } 218474572d2SBruce Richardson break; 219474572d2SBruce Richardson 220474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY8_LRU: 221474572d2SBruce Richardson { 222474572d2SBruce Richardson struct rte_pipeline_table_params table_params = { 223474572d2SBruce Richardson .ops = &rte_table_hash_key8_lru_ops, 224474572d2SBruce Richardson .arg_create = &table_hash_params, 225474572d2SBruce Richardson .f_action_hit = NULL, 226474572d2SBruce Richardson .f_action_miss = NULL, 227474572d2SBruce Richardson .arg_ah = NULL, 228474572d2SBruce Richardson .action_data_size = 0, 229474572d2SBruce Richardson }; 230474572d2SBruce Richardson 231474572d2SBruce Richardson if (rte_pipeline_table_create(p, &table_params, &table_id)) 232474572d2SBruce Richardson rte_panic("Unable to configure the hash table\n"); 233474572d2SBruce Richardson } 234474572d2SBruce Richardson break; 235474572d2SBruce Richardson 236474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT: 237474572d2SBruce Richardson { 238474572d2SBruce Richardson struct rte_pipeline_table_params table_params = { 239474572d2SBruce Richardson .ops = &rte_table_hash_key16_ext_ops, 240474572d2SBruce Richardson .arg_create = &table_hash_params, 241474572d2SBruce Richardson .f_action_hit = NULL, 242474572d2SBruce Richardson .f_action_miss = NULL, 243474572d2SBruce Richardson .arg_ah = NULL, 244474572d2SBruce Richardson .action_data_size = 0, 245474572d2SBruce Richardson }; 246474572d2SBruce Richardson 247474572d2SBruce Richardson if (rte_pipeline_table_create(p, &table_params, &table_id)) 248474572d2SBruce Richardson rte_panic("Unable to configure the hash table)\n"); 249474572d2SBruce Richardson } 250474572d2SBruce Richardson break; 251474572d2SBruce Richardson 252474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU: 253474572d2SBruce Richardson { 254474572d2SBruce Richardson struct rte_pipeline_table_params table_params = { 255474572d2SBruce Richardson .ops = &rte_table_hash_key16_lru_ops, 256474572d2SBruce Richardson .arg_create = &table_hash_params, 257474572d2SBruce Richardson .f_action_hit = NULL, 258474572d2SBruce Richardson .f_action_miss = NULL, 259474572d2SBruce Richardson .arg_ah = NULL, 260474572d2SBruce Richardson .action_data_size = 0, 261474572d2SBruce Richardson }; 262474572d2SBruce Richardson 263474572d2SBruce Richardson if (rte_pipeline_table_create(p, &table_params, &table_id)) 264474572d2SBruce Richardson rte_panic("Unable to configure the hash table\n"); 265474572d2SBruce Richardson } 266474572d2SBruce Richardson break; 267474572d2SBruce Richardson 268474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY32_EXT: 269474572d2SBruce Richardson { 270474572d2SBruce Richardson struct rte_pipeline_table_params table_params = { 271474572d2SBruce Richardson .ops = &rte_table_hash_key32_ext_ops, 272474572d2SBruce Richardson .arg_create = &table_hash_params, 273474572d2SBruce Richardson .f_action_hit = NULL, 274474572d2SBruce Richardson .f_action_miss = NULL, 275474572d2SBruce Richardson .arg_ah = NULL, 276474572d2SBruce Richardson .action_data_size = 0, 277474572d2SBruce Richardson }; 278474572d2SBruce Richardson 279474572d2SBruce Richardson if (rte_pipeline_table_create(p, &table_params, &table_id)) 280474572d2SBruce Richardson rte_panic("Unable to configure the hash table\n"); 281474572d2SBruce Richardson } 282474572d2SBruce Richardson break; 283474572d2SBruce Richardson 284474572d2SBruce Richardson 285474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU: 286474572d2SBruce Richardson { 287474572d2SBruce Richardson struct rte_pipeline_table_params table_params = { 288474572d2SBruce Richardson .ops = &rte_table_hash_key32_lru_ops, 289474572d2SBruce Richardson .arg_create = &table_hash_params, 290474572d2SBruce Richardson .f_action_hit = NULL, 291474572d2SBruce Richardson .f_action_miss = NULL, 292474572d2SBruce Richardson .arg_ah = NULL, 293474572d2SBruce Richardson .action_data_size = 0, 294474572d2SBruce Richardson }; 295474572d2SBruce Richardson 296474572d2SBruce Richardson if (rte_pipeline_table_create(p, &table_params, &table_id)) 297474572d2SBruce Richardson rte_panic("Unable to configure the hash table\n"); 298474572d2SBruce Richardson } 299474572d2SBruce Richardson break; 300474572d2SBruce Richardson 301474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY8: 302474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY16: 303474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY32: 304474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY48: 305474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY64: 306474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY80: 307474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY96: 308474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY112: 309474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY128: 310474572d2SBruce Richardson { 311474572d2SBruce Richardson struct rte_pipeline_table_params table_params = { 312474572d2SBruce Richardson .ops = &rte_table_hash_cuckoo_ops, 313474572d2SBruce Richardson .arg_create = &table_hash_cuckoo_params, 314474572d2SBruce Richardson .f_action_hit = NULL, 315474572d2SBruce Richardson .f_action_miss = NULL, 316474572d2SBruce Richardson .arg_ah = NULL, 317474572d2SBruce Richardson .action_data_size = 0, 318474572d2SBruce Richardson }; 319474572d2SBruce Richardson 320474572d2SBruce Richardson if (rte_pipeline_table_create(p, &table_params, &table_id)) 321474572d2SBruce Richardson rte_panic("Unable to configure the hash table\n"); 322474572d2SBruce Richardson } 323474572d2SBruce Richardson break; 324474572d2SBruce Richardson 325474572d2SBruce Richardson default: 326474572d2SBruce Richardson rte_panic("Invalid hash table type or key size\n"); 327474572d2SBruce Richardson } 328474572d2SBruce Richardson 329474572d2SBruce Richardson /* Interconnecting ports and tables */ 330474572d2SBruce Richardson for (i = 0; i < app.n_ports; i++) 331474572d2SBruce Richardson if (rte_pipeline_port_in_connect_to_table(p, port_in_id[i], 332474572d2SBruce Richardson table_id)) 333474572d2SBruce Richardson rte_panic("Unable to connect input port %u to " 334474572d2SBruce Richardson "table %u\n", port_in_id[i], table_id); 335474572d2SBruce Richardson 336474572d2SBruce Richardson /* Add entries to tables */ 337474572d2SBruce Richardson for (i = 0; i < (1 << 24); i++) { 338474572d2SBruce Richardson struct rte_pipeline_table_entry entry = { 339474572d2SBruce Richardson .action = RTE_PIPELINE_ACTION_PORT, 340474572d2SBruce Richardson {.port_id = port_out_id[i & (app.n_ports - 1)]}, 341474572d2SBruce Richardson }; 342474572d2SBruce Richardson struct rte_pipeline_table_entry *entry_ptr; 343474572d2SBruce Richardson uint8_t key[32]; 344474572d2SBruce Richardson uint32_t *k32 = (uint32_t *) key; 345474572d2SBruce Richardson int key_found, status; 346474572d2SBruce Richardson 347474572d2SBruce Richardson memset(key, 0, sizeof(key)); 348474572d2SBruce Richardson k32[0] = rte_be_to_cpu_32(i); 349474572d2SBruce Richardson 350474572d2SBruce Richardson status = rte_pipeline_table_entry_add(p, table_id, key, &entry, 351474572d2SBruce Richardson &key_found, &entry_ptr); 352474572d2SBruce Richardson if (status < 0) 353474572d2SBruce Richardson rte_panic("Unable to add entry to table %u (%d)\n", 354474572d2SBruce Richardson table_id, status); 355474572d2SBruce Richardson } 356474572d2SBruce Richardson 357474572d2SBruce Richardson /* Enable input ports */ 358474572d2SBruce Richardson for (i = 0; i < app.n_ports; i++) 359474572d2SBruce Richardson if (rte_pipeline_port_in_enable(p, port_in_id[i])) 360474572d2SBruce Richardson rte_panic("Unable to enable input port %u\n", 361474572d2SBruce Richardson port_in_id[i]); 362474572d2SBruce Richardson 363474572d2SBruce Richardson /* Check pipeline consistency */ 364474572d2SBruce Richardson if (rte_pipeline_check(p) < 0) 365474572d2SBruce Richardson rte_panic("Pipeline consistency check failed\n"); 366474572d2SBruce Richardson 367474572d2SBruce Richardson /* Run-time */ 368474572d2SBruce Richardson #if APP_FLUSH == 0 369f6897b23SFeifei Wang while (!force_quit) 370474572d2SBruce Richardson rte_pipeline_run(p); 371474572d2SBruce Richardson #else 372f6897b23SFeifei Wang i = 0; 373f6897b23SFeifei Wang while (!force_quit) { 374474572d2SBruce Richardson rte_pipeline_run(p); 375474572d2SBruce Richardson 376474572d2SBruce Richardson if ((i & APP_FLUSH) == 0) 377474572d2SBruce Richardson rte_pipeline_flush(p); 378f6897b23SFeifei Wang i++; 379474572d2SBruce Richardson } 380474572d2SBruce Richardson #endif 381474572d2SBruce Richardson } 382474572d2SBruce Richardson 383474572d2SBruce Richardson uint64_t test_hash( 384474572d2SBruce Richardson void *key, 385f2fc83b4SThomas Monjalon __rte_unused void *key_mask, 386f2fc83b4SThomas Monjalon __rte_unused uint32_t key_size, 387f2fc83b4SThomas Monjalon __rte_unused uint64_t seed) 388474572d2SBruce Richardson { 389474572d2SBruce Richardson uint32_t *k32 = key; 390474572d2SBruce Richardson uint32_t ip_dst = rte_be_to_cpu_32(k32[0]); 391474572d2SBruce Richardson uint64_t signature = (ip_dst >> 2) | ((ip_dst & 0x3) << 30); 392474572d2SBruce Richardson 393474572d2SBruce Richardson return signature; 394474572d2SBruce Richardson } 395474572d2SBruce Richardson 396474572d2SBruce Richardson uint32_t test_hash_cuckoo( 397474572d2SBruce Richardson const void *key, 398f2fc83b4SThomas Monjalon __rte_unused uint32_t key_size, 399f2fc83b4SThomas Monjalon __rte_unused uint32_t seed) 400474572d2SBruce Richardson { 401474572d2SBruce Richardson const uint32_t *k32 = key; 402474572d2SBruce Richardson uint32_t ip_dst = rte_be_to_cpu_32(k32[0]); 403474572d2SBruce Richardson uint32_t signature = (ip_dst >> 2) | ((ip_dst & 0x3) << 30); 404474572d2SBruce Richardson 405474572d2SBruce Richardson return signature; 406474572d2SBruce Richardson } 407474572d2SBruce Richardson 408474572d2SBruce Richardson void 409474572d2SBruce Richardson app_main_loop_rx_metadata(void) { 410474572d2SBruce Richardson uint32_t i, j; 411474572d2SBruce Richardson int ret; 412474572d2SBruce Richardson 413474572d2SBruce Richardson RTE_LOG(INFO, USER1, "Core %u is doing RX (with meta-data)\n", 414474572d2SBruce Richardson rte_lcore_id()); 415474572d2SBruce Richardson 416f6897b23SFeifei Wang while (!force_quit) { 417f6897b23SFeifei Wang for (i = 0; i < app.n_ports; i++) { 418474572d2SBruce Richardson uint16_t n_mbufs; 419474572d2SBruce Richardson 420474572d2SBruce Richardson n_mbufs = rte_eth_rx_burst( 421474572d2SBruce Richardson app.ports[i], 422474572d2SBruce Richardson 0, 423474572d2SBruce Richardson app.mbuf_rx.array, 424474572d2SBruce Richardson app.burst_size_rx_read); 425474572d2SBruce Richardson 426474572d2SBruce Richardson if (n_mbufs == 0) 427474572d2SBruce Richardson continue; 428474572d2SBruce Richardson 429474572d2SBruce Richardson for (j = 0; j < n_mbufs; j++) { 430474572d2SBruce Richardson struct rte_mbuf *m; 431474572d2SBruce Richardson uint8_t *m_data, *key; 432a7c528e5SOlivier Matz struct rte_ipv4_hdr *ip_hdr; 433a7c528e5SOlivier Matz struct rte_ipv6_hdr *ipv6_hdr; 434474572d2SBruce Richardson uint32_t ip_dst; 435474572d2SBruce Richardson uint32_t *signature, *k32; 436474572d2SBruce Richardson 437474572d2SBruce Richardson m = app.mbuf_rx.array[j]; 438474572d2SBruce Richardson m_data = rte_pktmbuf_mtod(m, uint8_t *); 439474572d2SBruce Richardson signature = RTE_MBUF_METADATA_UINT32_PTR(m, 440474572d2SBruce Richardson APP_METADATA_OFFSET(0)); 441474572d2SBruce Richardson key = RTE_MBUF_METADATA_UINT8_PTR(m, 442474572d2SBruce Richardson APP_METADATA_OFFSET(32)); 443474572d2SBruce Richardson 444474572d2SBruce Richardson if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) { 445a7c528e5SOlivier Matz ip_hdr = (struct rte_ipv4_hdr *) 4466d13ea8eSOlivier Matz &m_data[sizeof(struct rte_ether_hdr)]; 447474572d2SBruce Richardson ip_dst = ip_hdr->dst_addr; 448474572d2SBruce Richardson 449474572d2SBruce Richardson k32 = (uint32_t *) key; 450474572d2SBruce Richardson k32[0] = ip_dst & 0xFFFFFF00; 451474572d2SBruce Richardson } else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) { 452a7c528e5SOlivier Matz ipv6_hdr = (struct rte_ipv6_hdr *) 4536d13ea8eSOlivier Matz &m_data[sizeof(struct rte_ether_hdr)]; 454474572d2SBruce Richardson 455*89b5642dSRobin Jarry memcpy(key, &ipv6_hdr->dst_addr, 16); 456474572d2SBruce Richardson } else 457474572d2SBruce Richardson continue; 458474572d2SBruce Richardson 459474572d2SBruce Richardson *signature = test_hash(key, NULL, 0, 0); 460474572d2SBruce Richardson } 461474572d2SBruce Richardson 462474572d2SBruce Richardson do { 463474572d2SBruce Richardson ret = rte_ring_sp_enqueue_bulk( 464474572d2SBruce Richardson app.rings_rx[i], 465474572d2SBruce Richardson (void **) app.mbuf_rx.array, 466474572d2SBruce Richardson n_mbufs, 467474572d2SBruce Richardson NULL); 468f6897b23SFeifei Wang } while (ret == 0 && !force_quit); 469f6897b23SFeifei Wang } 470474572d2SBruce Richardson } 471474572d2SBruce Richardson } 472