1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation.
4 #include <rte_spinlock.h>
5 #include <rte_service_component.h>
6 #include <ethdev_driver.h>
8 #include "eventdev_pmd.h"
9 #include "rte_eventdev_trace.h"
10 #include "rte_event_eth_tx_adapter.h"
12 #define TXA_BATCH_SIZE 32
13 #define TXA_SERVICE_NAME_LEN 32
14 #define TXA_MEM_NAME_LEN 32
15 #define TXA_FLUSH_THRESHOLD 1024
16 #define TXA_RETRY_CNT 100
17 #define TXA_MAX_NB_TX 128
18 #define TXA_INVALID_DEV_ID INT32_C(-1)
19 #define TXA_INVALID_SERVICE_ID INT64_C(-1)
21 #define txa_evdev(id) (&rte_eventdevs[txa_dev_id_array[(id)]])
23 #define txa_dev_caps_get(id) txa_evdev((id))->dev_ops->eth_tx_adapter_caps_get
25 #define txa_dev_adapter_create(t) txa_evdev(t)->dev_ops->eth_tx_adapter_create
27 #define txa_dev_adapter_create_ext(t) \
28 txa_evdev(t)->dev_ops->eth_tx_adapter_create
30 #define txa_dev_adapter_free(t) txa_evdev(t)->dev_ops->eth_tx_adapter_free
32 #define txa_dev_queue_add(id) txa_evdev(id)->dev_ops->eth_tx_adapter_queue_add
34 #define txa_dev_queue_del(t) txa_evdev(t)->dev_ops->eth_tx_adapter_queue_del
36 #define txa_dev_start(t) txa_evdev(t)->dev_ops->eth_tx_adapter_start
38 #define txa_dev_stop(t) txa_evdev(t)->dev_ops->eth_tx_adapter_stop
40 #define txa_dev_stats_reset(t) txa_evdev(t)->dev_ops->eth_tx_adapter_stats_reset
42 #define txa_dev_stats_get(t) txa_evdev(t)->dev_ops->eth_tx_adapter_stats_get
44 #define RTE_EVENT_ETH_TX_ADAPTER_ID_VALID_OR_ERR_RET(id, retval) \
46 if (!txa_valid_id(id)) { \
47 RTE_EDEV_LOG_ERR("Invalid eth Rx adapter id = %d", id); \
52 #define TXA_CHECK_OR_ERR_RET(id) \
55 RTE_EVENT_ETH_TX_ADAPTER_ID_VALID_OR_ERR_RET((id), -EINVAL); \
59 if (!txa_adapter_exist((id))) \
63 #define TXA_CHECK_TXQ(dev, queue) \
65 if ((dev)->data->nb_tx_queues == 0) { \
66 RTE_EDEV_LOG_ERR("No tx queues configured"); \
69 if ((queue) != -1 && \
70 (uint16_t)(queue) >= (dev)->data->nb_tx_queues) { \
71 RTE_EDEV_LOG_ERR("Invalid tx queue_id %" PRIu16, \
77 /* Tx retry callback structure */
79 /* Ethernet port id */
87 /* Per queue structure */
88 struct txa_service_queue_info {
89 /* Queue has been added */
91 /* Retry callback argument */
92 struct txa_retry txa_retry;
94 struct rte_eth_dev_tx_buffer *tx_buf;
97 /* PMD private structure */
98 struct txa_service_data {
99 /* Max mbufs processed in any service function invocation */
101 /* Number of Tx queues in adapter */
103 /* Synchronization with data path */
104 rte_spinlock_t tx_lock;
107 /* Event device identifier */
109 /* Highest port id supported + 1 */
111 /* Loop count to flush Tx buffers */
113 /* Per ethernet device structure */
114 struct txa_service_ethdev *txa_ethdev;
116 struct rte_event_eth_tx_adapter_stats stats;
117 /* Adapter Identifier */
119 /* Conf arg must be freed */
121 /* Configuration callback */
122 rte_event_eth_tx_adapter_conf_cb conf_cb;
123 /* Configuration callback argument */
127 /* Per adapter EAL service */
129 /* Memory allocation name */
130 char mem_name[TXA_MEM_NAME_LEN];
131 } __rte_cache_aligned;
133 /* Per eth device structure */
134 struct txa_service_ethdev {
135 /* Pointer to ethernet device */
136 struct rte_eth_dev *dev;
137 /* Number of queues added */
139 /* PMD specific queue data */
143 /* Array of adapter instances, initialized with event device id
144 * when adapter is created
146 static int *txa_dev_id_array;
148 /* Array of pointers to service implementation data */
149 static struct txa_service_data **txa_service_data_array;
151 static int32_t txa_service_func(void *args);
152 static int txa_service_adapter_create_ext(uint8_t id,
153 struct rte_eventdev *dev,
154 rte_event_eth_tx_adapter_conf_cb conf_cb,
156 static int txa_service_queue_del(uint8_t id,
157 const struct rte_eth_dev *dev,
158 int32_t tx_queue_id);
161 txa_adapter_exist(uint8_t id)
163 return txa_dev_id_array[id] != TXA_INVALID_DEV_ID;
167 txa_valid_id(uint8_t id)
169 return id < RTE_EVENT_ETH_TX_ADAPTER_MAX_INSTANCE;
173 txa_memzone_array_get(const char *name, unsigned int elt_size, int nb_elems)
175 const struct rte_memzone *mz;
178 sz = elt_size * nb_elems;
179 sz = RTE_ALIGN(sz, RTE_CACHE_LINE_SIZE);
181 mz = rte_memzone_lookup(name);
183 mz = rte_memzone_reserve_aligned(name, sz, rte_socket_id(), 0,
184 RTE_CACHE_LINE_SIZE);
186 RTE_EDEV_LOG_ERR("failed to reserve memzone"
188 PRId32, name, rte_errno);
197 txa_dev_id_array_init(void)
199 if (txa_dev_id_array == NULL) {
202 txa_dev_id_array = txa_memzone_array_get("txa_adapter_array",
204 RTE_EVENT_ETH_TX_ADAPTER_MAX_INSTANCE);
205 if (txa_dev_id_array == NULL)
208 for (i = 0; i < RTE_EVENT_ETH_TX_ADAPTER_MAX_INSTANCE; i++)
209 txa_dev_id_array[i] = TXA_INVALID_DEV_ID;
218 return txa_dev_id_array_init();
222 txa_service_data_init(void)
224 if (txa_service_data_array == NULL) {
225 txa_service_data_array =
226 txa_memzone_array_get("txa_service_data_array",
228 RTE_EVENT_ETH_TX_ADAPTER_MAX_INSTANCE);
229 if (txa_service_data_array == NULL)
236 static inline struct txa_service_data *
237 txa_service_id_to_data(uint8_t id)
239 return txa_service_data_array[id];
242 static inline struct txa_service_queue_info *
243 txa_service_queue(struct txa_service_data *txa, uint16_t port_id,
244 uint16_t tx_queue_id)
246 struct txa_service_queue_info *tqi;
248 if (unlikely(txa->txa_ethdev == NULL || txa->dev_count < port_id + 1))
251 tqi = txa->txa_ethdev[port_id].queues;
253 return likely(tqi != NULL) ? tqi + tx_queue_id : NULL;
257 txa_service_conf_cb(uint8_t __rte_unused id, uint8_t dev_id,
258 struct rte_event_eth_tx_adapter_conf *conf, void *arg)
261 struct rte_eventdev *dev;
262 struct rte_event_port_conf *pc;
263 struct rte_event_dev_config dev_conf;
268 dev = &rte_eventdevs[dev_id];
269 dev_conf = dev->data->dev_conf;
271 started = dev->data->dev_started;
273 rte_event_dev_stop(dev_id);
275 port_id = dev_conf.nb_event_ports;
276 dev_conf.nb_event_ports += 1;
278 ret = rte_event_dev_configure(dev_id, &dev_conf);
280 RTE_EDEV_LOG_ERR("failed to configure event dev %u",
283 if (rte_event_dev_start(dev_id))
289 ret = rte_event_port_setup(dev_id, port_id, pc);
291 RTE_EDEV_LOG_ERR("failed to setup event port %u\n",
294 if (rte_event_dev_start(dev_id))
300 conf->event_port_id = port_id;
301 conf->max_nb_tx = TXA_MAX_NB_TX;
303 ret = rte_event_dev_start(dev_id);
308 txa_service_ethdev_alloc(struct txa_service_data *txa)
310 struct txa_service_ethdev *txa_ethdev;
311 uint16_t i, dev_count;
313 dev_count = rte_eth_dev_count_avail();
314 if (txa->txa_ethdev && dev_count == txa->dev_count)
317 txa_ethdev = rte_zmalloc_socket(txa->mem_name,
318 dev_count * sizeof(*txa_ethdev),
321 if (txa_ethdev == NULL) {
322 RTE_EDEV_LOG_ERR("Failed to alloc txa::txa_ethdev ");
327 memcpy(txa_ethdev, txa->txa_ethdev,
328 txa->dev_count * sizeof(*txa_ethdev));
330 RTE_ETH_FOREACH_DEV(i) {
333 txa_ethdev[i].dev = &rte_eth_devices[i];
336 txa->txa_ethdev = txa_ethdev;
337 txa->dev_count = dev_count;
342 txa_service_queue_array_alloc(struct txa_service_data *txa,
345 struct txa_service_queue_info *tqi;
349 ret = txa_service_ethdev_alloc(txa);
353 if (txa->txa_ethdev[port_id].queues)
356 nb_queue = txa->txa_ethdev[port_id].dev->data->nb_tx_queues;
357 tqi = rte_zmalloc_socket(txa->mem_name,
359 sizeof(struct txa_service_queue_info), 0,
363 txa->txa_ethdev[port_id].queues = tqi;
368 txa_service_queue_array_free(struct txa_service_data *txa,
371 struct txa_service_ethdev *txa_ethdev;
372 struct txa_service_queue_info *tqi;
374 txa_ethdev = &txa->txa_ethdev[port_id];
375 if (txa->txa_ethdev == NULL || txa_ethdev->nb_queues != 0)
378 tqi = txa_ethdev->queues;
379 txa_ethdev->queues = NULL;
382 if (txa->nb_queues == 0) {
383 rte_free(txa->txa_ethdev);
384 txa->txa_ethdev = NULL;
389 txa_service_unregister(struct txa_service_data *txa)
391 if (txa->service_id != TXA_INVALID_SERVICE_ID) {
392 rte_service_component_runstate_set(txa->service_id, 0);
393 while (rte_service_may_be_active(txa->service_id))
395 rte_service_component_unregister(txa->service_id);
397 txa->service_id = TXA_INVALID_SERVICE_ID;
401 txa_service_register(struct txa_service_data *txa)
404 struct rte_service_spec service;
405 struct rte_event_eth_tx_adapter_conf conf;
407 if (txa->service_id != TXA_INVALID_SERVICE_ID)
410 memset(&service, 0, sizeof(service));
411 snprintf(service.name, TXA_SERVICE_NAME_LEN, "txa_%d", txa->id);
412 service.socket_id = txa->socket_id;
413 service.callback = txa_service_func;
414 service.callback_userdata = txa;
415 service.capabilities = RTE_SERVICE_CAP_MT_SAFE;
416 ret = rte_service_component_register(&service,
417 (uint32_t *)&txa->service_id);
419 RTE_EDEV_LOG_ERR("failed to register service %s err = %"
420 PRId32, service.name, ret);
424 ret = txa->conf_cb(txa->id, txa->eventdev_id, &conf, txa->conf_arg);
426 txa_service_unregister(txa);
430 rte_service_component_runstate_set(txa->service_id, 1);
431 txa->port_id = conf.event_port_id;
432 txa->max_nb_tx = conf.max_nb_tx;
436 static struct rte_eth_dev_tx_buffer *
437 txa_service_tx_buf_alloc(struct txa_service_data *txa,
438 const struct rte_eth_dev *dev)
440 struct rte_eth_dev_tx_buffer *tb;
443 port_id = dev->data->port_id;
444 tb = rte_zmalloc_socket(txa->mem_name,
445 RTE_ETH_TX_BUFFER_SIZE(TXA_BATCH_SIZE),
447 rte_eth_dev_socket_id(port_id));
449 RTE_EDEV_LOG_ERR("Failed to allocate memory for tx buffer");
454 txa_service_is_queue_added(struct txa_service_data *txa,
455 const struct rte_eth_dev *dev,
456 uint16_t tx_queue_id)
458 struct txa_service_queue_info *tqi;
460 tqi = txa_service_queue(txa, dev->data->port_id, tx_queue_id);
461 return tqi && tqi->added;
465 txa_service_ctrl(uint8_t id, int start)
468 struct txa_service_data *txa;
470 txa = txa_service_id_to_data(id);
471 if (txa->service_id == TXA_INVALID_SERVICE_ID)
474 ret = rte_service_runstate_set(txa->service_id, start);
475 if (ret == 0 && !start) {
476 while (rte_service_may_be_active(txa->service_id))
483 txa_service_buffer_retry(struct rte_mbuf **pkts, uint16_t unsent,
486 struct txa_retry *tr;
487 struct txa_service_data *data;
488 struct rte_event_eth_tx_adapter_stats *stats;
490 unsigned int retry = 0;
493 tr = (struct txa_retry *)(uintptr_t)userdata;
494 data = txa_service_id_to_data(tr->id);
495 stats = &data->stats;
498 n = rte_eth_tx_burst(tr->port_id, tr->tx_queue,
499 &pkts[sent], unsent - sent);
502 } while (sent != unsent && retry++ < TXA_RETRY_CNT);
504 for (i = sent; i < unsent; i++)
505 rte_pktmbuf_free(pkts[i]);
507 stats->tx_retry += retry;
508 stats->tx_packets += sent;
509 stats->tx_dropped += unsent - sent;
513 txa_process_event_vector(struct txa_service_data *txa,
514 struct rte_event_vector *vec)
516 struct txa_service_queue_info *tqi;
517 uint16_t port, queue, nb_tx = 0;
518 struct rte_mbuf **mbufs;
521 mbufs = (struct rte_mbuf **)vec->mbufs;
522 if (vec->attr_valid) {
525 tqi = txa_service_queue(txa, port, queue);
526 if (unlikely(tqi == NULL || !tqi->added)) {
527 rte_pktmbuf_free_bulk(mbufs, vec->nb_elem);
528 rte_mempool_put(rte_mempool_from_obj(vec), vec);
531 for (i = 0; i < vec->nb_elem; i++) {
532 nb_tx += rte_eth_tx_buffer(port, queue, tqi->tx_buf,
536 for (i = 0; i < vec->nb_elem; i++) {
537 port = mbufs[i]->port;
538 queue = rte_event_eth_tx_adapter_txq_get(mbufs[i]);
539 tqi = txa_service_queue(txa, port, queue);
540 if (unlikely(tqi == NULL || !tqi->added)) {
541 rte_pktmbuf_free(mbufs[i]);
544 nb_tx += rte_eth_tx_buffer(port, queue, tqi->tx_buf,
548 rte_mempool_put(rte_mempool_from_obj(vec), vec);
554 txa_service_tx(struct txa_service_data *txa, struct rte_event *ev,
559 struct rte_event_eth_tx_adapter_stats *stats;
564 for (i = 0; i < n; i++) {
567 struct txa_service_queue_info *tqi;
569 if (!(ev[i].event_type & RTE_EVENT_TYPE_VECTOR)) {
574 queue = rte_event_eth_tx_adapter_txq_get(m);
576 tqi = txa_service_queue(txa, port, queue);
577 if (unlikely(tqi == NULL || !tqi->added)) {
582 nb_tx += rte_eth_tx_buffer(port, queue, tqi->tx_buf, m);
584 nb_tx += txa_process_event_vector(txa, ev[i].vec);
588 stats->tx_packets += nb_tx;
592 txa_service_func(void *args)
594 struct txa_service_data *txa = args;
598 uint32_t nb_tx, max_nb_tx;
599 struct rte_event ev[TXA_BATCH_SIZE];
601 dev_id = txa->eventdev_id;
602 max_nb_tx = txa->max_nb_tx;
605 if (txa->nb_queues == 0)
608 if (!rte_spinlock_trylock(&txa->tx_lock))
611 for (nb_tx = 0; nb_tx < max_nb_tx; nb_tx += n) {
613 n = rte_event_dequeue_burst(dev_id, port, ev, RTE_DIM(ev), 0);
616 txa_service_tx(txa, ev, n);
619 if ((txa->loop_cnt++ & (TXA_FLUSH_THRESHOLD - 1)) == 0) {
621 struct txa_service_ethdev *tdi;
622 struct txa_service_queue_info *tqi;
623 struct rte_eth_dev *dev;
626 tdi = txa->txa_ethdev;
629 RTE_ETH_FOREACH_DEV(i) {
632 if (i == txa->dev_count)
636 if (tdi[i].nb_queues == 0)
638 for (q = 0; q < dev->data->nb_tx_queues; q++) {
640 tqi = txa_service_queue(txa, i, q);
641 if (unlikely(tqi == NULL || !tqi->added))
644 nb_tx += rte_eth_tx_buffer_flush(i, q,
649 txa->stats.tx_packets += nb_tx;
651 rte_spinlock_unlock(&txa->tx_lock);
656 txa_service_adapter_create(uint8_t id, struct rte_eventdev *dev,
657 struct rte_event_port_conf *port_conf)
659 struct txa_service_data *txa;
660 struct rte_event_port_conf *cb_conf;
663 cb_conf = rte_malloc(NULL, sizeof(*cb_conf), 0);
667 *cb_conf = *port_conf;
668 ret = txa_service_adapter_create_ext(id, dev, txa_service_conf_cb,
675 txa = txa_service_id_to_data(id);
681 txa_service_adapter_create_ext(uint8_t id, struct rte_eventdev *dev,
682 rte_event_eth_tx_adapter_conf_cb conf_cb,
685 struct txa_service_data *txa;
687 char mem_name[TXA_SERVICE_NAME_LEN];
693 socket_id = dev->data->socket_id;
694 snprintf(mem_name, TXA_MEM_NAME_LEN,
695 "rte_event_eth_txa_%d",
698 ret = txa_service_data_init();
702 txa = rte_zmalloc_socket(mem_name,
704 RTE_CACHE_LINE_SIZE, socket_id);
706 RTE_EDEV_LOG_ERR("failed to get mem for tx adapter");
711 txa->eventdev_id = dev->data->dev_id;
712 txa->socket_id = socket_id;
713 strncpy(txa->mem_name, mem_name, TXA_SERVICE_NAME_LEN);
714 txa->conf_cb = conf_cb;
715 txa->conf_arg = conf_arg;
716 txa->service_id = TXA_INVALID_SERVICE_ID;
717 rte_spinlock_init(&txa->tx_lock);
718 txa_service_data_array[id] = txa;
724 txa_service_event_port_get(uint8_t id, uint8_t *port)
726 struct txa_service_data *txa;
728 txa = txa_service_id_to_data(id);
729 if (txa->service_id == TXA_INVALID_SERVICE_ID)
732 *port = txa->port_id;
737 txa_service_adapter_free(uint8_t id)
739 struct txa_service_data *txa;
741 txa = txa_service_id_to_data(id);
742 if (txa->nb_queues) {
743 RTE_EDEV_LOG_ERR("%" PRIu16 " Tx queues not deleted",
749 rte_free(txa->conf_arg);
755 txa_service_queue_add(uint8_t id,
756 __rte_unused struct rte_eventdev *dev,
757 const struct rte_eth_dev *eth_dev,
760 struct txa_service_data *txa;
761 struct txa_service_ethdev *tdi;
762 struct txa_service_queue_info *tqi;
763 struct rte_eth_dev_tx_buffer *tb;
764 struct txa_retry *txa_retry;
767 txa = txa_service_id_to_data(id);
769 if (tx_queue_id == -1) {
774 nb_queues = eth_dev->data->nb_tx_queues;
775 if (txa->dev_count > eth_dev->data->port_id) {
776 tdi = &txa->txa_ethdev[eth_dev->data->port_id];
777 nb_queues -= tdi->nb_queues;
780 qdone = rte_zmalloc(txa->mem_name,
781 nb_queues * sizeof(*qdone), 0);
785 for (i = 0; i < nb_queues; i++) {
786 if (txa_service_is_queue_added(txa, eth_dev, i))
788 ret = txa_service_queue_add(id, dev, eth_dev, i);
795 if (i != nb_queues) {
796 for (i = 0; i < j; i++)
797 txa_service_queue_del(id, eth_dev, qdone[i]);
803 ret = txa_service_register(txa);
807 rte_spinlock_lock(&txa->tx_lock);
809 if (txa_service_is_queue_added(txa, eth_dev, tx_queue_id)) {
810 rte_spinlock_unlock(&txa->tx_lock);
814 ret = txa_service_queue_array_alloc(txa, eth_dev->data->port_id);
818 tb = txa_service_tx_buf_alloc(txa, eth_dev);
822 tdi = &txa->txa_ethdev[eth_dev->data->port_id];
823 tqi = txa_service_queue(txa, eth_dev->data->port_id, tx_queue_id);
825 txa_retry = &tqi->txa_retry;
826 txa_retry->id = txa->id;
827 txa_retry->port_id = eth_dev->data->port_id;
828 txa_retry->tx_queue = tx_queue_id;
830 rte_eth_tx_buffer_init(tb, TXA_BATCH_SIZE);
831 rte_eth_tx_buffer_set_err_callback(tb,
832 txa_service_buffer_retry, txa_retry);
840 if (txa->nb_queues == 0) {
841 txa_service_queue_array_free(txa,
842 eth_dev->data->port_id);
843 txa_service_unregister(txa);
846 rte_spinlock_unlock(&txa->tx_lock);
851 txa_service_queue_del(uint8_t id,
852 const struct rte_eth_dev *dev,
855 struct txa_service_data *txa;
856 struct txa_service_queue_info *tqi;
857 struct rte_eth_dev_tx_buffer *tb;
860 txa = txa_service_id_to_data(id);
861 port_id = dev->data->port_id;
863 if (tx_queue_id == -1) {
864 uint16_t i, q, nb_queues;
867 nb_queues = txa->nb_queues;
873 tqi = txa->txa_ethdev[port_id].queues;
875 while (i < nb_queues) {
878 ret = txa_service_queue_del(id, dev, q);
888 txa = txa_service_id_to_data(id);
890 tqi = txa_service_queue(txa, port_id, tx_queue_id);
891 if (tqi == NULL || !tqi->added)
899 txa->txa_ethdev[port_id].nb_queues--;
901 txa_service_queue_array_free(txa, port_id);
906 txa_service_id_get(uint8_t id, uint32_t *service_id)
908 struct txa_service_data *txa;
910 txa = txa_service_id_to_data(id);
911 if (txa->service_id == TXA_INVALID_SERVICE_ID)
914 if (service_id == NULL)
917 *service_id = txa->service_id;
922 txa_service_start(uint8_t id)
924 return txa_service_ctrl(id, 1);
928 txa_service_stats_get(uint8_t id,
929 struct rte_event_eth_tx_adapter_stats *stats)
931 struct txa_service_data *txa;
933 txa = txa_service_id_to_data(id);
939 txa_service_stats_reset(uint8_t id)
941 struct txa_service_data *txa;
943 txa = txa_service_id_to_data(id);
944 memset(&txa->stats, 0, sizeof(txa->stats));
949 txa_service_stop(uint8_t id)
951 return txa_service_ctrl(id, 0);
956 rte_event_eth_tx_adapter_create(uint8_t id, uint8_t dev_id,
957 struct rte_event_port_conf *port_conf)
959 struct rte_eventdev *dev;
962 if (port_conf == NULL)
965 RTE_EVENT_ETH_TX_ADAPTER_ID_VALID_OR_ERR_RET(id, -EINVAL);
966 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
968 dev = &rte_eventdevs[dev_id];
974 if (txa_adapter_exist(id))
977 txa_dev_id_array[id] = dev_id;
978 if (txa_dev_adapter_create(id))
979 ret = txa_dev_adapter_create(id)(id, dev);
982 txa_dev_id_array[id] = TXA_INVALID_DEV_ID;
986 ret = txa_service_adapter_create(id, dev, port_conf);
988 if (txa_dev_adapter_free(id))
989 txa_dev_adapter_free(id)(id, dev);
990 txa_dev_id_array[id] = TXA_INVALID_DEV_ID;
993 rte_eventdev_trace_eth_tx_adapter_create(id, dev_id, NULL, port_conf,
995 txa_dev_id_array[id] = dev_id;
1000 rte_event_eth_tx_adapter_create_ext(uint8_t id, uint8_t dev_id,
1001 rte_event_eth_tx_adapter_conf_cb conf_cb,
1004 struct rte_eventdev *dev;
1007 RTE_EVENT_ETH_TX_ADAPTER_ID_VALID_OR_ERR_RET(id, -EINVAL);
1008 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1014 if (txa_adapter_exist(id))
1017 dev = &rte_eventdevs[dev_id];
1019 txa_dev_id_array[id] = dev_id;
1020 if (txa_dev_adapter_create_ext(id))
1021 ret = txa_dev_adapter_create_ext(id)(id, dev);
1024 txa_dev_id_array[id] = TXA_INVALID_DEV_ID;
1028 ret = txa_service_adapter_create_ext(id, dev, conf_cb, conf_arg);
1030 if (txa_dev_adapter_free(id))
1031 txa_dev_adapter_free(id)(id, dev);
1032 txa_dev_id_array[id] = TXA_INVALID_DEV_ID;
1036 rte_eventdev_trace_eth_tx_adapter_create(id, dev_id, conf_cb, conf_arg,
1038 txa_dev_id_array[id] = dev_id;
1044 rte_event_eth_tx_adapter_event_port_get(uint8_t id, uint8_t *event_port_id)
1046 TXA_CHECK_OR_ERR_RET(id);
1048 return txa_service_event_port_get(id, event_port_id);
1052 rte_event_eth_tx_adapter_free(uint8_t id)
1056 TXA_CHECK_OR_ERR_RET(id);
1058 ret = txa_dev_adapter_free(id) ?
1059 txa_dev_adapter_free(id)(id, txa_evdev(id)) :
1063 ret = txa_service_adapter_free(id);
1064 txa_dev_id_array[id] = TXA_INVALID_DEV_ID;
1066 rte_eventdev_trace_eth_tx_adapter_free(id, ret);
1071 rte_event_eth_tx_adapter_queue_add(uint8_t id,
1072 uint16_t eth_dev_id,
1075 struct rte_eth_dev *eth_dev;
1079 RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_dev_id, -EINVAL);
1080 TXA_CHECK_OR_ERR_RET(id);
1082 eth_dev = &rte_eth_devices[eth_dev_id];
1083 TXA_CHECK_TXQ(eth_dev, queue);
1086 if (txa_dev_caps_get(id))
1087 txa_dev_caps_get(id)(txa_evdev(id), eth_dev, &caps);
1089 if (caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT)
1090 ret = txa_dev_queue_add(id) ?
1091 txa_dev_queue_add(id)(id,
1096 ret = txa_service_queue_add(id, txa_evdev(id), eth_dev, queue);
1098 rte_eventdev_trace_eth_tx_adapter_queue_add(id, eth_dev_id, queue,
1104 rte_event_eth_tx_adapter_queue_del(uint8_t id,
1105 uint16_t eth_dev_id,
1108 struct rte_eth_dev *eth_dev;
1112 RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_dev_id, -EINVAL);
1113 TXA_CHECK_OR_ERR_RET(id);
1115 eth_dev = &rte_eth_devices[eth_dev_id];
1119 if (txa_dev_caps_get(id))
1120 txa_dev_caps_get(id)(txa_evdev(id), eth_dev, &caps);
1122 if (caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT)
1123 ret = txa_dev_queue_del(id) ?
1124 txa_dev_queue_del(id)(id, txa_evdev(id),
1128 ret = txa_service_queue_del(id, eth_dev, queue);
1130 rte_eventdev_trace_eth_tx_adapter_queue_del(id, eth_dev_id, queue,
1136 rte_event_eth_tx_adapter_service_id_get(uint8_t id, uint32_t *service_id)
1138 TXA_CHECK_OR_ERR_RET(id);
1140 return txa_service_id_get(id, service_id);
1144 rte_event_eth_tx_adapter_start(uint8_t id)
1148 TXA_CHECK_OR_ERR_RET(id);
1150 ret = txa_dev_start(id) ? txa_dev_start(id)(id, txa_evdev(id)) : 0;
1152 ret = txa_service_start(id);
1153 rte_eventdev_trace_eth_tx_adapter_start(id, ret);
1158 rte_event_eth_tx_adapter_stats_get(uint8_t id,
1159 struct rte_event_eth_tx_adapter_stats *stats)
1163 TXA_CHECK_OR_ERR_RET(id);
1168 *stats = (struct rte_event_eth_tx_adapter_stats){0};
1170 ret = txa_dev_stats_get(id) ?
1171 txa_dev_stats_get(id)(id, txa_evdev(id), stats) : 0;
1173 if (ret == 0 && txa_service_id_get(id, NULL) != ESRCH) {
1174 if (txa_dev_stats_get(id)) {
1175 struct rte_event_eth_tx_adapter_stats service_stats;
1177 ret = txa_service_stats_get(id, &service_stats);
1179 stats->tx_retry += service_stats.tx_retry;
1180 stats->tx_packets += service_stats.tx_packets;
1181 stats->tx_dropped += service_stats.tx_dropped;
1184 ret = txa_service_stats_get(id, stats);
1191 rte_event_eth_tx_adapter_stats_reset(uint8_t id)
1195 TXA_CHECK_OR_ERR_RET(id);
1197 ret = txa_dev_stats_reset(id) ?
1198 txa_dev_stats_reset(id)(id, txa_evdev(id)) : 0;
1200 ret = txa_service_stats_reset(id);
1205 rte_event_eth_tx_adapter_stop(uint8_t id)
1209 TXA_CHECK_OR_ERR_RET(id);
1211 ret = txa_dev_stop(id) ? txa_dev_stop(id)(id, txa_evdev(id)) : 0;
1213 ret = txa_service_stop(id);
1214 rte_eventdev_trace_eth_tx_adapter_stop(id, ret);