From patchwork Wed May 18 19:15:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauricio Vasquez B X-Patchwork-Id: 12884 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 31DD45A64; Wed, 18 May 2016 21:15:19 +0200 (CEST) Received: from compass.polito.it (compass.polito.it [130.192.55.110]) by dpdk.org (Postfix) with ESMTP id 8F0045A49 for ; Wed, 18 May 2016 21:15:17 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by compass.polito.it (Postfix) with ESMTP id 6AF3C100130; Wed, 18 May 2016 21:15:17 +0200 (CEST) Authentication-Results: compass.polito.it (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=studenti.polito.it DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= studenti.polito.it; h=references:in-reply-to:x-mailer:message-id :date:date:subject:subject:cc:to:from:from:received:received; s= y2k10; t=1463598915; bh=GfWJ74uDC29HrAy3hiNhU68fuE4gMrL7q/pTMZfH VMs=; b=H4C30HaibsPo/mJ4wtXlTcegylFuIF0n6GxocY8ichYzndJB834Zrhz2 f0wOkEbxuqv4kmp+3l/6qrkIqhQzggmCEkbCTvWz64Zv0cKKe9Eg2ofaBp3oK47K Ufq9a6sdyY5WXpT1sevkcBPGrXW5ZwtPx27bjlz2tdh8YjMx4HM= X-Virus-Scanned: amavisd-new at studenti.polito.it X-Spam-Flag: NO X-Spam-Score: -5.877 X-Spam-Level: X-Spam-Status: No, score=-5.877 tagged_above=-100 required=3.5 tests=[ALL_TRUSTED=-5, AWL=0.623, BAYES_00=-1.5] autolearn=ham Received: from compass.polito.it ([127.0.0.1]) by localhost (compass.polito.it [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id bUqipfhnI0s4; Wed, 18 May 2016 21:15:15 +0200 (CEST) Received: from mvb-X455LJ.lan (unknown [93.56.119.81]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: s203403@studenti.polito.it) by compass.polito.it (Postfix) with ESMTPSA id B1B7E100129; Wed, 18 May 2016 21:15:15 +0200 (CEST) From: Mauricio Vasquez B To: thomas.monjalon@6wind.com Cc: dev@dpdk.org Date: Wed, 18 May 2016 21:15:11 +0200 Message-Id: <1463598911-18176-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1463515316-4949-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> References: <1463515316-4949-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> Subject: [dpdk-dev] [PATCH v3] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The RTE_ETH_VALID_PORTID_OR_ERR_RET macro is used in some places to check if a port id is valid or not. This commit makes use of it in some new parts of the code. Signed-off-by: Mauricio Vasquez B --- v3: - use it also in rte_eth_add_rx_callback and rte_eth_add_tx_callback v2: - add missed case - change also cases in examples/ethtool/lib/rte_ethtool.c examples/ethtool/lib/rte_ethtool.c | 15 ++++++----- lib/librte_ether/rte_ethdev.c | 51 +++++++++++++------------------------- 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c index 42e05f1..9b18e46 100644 --- a/examples/ethtool/lib/rte_ethtool.c +++ b/examples/ethtool/lib/rte_ethtool.c @@ -51,8 +51,7 @@ rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo) if (drvinfo == NULL) return -EINVAL; - if (!rte_eth_dev_is_valid_port(port_id)) - return -ENODEV; + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); memset(&dev_info, 0, sizeof(dev_info)); rte_eth_dev_info_get(port_id, &dev_info); @@ -120,8 +119,8 @@ rte_ethtool_get_link(uint8_t port_id) { struct rte_eth_link link; - if (!rte_eth_dev_is_valid_port(port_id)) - return -ENODEV; + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + rte_eth_link_get(port_id, &link); return link.link_status; } @@ -267,8 +266,8 @@ rte_ethtool_net_open(uint8_t port_id) int rte_ethtool_net_stop(uint8_t port_id) { - if (!rte_eth_dev_is_valid_port(port_id)) - return -ENODEV; + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + rte_eth_dev_stop(port_id); return 0; @@ -277,8 +276,8 @@ rte_ethtool_net_stop(uint8_t port_id) int rte_ethtool_net_get_mac_addr(uint8_t port_id, struct ether_addr *addr) { - if (!rte_eth_dev_is_valid_port(port_id)) - return -ENODEV; + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + if (addr == NULL) return -EINVAL; rte_eth_macaddr_get(port_id, addr); diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index a31018e..80adbd3 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -369,8 +369,8 @@ rte_eth_dev_is_valid_port(uint8_t port_id) int rte_eth_dev_socket_id(uint8_t port_id) { - if (!rte_eth_dev_is_valid_port(port_id)) - return -1; + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1); + return rte_eth_devices[port_id].data->numa_node; } @@ -383,8 +383,8 @@ rte_eth_dev_count(void) static enum rte_eth_dev_type rte_eth_dev_get_device_type(uint8_t port_id) { - if (!rte_eth_dev_is_valid_port(port_id)) - return RTE_ETH_DEV_UNKNOWN; + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, RTE_ETH_DEV_UNKNOWN); + return rte_eth_devices[port_id].dev_type; } @@ -479,10 +479,7 @@ rte_eth_dev_is_detachable(uint8_t port_id) { uint32_t dev_flags; - if (!rte_eth_dev_is_valid_port(port_id)) { - RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); - return -EINVAL; - } + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); switch (rte_eth_devices[port_id].data->kdrv) { case RTE_KDRV_IGB_UIO: @@ -1994,10 +1991,7 @@ rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_dev *dev; int ret; - if (port_id >= nb_ports) { - RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); - return -ENODEV; - } + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); /* Check mask bits */ ret = rte_eth_check_reta_mask(reta_conf, reta_size); @@ -2641,10 +2635,7 @@ rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data) uint16_t qid; int rc; - if (!rte_eth_dev_is_valid_port(port_id)) { - RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id); - return -ENODEV; - } + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; intr_handle = &dev->pci_dev->intr_handle; @@ -2699,10 +2690,7 @@ rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id, struct rte_intr_handle *intr_handle; int rc; - if (!rte_eth_dev_is_valid_port(port_id)) { - RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id); - return -ENODEV; - } + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; if (queue_id >= dev->data->nb_rx_queues) { @@ -2734,10 +2722,7 @@ rte_eth_dev_rx_intr_enable(uint8_t port_id, { struct rte_eth_dev *dev; - if (!rte_eth_dev_is_valid_port(port_id)) { - RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); - return -ENODEV; - } + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; @@ -2751,10 +2736,7 @@ rte_eth_dev_rx_intr_disable(uint8_t port_id, { struct rte_eth_dev *dev; - if (!rte_eth_dev_is_valid_port(port_id)) { - RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); - return -ENODEV; - } + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; @@ -3001,7 +2983,9 @@ rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id, return -ENOTSUP; #endif /* Check input parameters. */ - if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL || + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); + + if (user_cb == NULL || queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) { return -EINVAL; } @@ -3040,7 +3024,9 @@ rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id, return -ENOTSUP; #endif /* Check input parameters. */ - if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL || + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); + + if (user_cb == NULL || queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) { return -EINVAL; } @@ -3284,10 +3270,7 @@ rte_eth_dev_get_dcb_info(uint8_t port_id, { struct rte_eth_dev *dev; - if (!rte_eth_dev_is_valid_port(port_id)) { - RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); - return -ENODEV; - } + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));