net/mlx4: refactor internal flow rules
[dpdk.git] / drivers / net / mlx4 / mlx4.c
index 317d0e6..40c0ee2 100644 (file)
@@ -44,7 +44,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 
 /* Verbs headers do not support -pedantic. */
 #ifdef PEDANTIC
@@ -88,8 +87,6 @@ const char *pmd_mlx4_init_params[] = {
 /**
  * DPDK callback for Ethernet device configuration.
  *
- * Prepare the driver for a given number of TX and RX queues.
- *
  * @param dev
  *   Pointer to Ethernet device structure.
  *
@@ -100,22 +97,14 @@ static int
 mlx4_dev_configure(struct rte_eth_dev *dev)
 {
        struct priv *priv = dev->data->dev_private;
-       unsigned int rxqs_n = dev->data->nb_rx_queues;
-       unsigned int txqs_n = dev->data->nb_tx_queues;
-
-       priv->rxqs = (void *)dev->data->rx_queues;
-       priv->txqs = (void *)dev->data->tx_queues;
-       if (txqs_n != priv->txqs_n) {
-               INFO("%p: TX queues number update: %u -> %u",
-                    (void *)dev, priv->txqs_n, txqs_n);
-               priv->txqs_n = txqs_n;
-       }
-       if (rxqs_n != priv->rxqs_n) {
-               INFO("%p: Rx queues number update: %u -> %u",
-                    (void *)dev, priv->rxqs_n, rxqs_n);
-               priv->rxqs_n = rxqs_n;
-       }
-       return 0;
+       int ret;
+
+       /* Prepare internal flow rules. */
+       ret = mlx4_flow_sync(priv);
+       if (ret)
+               ERROR("cannot set up internal flow rules: %s",
+                     strerror(-ret));
+       return ret;
 }
 
 /**
@@ -139,9 +128,6 @@ mlx4_dev_start(struct rte_eth_dev *dev)
                return 0;
        DEBUG("%p: attaching configured flows to all RX queues", (void *)dev);
        priv->started = 1;
-       ret = mlx4_mac_addr_add(priv);
-       if (ret)
-               goto err;
        ret = mlx4_intr_install(priv);
        if (ret) {
                ERROR("%p: interrupt handler installation failed",
@@ -157,7 +143,6 @@ mlx4_dev_start(struct rte_eth_dev *dev)
        return 0;
 err:
        /* Rollback. */
-       mlx4_mac_addr_del(priv);
        priv->started = 0;
        return ret;
 }
@@ -181,7 +166,6 @@ mlx4_dev_stop(struct rte_eth_dev *dev)
        priv->started = 0;
        mlx4_flow_stop(priv);
        mlx4_intr_uninstall(priv);
-       mlx4_mac_addr_del(priv);
 }
 
 /**
@@ -196,7 +180,6 @@ static void
 mlx4_dev_close(struct rte_eth_dev *dev)
 {
        struct priv *priv = dev->data->dev_private;
-       void *tmp;
        unsigned int i;
 
        if (priv == NULL)
@@ -204,42 +187,13 @@ mlx4_dev_close(struct rte_eth_dev *dev)
        DEBUG("%p: closing device \"%s\"",
              (void *)dev,
              ((priv->ctx != NULL) ? priv->ctx->device->name : ""));
-       mlx4_mac_addr_del(priv);
-       /*
-        * Prevent crashes when queues are still in use. This is unfortunately
-        * still required for DPDK 1.3 because some programs (such as testpmd)
-        * never release them before closing the device.
-        */
+       mlx4_flow_clean(priv);
        dev->rx_pkt_burst = mlx4_rx_burst_removed;
        dev->tx_pkt_burst = mlx4_tx_burst_removed;
-       if (priv->rxqs != NULL) {
-               /* XXX race condition if mlx4_rx_burst() is still running. */
-               usleep(1000);
-               for (i = 0; (i != priv->rxqs_n); ++i) {
-                       tmp = (*priv->rxqs)[i];
-                       if (tmp == NULL)
-                               continue;
-                       (*priv->rxqs)[i] = NULL;
-                       mlx4_rxq_cleanup(tmp);
-                       rte_free(tmp);
-               }
-               priv->rxqs_n = 0;
-               priv->rxqs = NULL;
-       }
-       if (priv->txqs != NULL) {
-               /* XXX race condition if mlx4_tx_burst() is still running. */
-               usleep(1000);
-               for (i = 0; (i != priv->txqs_n); ++i) {
-                       tmp = (*priv->txqs)[i];
-                       if (tmp == NULL)
-                               continue;
-                       (*priv->txqs)[i] = NULL;
-                       mlx4_txq_cleanup(tmp);
-                       rte_free(tmp);
-               }
-               priv->txqs_n = 0;
-               priv->txqs = NULL;
-       }
+       for (i = 0; i != dev->data->nb_rx_queues; ++i)
+               mlx4_rx_queue_release(dev->data->rx_queues[i]);
+       for (i = 0; i != dev->data->nb_tx_queues; ++i)
+               mlx4_tx_queue_release(dev->data->tx_queues[i]);
        if (priv->pd != NULL) {
                assert(priv->ctx != NULL);
                claim_zero(ibv_dealloc_pd(priv->pd));
@@ -590,8 +544,6 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                     mac.addr_bytes[4], mac.addr_bytes[5]);
                /* Register MAC address. */
                priv->mac = mac;
-               if (mlx4_mac_addr_add(priv))
-                       goto port_error;
 #ifndef NDEBUG
                {
                        char ifname[IF_NAMESIZE];