ethdev: remove PCI helper from generic ethdev header
[dpdk.git] / lib / librte_ether / rte_ethdev.c
index 6bd7b26..a87ddd9 100644 (file)
@@ -138,10 +138,18 @@ enum {
        STAT_QMAP_RX
 };
 
-enum {
-       DEV_DETACHED = 0,
-       DEV_ATTACHED
-};
+uint8_t
+rte_eth_find_next(uint8_t port_id)
+{
+       while (port_id < RTE_MAX_ETHPORTS &&
+              rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
+               port_id++;
+
+       if (port_id >= RTE_MAX_ETHPORTS)
+               return RTE_MAX_ETHPORTS;
+
+       return port_id;
+}
 
 static void
 rte_eth_dev_data_alloc(void)
@@ -170,7 +178,7 @@ rte_eth_dev_allocated(const char *name)
        unsigned i;
 
        for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-               if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
+               if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
                    strcmp(rte_eth_devices[i].data->name, name) == 0)
                        return &rte_eth_devices[i];
        }
@@ -183,7 +191,7 @@ rte_eth_dev_find_free_port(void)
        unsigned i;
 
        for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-               if (rte_eth_devices[i].attached == DEV_DETACHED)
+               if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
                        return i;
        }
        return RTE_MAX_ETHPORTS;
@@ -195,7 +203,7 @@ eth_dev_get(uint8_t port_id)
        struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
 
        eth_dev->data = &rte_eth_dev_data[port_id];
-       eth_dev->attached = DEV_ATTACHED;
+       eth_dev->state = RTE_ETH_DEV_ATTACHED;
        TAILQ_INIT(&(eth_dev->link_intr_cbs));
 
        eth_dev_last_created_port = port_id;
@@ -239,8 +247,8 @@ rte_eth_dev_allocate(const char *name)
  * makes sure that the same device would have the same port id both
  * in the primary and secondary process.
  */
-static struct rte_eth_dev *
-eth_dev_attach_secondary(const char *name)
+struct rte_eth_dev *
+rte_eth_dev_attach_secondary(const char *name)
 {
        uint8_t i;
        struct rte_eth_dev *eth_dev;
@@ -271,113 +279,16 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
        if (eth_dev == NULL)
                return -EINVAL;
 
-       eth_dev->attached = DEV_DETACHED;
+       eth_dev->state = RTE_ETH_DEV_UNUSED;
        nb_ports--;
        return 0;
 }
 
-int
-rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
-                     struct rte_pci_device *pci_dev)
-{
-       struct eth_driver    *eth_drv;
-       struct rte_eth_dev *eth_dev;
-       char ethdev_name[RTE_ETH_NAME_MAX_LEN];
-
-       int diag;
-
-       eth_drv = (struct eth_driver *)pci_drv;
-
-       rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
-                       sizeof(ethdev_name));
-
-       if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-               eth_dev = rte_eth_dev_allocate(ethdev_name);
-               if (eth_dev == NULL)
-                       return -ENOMEM;
-
-               eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
-                                 eth_drv->dev_private_size,
-                                 RTE_CACHE_LINE_SIZE);
-               if (eth_dev->data->dev_private == NULL)
-                       rte_panic("Cannot allocate memzone for private port data\n");
-       } else {
-               eth_dev = eth_dev_attach_secondary(ethdev_name);
-               if (eth_dev == NULL) {
-                       /*
-                        * if we failed to attach a device, it means the
-                        * device is skipped in primary process, due to
-                        * some errors. If so, we return a positive value,
-                        * to let EAL skip it for the secondary process
-                        * as well.
-                        */
-                       return 1;
-               }
-       }
-       eth_dev->device = &pci_dev->device;
-       eth_dev->intr_handle = &pci_dev->intr_handle;
-       eth_dev->driver = eth_drv;
-
-       /* Invoke PMD device initialization function */
-       diag = (*eth_drv->eth_dev_init)(eth_dev);
-       if (diag == 0)
-               return 0;
-
-       RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%x device_id=0x%x) failed\n",
-                       pci_drv->driver.name,
-                       (unsigned) pci_dev->id.vendor_id,
-                       (unsigned) pci_dev->id.device_id);
-       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-               rte_free(eth_dev->data->dev_private);
-       rte_eth_dev_release_port(eth_dev);
-       return diag;
-}
-
-int
-rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
-{
-       const struct eth_driver *eth_drv;
-       struct rte_eth_dev *eth_dev;
-       char ethdev_name[RTE_ETH_NAME_MAX_LEN];
-       int ret;
-
-       if (pci_dev == NULL)
-               return -EINVAL;
-
-       rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
-                       sizeof(ethdev_name));
-
-       eth_dev = rte_eth_dev_allocated(ethdev_name);
-       if (eth_dev == NULL)
-               return -ENODEV;
-
-       eth_drv = (const struct eth_driver *)pci_dev->driver;
-
-       /* Invoke PMD device uninit function */
-       if (*eth_drv->eth_dev_uninit) {
-               ret = (*eth_drv->eth_dev_uninit)(eth_dev);
-               if (ret)
-                       return ret;
-       }
-
-       /* free ether device */
-       rte_eth_dev_release_port(eth_dev);
-
-       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-               rte_free(eth_dev->data->dev_private);
-
-       eth_dev->device = NULL;
-       eth_dev->driver = NULL;
-       eth_dev->data = NULL;
-
-       return 0;
-}
-
 int
 rte_eth_dev_is_valid_port(uint8_t port_id)
 {
        if (port_id >= RTE_MAX_ETHPORTS ||
-           rte_eth_devices[port_id].attached != DEV_ATTACHED)
+           rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
                return 0;
        else
                return 1;
@@ -429,9 +340,7 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
                return -ENODEV;
 
        *port_id = RTE_MAX_ETHPORTS;
-
-       for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-
+       RTE_ETH_FOREACH_DEV(i) {
                if (!strncmp(name,
                        rte_eth_dev_data[i].name, strlen(name))) {
 
@@ -455,8 +364,8 @@ rte_eth_dev_is_detachable(uint8_t port_id)
        case RTE_KDRV_UIO_GENERIC:
        case RTE_KDRV_NIC_UIO:
        case RTE_KDRV_NONE:
-               break;
        case RTE_KDRV_VFIO:
+               break;
        default:
                return -ENOTSUP;
        }
@@ -1275,6 +1184,20 @@ rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
        return ret;
 }
 
+int
+rte_eth_tx_done_cleanup(uint8_t port_id, uint16_t queue_id, uint32_t free_cnt)
+{
+       struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+
+       /* Validate Input Data. Bail if not valid or not supported. */
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
+
+       /* Call driver to free pending mbufs. */
+       return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
+                       free_cnt);
+}
+
 void
 rte_eth_promiscuous_enable(uint8_t port_id)
 {
@@ -1935,13 +1858,7 @@ rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
        if (!reta_conf)
                return -EINVAL;
 
-       if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
-               RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
-                                                       RTE_RETA_GROUP_SIZE);
-               return -EINVAL;
-       }
-
-       num = reta_size / RTE_RETA_GROUP_SIZE;
+       num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
        for (i = 0; i < num; i++) {
                if (reta_conf[i].mask)
                        return 0;
@@ -2370,7 +2287,7 @@ rte_eth_mirror_rule_set(uint8_t port_id,
                        struct rte_eth_mirror_conf *mirror_conf,
                        uint8_t rule_id, uint8_t on)
 {
-       struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+       struct rte_eth_dev *dev;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        if (mirror_conf->rule_type == 0) {
@@ -2406,7 +2323,7 @@ rte_eth_mirror_rule_set(uint8_t port_id,
 int
 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
 {
-       struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+       struct rte_eth_dev *dev;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 
@@ -2513,7 +2430,7 @@ _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
                dev_cb = *cb_lst;
                cb_lst->active = 1;
                if (cb_arg != NULL)
-                       dev_cb.cb_arg = (void *) cb_arg;
+                       dev_cb.cb_arg = cb_arg;
 
                rte_spinlock_unlock(&rte_eth_dev_cb_lock);
                dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
@@ -3200,26 +3117,6 @@ rte_eth_dev_get_dcb_info(uint8_t port_id,
        return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
 }
 
-void
-rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
-{
-       if ((eth_dev == NULL) || (pci_dev == NULL)) {
-               RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
-                               eth_dev, pci_dev);
-               return;
-       }
-
-       eth_dev->intr_handle = &pci_dev->intr_handle;
-
-       eth_dev->data->dev_flags = 0;
-       if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
-               eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
-
-       eth_dev->data->kdrv = pci_dev->kdrv;
-       eth_dev->data->numa_node = pci_dev->device.numa_node;
-       eth_dev->data->drv_name = pci_dev->driver->driver.name;
-}
-
 int
 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
                                    struct rte_eth_l2_tunnel_conf *l2_tunnel)