From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id C5FAA8D36 for ; Wed, 9 Sep 2015 17:10:40 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 09 Sep 2015 08:09:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,496,1437462000"; d="scan'208";a="800926497" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 09 Sep 2015 08:09:36 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t89F9YBZ011331; Wed, 9 Sep 2015 16:09:34 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t89F9YBq029047; Wed, 9 Sep 2015 16:09:34 +0100 Received: (from bricha3@localhost) by sivswdev01.ir.intel.com with id t89F9YwJ029043; Wed, 9 Sep 2015 16:09:34 +0100 From: Bruce Richardson To: dev@dpdk.org Date: Wed, 9 Sep 2015 16:09:34 +0100 Message-Id: <1441811374-28984-5-git-send-email-bruce.richardson@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1441811374-28984-1-git-send-email-bruce.richardson@intel.com> References: <1434108496-1993-1-git-send-email-bruce.richardson@intel.com> <1441811374-28984-1-git-send-email-bruce.richardson@intel.com> Subject: [dpdk-dev] [PATCH v2 4/4] ethdev: check driver support for functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Sep 2015 15:10:41 -0000 The functions rte_eth_rx_queue_count and rte_eth_descriptor_done are supported by very few PMDs. Therefore, it is best to check for support for the functions in the ethdev library, so as to avoid run-time crashes at run-time if the application goes to use those APIs. The performance impact of this change should be very small as this is a predictable branch in the function. Signed-off-by: Bruce Richardson --- lib/librte_ether/rte_ethdev.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 1113ed2..0759de4 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -2608,16 +2608,18 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id, * @param queue_id * The queue id on the specific port. * @return - * The number of used descriptors in the specific queue. + * The number of used descriptors in the specific queue, or: + * (-EINVAL) if *port_id* is invalid + * (-ENOTSUP) if the device does not support this function */ -static inline uint32_t +static inline int rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; #ifdef RTE_LIBRTE_ETHDEV_DEBUG - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0); - RTE_ETH_FPTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0); + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); #endif + RTE_ETH_FPTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP); return (*dev->dev_ops->rx_queue_count)(dev, queue_id); } @@ -2634,6 +2636,7 @@ rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id) * - (1) if the specific DD bit is set. * - (0) if the specific DD bit is not set. * - (-ENODEV) if *port_id* invalid. + * - (-ENOTSUP) if the device does not support this function */ static inline int rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset) @@ -2641,8 +2644,8 @@ rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset) struct rte_eth_dev *dev = &rte_eth_devices[port_id]; #ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); - RTE_ETH_FPTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP); #endif + RTE_ETH_FPTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP); return (*dev->dev_ops->rx_descriptor_done)( \ dev->data->rx_queues[queue_id], offset); } -- 2.4.3