DPDK logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2018 Intel Corporation
 */

#include <string.h>

#include <rte_bus_vdev.h>
#include <rte_common.h>
#include <rte_ethdev.h>
#include <rte_eth_ring.h>
#include <rte_eventdev.h>
#include <rte_event_eth_tx_adapter.h>
#include <rte_mbuf.h>
#include <rte_mempool.h>
#include <rte_service.h>

#include "test.h"

#define MAX_NUM_QUEUE		RTE_PMD_RING_MAX_RX_RINGS
#define TEST_INST_ID		0
#define TEST_DEV_ID		0
#define SOCKET0			0
#define RING_SIZE		256
#define ETH_NAME_LEN		32
#define NUM_ETH_PAIR		1
#define NUM_ETH_DEV		(2 * NUM_ETH_PAIR)
#define NB_MBUF			512
#define PAIR_PORT_INDEX(p)	((p) + NUM_ETH_PAIR)
#define PORT(p)			default_params.port[(p)]
#define TEST_ETHDEV_ID		PORT(0)
#define TEST_ETHDEV_PAIR_ID	PORT(PAIR_PORT_INDEX(0))

#define EDEV_RETRY		0xffff

struct event_eth_tx_adapter_test_params {
	struct rte_mempool *mp;
	uint16_t rx_rings, tx_rings;
	struct rte_ring *r[NUM_ETH_DEV][MAX_NUM_QUEUE];
	int port[NUM_ETH_DEV];
};

static int event_dev_delete;
static struct event_eth_tx_adapter_test_params default_params;
static uint64_t eid = ~0ULL;
static uint32_t tid;

static inline int
port_init_common(uint8_t port, const struct rte_eth_conf *port_conf,
		struct rte_mempool *mp)
{
	const uint16_t rx_ring_size = RING_SIZE, tx_ring_size = RING_SIZE;
	int retval;
	uint16_t q;

	if (!rte_eth_dev_is_valid_port(port))
		return -1;

	default_params.rx_rings = MAX_NUM_QUEUE;
	default_params.tx_rings = MAX_NUM_QUEUE;

	/* Configure the Ethernet device. */
	retval = rte_eth_dev_configure(port, default_params.rx_rings,
				default_params.tx_rings, port_conf);
	if (retval != 0)
		return retval;

	for (q = 0; q < default_params.rx_rings; q++) {
		retval = rte_eth_rx_queue_setup(port, q, rx_ring_size,
				rte_eth_dev_socket_id(port), NULL, mp);
		if (retval < 0)
			return retval;
	}

	for (q = 0; q < default_params.tx_rings; q++) {
		retval = rte_eth_tx_queue_setup(port, q, tx_ring_size,
				rte_eth_dev_socket_id(port), NULL);
		if (retval < 0)
			return retval;
	}

	/* Start the Ethernet port. */
	retval = rte_eth_dev_start(port);
	if (retval < 0)
		return retval;

	/* Display the port MAC address. */
	struct rte_ether_addr addr;
	retval = rte_eth_macaddr_get(port, &addr);
	if (retval < 0)
		return retval;
	printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
			   " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
			(unsigned int)port,
			addr.addr_bytes[0], addr.addr_bytes[1],
			addr.addr_bytes[2], addr.addr_bytes[3],
			addr.addr_bytes[4], addr.addr_bytes[5]);

	/* Enable RX in promiscuous mode for the Ethernet device. */
	retval = rte_eth_promiscuous_enable(port);
	if (retval != 0)
		return retval;

	return 0;
}

static inline int
port_init(uint8_t port, struct rte_mempool *mp)
{
	struct rte_eth_conf conf = { 0 };
	return port_init_common(port, &conf, mp);
}

#define RING_NAME_LEN	20
#define DEV_NAME_LEN	20

static int
init_ports(void)
{
	char ring_name[ETH_NAME_LEN];
	unsigned int i, j;
	struct rte_ring * const *c1;
	struct rte_ring * const *c2;
	int err;

	if (!default_params.mp)
		default_params.mp = rte_pktmbuf_pool_create("mbuf_pool",
			NB_MBUF, 32,
			0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());

	if (!default_params.mp)
		return -ENOMEM;

	for (i = 0; i < NUM_ETH_DEV; i++) {
		for (j = 0; j < MAX_NUM_QUEUE; j++) {
			snprintf(ring_name, sizeof(ring_name), "R%u%u", i, j);
			default_params.r[i][j] = rte_ring_create(ring_name,
						RING_SIZE,
						SOCKET0,
						RING_F_SP_ENQ | RING_F_SC_DEQ);
			TEST_ASSERT((default_params.r[i][j] != NULL),
				"Failed to allocate ring");
		}
	}

	/*
	 * To create two pseudo-Ethernet ports where the traffic is
	 * switched between them, that is, traffic sent to port 1 is
	 * read back from port 2 and vice-versa
	 */
	for (i = 0; i < NUM_ETH_PAIR; i++) {
		char dev_name[DEV_NAME_LEN];
		int p;

		c1 = default_params.r[i];
		c2 = default_params.r[PAIR_PORT_INDEX(i)];

		snprintf(dev_name, DEV_NAME_LEN, "%u-%u", i, i + NUM_ETH_PAIR);
		p = rte_eth_from_rings(dev_name, c1, MAX_NUM_QUEUE,
				 c2, MAX_NUM_QUEUE, SOCKET0);
		TEST_ASSERT(p >= 0, "Port creation failed %s", dev_name);
		err = port_init(p, default_params.mp);
		TEST_ASSERT(err == 0, "Port init failed %s", dev_name);
		default_params.port[i] = p;

		snprintf(dev_name, DEV_NAME_LEN, "%u-%u",  i + NUM_ETH_PAIR, i);
		p = rte_eth_from_rings(dev_name, c2, MAX_NUM_QUEUE,
				c1, MAX_NUM_QUEUE, SOCKET0);
		TEST_ASSERT(p > 0, "Port creation failed %s", dev_name);
		err = port_init(p, default_params.mp);
		TEST_ASSERT(err == 0, "Port init failed %s", dev_name);
		default_params.port[PAIR_PORT_INDEX(i)] = p;
	}

	return 0;
}

static void
deinit_ports(void)
{
	uint16_t i, j;
	char name[ETH_NAME_LEN];

	for (i = 0; i < RTE_DIM(default_params.port); i++) {
		rte_eth_dev_stop(default_params.port[i]);
		rte_eth_dev_get_name_by_port(default_params.port[i], name);
		rte_vdev_uninit(name);
		for (j = 0; j < RTE_DIM(default_params.r[i]); j++)
			rte_ring_free(default_params.r[i][j]);
	}
}

static int
testsuite_setup(void)
{
	const char *vdev_name = "event_sw0";

	int err = init_ports();
	TEST_ASSERT(err == 0, "Port initialization failed err %d\n", err);

	if (rte_event_dev_count() == 0) {
		printf("Failed to find a valid event device,"
			" testing with event_sw0 device\n");
		err = rte_vdev_init(vdev_name, NULL);
		TEST_ASSERT(err == 0, "vdev %s creation failed  %d\n",
			vdev_name, err);
		event_dev_delete = 1;
	}
	return err;
}

#define DEVICE_ID_SIZE 64

static void
testsuite_teardown(void)
{
	deinit_ports();
	rte_mempool_free(default_params.mp);
	default_params.mp = NULL;
	if (event_dev_delete)
		rte_vdev_uninit("event_sw0");
}

static int
tx_adapter_create(void)
{
	int err;
	struct rte_event_dev_info dev_info;
	struct rte_event_port_conf tx_p_conf;
	uint8_t priority;
	uint8_t queue_id;

	struct rte_event_dev_config config = {
			.nb_event_queues = 1,
			.nb_event_ports = 1,
	};

	struct rte_event_queue_conf wkr_q_conf = {
			.schedule_type = RTE_SCHED_TYPE_ORDERED,
			.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
			.nb_atomic_flows = 1024,
			.nb_atomic_order_sequences = 1024,
	};

	memset(&tx_p_conf, 0, sizeof(tx_p_conf));
	err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
	config.nb_event_queue_flows = dev_info.max_event_queue_flows;
	config.nb_event_port_dequeue_depth =
			dev_info.max_event_port_dequeue_depth;
	config.nb_event_port_enqueue_depth =
			dev_info.max_event_port_enqueue_depth;
	config.nb_events_limit =
			dev_info.max_num_events;

	err = rte_event_dev_configure(TEST_DEV_ID, &config);
	TEST_ASSERT(err == 0, "Event device initialization failed err %d\n",
			err);

	queue_id = 0;
	err = rte_event_queue_setup(TEST_DEV_ID, 0, &wkr_q_conf);
	TEST_ASSERT(err == 0, "Event queue setup failed %d\n", err);

	err = rte_event_port_setup(TEST_DEV_ID, 0, NULL);
	TEST_ASSERT(err == 0, "Event port setup failed %d\n", err);

	priority = RTE_EVENT_DEV_PRIORITY_LOWEST;
	err = rte_event_port_link(TEST_DEV_ID, 0, &queue_id, &priority, 1);
	TEST_ASSERT(err == 1, "Error linking port %s\n",
		rte_strerror(rte_errno));
	err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	tx_p_conf.new_event_threshold = dev_info.max_num_events;
	tx_p_conf.dequeue_depth = dev_info.max_event_port_dequeue_depth;
	tx_p_conf.enqueue_depth = dev_info.max_event_port_enqueue_depth;
	err = rte_event_eth_tx_adapter_create(TEST_INST_ID, TEST_DEV_ID,
					&tx_p_conf);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	return err;
}

static void
tx_adapter_free(void)
{
	rte_event_eth_tx_adapter_free(TEST_INST_ID);
}

static int
tx_adapter_create_free(void)
{
	int err;
	struct rte_event_dev_info dev_info;
	struct rte_event_port_conf tx_p_conf;

	err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	tx_p_conf.new_event_threshold = dev_info.max_num_events;
	tx_p_conf.dequeue_depth = dev_info.max_event_port_dequeue_depth;
	tx_p_conf.enqueue_depth = dev_info.max_event_port_enqueue_depth;

	err = rte_event_eth_tx_adapter_create(TEST_INST_ID, TEST_DEV_ID,
					NULL);
	TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);

	err = rte_event_eth_tx_adapter_create(TEST_INST_ID, TEST_DEV_ID,
					&tx_p_conf);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_create(TEST_INST_ID,
					TEST_DEV_ID, &tx_p_conf);
	TEST_ASSERT(err == -EEXIST, "Expected -EEXIST %d got %d", -EEXIST, err);

	err = rte_event_eth_tx_adapter_free(TEST_INST_ID);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_free(TEST_INST_ID);
	TEST_ASSERT(err == -EINVAL, "Expected -EINVAL %d got %d", -EINVAL, err);

	err = rte_event_eth_tx_adapter_free(1);
	TEST_ASSERT(err == -EINVAL, "Expected -EINVAL %d got %d", -EINVAL, err);

	return TEST_SUCCESS;
}

static int
tx_adapter_queue_add_del(void)
{
	int err;
	uint32_t cap;

	err = rte_event_eth_tx_adapter_caps_get(TEST_DEV_ID, TEST_ETHDEV_ID,
					 &cap);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);


	err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID,
						rte_eth_dev_count_total(),
						-1);
	TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);

	err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID,
						TEST_ETHDEV_ID,
						0);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID,
						TEST_ETHDEV_ID,
						-1);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID,
						TEST_ETHDEV_ID,
						0);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID,
						TEST_ETHDEV_ID,
						-1);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID,
						TEST_ETHDEV_ID,
						-1);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_queue_add(1, TEST_ETHDEV_ID, -1);
	TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);

	err = rte_event_eth_tx_adapter_queue_del(1, TEST_ETHDEV_ID, -1);
	TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);

	return TEST_SUCCESS;
}

static int
tx_adapter_start_stop(void)
{
	int err;

	err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID, TEST_ETHDEV_ID,
						-1);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_start(TEST_INST_ID);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_stop(TEST_INST_ID);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID, TEST_ETHDEV_ID,
						-1);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_start(TEST_INST_ID);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_stop(TEST_INST_ID);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_start(1);

	err = rte_event_eth_tx_adapter_stop(1);
	TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);

	return TEST_SUCCESS;
}


static int
tx_adapter_single(uint16_t port, uint16_t tx_queue_id,
		struct rte_mbuf *m, uint8_t qid,
		uint8_t sched_type)
{
	struct rte_event event;
	struct rte_mbuf *r;
	int ret;
	unsigned int l;

	event.queue_id = qid;
	event.op = RTE_EVENT_OP_NEW;
	event.event_type = RTE_EVENT_TYPE_CPU;
	event.sched_type = sched_type;
	event.mbuf = m;

	m->port = port;
	rte_event_eth_tx_adapter_txq_set(m, tx_queue_id);

	l = 0;
	while (rte_event_enqueue_burst(TEST_DEV_ID, 0, &event, 1) != 1) {
		l++;
		if (l > EDEV_RETRY)
			break;
	}

	TEST_ASSERT(l < EDEV_RETRY, "Unable to enqueue to eventdev");
	l = 0;
	while (l++ < EDEV_RETRY) {

		if (eid != ~0ULL) {
			ret = rte_service_run_iter_on_app_lcore(eid, 0);
			TEST_ASSERT(ret == 0, "failed to run service %d", ret);
		}

		ret = rte_service_run_iter_on_app_lcore(tid, 0);
		TEST_ASSERT(ret == 0, "failed to run service %d", ret);

		if (rte_eth_rx_burst(TEST_ETHDEV_PAIR_ID, tx_queue_id,
				&r, 1)) {
			TEST_ASSERT_EQUAL(r, m, "mbuf comparison failed"
					" expected %p received %p", m, r);
			return 0;
		}
	}

	TEST_ASSERT(0, "Failed to receive packet");
	return -1;
}

static int
tx_adapter_service(void)
{
	struct rte_event_eth_tx_adapter_stats stats;
	uint32_t i;
	int err;
	uint8_t ev_port, ev_qid;
	struct rte_mbuf  bufs[RING_SIZE];
	struct rte_mbuf *pbufs[RING_SIZE];
	struct rte_event_dev_info dev_info;
	struct rte_event_dev_config dev_conf;
	struct rte_event_queue_conf qconf;
	uint32_t qcnt, pcnt;
	uint16_t q;
	int internal_port;
	uint32_t cap;

	memset(&dev_conf, 0, sizeof(dev_conf));
	err = rte_event_eth_tx_adapter_caps_get(TEST_DEV_ID, TEST_ETHDEV_ID,
						&cap);
	TEST_ASSERT(err == 0, "Failed to get adapter cap err %d\n", err);

	internal_port = !!(cap & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT);
	if (internal_port)
		return TEST_SUCCESS;

	err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID, TEST_ETHDEV_ID,
						-1);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_event_port_get(TEST_INST_ID,
						&ev_port);
	TEST_ASSERT_SUCCESS(err, "Failed to get event port %d", err);

	err = rte_event_dev_attr_get(TEST_DEV_ID, RTE_EVENT_DEV_ATTR_PORT_COUNT,
					&pcnt);
	TEST_ASSERT_SUCCESS(err, "Port count get failed");

	err = rte_event_dev_attr_get(TEST_DEV_ID,
				RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &qcnt);
	TEST_ASSERT_SUCCESS(err, "Queue count get failed");

	err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
	TEST_ASSERT_SUCCESS(err, "Dev info failed");

	dev_conf.nb_event_queue_flows = dev_info.max_event_queue_flows;
	dev_conf.nb_event_port_dequeue_depth =
			dev_info.max_event_port_dequeue_depth;
	dev_conf.nb_event_port_enqueue_depth =
			dev_info.max_event_port_enqueue_depth;
	dev_conf.nb_events_limit =
			dev_info.max_num_events;
	dev_conf.nb_event_queues = qcnt + 1;
	dev_conf.nb_event_ports = pcnt;
	err = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
	TEST_ASSERT(err == 0, "Event device initialization failed err %d\n",
			err);

	ev_qid = qcnt;
	qconf.nb_atomic_flows = dev_info.max_event_queue_flows;
	qconf.nb_atomic_order_sequences = 32;
	qconf.schedule_type = RTE_SCHED_TYPE_ATOMIC;
	qconf.priority = RTE_EVENT_DEV_PRIORITY_HIGHEST;
	qconf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
	err = rte_event_queue_setup(TEST_DEV_ID, ev_qid, &qconf);
	TEST_ASSERT_SUCCESS(err, "Failed to setup queue %u", ev_qid);

	/*
	 * Setup ports again so that the newly added queue is visible
	 * to them
	 */
	for (i = 0; i < pcnt; i++) {

		int n_links;
		uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
		uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];

		if (i == ev_port)
			continue;

		n_links = rte_event_port_links_get(TEST_DEV_ID, i, queues,
						priorities);
		TEST_ASSERT(n_links > 0, "Failed to get port links %d\n",
			n_links);
		err = rte_event_port_setup(TEST_DEV_ID, i, NULL);
		TEST_ASSERT(err == 0, "Failed to setup port err %d\n", err);
		err = rte_event_port_link(TEST_DEV_ID, i, queues, priorities,
					n_links);
		TEST_ASSERT(n_links == err, "Failed to link all queues"
			" err %s\n", rte_strerror(rte_errno));
	}

	err = rte_event_port_link(TEST_DEV_ID, ev_port, &ev_qid, NULL, 1);
	TEST_ASSERT(err == 1, "Failed to link queue port %u",
		    ev_port);

	err = rte_event_eth_tx_adapter_start(TEST_INST_ID);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	if (!(dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED)) {
		err = rte_event_dev_service_id_get(0, (uint32_t *)&eid);
		TEST_ASSERT(err == 0, "Expected 0 got %d", err);

		err = rte_service_runstate_set(eid, 1);
		TEST_ASSERT(err == 0, "Expected 0 got %d", err);

		err = rte_service_set_runstate_mapped_check(eid, 0);
		TEST_ASSERT(err == 0, "Expected 0 got %d", err);
	}

	err = rte_event_eth_tx_adapter_service_id_get(TEST_INST_ID, &tid);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_service_runstate_set(tid, 1);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_service_set_runstate_mapped_check(tid, 0);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_dev_start(TEST_DEV_ID);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	for (q = 0; q < MAX_NUM_QUEUE; q++) {
		for (i = 0; i < RING_SIZE; i++)
			pbufs[i] = &bufs[i];
		for (i = 0; i < RING_SIZE; i++) {
			pbufs[i] = &bufs[i];
			err = tx_adapter_single(TEST_ETHDEV_ID, q, pbufs[i],
						ev_qid,
						RTE_SCHED_TYPE_ORDERED);
			TEST_ASSERT(err == 0, "Expected 0 got %d", err);
		}
		for (i = 0; i < RING_SIZE; i++) {
			TEST_ASSERT_EQUAL(pbufs[i], &bufs[i],
				"Error: received data does not match"
				" that transmitted");
		}
	}

	err = rte_event_eth_tx_adapter_stats_get(TEST_INST_ID, NULL);
	TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);

	err = rte_event_eth_tx_adapter_stats_get(TEST_INST_ID, &stats);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
	TEST_ASSERT_EQUAL(stats.tx_packets, MAX_NUM_QUEUE * RING_SIZE,
			"stats.tx_packets expected %u got %"PRIu64,
			MAX_NUM_QUEUE * RING_SIZE,
			stats.tx_packets);

	err = rte_event_eth_tx_adapter_stats_reset(TEST_INST_ID);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_stats_get(TEST_INST_ID, &stats);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);
	TEST_ASSERT_EQUAL(stats.tx_packets, 0,
			"stats.tx_packets expected %u got %"PRIu64,
			0,
			stats.tx_packets);

	err = rte_event_eth_tx_adapter_stats_get(1, &stats);
	TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);

	err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID, TEST_ETHDEV_ID,
						-1);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	err = rte_event_eth_tx_adapter_free(TEST_INST_ID);
	TEST_ASSERT(err == 0, "Expected 0 got %d", err);

	rte_event_dev_stop(TEST_DEV_ID);

	return TEST_SUCCESS;
}

static int
tx_adapter_dynamic_device(void)
{
	uint16_t port_id = rte_eth_dev_count_avail();
	const char *null_dev[2] = { "eth_null0", "eth_null1" };
	struct rte_eth_conf dev_conf;
	int ret;
	size_t i;

	memset(&dev_conf, 0, sizeof(dev_conf));
	for (i = 0; i < RTE_DIM(null_dev); i++) {
		ret = rte_vdev_init(null_dev[i], NULL);
		TEST_ASSERT_SUCCESS(ret, "%s Port creation failed %d",
				null_dev[i], ret);

		if (i == 0) {
			ret = tx_adapter_create();
			TEST_ASSERT_SUCCESS(ret, "Adapter create failed %d",
					ret);
		}

		ret = rte_eth_dev_configure(port_id + i, MAX_NUM_QUEUE,
					MAX_NUM_QUEUE, &dev_conf);
		TEST_ASSERT_SUCCESS(ret, "Failed to configure device %d", ret);

		ret = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID,
							port_id + i, 0);
		TEST_ASSERT_SUCCESS(ret, "Failed to add queues %d", ret);

	}

	for (i = 0; i < RTE_DIM(null_dev); i++) {
		ret = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID,
							port_id + i, -1);
		TEST_ASSERT_SUCCESS(ret, "Failed to delete queues %d", ret);
	}

	tx_adapter_free();

	for (i = 0; i < RTE_DIM(null_dev); i++)
		rte_vdev_uninit(null_dev[i]);

	return TEST_SUCCESS;
}

static struct unit_test_suite event_eth_tx_tests = {
	.setup = testsuite_setup,
	.teardown = testsuite_teardown,
	.suite_name = "tx event eth adapter test suite",
	.unit_test_cases = {
		TEST_CASE_ST(NULL, NULL, tx_adapter_create_free),
		TEST_CASE_ST(tx_adapter_create, tx_adapter_free,
					tx_adapter_queue_add_del),
		TEST_CASE_ST(tx_adapter_create, tx_adapter_free,
					tx_adapter_start_stop),
		TEST_CASE_ST(tx_adapter_create, tx_adapter_free,
					tx_adapter_service),
		TEST_CASE_ST(NULL, NULL, tx_adapter_dynamic_device),
		TEST_CASES_END() /**< NULL terminate unit test array */
	}
};

static int
test_event_eth_tx_adapter_common(void)
{
	return unit_test_suite_runner(&event_eth_tx_tests);
}

REGISTER_TEST_COMMAND(event_eth_tx_adapter_autotest,
		test_event_eth_tx_adapter_common);