[dpdk-dev,v3,4/4] ethdev: check driver support for functions

Message ID 1446552059-5446-5-git-send-email-bruce.richardson@intel.com (mailing list archive)
State Changes Requested, archived
Headers

Commit Message

Bruce Richardson Nov. 3, 2015, noon UTC
  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 <bruce.richardson@intel.com>
---
 lib/librte_ether/rte_ethdev.h | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
  

Comments

Stephen Hemminger Nov. 3, 2015, 10 p.m. UTC | #1
On Tue,  3 Nov 2015 12:00:59 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:

>  * @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

I think it should always check validity of portid/queueid
the check is very brief.
  
Bruce Richardson Nov. 4, 2015, 2:15 p.m. UTC | #2
On Tue, Nov 03, 2015 at 02:00:29PM -0800, Stephen Hemminger wrote:
> On Tue,  3 Nov 2015 12:00:59 +0000
> Bruce Richardson <bruce.richardson@intel.com> wrote:
> 
> >  * @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
> 
> I think it should always check validity of portid/queueid
> the check is very brief.

I would tend to agree. I'll add in the checks for the rx_queue_count and 
descriptor done calls, if there are no objections.

/Bruce
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 2b702c6..78267b0 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -2525,16 +2525,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);
 }
 
@@ -2551,6 +2553,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)
@@ -2558,8 +2561,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);
 }