1540914bcSEd Czeck /* SPDX-License-Identifier: BSD-3-Clause
2540914bcSEd Czeck * Copyright (c) 2015-2018 Atomic Rules LLC
39c7188a6SEd Czeck */
49c7188a6SEd Czeck
572b452c5SDmitry Kozlyuk #include <stdlib.h>
69c7188a6SEd Czeck #include <unistd.h>
79c7188a6SEd Czeck
86723c0fcSBruce Richardson #include <rte_string_fns.h>
99c7188a6SEd Czeck #include <rte_malloc.h>
10*a7ba40b2SThomas Monjalon #include <rte_thread.h>
119c7188a6SEd Czeck
129c7188a6SEd Czeck #include "ark_pktgen.h"
139c7188a6SEd Czeck #include "ark_logs.h"
149c7188a6SEd Czeck
159c7188a6SEd Czeck #define ARK_MAX_STR_LEN 64
169c7188a6SEd Czeck union OPTV {
179c7188a6SEd Czeck int INT;
189c7188a6SEd Czeck int BOOL;
199c7188a6SEd Czeck uint64_t LONG;
209c7188a6SEd Czeck char STR[ARK_MAX_STR_LEN];
219c7188a6SEd Czeck };
229c7188a6SEd Czeck
239c7188a6SEd Czeck enum OPTYPE {
249c7188a6SEd Czeck OTINT,
259c7188a6SEd Czeck OTLONG,
269c7188a6SEd Czeck OTBOOL,
279c7188a6SEd Czeck OTSTRING
289c7188a6SEd Czeck };
299c7188a6SEd Czeck
309c7188a6SEd Czeck struct OPTIONS {
319c7188a6SEd Czeck char opt[ARK_MAX_STR_LEN];
329c7188a6SEd Czeck enum OPTYPE t;
339c7188a6SEd Czeck union OPTV v;
349c7188a6SEd Czeck };
359c7188a6SEd Czeck
369c7188a6SEd Czeck static struct OPTIONS toptions[] = {
379c7188a6SEd Czeck {{"configure"}, OTBOOL, {1} },
389c7188a6SEd Czeck {{"dg-mode"}, OTBOOL, {1} },
399c7188a6SEd Czeck {{"run"}, OTBOOL, {0} },
409c7188a6SEd Czeck {{"pause"}, OTBOOL, {0} },
419c7188a6SEd Czeck {{"reset"}, OTBOOL, {0} },
429c7188a6SEd Czeck {{"dump"}, OTBOOL, {0} },
439c7188a6SEd Czeck {{"gen_forever"}, OTBOOL, {0} },
449c7188a6SEd Czeck {{"en_slaved_start"}, OTBOOL, {0} },
459c7188a6SEd Czeck {{"vary_length"}, OTBOOL, {0} },
469c7188a6SEd Czeck {{"incr_payload"}, OTBOOL, {0} },
479c7188a6SEd Czeck {{"incr_first_byte"}, OTBOOL, {0} },
489c7188a6SEd Czeck {{"ins_seq_num"}, OTBOOL, {0} },
499c7188a6SEd Czeck {{"ins_time_stamp"}, OTBOOL, {1} },
509c7188a6SEd Czeck {{"ins_udp_hdr"}, OTBOOL, {0} },
519c7188a6SEd Czeck {{"num_pkts"}, OTLONG, .v.LONG = 100000000},
529c7188a6SEd Czeck {{"payload_byte"}, OTINT, {0x55} },
539c7188a6SEd Czeck {{"pkt_spacing"}, OTINT, {130} },
549c7188a6SEd Czeck {{"pkt_size_min"}, OTINT, {2006} },
559c7188a6SEd Czeck {{"pkt_size_max"}, OTINT, {1514} },
569c7188a6SEd Czeck {{"pkt_size_incr"}, OTINT, {1} },
579c7188a6SEd Czeck {{"eth_type"}, OTINT, {0x0800} },
589c7188a6SEd Czeck {{"src_mac_addr"}, OTLONG, .v.LONG = 0xdC3cF6425060L},
599c7188a6SEd Czeck {{"dst_mac_addr"}, OTLONG, .v.LONG = 0x112233445566L},
609c7188a6SEd Czeck {{"hdr_dW0"}, OTINT, {0x0016e319} },
619c7188a6SEd Czeck {{"hdr_dW1"}, OTINT, {0x27150004} },
629c7188a6SEd Czeck {{"hdr_dW2"}, OTINT, {0x76967bda} },
639c7188a6SEd Czeck {{"hdr_dW3"}, OTINT, {0x08004500} },
649c7188a6SEd Czeck {{"hdr_dW4"}, OTINT, {0x005276ed} },
659c7188a6SEd Czeck {{"hdr_dW5"}, OTINT, {0x40004006} },
669c7188a6SEd Czeck {{"hdr_dW6"}, OTINT, {0x56cfc0a8} },
679c7188a6SEd Czeck {{"start_offset"}, OTINT, {0} },
689c7188a6SEd Czeck {{"bytes_per_cycle"}, OTINT, {10} },
699c7188a6SEd Czeck {{"shaping"}, OTBOOL, {0} },
709c7188a6SEd Czeck {{"dst_ip"}, OTSTRING, .v.STR = "169.254.10.240"},
719c7188a6SEd Czeck {{"dst_port"}, OTINT, {65536} },
729c7188a6SEd Czeck {{"src_port"}, OTINT, {65536} },
739c7188a6SEd Czeck };
749c7188a6SEd Czeck
759c7188a6SEd Czeck ark_pkt_gen_t
ark_pktgen_init(void * adr,int ord,int l2_mode)769c7188a6SEd Czeck ark_pktgen_init(void *adr, int ord, int l2_mode)
779c7188a6SEd Czeck {
789c7188a6SEd Czeck struct ark_pkt_gen_inst *inst =
799c7188a6SEd Czeck rte_malloc("ark_pkt_gen_inst_pmd",
809c7188a6SEd Czeck sizeof(struct ark_pkt_gen_inst), 0);
8153a9ba13SYong Wang if (inst == NULL) {
821502d443SEd Czeck ARK_PMD_LOG(ERR, "Failed to malloc ark_pkt_gen_inst.\n");
8353a9ba13SYong Wang return inst;
8453a9ba13SYong Wang }
859c7188a6SEd Czeck inst->regs = (struct ark_pkt_gen_regs *)adr;
869c7188a6SEd Czeck inst->ordinal = ord;
879c7188a6SEd Czeck inst->l2_mode = l2_mode;
889c7188a6SEd Czeck return inst;
899c7188a6SEd Czeck }
909c7188a6SEd Czeck
919c7188a6SEd Czeck void
ark_pktgen_uninit(ark_pkt_gen_t handle)929c7188a6SEd Czeck ark_pktgen_uninit(ark_pkt_gen_t handle)
939c7188a6SEd Czeck {
949c7188a6SEd Czeck rte_free(handle);
959c7188a6SEd Czeck }
969c7188a6SEd Czeck
979c7188a6SEd Czeck void
ark_pktgen_run(ark_pkt_gen_t handle)989c7188a6SEd Czeck ark_pktgen_run(ark_pkt_gen_t handle)
999c7188a6SEd Czeck {
1009c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
1019c7188a6SEd Czeck
1029c7188a6SEd Czeck inst->regs->pkt_start_stop = 1;
1039c7188a6SEd Czeck }
1049c7188a6SEd Czeck
1059c7188a6SEd Czeck uint32_t
ark_pktgen_paused(ark_pkt_gen_t handle)1069c7188a6SEd Czeck ark_pktgen_paused(ark_pkt_gen_t handle)
1079c7188a6SEd Czeck {
1089c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
1099c7188a6SEd Czeck uint32_t r = inst->regs->pkt_start_stop;
1109c7188a6SEd Czeck
1114f2f1bd8SJohn Miller return (((r >> 24) & 1) == 1) || (((r >> 16) & 1) == 1) || (r == 0);
1129c7188a6SEd Czeck }
1139c7188a6SEd Czeck
1149c7188a6SEd Czeck void
ark_pktgen_pause(ark_pkt_gen_t handle)1159c7188a6SEd Czeck ark_pktgen_pause(ark_pkt_gen_t handle)
1169c7188a6SEd Czeck {
1179c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
1189c7188a6SEd Czeck int cnt = 0;
1199c7188a6SEd Czeck
1209c7188a6SEd Czeck inst->regs->pkt_start_stop = 0;
1219c7188a6SEd Czeck
1229c7188a6SEd Czeck while (!ark_pktgen_paused(handle)) {
1239c7188a6SEd Czeck usleep(1000);
1249c7188a6SEd Czeck if (cnt++ > 100) {
1251502d443SEd Czeck ARK_PMD_LOG(NOTICE, "Pktgen %d failed to pause.\n",
1269c7188a6SEd Czeck inst->ordinal);
1279c7188a6SEd Czeck break;
1289c7188a6SEd Czeck }
1299c7188a6SEd Czeck }
1301502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Pktgen %d paused.\n", inst->ordinal);
1319c7188a6SEd Czeck }
1329c7188a6SEd Czeck
1339c7188a6SEd Czeck void
ark_pktgen_reset(ark_pkt_gen_t handle)1349c7188a6SEd Czeck ark_pktgen_reset(ark_pkt_gen_t handle)
1359c7188a6SEd Czeck {
1369c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
1379c7188a6SEd Czeck
1389c7188a6SEd Czeck if (!ark_pktgen_is_running(handle) &&
1399c7188a6SEd Czeck !ark_pktgen_paused(handle)) {
1401502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Pktgen %d is not running"
1419c7188a6SEd Czeck " and is not paused. No need to reset.\n",
1429c7188a6SEd Czeck inst->ordinal);
1439c7188a6SEd Czeck return;
1449c7188a6SEd Czeck }
1459c7188a6SEd Czeck
1469c7188a6SEd Czeck if (ark_pktgen_is_running(handle) &&
1479c7188a6SEd Czeck !ark_pktgen_paused(handle)) {
1481502d443SEd Czeck ARK_PMD_LOG(DEBUG,
1499c7188a6SEd Czeck "Pktgen %d is not paused. Pausing first.\n",
1509c7188a6SEd Czeck inst->ordinal);
1519c7188a6SEd Czeck ark_pktgen_pause(handle);
1529c7188a6SEd Czeck }
1539c7188a6SEd Czeck
1541502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Resetting pktgen %d.\n", inst->ordinal);
1559c7188a6SEd Czeck inst->regs->pkt_start_stop = (1 << 8);
1569c7188a6SEd Czeck }
1579c7188a6SEd Czeck
1589c7188a6SEd Czeck uint32_t
ark_pktgen_tx_done(ark_pkt_gen_t handle)1599c7188a6SEd Czeck ark_pktgen_tx_done(ark_pkt_gen_t handle)
1609c7188a6SEd Czeck {
1619c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
1629c7188a6SEd Czeck uint32_t r = inst->regs->pkt_start_stop;
1639c7188a6SEd Czeck
1649c7188a6SEd Czeck return (((r >> 24) & 1) == 1);
1659c7188a6SEd Czeck }
1669c7188a6SEd Czeck
1679c7188a6SEd Czeck uint32_t
ark_pktgen_is_running(ark_pkt_gen_t handle)1689c7188a6SEd Czeck ark_pktgen_is_running(ark_pkt_gen_t handle)
1699c7188a6SEd Czeck {
1709c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
1719c7188a6SEd Czeck uint32_t r = inst->regs->pkt_start_stop;
1729c7188a6SEd Czeck
1739c7188a6SEd Czeck return ((r & 1) == 1);
1749c7188a6SEd Czeck }
1759c7188a6SEd Czeck
1769c7188a6SEd Czeck uint32_t
ark_pktgen_is_gen_forever(ark_pkt_gen_t handle)1779c7188a6SEd Czeck ark_pktgen_is_gen_forever(ark_pkt_gen_t handle)
1789c7188a6SEd Czeck {
1799c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
1809c7188a6SEd Czeck uint32_t r = inst->regs->pkt_ctrl;
1819c7188a6SEd Czeck
1829c7188a6SEd Czeck return (((r >> 24) & 1) == 1);
1839c7188a6SEd Czeck }
1849c7188a6SEd Czeck
1859c7188a6SEd Czeck void
ark_pktgen_wait_done(ark_pkt_gen_t handle)1869c7188a6SEd Czeck ark_pktgen_wait_done(ark_pkt_gen_t handle)
1879c7188a6SEd Czeck {
1889c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
1899c7188a6SEd Czeck int wait_cycle = 10;
1909c7188a6SEd Czeck
1919c7188a6SEd Czeck if (ark_pktgen_is_gen_forever(handle))
1921502d443SEd Czeck ARK_PMD_LOG(NOTICE, "Pktgen wait_done will not terminate"
1939c7188a6SEd Czeck " because gen_forever=1\n");
1949c7188a6SEd Czeck
1959c7188a6SEd Czeck while (!ark_pktgen_tx_done(handle) && (wait_cycle > 0)) {
1969c7188a6SEd Czeck usleep(1000);
1979c7188a6SEd Czeck wait_cycle--;
1981502d443SEd Czeck ARK_PMD_LOG(DEBUG,
1999c7188a6SEd Czeck "Waiting for pktgen %d to finish sending...\n",
2009c7188a6SEd Czeck inst->ordinal);
2019c7188a6SEd Czeck }
2021502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Pktgen %d done.\n", inst->ordinal);
2039c7188a6SEd Czeck }
2049c7188a6SEd Czeck
2059c7188a6SEd Czeck uint32_t
ark_pktgen_get_pkts_sent(ark_pkt_gen_t handle)2069c7188a6SEd Czeck ark_pktgen_get_pkts_sent(ark_pkt_gen_t handle)
2079c7188a6SEd Czeck {
2089c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2099c7188a6SEd Czeck return inst->regs->pkts_sent;
2109c7188a6SEd Czeck }
2119c7188a6SEd Czeck
2129c7188a6SEd Czeck void
ark_pktgen_set_payload_byte(ark_pkt_gen_t handle,uint32_t b)2139c7188a6SEd Czeck ark_pktgen_set_payload_byte(ark_pkt_gen_t handle, uint32_t b)
2149c7188a6SEd Czeck {
2159c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2169c7188a6SEd Czeck inst->regs->pkt_payload = b;
2179c7188a6SEd Czeck }
2189c7188a6SEd Czeck
2199c7188a6SEd Czeck void
ark_pktgen_set_pkt_spacing(ark_pkt_gen_t handle,uint32_t x)2209c7188a6SEd Czeck ark_pktgen_set_pkt_spacing(ark_pkt_gen_t handle, uint32_t x)
2219c7188a6SEd Czeck {
2229c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2239c7188a6SEd Czeck inst->regs->pkt_spacing = x;
2249c7188a6SEd Czeck }
2259c7188a6SEd Czeck
2269c7188a6SEd Czeck void
ark_pktgen_set_pkt_size_min(ark_pkt_gen_t handle,uint32_t x)2279c7188a6SEd Czeck ark_pktgen_set_pkt_size_min(ark_pkt_gen_t handle, uint32_t x)
2289c7188a6SEd Czeck {
2299c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2309c7188a6SEd Czeck inst->regs->pkt_size_min = x;
2319c7188a6SEd Czeck }
2329c7188a6SEd Czeck
2339c7188a6SEd Czeck void
ark_pktgen_set_pkt_size_max(ark_pkt_gen_t handle,uint32_t x)2349c7188a6SEd Czeck ark_pktgen_set_pkt_size_max(ark_pkt_gen_t handle, uint32_t x)
2359c7188a6SEd Czeck {
2369c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2379c7188a6SEd Czeck inst->regs->pkt_size_max = x;
2389c7188a6SEd Czeck }
2399c7188a6SEd Czeck
2409c7188a6SEd Czeck void
ark_pktgen_set_pkt_size_incr(ark_pkt_gen_t handle,uint32_t x)2419c7188a6SEd Czeck ark_pktgen_set_pkt_size_incr(ark_pkt_gen_t handle, uint32_t x)
2429c7188a6SEd Czeck {
2439c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2449c7188a6SEd Czeck inst->regs->pkt_size_incr = x;
2459c7188a6SEd Czeck }
2469c7188a6SEd Czeck
2479c7188a6SEd Czeck void
ark_pktgen_set_num_pkts(ark_pkt_gen_t handle,uint32_t x)2489c7188a6SEd Czeck ark_pktgen_set_num_pkts(ark_pkt_gen_t handle, uint32_t x)
2499c7188a6SEd Czeck {
2509c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2519c7188a6SEd Czeck inst->regs->num_pkts = x;
2529c7188a6SEd Czeck }
2539c7188a6SEd Czeck
2549c7188a6SEd Czeck void
ark_pktgen_set_src_mac_addr(ark_pkt_gen_t handle,uint64_t mac_addr)2559c7188a6SEd Czeck ark_pktgen_set_src_mac_addr(ark_pkt_gen_t handle, uint64_t mac_addr)
2569c7188a6SEd Czeck {
2579c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2589c7188a6SEd Czeck inst->regs->src_mac_addr_h = (mac_addr >> 32) & 0xffff;
2599c7188a6SEd Czeck inst->regs->src_mac_addr_l = mac_addr & 0xffffffff;
2609c7188a6SEd Czeck }
2619c7188a6SEd Czeck
2629c7188a6SEd Czeck void
ark_pktgen_set_dst_mac_addr(ark_pkt_gen_t handle,uint64_t mac_addr)2639c7188a6SEd Czeck ark_pktgen_set_dst_mac_addr(ark_pkt_gen_t handle, uint64_t mac_addr)
2649c7188a6SEd Czeck {
2659c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2669c7188a6SEd Czeck inst->regs->dst_mac_addr_h = (mac_addr >> 32) & 0xffff;
2679c7188a6SEd Czeck inst->regs->dst_mac_addr_l = mac_addr & 0xffffffff;
2689c7188a6SEd Czeck }
2699c7188a6SEd Czeck
2709c7188a6SEd Czeck void
ark_pktgen_set_eth_type(ark_pkt_gen_t handle,uint32_t x)2719c7188a6SEd Czeck ark_pktgen_set_eth_type(ark_pkt_gen_t handle, uint32_t x)
2729c7188a6SEd Czeck {
2739c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2749c7188a6SEd Czeck inst->regs->eth_type = x;
2759c7188a6SEd Czeck }
2769c7188a6SEd Czeck
2779c7188a6SEd Czeck void
ark_pktgen_set_hdr_dW(ark_pkt_gen_t handle,uint32_t * hdr)2789c7188a6SEd Czeck ark_pktgen_set_hdr_dW(ark_pkt_gen_t handle, uint32_t *hdr)
2799c7188a6SEd Czeck {
2809c7188a6SEd Czeck uint32_t i;
2819c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2829c7188a6SEd Czeck
2839c7188a6SEd Czeck for (i = 0; i < 7; i++)
2849c7188a6SEd Czeck inst->regs->hdr_dw[i] = hdr[i];
2859c7188a6SEd Czeck }
2869c7188a6SEd Czeck
2879c7188a6SEd Czeck void
ark_pktgen_set_start_offset(ark_pkt_gen_t handle,uint32_t x)2889c7188a6SEd Czeck ark_pktgen_set_start_offset(ark_pkt_gen_t handle, uint32_t x)
2899c7188a6SEd Czeck {
2909c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
2919c7188a6SEd Czeck
2929c7188a6SEd Czeck inst->regs->start_offset = x;
2939c7188a6SEd Czeck }
2949c7188a6SEd Czeck
2959c7188a6SEd Czeck static struct OPTIONS *
options(const char * id)2969c7188a6SEd Czeck options(const char *id)
2979c7188a6SEd Czeck {
2989c7188a6SEd Czeck unsigned int i;
2999c7188a6SEd Czeck
3009c7188a6SEd Czeck for (i = 0; i < sizeof(toptions) / sizeof(struct OPTIONS); i++) {
3019c7188a6SEd Czeck if (strcmp(id, toptions[i].opt) == 0)
3029c7188a6SEd Czeck return &toptions[i];
3039c7188a6SEd Czeck }
3049c7188a6SEd Czeck
3051502d443SEd Czeck ARK_PMD_LOG(ERR,
3069c7188a6SEd Czeck "Pktgen: Could not find requested option!, "
3079c7188a6SEd Czeck "option = %s\n",
3089c7188a6SEd Czeck id
3099c7188a6SEd Czeck );
3109c7188a6SEd Czeck return NULL;
3119c7188a6SEd Czeck }
3129c7188a6SEd Czeck
3139c7188a6SEd Czeck static int pmd_set_arg(char *arg, char *val);
3149c7188a6SEd Czeck static int
pmd_set_arg(char * arg,char * val)3159c7188a6SEd Czeck pmd_set_arg(char *arg, char *val)
3169c7188a6SEd Czeck {
3179c7188a6SEd Czeck struct OPTIONS *o = options(arg);
3189c7188a6SEd Czeck
3199c7188a6SEd Czeck if (o) {
3209c7188a6SEd Czeck switch (o->t) {
3219c7188a6SEd Czeck case OTINT:
3229c7188a6SEd Czeck case OTBOOL:
3239c7188a6SEd Czeck o->v.INT = atoi(val);
3249c7188a6SEd Czeck break;
3259c7188a6SEd Czeck case OTLONG:
3269c7188a6SEd Czeck o->v.INT = atoll(val);
3279c7188a6SEd Czeck break;
3289c7188a6SEd Czeck case OTSTRING:
3296723c0fcSBruce Richardson strlcpy(o->v.STR, val, ARK_MAX_STR_LEN);
3309c7188a6SEd Czeck break;
3319c7188a6SEd Czeck }
3329c7188a6SEd Czeck return 1;
3339c7188a6SEd Czeck }
3349c7188a6SEd Czeck return 0;
3359c7188a6SEd Czeck }
3369c7188a6SEd Czeck
3379c7188a6SEd Czeck /******
3389c7188a6SEd Czeck * Arg format = "opt0=v,opt_n=v ..."
3399c7188a6SEd Czeck ******/
3409c7188a6SEd Czeck void
ark_pktgen_parse(char * args)3419c7188a6SEd Czeck ark_pktgen_parse(char *args)
3429c7188a6SEd Czeck {
3439c7188a6SEd Czeck char *argv, *v;
3449c7188a6SEd Czeck const char toks[] = " =\n\t\v\f \r";
3459c7188a6SEd Czeck argv = strtok(args, toks);
3469c7188a6SEd Czeck v = strtok(NULL, toks);
3479c7188a6SEd Czeck while (argv && v) {
3489c7188a6SEd Czeck pmd_set_arg(argv, v);
3499c7188a6SEd Czeck argv = strtok(NULL, toks);
3509c7188a6SEd Czeck v = strtok(NULL, toks);
3519c7188a6SEd Czeck }
3529c7188a6SEd Czeck }
3539c7188a6SEd Czeck
3549c7188a6SEd Czeck static int32_t parse_ipv4_string(char const *ip_address);
3559c7188a6SEd Czeck static int32_t
parse_ipv4_string(char const * ip_address)3569c7188a6SEd Czeck parse_ipv4_string(char const *ip_address)
3579c7188a6SEd Czeck {
3589c7188a6SEd Czeck unsigned int ip[4];
3599c7188a6SEd Czeck
3609c7188a6SEd Czeck if (sscanf(ip_address, "%u.%u.%u.%u",
3619c7188a6SEd Czeck &ip[0], &ip[1], &ip[2], &ip[3]) != 4)
3629c7188a6SEd Czeck return 0;
3639c7188a6SEd Czeck return ip[3] + ip[2] * 0x100 + ip[1] * 0x10000ul + ip[0] * 0x1000000ul;
3649c7188a6SEd Czeck }
3659c7188a6SEd Czeck
3669c7188a6SEd Czeck static void
ark_pktgen_set_pkt_ctrl(ark_pkt_gen_t handle,uint32_t gen_forever,uint32_t en_slaved_start,uint32_t vary_length,uint32_t incr_payload,uint32_t incr_first_byte,uint32_t ins_seq_num,uint32_t ins_udp_hdr,uint32_t ins_time_stamp)3679c7188a6SEd Czeck ark_pktgen_set_pkt_ctrl(ark_pkt_gen_t handle,
3689c7188a6SEd Czeck uint32_t gen_forever,
3699c7188a6SEd Czeck uint32_t en_slaved_start,
3709c7188a6SEd Czeck uint32_t vary_length,
3719c7188a6SEd Czeck uint32_t incr_payload,
3729c7188a6SEd Czeck uint32_t incr_first_byte,
3739c7188a6SEd Czeck uint32_t ins_seq_num,
3749c7188a6SEd Czeck uint32_t ins_udp_hdr,
3759c7188a6SEd Czeck uint32_t ins_time_stamp)
3769c7188a6SEd Czeck {
3779c7188a6SEd Czeck uint32_t r;
3789c7188a6SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)handle;
3799c7188a6SEd Czeck
3809c7188a6SEd Czeck if (!inst->l2_mode)
3819c7188a6SEd Czeck ins_udp_hdr = 0;
3829c7188a6SEd Czeck
3839c7188a6SEd Czeck r = ((gen_forever << 24) |
3849c7188a6SEd Czeck (en_slaved_start << 20) |
3859c7188a6SEd Czeck (vary_length << 16) |
3869c7188a6SEd Czeck (incr_payload << 12) |
3879c7188a6SEd Czeck (incr_first_byte << 8) |
3889c7188a6SEd Czeck (ins_time_stamp << 5) |
3899c7188a6SEd Czeck (ins_seq_num << 4) |
3909c7188a6SEd Czeck ins_udp_hdr);
3919c7188a6SEd Czeck
3929c7188a6SEd Czeck inst->regs->bytes_per_cycle = options("bytes_per_cycle")->v.INT;
3939c7188a6SEd Czeck if (options("shaping")->v.BOOL)
3949c7188a6SEd Czeck r = r | (1 << 28); /* enable shaping */
3959c7188a6SEd Czeck
3969c7188a6SEd Czeck inst->regs->pkt_ctrl = r;
3979c7188a6SEd Czeck }
3989c7188a6SEd Czeck
3999c7188a6SEd Czeck void
ark_pktgen_setup(ark_pkt_gen_t handle)4009c7188a6SEd Czeck ark_pktgen_setup(ark_pkt_gen_t handle)
4019c7188a6SEd Czeck {
4029c7188a6SEd Czeck uint32_t hdr[7];
4039c7188a6SEd Czeck int32_t dst_ip = parse_ipv4_string(options("dst_ip")->v.STR);
4049c7188a6SEd Czeck
4059c7188a6SEd Czeck if (!options("pause")->v.BOOL &&
4069c7188a6SEd Czeck (!options("reset")->v.BOOL &&
4079c7188a6SEd Czeck (options("configure")->v.BOOL))) {
4089c7188a6SEd Czeck ark_pktgen_set_payload_byte(handle,
4099c7188a6SEd Czeck options("payload_byte")->v.INT);
4109c7188a6SEd Czeck ark_pktgen_set_src_mac_addr(handle,
4119c7188a6SEd Czeck options("src_mac_addr")->v.INT);
4129c7188a6SEd Czeck ark_pktgen_set_dst_mac_addr(handle,
4139c7188a6SEd Czeck options("dst_mac_addr")->v.LONG);
4149c7188a6SEd Czeck ark_pktgen_set_eth_type(handle,
4159c7188a6SEd Czeck options("eth_type")->v.INT);
4169c7188a6SEd Czeck
4179c7188a6SEd Czeck if (options("dg-mode")->v.BOOL) {
4189c7188a6SEd Czeck hdr[0] = options("hdr_dW0")->v.INT;
4199c7188a6SEd Czeck hdr[1] = options("hdr_dW1")->v.INT;
4209c7188a6SEd Czeck hdr[2] = options("hdr_dW2")->v.INT;
4219c7188a6SEd Czeck hdr[3] = options("hdr_dW3")->v.INT;
4229c7188a6SEd Czeck hdr[4] = options("hdr_dW4")->v.INT;
4239c7188a6SEd Czeck hdr[5] = options("hdr_dW5")->v.INT;
4249c7188a6SEd Czeck hdr[6] = options("hdr_dW6")->v.INT;
4259c7188a6SEd Czeck } else {
4269c7188a6SEd Czeck hdr[0] = dst_ip;
4279c7188a6SEd Czeck hdr[1] = options("dst_port")->v.INT;
4289c7188a6SEd Czeck hdr[2] = options("src_port")->v.INT;
4299c7188a6SEd Czeck hdr[3] = 0;
4309c7188a6SEd Czeck hdr[4] = 0;
4319c7188a6SEd Czeck hdr[5] = 0;
4329c7188a6SEd Czeck hdr[6] = 0;
4339c7188a6SEd Czeck }
4349c7188a6SEd Czeck ark_pktgen_set_hdr_dW(handle, hdr);
4359c7188a6SEd Czeck ark_pktgen_set_num_pkts(handle,
4369c7188a6SEd Czeck options("num_pkts")->v.INT);
4379c7188a6SEd Czeck ark_pktgen_set_pkt_size_min(handle,
4389c7188a6SEd Czeck options("pkt_size_min")->v.INT);
4399c7188a6SEd Czeck ark_pktgen_set_pkt_size_max(handle,
4409c7188a6SEd Czeck options("pkt_size_max")->v.INT);
4419c7188a6SEd Czeck ark_pktgen_set_pkt_size_incr(handle,
4429c7188a6SEd Czeck options("pkt_size_incr")->v.INT);
4439c7188a6SEd Czeck ark_pktgen_set_pkt_spacing(handle,
4449c7188a6SEd Czeck options("pkt_spacing")->v.INT);
4459c7188a6SEd Czeck ark_pktgen_set_start_offset(handle,
4469c7188a6SEd Czeck options("start_offset")->v.INT);
4479c7188a6SEd Czeck ark_pktgen_set_pkt_ctrl(handle,
4489c7188a6SEd Czeck options("gen_forever")->v.BOOL,
4499c7188a6SEd Czeck options("en_slaved_start")->v.BOOL,
4509c7188a6SEd Czeck options("vary_length")->v.BOOL,
4519c7188a6SEd Czeck options("incr_payload")->v.BOOL,
4529c7188a6SEd Czeck options("incr_first_byte")->v.BOOL,
4539c7188a6SEd Czeck options("ins_seq_num")->v.INT,
4549c7188a6SEd Czeck options("ins_udp_hdr")->v.BOOL,
4559c7188a6SEd Czeck options("ins_time_stamp")->v.INT);
4569c7188a6SEd Czeck }
4579c7188a6SEd Czeck
4589c7188a6SEd Czeck if (options("pause")->v.BOOL)
4599c7188a6SEd Czeck ark_pktgen_pause(handle);
4609c7188a6SEd Czeck
4619c7188a6SEd Czeck if (options("reset")->v.BOOL)
4629c7188a6SEd Czeck ark_pktgen_reset(handle);
4639c7188a6SEd Czeck if (options("run")->v.BOOL) {
4641502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Starting packet generator on port %d\n",
4659c7188a6SEd Czeck options("port")->v.INT);
4669c7188a6SEd Czeck ark_pktgen_run(handle);
4679c7188a6SEd Czeck }
4689c7188a6SEd Czeck }
4692b88daf7SEd Czeck
470*a7ba40b2SThomas Monjalon uint32_t
ark_pktgen_delay_start(void * arg)4712b88daf7SEd Czeck ark_pktgen_delay_start(void *arg)
4722b88daf7SEd Czeck {
4732b88daf7SEd Czeck struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)arg;
4742b88daf7SEd Czeck
4752b88daf7SEd Czeck /* This function is used exclusively for regression testing, We
4762b88daf7SEd Czeck * perform a blind sleep here to ensure that the external test
4772b88daf7SEd Czeck * application has time to setup the test before we generate packets
4782b88daf7SEd Czeck */
479*a7ba40b2SThomas Monjalon rte_thread_detach(rte_thread_self());
4802b88daf7SEd Czeck usleep(100000);
4812b88daf7SEd Czeck ark_pktgen_run(inst);
482*a7ba40b2SThomas Monjalon return 0;
4832b88daf7SEd Czeck }
484