1540914bcSEd Czeck /* SPDX-License-Identifier: BSD-3-Clause
2540914bcSEd Czeck * Copyright (c) 2015-2018 Atomic Rules LLC
39c7188a6SEd Czeck */
49c7188a6SEd Czeck
5*72b452c5SDmitry Kozlyuk #include <stdlib.h>
69c7188a6SEd Czeck #include <unistd.h>
79c7188a6SEd Czeck
86723c0fcSBruce Richardson #include <rte_string_fns.h>
99c7188a6SEd Czeck #include <rte_malloc.h>
109c7188a6SEd Czeck
119c7188a6SEd Czeck #include "ark_pktchkr.h"
129c7188a6SEd Czeck #include "ark_logs.h"
139c7188a6SEd Czeck
149c7188a6SEd Czeck static int set_arg(char *arg, char *val);
159c7188a6SEd Czeck static int ark_pktchkr_is_gen_forever(ark_pkt_chkr_t handle);
169c7188a6SEd Czeck
179c7188a6SEd Czeck #define ARK_MAX_STR_LEN 64
189c7188a6SEd Czeck union OPTV {
199c7188a6SEd Czeck int INT;
209c7188a6SEd Czeck int BOOL;
219c7188a6SEd Czeck uint64_t LONG;
229c7188a6SEd Czeck char STR[ARK_MAX_STR_LEN];
239c7188a6SEd Czeck };
249c7188a6SEd Czeck
259c7188a6SEd Czeck enum OPTYPE {
269c7188a6SEd Czeck OTINT,
279c7188a6SEd Czeck OTLONG,
289c7188a6SEd Czeck OTBOOL,
299c7188a6SEd Czeck OTSTRING
309c7188a6SEd Czeck };
319c7188a6SEd Czeck
329c7188a6SEd Czeck struct OPTIONS {
339c7188a6SEd Czeck char opt[ARK_MAX_STR_LEN];
349c7188a6SEd Czeck enum OPTYPE t;
359c7188a6SEd Czeck union OPTV v;
369c7188a6SEd Czeck };
379c7188a6SEd Czeck
389c7188a6SEd Czeck static struct OPTIONS toptions[] = {
399c7188a6SEd Czeck {{"configure"}, OTBOOL, {1} },
409c7188a6SEd Czeck {{"port"}, OTINT, {0} },
419c7188a6SEd Czeck {{"mac-dump"}, OTBOOL, {0} },
429c7188a6SEd Czeck {{"dg-mode"}, OTBOOL, {1} },
439c7188a6SEd Czeck {{"run"}, OTBOOL, {0} },
449c7188a6SEd Czeck {{"stop"}, OTBOOL, {0} },
459c7188a6SEd Czeck {{"dump"}, OTBOOL, {0} },
469c7188a6SEd Czeck {{"en_resync"}, OTBOOL, {0} },
479c7188a6SEd Czeck {{"tuser_err_val"}, OTINT, {1} },
489c7188a6SEd Czeck {{"gen_forever"}, OTBOOL, {0} },
499c7188a6SEd Czeck {{"en_slaved_start"}, OTBOOL, {0} },
509c7188a6SEd Czeck {{"vary_length"}, OTBOOL, {0} },
519c7188a6SEd Czeck {{"incr_payload"}, OTINT, {0} },
529c7188a6SEd Czeck {{"incr_first_byte"}, OTBOOL, {0} },
539c7188a6SEd Czeck {{"ins_seq_num"}, OTBOOL, {0} },
549c7188a6SEd Czeck {{"ins_time_stamp"}, OTBOOL, {1} },
559c7188a6SEd Czeck {{"ins_udp_hdr"}, OTBOOL, {0} },
569c7188a6SEd Czeck {{"num_pkts"}, OTLONG, .v.LONG = 10000000000000L},
579c7188a6SEd Czeck {{"payload_byte"}, OTINT, {0x55} },
589c7188a6SEd Czeck {{"pkt_spacing"}, OTINT, {60} },
599c7188a6SEd Czeck {{"pkt_size_min"}, OTINT, {2005} },
609c7188a6SEd Czeck {{"pkt_size_max"}, OTINT, {1514} },
619c7188a6SEd Czeck {{"pkt_size_incr"}, OTINT, {1} },
629c7188a6SEd Czeck {{"eth_type"}, OTINT, {0x0800} },
639c7188a6SEd Czeck {{"src_mac_addr"}, OTLONG, .v.LONG = 0xdC3cF6425060L},
649c7188a6SEd Czeck {{"dst_mac_addr"}, OTLONG, .v.LONG = 0x112233445566L},
659c7188a6SEd Czeck {{"hdr_dW0"}, OTINT, {0x0016e319} },
669c7188a6SEd Czeck {{"hdr_dW1"}, OTINT, {0x27150004} },
679c7188a6SEd Czeck {{"hdr_dW2"}, OTINT, {0x76967bda} },
689c7188a6SEd Czeck {{"hdr_dW3"}, OTINT, {0x08004500} },
699c7188a6SEd Czeck {{"hdr_dW4"}, OTINT, {0x005276ed} },
709c7188a6SEd Czeck {{"hdr_dW5"}, OTINT, {0x40004006} },
719c7188a6SEd Czeck {{"hdr_dW6"}, OTINT, {0x56cfc0a8} },
729c7188a6SEd Czeck {{"start_offset"}, OTINT, {0} },
739c7188a6SEd Czeck {{"dst_ip"}, OTSTRING, .v.STR = "169.254.10.240"},
749c7188a6SEd Czeck {{"dst_port"}, OTINT, {65536} },
759c7188a6SEd Czeck {{"src_port"}, OTINT, {65536} },
769c7188a6SEd Czeck };
779c7188a6SEd Czeck
789c7188a6SEd Czeck ark_pkt_chkr_t
ark_pktchkr_init(void * addr,int ord,int l2_mode)799c7188a6SEd Czeck ark_pktchkr_init(void *addr, int ord, int l2_mode)
809c7188a6SEd Czeck {
819c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst =
829c7188a6SEd Czeck rte_malloc("ark_pkt_chkr_inst",
839c7188a6SEd Czeck sizeof(struct ark_pkt_chkr_inst), 0);
8453a9ba13SYong Wang if (inst == NULL) {
851502d443SEd Czeck ARK_PMD_LOG(ERR, "Failed to malloc ark_pkt_chkr_inst.\n");
8653a9ba13SYong Wang return inst;
8753a9ba13SYong Wang }
889c7188a6SEd Czeck inst->sregs = (struct ark_pkt_chkr_stat_regs *)addr;
899c7188a6SEd Czeck inst->cregs =
909c7188a6SEd Czeck (struct ark_pkt_chkr_ctl_regs *)(((uint8_t *)addr) + 0x100);
919c7188a6SEd Czeck inst->ordinal = ord;
929c7188a6SEd Czeck inst->l2_mode = l2_mode;
939c7188a6SEd Czeck return inst;
949c7188a6SEd Czeck }
959c7188a6SEd Czeck
969c7188a6SEd Czeck void
ark_pktchkr_uninit(ark_pkt_chkr_t handle)979c7188a6SEd Czeck ark_pktchkr_uninit(ark_pkt_chkr_t handle)
989c7188a6SEd Czeck {
999c7188a6SEd Czeck rte_free(handle);
1009c7188a6SEd Czeck }
1019c7188a6SEd Czeck
1029c7188a6SEd Czeck void
ark_pktchkr_run(ark_pkt_chkr_t handle)1039c7188a6SEd Czeck ark_pktchkr_run(ark_pkt_chkr_t handle)
1049c7188a6SEd Czeck {
1059c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
1069c7188a6SEd Czeck
1079c7188a6SEd Czeck inst->sregs->pkt_start_stop = 0;
1089c7188a6SEd Czeck inst->sregs->pkt_start_stop = 0x1;
1099c7188a6SEd Czeck }
1109c7188a6SEd Czeck
1119c7188a6SEd Czeck int
ark_pktchkr_stopped(ark_pkt_chkr_t handle)1129c7188a6SEd Czeck ark_pktchkr_stopped(ark_pkt_chkr_t handle)
1139c7188a6SEd Czeck {
1149c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
1159c7188a6SEd Czeck uint32_t r = inst->sregs->pkt_start_stop;
1169c7188a6SEd Czeck
1174f2f1bd8SJohn Miller return (((r >> 16) & 1) == 1) || (r == 0);
1189c7188a6SEd Czeck }
1199c7188a6SEd Czeck
1209c7188a6SEd Czeck void
ark_pktchkr_stop(ark_pkt_chkr_t handle)1219c7188a6SEd Czeck ark_pktchkr_stop(ark_pkt_chkr_t handle)
1229c7188a6SEd Czeck {
1239c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
1249c7188a6SEd Czeck int wait_cycle = 10;
1259c7188a6SEd Czeck
1269c7188a6SEd Czeck inst->sregs->pkt_start_stop = 0;
1279c7188a6SEd Czeck while (!ark_pktchkr_stopped(handle) && (wait_cycle > 0)) {
1289c7188a6SEd Czeck usleep(1000);
1299c7188a6SEd Czeck wait_cycle--;
1301502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Waiting for pktchk %d to stop...\n",
1319c7188a6SEd Czeck inst->ordinal);
1329c7188a6SEd Czeck }
1331502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Pktchk %d stopped.\n", inst->ordinal);
1349c7188a6SEd Czeck }
1359c7188a6SEd Czeck
1369c7188a6SEd Czeck int
ark_pktchkr_is_running(ark_pkt_chkr_t handle)1379c7188a6SEd Czeck ark_pktchkr_is_running(ark_pkt_chkr_t handle)
1389c7188a6SEd Czeck {
1399c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
1409c7188a6SEd Czeck uint32_t r = inst->sregs->pkt_start_stop;
1419c7188a6SEd Czeck
1429c7188a6SEd Czeck return ((r & 1) == 1);
1439c7188a6SEd Czeck }
1449c7188a6SEd Czeck
1459c7188a6SEd Czeck static void
ark_pktchkr_set_pkt_ctrl(ark_pkt_chkr_t handle,uint32_t gen_forever,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 en_resync,uint32_t tuser_err_val,uint32_t ins_time_stamp)1469c7188a6SEd Czeck ark_pktchkr_set_pkt_ctrl(ark_pkt_chkr_t handle,
1479c7188a6SEd Czeck uint32_t gen_forever,
1489c7188a6SEd Czeck uint32_t vary_length,
1499c7188a6SEd Czeck uint32_t incr_payload,
1509c7188a6SEd Czeck uint32_t incr_first_byte,
1519c7188a6SEd Czeck uint32_t ins_seq_num,
1529c7188a6SEd Czeck uint32_t ins_udp_hdr,
1539c7188a6SEd Czeck uint32_t en_resync,
1549c7188a6SEd Czeck uint32_t tuser_err_val,
1559c7188a6SEd Czeck uint32_t ins_time_stamp)
1569c7188a6SEd Czeck {
1579c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
1589c7188a6SEd Czeck uint32_t r = (tuser_err_val << 16) | (en_resync << 0);
1599c7188a6SEd Czeck
1609c7188a6SEd Czeck inst->sregs->pkt_ctrl = r;
1619c7188a6SEd Czeck if (!inst->l2_mode)
1629c7188a6SEd Czeck ins_udp_hdr = 0;
1639c7188a6SEd Czeck r = ((gen_forever << 24) |
1649c7188a6SEd Czeck (vary_length << 16) |
1659c7188a6SEd Czeck (incr_payload << 12) |
1669c7188a6SEd Czeck (incr_first_byte << 8) |
1679c7188a6SEd Czeck (ins_time_stamp << 5) |
1689c7188a6SEd Czeck (ins_seq_num << 4) |
1699c7188a6SEd Czeck ins_udp_hdr);
1709c7188a6SEd Czeck inst->cregs->pkt_ctrl = r;
1719c7188a6SEd Czeck }
1729c7188a6SEd Czeck
1739c7188a6SEd Czeck static
1749c7188a6SEd Czeck int
ark_pktchkr_is_gen_forever(ark_pkt_chkr_t handle)1759c7188a6SEd Czeck ark_pktchkr_is_gen_forever(ark_pkt_chkr_t handle)
1769c7188a6SEd Czeck {
1779c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
1789c7188a6SEd Czeck uint32_t r = inst->cregs->pkt_ctrl;
1799c7188a6SEd Czeck
1809c7188a6SEd Czeck return (((r >> 24) & 1) == 1);
1819c7188a6SEd Czeck }
1829c7188a6SEd Czeck
1839c7188a6SEd Czeck int
ark_pktchkr_wait_done(ark_pkt_chkr_t handle)1849c7188a6SEd Czeck ark_pktchkr_wait_done(ark_pkt_chkr_t handle)
1859c7188a6SEd Czeck {
1869c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
1879c7188a6SEd Czeck
1889c7188a6SEd Czeck if (ark_pktchkr_is_gen_forever(handle)) {
1891502d443SEd Czeck ARK_PMD_LOG(NOTICE, "Pktchk wait_done will not terminate"
1909c7188a6SEd Czeck " because gen_forever=1\n");
1919c7188a6SEd Czeck return -1;
1929c7188a6SEd Czeck }
1939c7188a6SEd Czeck int wait_cycle = 10;
1949c7188a6SEd Czeck
1959c7188a6SEd Czeck while (!ark_pktchkr_stopped(handle) && (wait_cycle > 0)) {
1969c7188a6SEd Czeck usleep(1000);
1979c7188a6SEd Czeck wait_cycle--;
1981502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Waiting for packet checker %d's"
1999c7188a6SEd Czeck " internal pktgen to finish sending...\n",
2009c7188a6SEd Czeck inst->ordinal);
2011502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Pktchk %d's pktgen done.\n",
2029c7188a6SEd Czeck inst->ordinal);
2039c7188a6SEd Czeck }
2049c7188a6SEd Czeck return 0;
2059c7188a6SEd Czeck }
2069c7188a6SEd Czeck
2079c7188a6SEd Czeck int
ark_pktchkr_get_pkts_sent(ark_pkt_chkr_t handle)2089c7188a6SEd Czeck ark_pktchkr_get_pkts_sent(ark_pkt_chkr_t handle)
2099c7188a6SEd Czeck {
2109c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2119c7188a6SEd Czeck
2129c7188a6SEd Czeck return inst->cregs->pkts_sent;
2139c7188a6SEd Czeck }
2149c7188a6SEd Czeck
2159c7188a6SEd Czeck void
ark_pktchkr_set_payload_byte(ark_pkt_chkr_t handle,uint32_t b)2169c7188a6SEd Czeck ark_pktchkr_set_payload_byte(ark_pkt_chkr_t handle, uint32_t b)
2179c7188a6SEd Czeck {
2189c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2199c7188a6SEd Czeck
2209c7188a6SEd Czeck inst->cregs->pkt_payload = b;
2219c7188a6SEd Czeck }
2229c7188a6SEd Czeck
2239c7188a6SEd Czeck void
ark_pktchkr_set_pkt_size_min(ark_pkt_chkr_t handle,uint32_t x)2249c7188a6SEd Czeck ark_pktchkr_set_pkt_size_min(ark_pkt_chkr_t handle, uint32_t x)
2259c7188a6SEd Czeck {
2269c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2279c7188a6SEd Czeck
2289c7188a6SEd Czeck inst->cregs->pkt_size_min = x;
2299c7188a6SEd Czeck }
2309c7188a6SEd Czeck
2319c7188a6SEd Czeck void
ark_pktchkr_set_pkt_size_max(ark_pkt_chkr_t handle,uint32_t x)2329c7188a6SEd Czeck ark_pktchkr_set_pkt_size_max(ark_pkt_chkr_t handle, uint32_t x)
2339c7188a6SEd Czeck {
2349c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2359c7188a6SEd Czeck
2369c7188a6SEd Czeck inst->cregs->pkt_size_max = x;
2379c7188a6SEd Czeck }
2389c7188a6SEd Czeck
2399c7188a6SEd Czeck void
ark_pktchkr_set_pkt_size_incr(ark_pkt_chkr_t handle,uint32_t x)2409c7188a6SEd Czeck ark_pktchkr_set_pkt_size_incr(ark_pkt_chkr_t handle, uint32_t x)
2419c7188a6SEd Czeck {
2429c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2439c7188a6SEd Czeck
2449c7188a6SEd Czeck inst->cregs->pkt_size_incr = x;
2459c7188a6SEd Czeck }
2469c7188a6SEd Czeck
2479c7188a6SEd Czeck void
ark_pktchkr_set_num_pkts(ark_pkt_chkr_t handle,uint32_t x)2489c7188a6SEd Czeck ark_pktchkr_set_num_pkts(ark_pkt_chkr_t handle, uint32_t x)
2499c7188a6SEd Czeck {
2509c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2519c7188a6SEd Czeck
2529c7188a6SEd Czeck inst->cregs->num_pkts = x;
2539c7188a6SEd Czeck }
2549c7188a6SEd Czeck
2559c7188a6SEd Czeck void
ark_pktchkr_set_src_mac_addr(ark_pkt_chkr_t handle,uint64_t mac_addr)2569c7188a6SEd Czeck ark_pktchkr_set_src_mac_addr(ark_pkt_chkr_t handle, uint64_t mac_addr)
2579c7188a6SEd Czeck {
2589c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2599c7188a6SEd Czeck
2609c7188a6SEd Czeck inst->cregs->src_mac_addr_h = (mac_addr >> 32) & 0xffff;
2619c7188a6SEd Czeck inst->cregs->src_mac_addr_l = mac_addr & 0xffffffff;
2629c7188a6SEd Czeck }
2639c7188a6SEd Czeck
2649c7188a6SEd Czeck void
ark_pktchkr_set_dst_mac_addr(ark_pkt_chkr_t handle,uint64_t mac_addr)2659c7188a6SEd Czeck ark_pktchkr_set_dst_mac_addr(ark_pkt_chkr_t handle, uint64_t mac_addr)
2669c7188a6SEd Czeck {
2679c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2689c7188a6SEd Czeck
2699c7188a6SEd Czeck inst->cregs->dst_mac_addr_h = (mac_addr >> 32) & 0xffff;
2709c7188a6SEd Czeck inst->cregs->dst_mac_addr_l = mac_addr & 0xffffffff;
2719c7188a6SEd Czeck }
2729c7188a6SEd Czeck
2739c7188a6SEd Czeck void
ark_pktchkr_set_eth_type(ark_pkt_chkr_t handle,uint32_t x)2749c7188a6SEd Czeck ark_pktchkr_set_eth_type(ark_pkt_chkr_t handle, uint32_t x)
2759c7188a6SEd Czeck {
2769c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2779c7188a6SEd Czeck
2789c7188a6SEd Czeck inst->cregs->eth_type = x;
2799c7188a6SEd Czeck }
2809c7188a6SEd Czeck
2819c7188a6SEd Czeck void
ark_pktchkr_set_hdr_dW(ark_pkt_chkr_t handle,uint32_t * hdr)2829c7188a6SEd Czeck ark_pktchkr_set_hdr_dW(ark_pkt_chkr_t handle, uint32_t *hdr)
2839c7188a6SEd Czeck {
2849c7188a6SEd Czeck uint32_t i;
2859c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2869c7188a6SEd Czeck
2879c7188a6SEd Czeck for (i = 0; i < 7; i++)
2889c7188a6SEd Czeck inst->cregs->hdr_dw[i] = hdr[i];
2899c7188a6SEd Czeck }
2909c7188a6SEd Czeck
2919c7188a6SEd Czeck void
ark_pktchkr_dump_stats(ark_pkt_chkr_t handle)2929c7188a6SEd Czeck ark_pktchkr_dump_stats(ark_pkt_chkr_t handle)
2939c7188a6SEd Czeck {
2949c7188a6SEd Czeck struct ark_pkt_chkr_inst *inst = (struct ark_pkt_chkr_inst *)handle;
2959c7188a6SEd Czeck
2961502d443SEd Czeck ARK_PMD_LOG(INFO, "pkts_rcvd = (%'u)\n",
2979c7188a6SEd Czeck inst->sregs->pkts_rcvd);
2981502d443SEd Czeck ARK_PMD_LOG(INFO, "bytes_rcvd = (%'" PRIU64 ")\n",
2999c7188a6SEd Czeck inst->sregs->bytes_rcvd);
3001502d443SEd Czeck ARK_PMD_LOG(INFO, "pkts_ok = (%'u)\n",
3019c7188a6SEd Czeck inst->sregs->pkts_ok);
3021502d443SEd Czeck ARK_PMD_LOG(INFO, "pkts_mismatch = (%'u)\n",
3039c7188a6SEd Czeck inst->sregs->pkts_mismatch);
3041502d443SEd Czeck ARK_PMD_LOG(INFO, "pkts_err = (%'u)\n",
3059c7188a6SEd Czeck inst->sregs->pkts_err);
3061502d443SEd Czeck ARK_PMD_LOG(INFO, "first_mismatch = (%'u)\n",
3079c7188a6SEd Czeck inst->sregs->first_mismatch);
3081502d443SEd Czeck ARK_PMD_LOG(INFO, "resync_events = (%'u)\n",
3099c7188a6SEd Czeck inst->sregs->resync_events);
3101502d443SEd Czeck ARK_PMD_LOG(INFO, "pkts_missing = (%'u)\n",
3119c7188a6SEd Czeck inst->sregs->pkts_missing);
3121502d443SEd Czeck ARK_PMD_LOG(INFO, "min_latency = (%'u)\n",
3139c7188a6SEd Czeck inst->sregs->min_latency);
3141502d443SEd Czeck ARK_PMD_LOG(INFO, "max_latency = (%'u)\n",
3159c7188a6SEd Czeck inst->sregs->max_latency);
3169c7188a6SEd Czeck }
3179c7188a6SEd Czeck
3189c7188a6SEd Czeck static struct OPTIONS *
options(const char * id)3199c7188a6SEd Czeck options(const char *id)
3209c7188a6SEd Czeck {
3219c7188a6SEd Czeck unsigned int i;
3229c7188a6SEd Czeck
3239c7188a6SEd Czeck for (i = 0; i < sizeof(toptions) / sizeof(struct OPTIONS); i++) {
3249c7188a6SEd Czeck if (strcmp(id, toptions[i].opt) == 0)
3259c7188a6SEd Czeck return &toptions[i];
3269c7188a6SEd Czeck }
3271502d443SEd Czeck ARK_PMD_LOG(ERR,
3289c7188a6SEd Czeck "pktchkr: Could not find requested option!, option = %s\n",
3299c7188a6SEd Czeck id);
3309c7188a6SEd Czeck return NULL;
3319c7188a6SEd Czeck }
3329c7188a6SEd Czeck
3339c7188a6SEd Czeck static int
set_arg(char * arg,char * val)3349c7188a6SEd Czeck set_arg(char *arg, char *val)
3359c7188a6SEd Czeck {
3369c7188a6SEd Czeck struct OPTIONS *o = options(arg);
3379c7188a6SEd Czeck
3389c7188a6SEd Czeck if (o) {
3399c7188a6SEd Czeck switch (o->t) {
3409c7188a6SEd Czeck case OTINT:
3419c7188a6SEd Czeck case OTBOOL:
3429c7188a6SEd Czeck o->v.INT = atoi(val);
3439c7188a6SEd Czeck break;
3449c7188a6SEd Czeck case OTLONG:
3459c7188a6SEd Czeck o->v.INT = atoll(val);
3469c7188a6SEd Czeck break;
3479c7188a6SEd Czeck case OTSTRING:
3486723c0fcSBruce Richardson strlcpy(o->v.STR, val, ARK_MAX_STR_LEN);
3499c7188a6SEd Czeck break;
3509c7188a6SEd Czeck }
3519c7188a6SEd Czeck return 1;
3529c7188a6SEd Czeck }
3539c7188a6SEd Czeck return 0;
3549c7188a6SEd Czeck }
3559c7188a6SEd Czeck
3569c7188a6SEd Czeck /******
3579c7188a6SEd Czeck * Arg format = "opt0=v,opt_n=v ..."
3589c7188a6SEd Czeck ******/
3599c7188a6SEd Czeck void
ark_pktchkr_parse(char * args)3609c7188a6SEd Czeck ark_pktchkr_parse(char *args)
3619c7188a6SEd Czeck {
3629c7188a6SEd Czeck char *argv, *v;
3639c7188a6SEd Czeck const char toks[] = "=\n\t\v\f \r";
3649c7188a6SEd Czeck argv = strtok(args, toks);
3659c7188a6SEd Czeck v = strtok(NULL, toks);
3669c7188a6SEd Czeck while (argv && v) {
3679c7188a6SEd Czeck set_arg(argv, v);
3689c7188a6SEd Czeck argv = strtok(NULL, toks);
3699c7188a6SEd Czeck v = strtok(NULL, toks);
3709c7188a6SEd Czeck }
3719c7188a6SEd Czeck }
3729c7188a6SEd Czeck
3739c7188a6SEd Czeck static int32_t parse_ipv4_string(char const *ip_address);
3749c7188a6SEd Czeck static int32_t
parse_ipv4_string(char const * ip_address)3759c7188a6SEd Czeck parse_ipv4_string(char const *ip_address)
3769c7188a6SEd Czeck {
3779c7188a6SEd Czeck unsigned int ip[4];
3789c7188a6SEd Czeck
3799c7188a6SEd Czeck if (sscanf(ip_address, "%u.%u.%u.%u",
3809c7188a6SEd Czeck &ip[0], &ip[1], &ip[2], &ip[3]) != 4)
3819c7188a6SEd Czeck return 0;
3829c7188a6SEd Czeck return ip[3] + ip[2] * 0x100 + ip[1] * 0x10000ul + ip[0] * 0x1000000ul;
3839c7188a6SEd Czeck }
3849c7188a6SEd Czeck
3859c7188a6SEd Czeck void
ark_pktchkr_setup(ark_pkt_chkr_t handle)3869c7188a6SEd Czeck ark_pktchkr_setup(ark_pkt_chkr_t handle)
3879c7188a6SEd Czeck {
3889c7188a6SEd Czeck uint32_t hdr[7];
3899c7188a6SEd Czeck int32_t dst_ip = parse_ipv4_string(options("dst_ip")->v.STR);
3909c7188a6SEd Czeck
3919c7188a6SEd Czeck if (!options("stop")->v.BOOL && options("configure")->v.BOOL) {
3929c7188a6SEd Czeck ark_pktchkr_set_payload_byte(handle,
3939c7188a6SEd Czeck options("payload_byte")->v.INT);
3949c7188a6SEd Czeck ark_pktchkr_set_src_mac_addr(handle,
3959c7188a6SEd Czeck options("src_mac_addr")->v.INT);
3969c7188a6SEd Czeck ark_pktchkr_set_dst_mac_addr(handle,
3979c7188a6SEd Czeck options("dst_mac_addr")->v.LONG);
3989c7188a6SEd Czeck
3999c7188a6SEd Czeck ark_pktchkr_set_eth_type(handle,
4009c7188a6SEd Czeck options("eth_type")->v.INT);
4019c7188a6SEd Czeck if (options("dg-mode")->v.BOOL) {
4029c7188a6SEd Czeck hdr[0] = options("hdr_dW0")->v.INT;
4039c7188a6SEd Czeck hdr[1] = options("hdr_dW1")->v.INT;
4049c7188a6SEd Czeck hdr[2] = options("hdr_dW2")->v.INT;
4059c7188a6SEd Czeck hdr[3] = options("hdr_dW3")->v.INT;
4069c7188a6SEd Czeck hdr[4] = options("hdr_dW4")->v.INT;
4079c7188a6SEd Czeck hdr[5] = options("hdr_dW5")->v.INT;
4089c7188a6SEd Czeck hdr[6] = options("hdr_dW6")->v.INT;
4099c7188a6SEd Czeck } else {
4109c7188a6SEd Czeck hdr[0] = dst_ip;
4119c7188a6SEd Czeck hdr[1] = options("dst_port")->v.INT;
4129c7188a6SEd Czeck hdr[2] = options("src_port")->v.INT;
4139c7188a6SEd Czeck hdr[3] = 0;
4149c7188a6SEd Czeck hdr[4] = 0;
4159c7188a6SEd Czeck hdr[5] = 0;
4169c7188a6SEd Czeck hdr[6] = 0;
4179c7188a6SEd Czeck }
4189c7188a6SEd Czeck ark_pktchkr_set_hdr_dW(handle, hdr);
4199c7188a6SEd Czeck ark_pktchkr_set_num_pkts(handle,
4209c7188a6SEd Czeck options("num_pkts")->v.INT);
4219c7188a6SEd Czeck ark_pktchkr_set_pkt_size_min(handle,
4229c7188a6SEd Czeck options("pkt_size_min")->v.INT);
4239c7188a6SEd Czeck ark_pktchkr_set_pkt_size_max(handle,
4249c7188a6SEd Czeck options("pkt_size_max")->v.INT);
4259c7188a6SEd Czeck ark_pktchkr_set_pkt_size_incr(handle,
4269c7188a6SEd Czeck options("pkt_size_incr")->v.INT);
4279c7188a6SEd Czeck ark_pktchkr_set_pkt_ctrl(handle,
4289c7188a6SEd Czeck options("gen_forever")->v.BOOL,
4299c7188a6SEd Czeck options("vary_length")->v.BOOL,
4309c7188a6SEd Czeck options("incr_payload")->v.BOOL,
4319c7188a6SEd Czeck options("incr_first_byte")->v.BOOL,
4329c7188a6SEd Czeck options("ins_seq_num")->v.INT,
4339c7188a6SEd Czeck options("ins_udp_hdr")->v.BOOL,
4349c7188a6SEd Czeck options("en_resync")->v.BOOL,
4359c7188a6SEd Czeck options("tuser_err_val")->v.INT,
4369c7188a6SEd Czeck options("ins_time_stamp")->v.INT);
4379c7188a6SEd Czeck }
4389c7188a6SEd Czeck
4399c7188a6SEd Czeck if (options("stop")->v.BOOL)
4409c7188a6SEd Czeck ark_pktchkr_stop(handle);
4419c7188a6SEd Czeck
4429c7188a6SEd Czeck if (options("run")->v.BOOL) {
4431502d443SEd Czeck ARK_PMD_LOG(DEBUG, "Starting packet checker on port %d\n",
4449c7188a6SEd Czeck options("port")->v.INT);
4459c7188a6SEd Czeck ark_pktchkr_run(handle);
4469c7188a6SEd Czeck }
4479c7188a6SEd Czeck }
448