From patchwork Thu Mar 9 08:16:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 124890 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C639B41E2B; Thu, 9 Mar 2023 09:16:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6487B40ED7; Thu, 9 Mar 2023 09:16:47 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id D1BD6400D7 for ; Thu, 9 Mar 2023 09:16:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678349805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iJM7eXu/uoVI8qVvXn91ysSFs3HY9rV6Eevf5PRd0JI=; b=jARkx+DA6rj3bKPQbvHqhKBJmAmHQdw6vQAGsvug9VXWDZ8ks1+/9Ev+q2sh+pIudu7uSd ExrWVecyBWsGSd/Wb0q4EPfP6OjIROL6vNQpKoEb6zj1m16rxthh4VI/Cf+jzaDF2PwWJk AxSxOOINL0nlel60J7vtgmKBbKdNlZ4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-GmuDqtiQM7aqu8upi9jhEA-1; Thu, 09 Mar 2023 03:16:38 -0500 X-MC-Unique: GmuDqtiQM7aqu8upi9jhEA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ADF82382C971; Thu, 9 Mar 2023 08:16:37 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8267D40B40E4; Thu, 9 Mar 2023 08:16:36 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko Subject: [PATCH] ethdev: prefer offload names in logs Date: Thu, 9 Mar 2023 09:16:33 +0100 Message-Id: <20230309081633.780438-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 Displaying a bitmask is terrible for users. Prefer offload names when refusing some offloads in rte_eth_dev_configure. Before: Ethdev port_id=0 requested Rx offloads 0x621 doesn't match Rx offloads capabilities 0x0 in rte_eth_dev_configure() After: Ethdev port_id=0 requested Rx offloads 'VLAN_STRIP,QINQ_STRIP,VLAN_FILTER, VLAN_EXTEND' in rte_eth_dev_configure(). Device supports '' Rx offloads but does not support 'VLAN_STRIP,QINQ_STRIP,VLAN_FILTER, VLAN_EXTEND'. Signed-off-by: David Marchand --- lib/ethdev/rte_ethdev.c | 80 ++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 12 deletions(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 4d03255683..ba5cfeecd9 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -1026,6 +1026,42 @@ rte_eth_dev_tx_offload_name(uint64_t offload) return name; } +static char * +eth_dev_offload_names(uint64_t bitmask, const char *(*offload_name)(uint64_t)) +{ + uint64_t offload; + char *names; + + if (bitmask == 0) { + names = strdup(""); + goto out; + } + + offload = RTE_BIT64(__builtin_ctzll(bitmask)); + names = strdup(offload_name(offload)); + if (names == NULL) + goto out; + + bitmask &= ~offload; + while (bitmask != 0) { + char *old = names; + int ret; + + offload = RTE_BIT64(__builtin_ctzll(bitmask)); + ret = asprintf(&names, "%s,%s", old, offload_name(offload)); + free(old); + if (ret == -1) { + names = NULL; + goto out; + } + + bitmask &= ~offload; + } + +out: + return names; +} + const char * rte_eth_dev_capability_name(uint64_t capability) { @@ -1332,23 +1368,43 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, /* Any requested offloading must be within its device capabilities */ if ((dev_conf->rxmode.offloads & dev_info.rx_offload_capa) != dev_conf->rxmode.offloads) { - RTE_ETHDEV_LOG(ERR, - "Ethdev port_id=%u requested Rx offloads 0x%"PRIx64" doesn't match Rx offloads " - "capabilities 0x%"PRIx64" in %s()\n", - port_id, dev_conf->rxmode.offloads, - dev_info.rx_offload_capa, - __func__); + char *requested = eth_dev_offload_names(dev_conf->rxmode.offloads, + rte_eth_dev_rx_offload_name); + char *available = eth_dev_offload_names(dev_info.rx_offload_capa, + rte_eth_dev_rx_offload_name); + char *unavailable = eth_dev_offload_names( + dev_conf->rxmode.offloads & ~dev_info.rx_offload_capa, + rte_eth_dev_rx_offload_name); + + RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u requested Rx offloads '%s' in %s(). " + "Device supports '%s' Rx offloads but does not support '%s'.\n", + port_id, requested != NULL ? requested : "N/A", __func__, + available != NULL ? available : "N/A", + unavailable != NULL ? unavailable : "N/A"); + free(requested); + free(available); + free(unavailable); ret = -EINVAL; goto rollback; } if ((dev_conf->txmode.offloads & dev_info.tx_offload_capa) != dev_conf->txmode.offloads) { - RTE_ETHDEV_LOG(ERR, - "Ethdev port_id=%u requested Tx offloads 0x%"PRIx64" doesn't match Tx offloads " - "capabilities 0x%"PRIx64" in %s()\n", - port_id, dev_conf->txmode.offloads, - dev_info.tx_offload_capa, - __func__); + char *requested = eth_dev_offload_names(dev_conf->txmode.offloads, + rte_eth_dev_tx_offload_name); + char *available = eth_dev_offload_names(dev_info.tx_offload_capa, + rte_eth_dev_tx_offload_name); + char *unavailable = eth_dev_offload_names( + dev_conf->txmode.offloads & ~dev_info.tx_offload_capa, + rte_eth_dev_tx_offload_name); + + RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u requested Tx offloads '%s' in %s(). " + "Device supports '%s' Tx offloads but does not support '%s'.\n", + port_id, requested != NULL ? requested : "N/A", __func__, + available != NULL ? available : "N/A", + unavailable != NULL ? unavailable : "N/A"); + free(requested); + free(available); + free(unavailable); ret = -EINVAL; goto rollback; }