i40evf: support Rx interrupt
[dpdk.git] / drivers / net / mlx5 / mlx5.c
index ddd74d0..821ee0f 100644 (file)
@@ -65,6 +65,7 @@
 #include "mlx5_utils.h"
 #include "mlx5_rxtx.h"
 #include "mlx5_autoconf.h"
+#include "mlx5_defs.h"
 
 /**
  * DPDK callback to close the device.
@@ -85,6 +86,12 @@ mlx5_dev_close(struct rte_eth_dev *dev)
        DEBUG("%p: closing device \"%s\"",
              (void *)dev,
              ((priv->ctx != NULL) ? priv->ctx->device->name : ""));
+       /* In case mlx5_dev_stop() has not been called. */
+       priv_dev_interrupt_handler_uninstall(priv, dev);
+       priv_allmulticast_disable(priv);
+       priv_promiscuous_disable(priv);
+       priv_mac_addrs_disable(priv);
+       priv_destroy_hash_rxqs(priv);
        /* Prevent crashes when queues are still in use. */
        dev->rx_pkt_burst = removed_rx_burst;
        dev->tx_pkt_burst = removed_tx_burst;
@@ -116,14 +123,19 @@ mlx5_dev_close(struct rte_eth_dev *dev)
                priv->txqs_n = 0;
                priv->txqs = NULL;
        }
-       if (priv->rss)
-               rxq_cleanup(&priv->rxq_parent);
        if (priv->pd != NULL) {
                assert(priv->ctx != NULL);
                claim_zero(ibv_dealloc_pd(priv->pd));
                claim_zero(ibv_close_device(priv->ctx));
        } else
                assert(priv->ctx == NULL);
+       if (priv->rss_conf != NULL) {
+               for (i = 0; (i != hash_rxq_init_n); ++i)
+                       rte_free((*priv->rss_conf)[i]);
+               rte_free(priv->rss_conf);
+       }
+       if (priv->reta_idx != NULL)
+               rte_free(priv->reta_idx);
        priv_unlock(priv);
        memset(priv, 0, sizeof(*priv));
 }
@@ -133,14 +145,28 @@ static const struct eth_dev_ops mlx5_dev_ops = {
        .dev_start = mlx5_dev_start,
        .dev_stop = mlx5_dev_stop,
        .dev_close = mlx5_dev_close,
+       .promiscuous_enable = mlx5_promiscuous_enable,
+       .promiscuous_disable = mlx5_promiscuous_disable,
+       .allmulticast_enable = mlx5_allmulticast_enable,
+       .allmulticast_disable = mlx5_allmulticast_disable,
+       .link_update = mlx5_link_update,
+       .stats_get = mlx5_stats_get,
+       .stats_reset = mlx5_stats_reset,
        .dev_infos_get = mlx5_dev_infos_get,
+       .vlan_filter_set = mlx5_vlan_filter_set,
        .rx_queue_setup = mlx5_rx_queue_setup,
        .tx_queue_setup = mlx5_tx_queue_setup,
        .rx_queue_release = mlx5_rx_queue_release,
        .tx_queue_release = mlx5_tx_queue_release,
+       .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
+       .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
        .mac_addr_remove = mlx5_mac_addr_remove,
        .mac_addr_add = mlx5_mac_addr_add,
        .mtu_set = mlx5_dev_set_mtu,
+       .reta_update = mlx5_dev_rss_reta_update,
+       .reta_query = mlx5_dev_rss_reta_query,
+       .rss_hash_update = mlx5_rss_hash_update,
+       .rss_hash_conf_get = mlx5_rss_hash_conf_get,
 };
 
 static struct {
@@ -286,10 +312,9 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                struct ether_addr mac;
 
 #ifdef HAVE_EXP_QUERY_DEVICE
-               exp_device_attr.comp_mask = IBV_EXP_DEVICE_ATTR_EXP_CAP_FLAGS;
-#ifdef RSS_SUPPORT
-               exp_device_attr.comp_mask |= IBV_EXP_DEVICE_ATTR_RSS_TBL_SZ;
-#endif /* RSS_SUPPORT */
+               exp_device_attr.comp_mask =
+                       IBV_EXP_DEVICE_ATTR_EXP_CAP_FLAGS |
+                       IBV_EXP_DEVICE_ATTR_RX_HASH;
 #endif /* HAVE_EXP_QUERY_DEVICE */
 
                DEBUG("using port %u (%08" PRIx32 ")", port, test);
@@ -339,32 +364,6 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                        ERROR("ibv_exp_query_device() failed");
                        goto port_error;
                }
-#ifdef RSS_SUPPORT
-               if ((exp_device_attr.exp_device_cap_flags &
-                    IBV_EXP_DEVICE_QPG) &&
-                   (exp_device_attr.exp_device_cap_flags &
-                    IBV_EXP_DEVICE_UD_RSS) &&
-                   (exp_device_attr.comp_mask &
-                    IBV_EXP_DEVICE_ATTR_RSS_TBL_SZ) &&
-                   (exp_device_attr.max_rss_tbl_sz > 0)) {
-                       priv->hw_qpg = 1;
-                       priv->hw_rss = 1;
-                       priv->max_rss_tbl_sz = exp_device_attr.max_rss_tbl_sz;
-               } else {
-                       priv->hw_qpg = 0;
-                       priv->hw_rss = 0;
-                       priv->max_rss_tbl_sz = 0;
-               }
-               priv->hw_tss = !!(exp_device_attr.exp_device_cap_flags &
-                                 IBV_EXP_DEVICE_UD_TSS);
-               DEBUG("device flags: %s%s%s",
-                     (priv->hw_qpg ? "IBV_DEVICE_QPG " : ""),
-                     (priv->hw_tss ? "IBV_DEVICE_TSS " : ""),
-                     (priv->hw_rss ? "IBV_DEVICE_RSS " : ""));
-               if (priv->hw_rss)
-                       DEBUG("maximum RSS indirection table size: %u",
-                             exp_device_attr.max_rss_tbl_sz);
-#endif /* RSS_SUPPORT */
 
                priv->hw_csum =
                        ((exp_device_attr.exp_device_cap_flags &
@@ -379,9 +378,32 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                DEBUG("L2 tunnel checksum offloads are %ssupported",
                      (priv->hw_csum_l2tun ? "" : "not "));
 
+               priv->ind_table_max_size = exp_device_attr.rx_hash_caps.max_rwq_indirection_table_size;
+               /* Remove this check once DPDK supports larger/variable
+                * indirection tables. */
+               if (priv->ind_table_max_size > (unsigned int)RSS_INDIRECTION_TABLE_SIZE)
+                       priv->ind_table_max_size = RSS_INDIRECTION_TABLE_SIZE;
+               DEBUG("maximum RX indirection table size is %u",
+                     priv->ind_table_max_size);
+
+#else /* HAVE_EXP_QUERY_DEVICE */
+               priv->ind_table_max_size = RSS_INDIRECTION_TABLE_SIZE;
 #endif /* HAVE_EXP_QUERY_DEVICE */
 
                priv->vf = vf;
+               /* Allocate and register default RSS hash keys. */
+               priv->rss_conf = rte_calloc(__func__, hash_rxq_init_n,
+                                           sizeof((*priv->rss_conf)[0]), 0);
+               if (priv->rss_conf == NULL) {
+                       err = ENOMEM;
+                       goto port_error;
+               }
+               err = rss_hash_rss_conf_new_key(priv,
+                                               rss_hash_default_key,
+                                               rss_hash_default_key_len,
+                                               ETH_RSS_PROTO_MASK);
+               if (err)
+                       goto port_error;
                /* Configure the first MAC address by default. */
                if (priv_get_mac(priv, &mac.addr_bytes)) {
                        ERROR("cannot get MAC address, is mlx5_en loaded?"
@@ -431,6 +453,9 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 
                eth_dev->data->dev_private = priv;
                eth_dev->pci_dev = pci_dev;
+
+               rte_eth_copy_pci_info(eth_dev, pci_dev);
+
                eth_dev->driver = &mlx5_driver;
                eth_dev->data->rx_mbuf_alloc_failed = 0;
                eth_dev->data->mtu = ETHER_MTU;
@@ -438,6 +463,7 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                priv->dev = eth_dev;
                eth_dev->dev_ops = &mlx5_dev_ops;
                eth_dev->data->mac_addrs = priv->mac;
+               TAILQ_INIT(&eth_dev->link_intr_cbs);
 
                /* Bring Ethernet device up. */
                DEBUG("forcing Ethernet interface up");
@@ -445,6 +471,7 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                continue;
 
 port_error:
+               rte_free(priv->rss_conf);
                rte_free(priv);
                if (pd)
                        claim_zero(ibv_dealloc_pd(pd));
@@ -510,6 +537,7 @@ static struct eth_driver mlx5_driver = {
                .name = MLX5_DRIVER_NAME,
                .id_table = mlx5_pci_id_map,
                .devinit = mlx5_pci_devinit,
+               .drv_flags = RTE_PCI_DRV_INTR_LSC,
        },
        .dev_private_size = sizeof(struct priv)
 };