From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9949CA04B7; Tue, 13 Oct 2020 13:51:31 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C491F1DADD; Tue, 13 Oct 2020 13:51:15 +0200 (CEST) Received: from incedge.chinasoftinc.com (unknown [114.113.233.8]) by dpdk.org (Postfix) with ESMTP id DDFDF1DADA for ; Tue, 13 Oct 2020 13:51:10 +0200 (CEST) X-ASG-Debug-ID: 1602589869-149d114caf207890001-TfluYd Received: from mail.chinasoftinc.com (inccas001.ito.icss [10.168.0.51]) by incedge.chinasoftinc.com with ESMTP id 1TqW1dgojW2HEi2r (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 13 Oct 2020 19:51:09 +0800 (CST) X-Barracuda-Envelope-From: huwei013@chinasoftinc.com X-Barracuda-RBL-Trusted-Forwarder: 10.168.0.51 X-ASG-Whitelist: Client Received: from localhost.localdomain (65.49.108.226) by INCCAS001.ito.icss (10.168.0.60) with Microsoft SMTP Server id 14.3.487.0; Tue, 13 Oct 2020 19:51:08 +0800 From: "Wei Hu (Xavier)" X-Barracuda-RBL-Trusted-Forwarder: 10.168.0.60 To: , , , , CC: Date: Tue, 13 Oct 2020 19:50:53 +0800 X-ASG-Orig-Subj: [PATCH v5 1/3] ethdev: extract checking queue id into common functions Message-ID: <20201013115055.34295-2-huwei013@chinasoftinc.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20201013115055.34295-1-huwei013@chinasoftinc.com> References: <20201010071212.24086-1-huwei013@chinasoftinc.com> <20201013115055.34295-1-huwei013@chinasoftinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [65.49.108.226] X-Barracuda-Connect: inccas001.ito.icss[10.168.0.51] X-Barracuda-Start-Time: 1602589869 X-Barracuda-Encrypted: ECDHE-RSA-AES256-SHA X-Barracuda-URL: https://incspam.chinasofti.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at chinasoftinc.com X-Barracuda-Scan-Msg-Size: 4783 Subject: [dpdk-dev] [PATCH v5 1/3] ethdev: extract checking queue id into common functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: "Wei Hu (Xavier)" This patch extact checking rx_queue_id or tx_queue_id into two separate common functions named eth_dev_validate_rx_queue and eth_dev_validate_tx_queue. Signed-off-by: Chengchang Tang Signed-off-by: Wei Hu (Xavier) Signed-off-by: Chengwen Feng Acked-by: Stephen Hemminger Reviewed-by: Kalesh AP --- v4 -> v5: 1. remove inline. 2. add 'const' to dev to highlight that it changes nothing. 3. RX -> Rx, TX -> Tx. 4. log port ID in the error branch. 5. 'if (ret)' -> 'if (ret != 0)' 6. split the original patch into three separate patches. v3 -> v4: 1. dropping the 'rte_' prefix from the funcitons names. 2. get "struct rte_eth_dev *dev" as parameter and drop the port_id validation in the function named eth_dev_validate_rx_queue and eth_dev_validate_tx_queue. 3. replace "setupped" with "setup" in the commit log and titile. v2 -> v3: don't break lines in format strings. v1 -> v2: 1. replace %"PRIu16" with %u. 2. extact two common functions which validate RXQ/TXQ ids and whether it has been set up or not. --- lib/librte_ethdev/rte_ethdev.c | 66 ++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 892c246..11e54d9 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -877,10 +877,43 @@ rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) return 0; } +static int +eth_dev_validate_rx_queue(const struct rte_eth_dev *dev, uint16_t rx_queue_id) +{ + uint16_t port_id; + + if (rx_queue_id >= dev->data->nb_rx_queues) { + port_id = dev->data->port_id; + RTE_ETHDEV_LOG(ERR, + "Invalid Rx queue_id=%u of device with port_id=%u\n", + rx_queue_id, port_id); + return -EINVAL; + } + + return 0; +} + +static int +eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id) +{ + uint16_t port_id; + + if (tx_queue_id >= dev->data->nb_tx_queues) { + port_id = dev->data->port_id; + RTE_ETHDEV_LOG(ERR, + "Invalid Tx queue_id=%u of device with port_id=%u\n", + tx_queue_id, port_id); + return -EINVAL; + } + + return 0; +} + int rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); @@ -892,10 +925,9 @@ rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id) return -EINVAL; } - if (rx_queue_id >= dev->data->nb_rx_queues) { - RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id); - return -EINVAL; - } + ret = eth_dev_validate_rx_queue(dev, rx_queue_id); + if (ret != 0) + return ret; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP); @@ -922,14 +954,15 @@ int rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); dev = &rte_eth_devices[port_id]; - if (rx_queue_id >= dev->data->nb_rx_queues) { - RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id); - return -EINVAL; - } + + ret = eth_dev_validate_rx_queue(dev, rx_queue_id); + if (ret != 0) + return ret; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP); @@ -955,6 +988,7 @@ int rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); @@ -966,10 +1000,9 @@ rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id) return -EINVAL; } - if (tx_queue_id >= dev->data->nb_tx_queues) { - RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id); - return -EINVAL; - } + ret = eth_dev_validate_tx_queue(dev, tx_queue_id); + if (ret != 0) + return ret; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP); @@ -994,14 +1027,15 @@ int rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); dev = &rte_eth_devices[port_id]; - if (tx_queue_id >= dev->data->nb_tx_queues) { - RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id); - return -EINVAL; - } + + ret = eth_dev_validate_tx_queue(dev, tx_queue_id); + if (ret != 0) + return ret; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP); -- 2.9.5