xen: allow determining DOM0 at runtime
[dpdk.git] / lib / librte_ether / rte_ethdev.c
index 56b97cc..0e41387 100644 (file)
@@ -427,7 +427,7 @@ rte_eth_dev_socket_id(uint8_t port_id)
 {
        if (!rte_eth_dev_is_valid_port(port_id))
                return -1;
-       return rte_eth_devices[port_id].pci_dev->numa_node;
+       return rte_eth_devices[port_id].data->numa_node;
 }
 
 uint8_t
@@ -533,27 +533,25 @@ rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
 static int
 rte_eth_dev_is_detachable(uint8_t port_id)
 {
-       uint32_t drv_flags;
+       uint32_t dev_flags;
 
        if (!rte_eth_dev_is_valid_port(port_id)) {
                PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
                return -EINVAL;
        }
 
-       if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
-               switch (rte_eth_devices[port_id].pci_dev->kdrv) {
-               case RTE_KDRV_IGB_UIO:
-               case RTE_KDRV_UIO_GENERIC:
-               case RTE_KDRV_NIC_UIO:
-                       break;
-               case RTE_KDRV_VFIO:
-               default:
-                       return -ENOTSUP;
-               }
+       switch (rte_eth_devices[port_id].data->kdrv) {
+       case RTE_KDRV_IGB_UIO:
+       case RTE_KDRV_UIO_GENERIC:
+       case RTE_KDRV_NIC_UIO:
+       case RTE_KDRV_NONE:
+               break;
+       case RTE_KDRV_VFIO:
+       default:
+               return -ENOTSUP;
        }
-
-       drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
-       return !(drv_flags & RTE_PCI_DRV_DETACHABLE);
+       dev_flags = rte_eth_devices[port_id].data->dev_flags;
+       return !(dev_flags & RTE_ETH_DEV_DETACHABLE);
 }
 
 /* attach the new physical device, then store port_id of the device */
@@ -780,6 +778,13 @@ rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
 
        FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
 
+       if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
+               PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
+                       " already started\n",
+                       rx_queue_id, port_id);
+               return 0;
+       }
+
        return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
 
 }
@@ -803,6 +808,13 @@ rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
 
        FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
 
+       if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
+               PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
+                       " already stopped\n",
+                       rx_queue_id, port_id);
+               return 0;
+       }
+
        return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
 
 }
@@ -826,6 +838,13 @@ rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
 
        FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
 
+       if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
+               PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
+                       " already started\n",
+                       tx_queue_id, port_id);
+               return 0;
+       }
+
        return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
 
 }
@@ -849,6 +868,13 @@ rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
 
        FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
 
+       if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
+               PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
+                       " already stopped\n",
+                       tx_queue_id, port_id);
+               return 0;
+       }
+
        return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
 
 }
@@ -965,14 +991,11 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
         * If link state interrupt is enabled, check that the
         * device supports it.
         */
-       if (dev_conf->intr_conf.lsc == 1) {
-               const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
-
-               if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
+       if ((dev_conf->intr_conf.lsc == 1) &&
+               (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
                        PMD_DEBUG_TRACE("driver %s does not support lsc\n",
-                                       pci_drv->name);
+                                       dev->data->drv_name);
                        return -EINVAL;
-               }
        }
 
        /*
@@ -1114,7 +1137,7 @@ rte_eth_dev_start(uint8_t port_id)
 
        rte_eth_dev_config_restore(port_id);
 
-       if (dev->data->dev_conf.intr_conf.lsc != 0) {
+       if (dev->data->dev_conf.intr_conf.lsc == 0) {
                FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
                (*dev->dev_ops->link_update)(dev, 0);
        }
@@ -1492,7 +1515,8 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
        dev = &rte_eth_devices[port_id];
 
        /* Return generic statistics */
-       count = RTE_NB_STATS;
+       count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
+               (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
 
        /* implemented by the driver */
        if (dev->dev_ops->xstats_get != NULL) {
@@ -1504,9 +1528,6 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 
                if (xcount < 0)
                        return xcount;
-       } else {
-               count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
-               count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
        }
 
        if (n < count + xcount)
@@ -1526,10 +1547,6 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
                xstats[count++].value = val;
        }
 
-       /* if xstats_get() is implemented by the PMD, the Q stats are done */
-       if (dev->dev_ops->xstats_get != NULL)
-               return count + xcount;
-
        /* per-rxq stats */
        for (q = 0; q < dev->data->nb_rx_queues; q++) {
                for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
@@ -1634,8 +1651,7 @@ rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
        FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
        (*dev->dev_ops->dev_infos_get)(dev, dev_info);
        dev_info->pci_dev = dev->pci_dev;
-       if (dev->driver)
-               dev_info->driver_name = dev->driver->pci_drv.name;
+       dev_info->driver_name = dev->data->drv_name;
 }
 
 void
@@ -2678,6 +2694,30 @@ rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
        return 0;
 }
 
+const struct rte_memzone *
+rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
+                        uint16_t queue_id, size_t size, unsigned align,
+                        int socket_id)
+{
+       char z_name[RTE_MEMZONE_NAMESIZE];
+       const struct rte_memzone *mz;
+
+       snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
+                dev->driver->pci_drv.name, ring_name,
+                dev->data->port_id, queue_id);
+
+       mz = rte_memzone_lookup(z_name);
+       if (mz)
+               return mz;
+
+       if (is_xen_dom0_supported())
+               return rte_memzone_reserve_bounded(z_name, size, socket_id,
+                                                  0, align, RTE_PGSIZE_2M);
+       else
+               return rte_memzone_reserve_aligned(z_name, size, socket_id,
+                                                  0, align);
+}
+
 int
 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
                          int epfd, int op, void *data)
@@ -3254,6 +3294,7 @@ rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_de
        if ((eth_dev == NULL) || (pci_dev == NULL)) {
                PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
                                eth_dev, pci_dev);
+               return;
        }
 
        eth_dev->data->dev_flags = 0;