DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
@ 2016-04-29 15:23 Mauricio Vasquez B
  2016-05-13 16:20 ` Thomas Monjalon
  2016-05-17 20:01 ` [dpdk-dev] [PATCH v2] " Mauricio Vasquez B
  0 siblings, 2 replies; 12+ messages in thread
From: Mauricio Vasquez B @ 2016-04-29 15:23 UTC (permalink / raw)
  To: thomas.monjalon; +Cc: 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 <mauricio.vasquezbernal@studenti.polito.it>
---
 lib/librte_ether/rte_ethdev.c | 39 +++++++++------------------------------
 1 file changed, 9 insertions(+), 30 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index a31018e..bf9d4d2 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -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];
 
@@ -3284,10 +3266,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));
-- 
1.9.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-04-29 15:23 [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id Mauricio Vasquez B
@ 2016-05-13 16:20 ` Thomas Monjalon
  2016-05-17 20:02   ` Mauricio Vásquez
  2016-05-17 20:01 ` [dpdk-dev] [PATCH v2] " Mauricio Vasquez B
  1 sibling, 1 reply; 12+ messages in thread
From: Thomas Monjalon @ 2016-05-13 16:20 UTC (permalink / raw)
  To: Mauricio Vasquez B; +Cc: dev

2016-04-29 17:23, Mauricio Vasquez B:
> 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.

There are other occurences:
	rte_eth_dev_socket_id
	rte_eth_add_rx_callback
	rte_eth_add_tx_callback
	rte_eth_remove_rx_callback
	rte_eth_remove_tx_callback
I think it could be done also in examples/ethtool/lib.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [dpdk-dev] [PATCH v2] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-04-29 15:23 [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id Mauricio Vasquez B
  2016-05-13 16:20 ` Thomas Monjalon
@ 2016-05-17 20:01 ` Mauricio Vasquez B
  2016-05-18 19:15   ` [dpdk-dev] [PATCH v3] " Mauricio Vasquez B
  1 sibling, 1 reply; 12+ messages in thread
From: Mauricio Vasquez B @ 2016-05-17 20:01 UTC (permalink / raw)
  To: thomas.monjalon; +Cc: 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 <mauricio.vasquezbernal@studenti.polito.it>
---
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      | 43 ++++++++++----------------------------
 2 files changed, 18 insertions(+), 40 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..4c06fb4 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];
 
@@ -3284,10 +3266,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));
-- 
1.9.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-05-13 16:20 ` Thomas Monjalon
@ 2016-05-17 20:02   ` Mauricio Vásquez
  2016-05-18  8:15     ` Thomas Monjalon
  0 siblings, 1 reply; 12+ messages in thread
From: Mauricio Vásquez @ 2016-05-17 20:02 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

Hello Thomas,



On Fri, May 13, 2016 at 6:20 PM, Thomas Monjalon <thomas.monjalon@6wind.com>
wrote:

> 2016-04-29 17:23, Mauricio Vasquez B:
> > 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.
>
> There are other occurences:
>         rte_eth_dev_socket_id
>
I missed it.

>         rte_eth_add_rx_callback
>         rte_eth_add_tx_callback
>         rte_eth_remove_rx_callback
>         rte_eth_remove_tx_callback
>
The macro can not be used on those ones because they set the rte_errno
variable before returning.

> I think it could be done also in examples/ethtool/lib.
>
I'll send v2 including that one.

Mauricio V,

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-05-17 20:02   ` Mauricio Vásquez
@ 2016-05-18  8:15     ` Thomas Monjalon
  2016-05-18 14:41       ` Mauricio Vásquez
  0 siblings, 1 reply; 12+ messages in thread
From: Thomas Monjalon @ 2016-05-18  8:15 UTC (permalink / raw)
  To: Mauricio Vásquez; +Cc: dev

2016-05-17 22:02, Mauricio Vásquez:
> On Fri, May 13, 2016 at 6:20 PM, Thomas Monjalon <thomas.monjalon@6wind.com>
> wrote:
> > 2016-04-29 17:23, Mauricio Vasquez B:
> > > 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.
> >
> > There are other occurences:
> >         rte_eth_dev_socket_id
> >
> I missed it.
> 
> >         rte_eth_add_rx_callback
> >         rte_eth_add_tx_callback
> >         rte_eth_remove_rx_callback
> >         rte_eth_remove_tx_callback
> >
> The macro can not be used on those ones because they set the rte_errno
> variable before returning.

It may be a good idea to set rte_errno to EINVAL in these macros.

Generally speaking, rte_errno is not used a lot currently.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-05-18  8:15     ` Thomas Monjalon
@ 2016-05-18 14:41       ` Mauricio Vásquez
  2016-05-18 15:01         ` Thomas Monjalon
  0 siblings, 1 reply; 12+ messages in thread
From: Mauricio Vásquez @ 2016-05-18 14:41 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

On Wed, May 18, 2016 at 10:15 AM, Thomas Monjalon <thomas.monjalon@6wind.com
> wrote:

> 2016-05-17 22:02, Mauricio Vásquez:
> > On Fri, May 13, 2016 at 6:20 PM, Thomas Monjalon <
> thomas.monjalon@6wind.com>
> > wrote:
> > > 2016-04-29 17:23, Mauricio Vasquez B:
> > > > 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.
> > >
> > > There are other occurences:
> > >         rte_eth_dev_socket_id
> > >
> > I missed it.
> >
> > >         rte_eth_add_rx_callback
> > >         rte_eth_add_tx_callback
> > >         rte_eth_remove_rx_callback
> > >         rte_eth_remove_tx_callback
> > >
> > The macro can not be used on those ones because they set the rte_errno
> > variable before returning.
>
> It may be a good idea to set rte_errno to EINVAL in these macros.
>
> Generally speaking, rte_errno is not used a lot currently.


I noticed that both EINVAL and ENODEV are used. I think that returning
ENODEV and setting rte_errno to EINVAL would be strange, what do you think
about always using ENODEV?

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-05-18 14:41       ` Mauricio Vásquez
@ 2016-05-18 15:01         ` Thomas Monjalon
  2016-05-18 15:25           ` Mauricio Vásquez
  0 siblings, 1 reply; 12+ messages in thread
From: Thomas Monjalon @ 2016-05-18 15:01 UTC (permalink / raw)
  To: Mauricio Vásquez; +Cc: dev

2016-05-18 16:41, Mauricio Vásquez:
> On Wed, May 18, 2016 at 10:15 AM, Thomas Monjalon <thomas.monjalon@6wind.com
> > wrote:
> 
> > 2016-05-17 22:02, Mauricio Vásquez:
> > > On Fri, May 13, 2016 at 6:20 PM, Thomas Monjalon <
> > thomas.monjalon@6wind.com>
> > > wrote:
> > > > 2016-04-29 17:23, Mauricio Vasquez B:
> > > > > 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.
> > > >
> > > > There are other occurences:
> > > >         rte_eth_dev_socket_id
> > > >
> > > I missed it.
> > >
> > > >         rte_eth_add_rx_callback
> > > >         rte_eth_add_tx_callback
> > > >         rte_eth_remove_rx_callback
> > > >         rte_eth_remove_tx_callback
> > > >
> > > The macro can not be used on those ones because they set the rte_errno
> > > variable before returning.
> >
> > It may be a good idea to set rte_errno to EINVAL in these macros.
> >
> > Generally speaking, rte_errno is not used a lot currently.
> 
> 
> I noticed that both EINVAL and ENODEV are used. I think that returning
> ENODEV and setting rte_errno to EINVAL would be strange, what do you think
> about always using ENODEV?

Why EINVAL is used?
Why not using retval to set errno?
I feel ENODEV would be better but it is an API change, so we should discuss
it later for another patch.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-05-18 15:01         ` Thomas Monjalon
@ 2016-05-18 15:25           ` Mauricio Vásquez
  2016-05-18 15:43             ` Thomas Monjalon
  0 siblings, 1 reply; 12+ messages in thread
From: Mauricio Vásquez @ 2016-05-18 15:25 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

On Wed, May 18, 2016 at 5:01 PM, Thomas Monjalon <thomas.monjalon@6wind.com>
wrote:

> 2016-05-18 16:41, Mauricio Vásquez:
> > On Wed, May 18, 2016 at 10:15 AM, Thomas Monjalon <
> thomas.monjalon@6wind.com
> > > wrote:
> >
> > > 2016-05-17 22:02, Mauricio Vásquez:
> > > > On Fri, May 13, 2016 at 6:20 PM, Thomas Monjalon <
> > > thomas.monjalon@6wind.com>
> > > > wrote:
> > > > > 2016-04-29 17:23, Mauricio Vasquez B:
> > > > > > 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.
> > > > >
> > > > > There are other occurences:
> > > > >         rte_eth_dev_socket_id
> > > > >
> > > > I missed it.
> > > >
> > > > >         rte_eth_add_rx_callback
> > > > >         rte_eth_add_tx_callback
> > > > >         rte_eth_remove_rx_callback
> > > > >         rte_eth_remove_tx_callback
> > > > >
> > > > The macro can not be used on those ones because they set the
> rte_errno
> > > > variable before returning.
> > >
> > > It may be a good idea to set rte_errno to EINVAL in these macros.
> > >
> > > Generally speaking, rte_errno is not used a lot currently.
> >
> >
> > I noticed that both EINVAL and ENODEV are used. I think that returning
> > ENODEV and setting rte_errno to EINVAL would be strange, what do you
> think
> > about always using ENODEV?
>
> Why EINVAL is used?
>
Why not using retval to set errno?
>

If we do it, the macro could no be used in
 rte_eth_dev_socket_id
 rte_eth_dev_get_device_type
 rte_eth_add_rx_callback
 rte_eth_add_tx_callback
 rte_eth_remove_rx_callback
 rte_eth_remove_tx_callback
as they do not return an error number.

I feel ENODEV would be better but it is an API change, so we should discuss
> it later for another patch.
>

I agree

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-05-18 15:25           ` Mauricio Vásquez
@ 2016-05-18 15:43             ` Thomas Monjalon
  2016-05-18 19:14               ` Mauricio Vásquez
  0 siblings, 1 reply; 12+ messages in thread
From: Thomas Monjalon @ 2016-05-18 15:43 UTC (permalink / raw)
  To: Mauricio Vásquez; +Cc: dev

2016-05-18 17:25, Mauricio Vásquez:
> On Wed, May 18, 2016 at 5:01 PM, Thomas Monjalon <thomas.monjalon@6wind.com>
> wrote:
> 
> > 2016-05-18 16:41, Mauricio Vásquez:
> > > On Wed, May 18, 2016 at 10:15 AM, Thomas Monjalon <
> > thomas.monjalon@6wind.com
> > > > wrote:
> > >
> > > > 2016-05-17 22:02, Mauricio Vásquez:
> > > > > On Fri, May 13, 2016 at 6:20 PM, Thomas Monjalon <
> > > > thomas.monjalon@6wind.com>
> > > > > wrote:
> > > > > > 2016-04-29 17:23, Mauricio Vasquez B:
> > > > > > > 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.
> > > > > >
> > > > > > There are other occurences:
> > > > > >         rte_eth_dev_socket_id
> > > > > >
> > > > > I missed it.
> > > > >
> > > > > >         rte_eth_add_rx_callback
> > > > > >         rte_eth_add_tx_callback
> > > > > >         rte_eth_remove_rx_callback
> > > > > >         rte_eth_remove_tx_callback
> > > > > >
> > > > > The macro can not be used on those ones because they set the
> > rte_errno
> > > > > variable before returning.
> > > >
> > > > It may be a good idea to set rte_errno to EINVAL in these macros.
> > > >
> > > > Generally speaking, rte_errno is not used a lot currently.
> > >
> > >
> > > I noticed that both EINVAL and ENODEV are used. I think that returning
> > > ENODEV and setting rte_errno to EINVAL would be strange, what do you
> > think
> > > about always using ENODEV?
> >
> > Why EINVAL is used?
> >
> Why not using retval to set errno?
> >
> 
> If we do it, the macro could no be used in
>  rte_eth_dev_socket_id
>  rte_eth_dev_get_device_type
>  rte_eth_add_rx_callback
>  rte_eth_add_tx_callback
>  rte_eth_remove_rx_callback
>  rte_eth_remove_tx_callback
> as they do not return an error number.

So you should not set errno in the existing macro.
But you can create a new macro RTE_ETH_VALID_PORTID_OR_ERRNO_RET
for these functions.

> I feel ENODEV would be better but it is an API change, so we should discuss
> > it later for another patch.

It looks to be really needed to have an unique kind of error interface to
clean all this mess.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-05-18 15:43             ` Thomas Monjalon
@ 2016-05-18 19:14               ` Mauricio Vásquez
  0 siblings, 0 replies; 12+ messages in thread
From: Mauricio Vásquez @ 2016-05-18 19:14 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

On Wed, May 18, 2016 at 5:43 PM, Thomas Monjalon <thomas.monjalon@6wind.com>
wrote:

> 2016-05-18 17:25, Mauricio Vásquez:
> > On Wed, May 18, 2016 at 5:01 PM, Thomas Monjalon <
> thomas.monjalon@6wind.com>
> > wrote:
> >
> > > 2016-05-18 16:41, Mauricio Vásquez:
> > > > On Wed, May 18, 2016 at 10:15 AM, Thomas Monjalon <
> > > thomas.monjalon@6wind.com
> > > > > wrote:
> > > >
> > > > > 2016-05-17 22:02, Mauricio Vásquez:
> > > > > > On Fri, May 13, 2016 at 6:20 PM, Thomas Monjalon <
> > > > > thomas.monjalon@6wind.com>
> > > > > > wrote:
> > > > > > > 2016-04-29 17:23, Mauricio Vasquez B:
> > > > > > > > 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.
> > > > > > >
> > > > > > > There are other occurences:
> > > > > > >         rte_eth_dev_socket_id
> > > > > > >
> > > > > > I missed it.
> > > > > >
> > > > > > >         rte_eth_add_rx_callback
> > > > > > >         rte_eth_add_tx_callback
> > > > > > >         rte_eth_remove_rx_callback
> > > > > > >         rte_eth_remove_tx_callback
> > > > > > >
> > > > > > The macro can not be used on those ones because they set the
> > > rte_errno
> > > > > > variable before returning.
> > > > >
> > > > > It may be a good idea to set rte_errno to EINVAL in these macros.
> > > > >
> > > > > Generally speaking, rte_errno is not used a lot currently.
> > > >
> > > >
> > > > I noticed that both EINVAL and ENODEV are used. I think that
> returning
> > > > ENODEV and setting rte_errno to EINVAL would be strange, what do you
> > > think
> > > > about always using ENODEV?
> > >
> > > Why EINVAL is used?
> > >
> > Why not using retval to set errno?
> > >
> >
> > If we do it, the macro could no be used in
> >  rte_eth_dev_socket_id
> >  rte_eth_dev_get_device_type
> >  rte_eth_add_rx_callback
> >  rte_eth_add_tx_callback
> >  rte_eth_remove_rx_callback
> >  rte_eth_remove_tx_callback
> > as they do not return an error number.
>
> So you should not set errno in the existing macro.
> But you can create a new macro RTE_ETH_VALID_PORTID_OR_ERRNO_RET
> for these functions.
>
> I realized that RTE_ETH_VALID_PORTID_OR_ERR_RET can be used also in
rte_eth_remove_rx_callback and rte_eth_remove_tx_callback.

Personally I think it is not worthy to create a macro just for the two
missing functions.


> > I feel ENODEV would be better but it is an API change, so we should
> discuss
> > > it later for another patch.
>
> It looks to be really needed to have an unique kind of error interface to
> clean all this mess.
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [dpdk-dev] [PATCH v3] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-05-17 20:01 ` [dpdk-dev] [PATCH v2] " Mauricio Vasquez B
@ 2016-05-18 19:15   ` Mauricio Vasquez B
  2016-05-24 13:31     ` Thomas Monjalon
  0 siblings, 1 reply; 12+ messages in thread
From: Mauricio Vasquez B @ 2016-05-18 19:15 UTC (permalink / raw)
  To: thomas.monjalon; +Cc: 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 <mauricio.vasquezbernal@studenti.polito.it>
---
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));
-- 
1.9.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [dpdk-dev] [PATCH v3] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id
  2016-05-18 19:15   ` [dpdk-dev] [PATCH v3] " Mauricio Vasquez B
@ 2016-05-24 13:31     ` Thomas Monjalon
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Monjalon @ 2016-05-24 13:31 UTC (permalink / raw)
  To: Mauricio Vasquez B; +Cc: dev

2016-05-18 21:15, Mauricio Vasquez B:
> 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 <mauricio.vasquezbernal@studenti.polito.it>
> ---
> 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(-)

I've fixed also 2 bond functions and removed some whitespace changes.
Applied, thanks

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-05-24 13:32 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-29 15:23 [dpdk-dev] [PATCH] librte_ether: use RTE_ETH_VALID_PORTID_OR_ERR_RET to check port_id Mauricio Vasquez B
2016-05-13 16:20 ` Thomas Monjalon
2016-05-17 20:02   ` Mauricio Vásquez
2016-05-18  8:15     ` Thomas Monjalon
2016-05-18 14:41       ` Mauricio Vásquez
2016-05-18 15:01         ` Thomas Monjalon
2016-05-18 15:25           ` Mauricio Vásquez
2016-05-18 15:43             ` Thomas Monjalon
2016-05-18 19:14               ` Mauricio Vásquez
2016-05-17 20:01 ` [dpdk-dev] [PATCH v2] " Mauricio Vasquez B
2016-05-18 19:15   ` [dpdk-dev] [PATCH v3] " Mauricio Vasquez B
2016-05-24 13:31     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).