ethdev: use dedicated macro to check port id

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>
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
This commit is contained in:
Mauricio Vasquez B 2016-05-18 21:15:11 +02:00 committed by Thomas Monjalon
parent e89880957f
commit 1414dabc1b
3 changed files with 21 additions and 52 deletions

View File

@ -60,18 +60,14 @@ check_for_bonded_ethdev(const struct rte_eth_dev *eth_dev)
int
valid_bonded_port_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 check_for_bonded_ethdev(&rte_eth_devices[port_id]);
}
int
valid_slave_port_id(uint8_t port_id)
{
/* Verify that port id's are valid */
if (!rte_eth_dev_is_valid_port(port_id))
return -1;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
/* Verify that port_id refers to a non bonded port */
if (check_for_bonded_ethdev(&rte_eth_devices[port_id]) == 0)

View File

@ -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,7 @@ 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 +265,7 @@ 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 +274,7 @@ 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);

View File

@ -369,8 +369,7 @@ 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 +382,7 @@ 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 +477,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 +1989,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 +2633,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 +2688,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 +2720,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 +2734,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,10 +2981,10 @@ 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 ||
queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
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;
}
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
@ -3040,10 +3020,10 @@ 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 ||
queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
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;
}
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
@ -3284,10 +3264,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));