From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 80BB4A0542; Mon, 6 Jun 2022 19:25:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 261EB406B4; Mon, 6 Jun 2022 19:25:58 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id C565A4069C for ; Mon, 6 Jun 2022 19:25:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654536357; x=1686072357; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=k79GPa3676wLe0M4tyek1GD6qsFddyp0vzof8TkTGjc=; b=fZCCdtlyvtkCUbJwRq7ekyAnYz/ly6PeiZMJK6jcOftt7/qD6ACxiB/6 3Xzrh1iFrmTQEQ3neMZyWswRVKjrdAj1FPpXPK/H/JfNt9jHwHMrbKTTv JrSVd9bcFrDQIQeBhNAlX8FV1lZi+5+uGZOdY+LpdynWIumv4LKtJzXYR YegeQHcHAczKH9blU6wGFazJSzimaN02ubTpsUMPHA6uT0K52/JJz9Wmu 4cRRR72E78ZS2vH9X73yzb8xlsrHOQ98OFUV0GvWRqwcy0EMRWYTePcug ehVmVLzY1OiT6h59IUpHa5V3p9BWkwUMQLl722yPIj+pmqdrz48V8ThFV Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10370"; a="276715411" X-IronPort-AV: E=Sophos;i="5.91,280,1647327600"; d="scan'208";a="276715411" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2022 10:25:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,280,1647327600"; d="scan'208";a="669581224" Received: from txandevlnx322.an.intel.com ([10.123.117.44]) by FMSMGA003.fm.intel.com with ESMTP; 06 Jun 2022 10:25:54 -0700 From: Ganapati Kundapura To: jerinjacobk@gmail.com, dev@dpdk.org, jay.jayatheerthan@intel.com Subject: [PATCH v1] eventdev: add adapter instance get API Date: Mon, 6 Jun 2022 12:25:49 -0500 Message-Id: <20220606172549.3248660-1-ganapati.kundapura@intel.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Added rte_event_eth_rx_adapter_instance_get() and rte_event_eth_tx_adapter_instance_get() api's to get the adapter instance id for a specified event port and queue index. Signed-off-by: Ganapati Kundapura diff --git a/app/test/test_event_eth_rx_adapter.c b/app/test/test_event_eth_rx_adapter.c index e358a70..878004b 100644 --- a/app/test/test_event_eth_rx_adapter.c +++ b/app/test/test_event_eth_rx_adapter.c @@ -39,6 +39,7 @@ test_event_eth_rx_intr_adapter_common(void) #define TEST_INST_ID 0 #define TEST_DEV_ID 0 #define TEST_ETHDEV_ID 0 +#define TEST_ETH_QUEUE_ID 0 struct event_eth_rx_adapter_test_params { struct rte_mempool *mp; @@ -1001,6 +1002,87 @@ adapter_queue_conf(void) return TEST_SUCCESS; } +static int +adapter_instance_get(void) +{ + int err; + uint8_t inst_id; + uint16_t eth_dev_id; + struct rte_eth_dev_info dev_info; + struct rte_event_eth_rx_adapter_queue_conf queue_conf = {0}; + + /* Case 1: Test without configuring eth */ + err = rte_event_eth_rx_adapter_instance_get(TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID, + &inst_id); + TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err); + + /* Case 2: Test with wrong eth port */ + eth_dev_id = rte_eth_dev_count_total() + 1; + err = rte_event_eth_rx_adapter_instance_get(eth_dev_id, + TEST_ETH_QUEUE_ID, + &inst_id); + TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err); + + /* Case 3: Test with wrong rx queue */ + err = rte_eth_dev_info_get(TEST_ETHDEV_ID, &dev_info); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + err = rte_event_eth_rx_adapter_instance_get(TEST_ETHDEV_ID, + dev_info.max_rx_queues + 1, + &inst_id); + TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err); + + /* Case 4: Test with right instance, port & rxq */ + /* Add queue to Rx adapter */ + queue_conf.ev.queue_id = TEST_ETH_QUEUE_ID; + queue_conf.ev.sched_type = RTE_SCHED_TYPE_ATOMIC; + queue_conf.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; + + err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID, + TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID, + &queue_conf); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + err = rte_event_eth_rx_adapter_instance_get(TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID, + &inst_id); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + /* Add another queue */ + queue_conf.ev.queue_id = TEST_ETH_QUEUE_ID + 1; + err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID, + TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID + 1, + &queue_conf); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + err = rte_event_eth_rx_adapter_instance_get(TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID + 1, + &inst_id); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + /* Case 5: Test with right instance, port & wrong rxq */ + err = rte_event_eth_rx_adapter_instance_get(TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID + 2, + &inst_id); + TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err); + + /* Delete queues from the Rx adapter */ + err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID, + TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID, + TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID + 1); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + return TEST_SUCCESS; +} + static struct unit_test_suite event_eth_rx_tests = { .suite_name = "rx event eth adapter test suite", .setup = testsuite_setup, @@ -1019,6 +1101,8 @@ static struct unit_test_suite event_eth_rx_tests = { adapter_queue_event_buf_test), TEST_CASE_ST(adapter_create_with_params, adapter_free, adapter_queue_stats_test), + TEST_CASE_ST(adapter_create, adapter_free, + adapter_instance_get), TEST_CASES_END() /**< NULL terminate unit test array */ } }; diff --git a/app/test/test_event_eth_tx_adapter.c b/app/test/test_event_eth_tx_adapter.c index 2900532..ebbc622 100644 --- a/app/test/test_event_eth_tx_adapter.c +++ b/app/test/test_event_eth_tx_adapter.c @@ -29,6 +29,7 @@ test_event_eth_tx_adapter_common(void) #define MAX_NUM_QUEUE RTE_PMD_RING_MAX_RX_RINGS #define TEST_INST_ID 0 #define TEST_DEV_ID 0 +#define TEST_ETH_QUEUE_ID 0 #define SOCKET0 0 #define RING_SIZE 256 #define ETH_NAME_LEN 32 @@ -639,6 +640,79 @@ tx_adapter_service(void) } static int +tx_adapter_instance_get(void) +{ + int err; + uint8_t inst_id; + uint16_t eth_dev_id; + struct rte_eth_dev_info dev_info; + + /* Case 1: Test without configuring eth */ + err = rte_event_eth_tx_adapter_instance_get(TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID, + &inst_id); + TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err); + + /* Case 2: Test with wrong eth port */ + eth_dev_id = rte_eth_dev_count_total() + 1; + err = rte_event_eth_tx_adapter_instance_get(eth_dev_id, + TEST_ETH_QUEUE_ID, + &inst_id); + TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err); + + /* Case 3: Test with wrong tx queue */ + err = rte_eth_dev_info_get(TEST_ETHDEV_ID, &dev_info); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + err = rte_event_eth_tx_adapter_instance_get(TEST_ETHDEV_ID, + dev_info.max_tx_queues + 1, + &inst_id); + TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err); + + /* Case 4: Test with right instance, port & rxq */ + /* Add queue to tx adapter */ + err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID, + TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + err = rte_event_eth_tx_adapter_instance_get(TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID, + &inst_id); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + /* Add another queue to tx adapter */ + err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID, + TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID + 1); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + err = rte_event_eth_tx_adapter_instance_get(TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID + 1, + &inst_id); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + /* Case 5: Test with right instance, port & wrong rxq */ + err = rte_event_eth_tx_adapter_instance_get(TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID + 2, + &inst_id); + TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err); + + /* Delete queues from the Tx adapter */ + err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID, + TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID, + TEST_ETHDEV_ID, + TEST_ETH_QUEUE_ID + 1); + TEST_ASSERT(err == 0, "Expected 0 got %d", err); + + return TEST_SUCCESS; +} + +static int tx_adapter_dynamic_device(void) { uint16_t port_id = rte_eth_dev_count_avail(); @@ -695,6 +769,8 @@ static struct unit_test_suite event_eth_tx_tests = { tx_adapter_start_stop), TEST_CASE_ST(tx_adapter_create, tx_adapter_free, tx_adapter_service), + TEST_CASE_ST(tx_adapter_create, tx_adapter_free, + tx_adapter_instance_get), TEST_CASE_ST(NULL, NULL, tx_adapter_dynamic_device), TEST_CASES_END() /**< NULL terminate unit test array */ } diff --git a/doc/guides/prog_guide/event_ethernet_rx_adapter.rst b/doc/guides/prog_guide/event_ethernet_rx_adapter.rst index 3b4ef50..a6d8987 100644 --- a/doc/guides/prog_guide/event_ethernet_rx_adapter.rst +++ b/doc/guides/prog_guide/event_ethernet_rx_adapter.rst @@ -177,6 +177,12 @@ used otherwise it returns -EINVAL. The ``rte_event_eth_rx_adapter_queue_stats_reset`` function can be used to reset queue level stats when queue level event buffer is in use. +Getting Adapter instance id +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``rte_event_eth_rx_adapter_instance_get()`` function reports +rx adapter instance id for a specified event port and rx queue index. + Interrupt Based Rx Queues ~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/guides/prog_guide/event_ethernet_tx_adapter.rst b/doc/guides/prog_guide/event_ethernet_tx_adapter.rst index f80d226..b14131d 100644 --- a/doc/guides/prog_guide/event_ethernet_tx_adapter.rst +++ b/doc/guides/prog_guide/event_ethernet_tx_adapter.rst @@ -165,6 +165,12 @@ in struct ``rte_event_eth_tx_adapter_stats``. The counter values are the sum of the counts from the eventdev PMD callback if the callback is supported, and the counts maintained by the service function, if one exists. +Getting Adapter instance id +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``rte_event_eth_tx_adapter_instanceget()`` function reports +tx adapter instance id for a specified event port and tx queue index. + Tx event vectorization ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index bf8741d..e0d2554 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -6,6 +6,7 @@ #include #endif #include +#include #include #include @@ -44,6 +45,8 @@ #define RXA_ADAPTER_ARRAY "rte_event_eth_rx_adapter_array" +#define INVALID_INSTANCE_ID UINT8_MAX + /* * Used to store port and queue ID of interrupting Rx queue */ @@ -251,7 +254,13 @@ struct eth_rx_queue_info { struct rte_event_eth_rx_adapter_stats *stats; }; +struct event_eth_rxa_inst_info { + uint8_t rxa_inst_id; +}; + +static int rxa_array_sz; static struct event_eth_rx_adapter **event_eth_rx_adapter; +static struct event_eth_rxa_inst_info **event_eth_rxa_inst_info; /* Enable dynamic timestamp field in mbuf */ static uint64_t event_eth_rx_timestamp_dynflag; @@ -1421,9 +1430,13 @@ rte_event_eth_rx_adapter_init(void) const char *name = RXA_ADAPTER_ARRAY; const struct rte_memzone *mz; unsigned int sz; + uint8_t i; sz = sizeof(*event_eth_rx_adapter) * RTE_EVENT_ETH_RX_ADAPTER_MAX_INSTANCE; + rxa_array_sz = sz; + + sz += RTE_MAX_ETHPORTS * sizeof(*event_eth_rxa_inst_info); sz = RTE_ALIGN(sz, RTE_CACHE_LINE_SIZE); mz = rte_memzone_lookup(name); @@ -1438,6 +1451,16 @@ rte_event_eth_rx_adapter_init(void) } event_eth_rx_adapter = mz->addr; + + /* event_eth_rxa_inst_info array starts after rxa array */ + event_eth_rxa_inst_info = (struct event_eth_rxa_inst_info **) + ((uint64_t)event_eth_rx_adapter + + rxa_array_sz); + + /* Reset the rxa instance pointers */ + for (i = 0; i < RTE_MAX_ETHPORTS; i++) + event_eth_rxa_inst_info[i] = NULL; + return 0; } @@ -1445,12 +1468,20 @@ static int rxa_memzone_lookup(void) { const struct rte_memzone *mz; + unsigned int rxa_array_sz; if (event_eth_rx_adapter == NULL) { mz = rte_memzone_lookup(RXA_ADAPTER_ARRAY); if (mz == NULL) return -ENOMEM; event_eth_rx_adapter = mz->addr; + + /* event_eth_rxa_inst_info array starts after rxa array */ + rxa_array_sz = sizeof(*event_eth_rx_adapter) * + RTE_EVENT_ETH_RX_ADAPTER_MAX_INSTANCE; + event_eth_rxa_inst_info = (struct event_eth_rxa_inst_info **) + ((uint64_t)event_eth_rx_adapter + + rxa_array_sz); } return 0; @@ -1950,6 +1981,7 @@ rxa_sw_del(struct event_eth_rx_adapter *rx_adapter, int pollq; int intrq; int sintrq; + uint16_t eth_dev_id = dev_info->dev->data->port_id; if (rx_adapter->nb_queues == 0) @@ -1993,6 +2025,11 @@ rxa_sw_del(struct event_eth_rx_adapter *rx_adapter, dev_info->rx_queue[rx_queue_id].event_buf = NULL; dev_info->rx_queue[rx_queue_id].stats = NULL; } + + /* unset rxa_inst_id for rx_queue_id */ + if (event_eth_rxa_inst_info[eth_dev_id]) + event_eth_rxa_inst_info[eth_dev_id][rx_queue_id].rxa_inst_id = + INVALID_INSTANCE_ID; } static int @@ -2085,6 +2122,33 @@ rxa_add_queue(struct event_eth_rx_adapter *rx_adapter, } } + /* Allocate storage to store rxa_inst_id for rxq */ + if (event_eth_rxa_inst_info[eth_dev_id] == NULL) { + uint16_t n, i; + struct event_eth_rxa_inst_info *i_info; + + n = rte_eth_devices[eth_dev_id].data->nb_rx_queues; + + i_info = rte_zmalloc_socket("event_eth_rxa_inst_info", + n * sizeof(struct event_eth_rxa_inst_info), + 0, + rx_adapter->socket_id); + if (i_info == NULL) { + RTE_EDEV_LOG_ERR("Failed to allocate storage for " + "event_eth_rxa_inst_info"); + return -ENOMEM; + } + + for (i = 0; i < n; i++) + i_info[i].rxa_inst_id = INVALID_INSTANCE_ID; + + event_eth_rxa_inst_info[eth_dev_id] = i_info; + } + + /* store rxa id for rx_queue_id in event_eth_rxa_inst_info */ + event_eth_rxa_inst_info[eth_dev_id][rx_queue_id].rxa_inst_id = + rx_adapter->id; + if (!rx_adapter->use_queue_event_buf) return 0; @@ -2523,6 +2587,10 @@ int rte_event_eth_rx_adapter_free(uint8_t id) { struct event_eth_rx_adapter *rx_adapter; + uint16_t eth_dev_id; + + if (rxa_memzone_lookup()) + return -ENOMEM; RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET(id, -EINVAL); @@ -2544,6 +2612,13 @@ rte_event_eth_rx_adapter_free(uint8_t id) rte_free(rx_adapter); event_eth_rx_adapter[id] = NULL; + for (eth_dev_id = 0; eth_dev_id < RTE_MAX_ETHPORTS; eth_dev_id++) { + if (event_eth_rxa_inst_info[eth_dev_id]) { + rte_free(event_eth_rxa_inst_info[eth_dev_id]); + event_eth_rxa_inst_info[eth_dev_id] = NULL; + } + } + rte_eventdev_trace_eth_rx_adapter_free(id); return 0; } @@ -2561,6 +2636,9 @@ rte_event_eth_rx_adapter_queue_add(uint8_t id, struct eth_device_info *dev_info; struct rte_event_eth_rx_adapter_vector_limits limits; + if (rxa_memzone_lookup()) + return -ENOMEM; + RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET(id, -EINVAL); RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_dev_id, -EINVAL); @@ -2726,6 +2804,9 @@ rte_event_eth_rx_adapter_queue_del(uint8_t id, uint16_t eth_dev_id, uint32_t *rx_wrr = NULL; int num_intr_vec; + if (rxa_memzone_lookup()) + return -ENOMEM; + RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET(id, -EINVAL); RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_dev_id, -EINVAL); @@ -2832,6 +2913,7 @@ rte_event_eth_rx_adapter_queue_del(uint8_t id, uint16_t eth_dev_id, rte_eventdev_trace_eth_rx_adapter_queue_del(id, eth_dev_id, rx_queue_id, ret); + return ret; } @@ -3286,6 +3368,49 @@ rte_event_eth_rx_adapter_queue_conf_get(uint8_t id, return 0; } +int +rte_event_eth_rx_adapter_instance_get(uint16_t eth_dev_id, + uint16_t rx_queue_id, + uint8_t *rxa_inst_id) +{ + uint8_t inst_id; + + if (rxa_memzone_lookup()) + return -ENOMEM; + + if (eth_dev_id >= rte_eth_dev_count_avail()) { + RTE_EDEV_LOG_ERR("Invalid ethernet port id %u", eth_dev_id); + return -EINVAL; + } + + if (rx_queue_id >= rte_eth_devices[eth_dev_id].data->nb_rx_queues) { + RTE_EDEV_LOG_ERR("Invalid Rx queue %u", rx_queue_id); + return -EINVAL; + } + + if (rxa_inst_id == NULL) { + RTE_EDEV_LOG_ERR("rxa_inst_id cannot be NULL"); + return -EINVAL; + } + + if (event_eth_rxa_inst_info[eth_dev_id] == NULL) { + RTE_EDEV_LOG_ERR("No valid rxa instance for eth_dev_id %u", + eth_dev_id); + return -EINVAL; + } + + inst_id = event_eth_rxa_inst_info[eth_dev_id][rx_queue_id].rxa_inst_id; + if (inst_id == INVALID_INSTANCE_ID) { + RTE_EDEV_LOG_ERR("Invalid rxa instance for eth_dev_id %u, " + "rx_queue_id %u", eth_dev_id, rx_queue_id); + return -EINVAL; + } + + *rxa_inst_id = inst_id; + + return 0; +} + #define RXA_ADD_DICT(stats, s) rte_tel_data_add_dict_u64(d, #s, stats.s) static int diff --git a/lib/eventdev/rte_event_eth_rx_adapter.h b/lib/eventdev/rte_event_eth_rx_adapter.h index 3608a7b..f56938d 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.h +++ b/lib/eventdev/rte_event_eth_rx_adapter.h @@ -38,6 +38,7 @@ * - rte_event_eth_rx_adapter_queue_stats_get() * - rte_event_eth_rx_adapter_queue_stats_reset() * - rte_event_eth_rx_adapter_event_port_get() + * - rte_event_eth_rx_adapter_instance_get() * * The application creates an ethernet to event adapter using * rte_event_eth_rx_adapter_create_ext() or rte_event_eth_rx_adapter_create() @@ -704,6 +705,28 @@ __rte_experimental int rte_event_eth_rx_adapter_event_port_get(uint8_t id, uint8_t *event_port_id); +/** + * Get RX adapter instance ID for a RX queue + * + * @param eth_dev_id + * Port identifier of Ethernet device. + * + * @param rx_queue_id + * Ethernet device receive queue index + * + * @param[out] rxa_inst_id + * RX adapter instance identifier. + * + * @return + * - 0: Success + * - <0: Error code on failure + */ +__rte_experimental +int +rte_event_eth_rx_adapter_instance_get(uint16_t eth_dev_id, + uint16_t rx_queue_id, + uint8_t *rxa_inst_id); + #ifdef __cplusplus } #endif diff --git a/lib/eventdev/rte_event_eth_tx_adapter.c b/lib/eventdev/rte_event_eth_tx_adapter.c index 1b304f0..1c9f9fc 100644 --- a/lib/eventdev/rte_event_eth_tx_adapter.c +++ b/lib/eventdev/rte_event_eth_tx_adapter.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2018 Intel Corporation. */ +#include + #include #include #include @@ -17,6 +19,11 @@ #define TXA_MAX_NB_TX 128 #define TXA_INVALID_DEV_ID INT32_C(-1) #define TXA_INVALID_SERVICE_ID INT64_C(-1) +#define INVALID_INSTANCE_ID UINT8_MAX + +#define TXA_ADAPTER_ARRAY "txa_adapter_array" +#define TXA_SERVICE_DATA_ARRAY "txa_service_data_array" +#define TXA_ADAPTER_INSTANCE_ARRAY "txa_adapter_instance_array" #define txa_evdev(id) (&rte_eventdevs[txa_dev_id_array[(id)]]) @@ -140,6 +147,10 @@ struct txa_service_ethdev { void *queues; }; +struct event_eth_txa_inst_info { + uint8_t txa_inst_id; +}; + /* Array of adapter instances, initialized with event device id * when adapter is created */ @@ -148,6 +159,9 @@ static int *txa_dev_id_array; /* Array of pointers to service implementation data */ static struct txa_service_data **txa_service_data_array; +/* array of adapter instances to store tx queue specific instance */ +static struct event_eth_txa_inst_info **event_eth_txa_inst_info; + static int32_t txa_service_func(void *args); static int txa_service_adapter_create_ext(uint8_t id, struct rte_eventdev *dev, @@ -194,12 +208,42 @@ txa_memzone_array_get(const char *name, unsigned int elt_size, int nb_elems) } static int +txa_memzone_lookup(void) +{ + const struct rte_memzone *mz; + + if (txa_dev_id_array == NULL) { + mz = rte_memzone_lookup(TXA_ADAPTER_ARRAY); + if (mz == NULL) + return -ENOMEM; + txa_dev_id_array = mz->addr; + } + + if (txa_service_data_array == NULL) { + mz = rte_memzone_lookup(TXA_SERVICE_DATA_ARRAY); + if (mz == NULL) + return -ENOMEM; + txa_service_data_array = mz->addr; + } + + if (event_eth_txa_inst_info == NULL) { + mz = rte_memzone_lookup(TXA_ADAPTER_INSTANCE_ARRAY); + if (mz == NULL) + return -ENOMEM; + event_eth_txa_inst_info = mz->addr; + } + + return 0; +} + + +static int txa_dev_id_array_init(void) { if (txa_dev_id_array == NULL) { int i; - txa_dev_id_array = txa_memzone_array_get("txa_adapter_array", + txa_dev_id_array = txa_memzone_array_get(TXA_ADAPTER_ARRAY, sizeof(int), RTE_EVENT_ETH_TX_ADAPTER_MAX_INSTANCE); if (txa_dev_id_array == NULL) @@ -221,15 +265,30 @@ txa_init(void) static int txa_service_data_init(void) { + uint8_t i; + if (txa_service_data_array == NULL) { txa_service_data_array = - txa_memzone_array_get("txa_service_data_array", + txa_memzone_array_get(TXA_SERVICE_DATA_ARRAY, sizeof(int), RTE_EVENT_ETH_TX_ADAPTER_MAX_INSTANCE); if (txa_service_data_array == NULL) return -ENOMEM; } + if (event_eth_txa_inst_info == NULL) { + event_eth_txa_inst_info = + txa_memzone_array_get(TXA_ADAPTER_INSTANCE_ARRAY, + sizeof(*event_eth_txa_inst_info), + RTE_MAX_ETHPORTS); + if (event_eth_txa_inst_info == NULL) + return -ENOMEM; + } + + /* Reset the txa instance pointers */ + for (i = 0; i < RTE_MAX_ETHPORTS; i++) + event_eth_txa_inst_info[i] = NULL; + return 0; } @@ -763,6 +822,7 @@ txa_service_queue_add(uint8_t id, struct rte_eth_dev_tx_buffer *tb; struct txa_retry *txa_retry; int ret = 0; + uint16_t eth_dev_id = eth_dev->data->port_id; txa = txa_service_id_to_data(id); @@ -836,6 +896,31 @@ txa_service_queue_add(uint8_t id, tdi->nb_queues++; txa->nb_queues++; + /* Allocate storage to store txa_inst_id for txq */ + if (event_eth_txa_inst_info[eth_dev_id] == NULL) { + uint16_t n, i; + struct event_eth_txa_inst_info *i_info; + + n = eth_dev->data->nb_tx_queues; + + i_info = rte_zmalloc_socket("event_eth_txa_inst_info", + n * sizeof(event_eth_txa_inst_info), + 0, + txa->socket_id); + if (i_info == NULL) { + RTE_EDEV_LOG_ERR("Failed to allocate storage for " + "event_eth_txa_inst_info"); + goto err_unlock; + } + + for (i = 0; i < n; i++) + i_info[i].txa_inst_id = INVALID_INSTANCE_ID; + + event_eth_txa_inst_info[eth_dev_id] = i_info; + } + + event_eth_txa_inst_info[eth_dev_id][tx_queue_id].txa_inst_id = id; + ret_unlock: rte_spinlock_unlock(&txa->tx_lock); return 0; @@ -902,6 +987,12 @@ txa_service_queue_del(uint8_t id, txa->nb_queues--; txa->txa_ethdev[port_id].nb_queues--; + /* unset txa_inst_id for tx_queue_id */ + if (event_eth_txa_inst_info[port_id]) + event_eth_txa_inst_info[port_id][tx_queue_id].txa_inst_id = + INVALID_INSTANCE_ID; + + txa_service_queue_array_free(txa, port_id); return 0; } @@ -1056,6 +1147,10 @@ int rte_event_eth_tx_adapter_free(uint8_t id) { int ret; + uint16_t eth_dev_id; + + if (txa_memzone_lookup()) + return -ENOMEM; TXA_CHECK_OR_ERR_RET(id); @@ -1067,6 +1162,13 @@ rte_event_eth_tx_adapter_free(uint8_t id) ret = txa_service_adapter_free(id); txa_dev_id_array[id] = TXA_INVALID_DEV_ID; + for (eth_dev_id = 0; eth_dev_id < RTE_MAX_ETHPORTS; eth_dev_id++) { + if (event_eth_txa_inst_info[eth_dev_id]) { + rte_free(event_eth_txa_inst_info[eth_dev_id]); + event_eth_txa_inst_info[eth_dev_id] = NULL; + } + } + rte_eventdev_trace_eth_tx_adapter_free(id, ret); return ret; } @@ -1080,6 +1182,9 @@ rte_event_eth_tx_adapter_queue_add(uint8_t id, int ret; uint32_t caps; + if (txa_memzone_lookup()) + return -ENOMEM; + RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_dev_id, -EINVAL); TXA_CHECK_OR_ERR_RET(id); @@ -1113,6 +1218,9 @@ rte_event_eth_tx_adapter_queue_del(uint8_t id, int ret; uint32_t caps; + if (txa_memzone_lookup()) + return -ENOMEM; + RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_dev_id, -EINVAL); TXA_CHECK_OR_ERR_RET(id); @@ -1218,3 +1326,46 @@ rte_event_eth_tx_adapter_stop(uint8_t id) rte_eventdev_trace_eth_tx_adapter_stop(id, ret); return ret; } + +int +rte_event_eth_tx_adapter_instance_get(uint16_t eth_dev_id, + uint16_t tx_queue_id, + uint8_t *txa_inst_id) +{ + uint8_t inst_id; + + if (txa_memzone_lookup()) + return -ENOMEM; + + if (eth_dev_id >= rte_eth_dev_count_avail()) { + RTE_EDEV_LOG_ERR("Invalid ethernet port id %u", eth_dev_id); + return -EINVAL; + } + + if (tx_queue_id >= rte_eth_devices[eth_dev_id].data->nb_tx_queues) { + RTE_EDEV_LOG_ERR("Invalid tx queue id %u", tx_queue_id); + return -EINVAL; + } + + if (txa_inst_id == NULL) { + RTE_EDEV_LOG_ERR("txa_instance_id cannot be NULL"); + return -EINVAL; + } + + if (event_eth_txa_inst_info[eth_dev_id] == NULL) { + RTE_EDEV_LOG_ERR("No valid txa instance for eth_dev_id %d", + eth_dev_id); + return -EINVAL; + } + + inst_id = event_eth_txa_inst_info[eth_dev_id][tx_queue_id].txa_inst_id; + if (inst_id == INVALID_INSTANCE_ID) { + RTE_EDEV_LOG_ERR("Invalid txa instance for eth_dev_id %u, " + "tx_queue_id %u", eth_dev_id, tx_queue_id); + return -EINVAL; + } + + *txa_inst_id = inst_id; + + return 0; +} diff --git a/lib/eventdev/rte_event_eth_tx_adapter.h b/lib/eventdev/rte_event_eth_tx_adapter.h index 3908c2d..28f4fa9 100644 --- a/lib/eventdev/rte_event_eth_tx_adapter.h +++ b/lib/eventdev/rte_event_eth_tx_adapter.h @@ -34,6 +34,7 @@ * - rte_event_eth_tx_adapter_enqueue() * - rte_event_eth_tx_adapter_event_port_get() * - rte_event_eth_tx_adapter_service_id_get() + * - rte_event_eth_tx_adapter_instance_get() * * The application creates the adapter using * rte_event_eth_tx_adapter_create() or rte_event_eth_tx_adapter_create_ext(). @@ -423,6 +424,24 @@ rte_event_eth_tx_adapter_stats_reset(uint8_t id); int rte_event_eth_tx_adapter_service_id_get(uint8_t id, uint32_t *service_id); +/** + * Get TX adapter instance id for TX queue + * + * @param eth_dev_id + * Port identifier of Ethernet device + * + * @param tx_queue_id + * Etherdev device TX queue index + * + * @param[out] txa_inst_id + * Pointer to TX adapter instance identifier + */ +__rte_experimental +int +rte_event_eth_tx_adapter_instance_get(uint16_t eth_dev_id, + uint16_t tx_queue_id, + uint8_t *txa_inst_id); + #ifdef __cplusplus } #endif diff --git a/lib/eventdev/version.map b/lib/eventdev/version.map index 886e2ec..b5bfcd5 100644 --- a/lib/eventdev/version.map +++ b/lib/eventdev/version.map @@ -105,6 +105,8 @@ EXPERIMENTAL { rte_event_eth_rx_adapter_queue_conf_get; rte_event_eth_rx_adapter_queue_stats_get; rte_event_eth_rx_adapter_queue_stats_reset; + rte_event_eth_rx_adapter_instance_get; + rte_event_eth_tx_adapter_instance_get; # added in 22.03 rte_event_eth_rx_adapter_event_port_get; -- 2.6.4