ethdev: query supported packet types
[dpdk.git] / drivers / net / mlx5 / mlx5.c
index e394d32..8e2c909 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.
@@ -86,10 +87,15 @@ mlx5_dev_close(struct rte_eth_dev *dev)
              (void *)dev,
              ((priv->ctx != NULL) ? priv->ctx->device->name : ""));
        /* In case mlx5_dev_stop() has not been called. */
-       priv_allmulticast_disable(priv);
-       priv_promiscuous_disable(priv);
+       priv_dev_interrupt_handler_uninstall(priv, dev);
+       priv_special_flow_disable_all(priv);
        priv_mac_addrs_disable(priv);
        priv_destroy_hash_rxqs(priv);
+
+       /* Remove flow director elements. */
+       priv_fdir_disable(priv);
+       priv_fdir_delete_filters_list(priv);
+
        /* Prevent crashes when queues are still in use. */
        dev->rx_pkt_burst = removed_rx_burst;
        dev->tx_pkt_burst = removed_tx_burst;
@@ -127,6 +133,13 @@ mlx5_dev_close(struct rte_eth_dev *dev)
                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));
 }
@@ -144,6 +157,7 @@ static const struct eth_dev_ops mlx5_dev_ops = {
        .stats_get = mlx5_stats_get,
        .stats_reset = mlx5_stats_reset,
        .dev_infos_get = mlx5_dev_infos_get,
+       .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
        .vlan_filter_set = mlx5_vlan_filter_set,
        .rx_queue_setup = mlx5_rx_queue_setup,
        .tx_queue_setup = mlx5_tx_queue_setup,
@@ -153,7 +167,19 @@ static const struct eth_dev_ops mlx5_dev_ops = {
        .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
        .mac_addr_remove = mlx5_mac_addr_remove,
        .mac_addr_add = mlx5_mac_addr_add,
+       .mac_addr_set = mlx5_mac_addr_set,
        .mtu_set = mlx5_dev_set_mtu,
+#ifdef HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS
+       .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
+       .vlan_offload_set = mlx5_vlan_offload_set,
+#endif /* HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS */
+       .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,
+#ifdef MLX5_FDIR_SUPPORT
+       .filter_ctrl = mlx5_dev_filter_ctrl,
+#endif /* MLX5_FDIR_SUPPORT */
 };
 
 static struct {
@@ -299,7 +325,13 @@ 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;
+               exp_device_attr.comp_mask =
+                       IBV_EXP_DEVICE_ATTR_EXP_CAP_FLAGS |
+                       IBV_EXP_DEVICE_ATTR_RX_HASH |
+#ifdef HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS
+                       IBV_EXP_DEVICE_ATTR_VLAN_OFFLOADS |
+#endif /* HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS */
+                       0;
 #endif /* HAVE_EXP_QUERY_DEVICE */
 
                DEBUG("using port %u (%08" PRIx32 ")", port, test);
@@ -314,6 +346,13 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                        ERROR("port query failed: %s", strerror(err));
                        goto port_error;
                }
+
+               if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
+                       ERROR("port %d is not configured in Ethernet mode",
+                             port);
+                       goto port_error;
+               }
+
                if (port_attr.state != IBV_PORT_ACTIVE)
                        DEBUG("port %d is not active: \"%s\" (%d)",
                              port, ibv_port_state_str(port_attr.state),
@@ -363,9 +402,38 @@ 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);
+#ifdef HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS
+               priv->hw_vlan_strip = !!(exp_device_attr.wq_vlan_offloads_cap &
+                                        IBV_EXP_RECEIVE_WQ_CVLAN_STRIP);
+#endif /* HAVE_EXP_DEVICE_ATTR_VLAN_OFFLOADS */
+               DEBUG("VLAN stripping is %ssupported",
+                     (priv->hw_vlan_strip ? "" : "not "));
+
+#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?"
@@ -377,13 +445,14 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                     mac.addr_bytes[0], mac.addr_bytes[1],
                     mac.addr_bytes[2], mac.addr_bytes[3],
                     mac.addr_bytes[4], mac.addr_bytes[5]);
-               /* Register MAC and broadcast addresses. */
+               /* Register MAC address. */
                claim_zero(priv_mac_addr_add(priv, 0,
                                             (const uint8_t (*)[ETHER_ADDR_LEN])
                                             mac.addr_bytes));
-               claim_zero(priv_mac_addr_add(priv, (RTE_DIM(priv->mac) - 1),
-                                            &(const uint8_t [ETHER_ADDR_LEN])
-                                            { "\xff\xff\xff\xff\xff\xff" }));
+               /* Initialize FD filters list. */
+               err = fdir_init_filters_list(priv);
+               if (err)
+                       goto port_error;
 #ifndef NDEBUG
                {
                        char ifname[IF_NAMESIZE];
@@ -415,6 +484,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;
@@ -422,6 +494,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");
@@ -429,7 +502,10 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                continue;
 
 port_error:
-               rte_free(priv);
+               if (priv) {
+                       rte_free(priv->rss_conf);
+                       rte_free(priv);
+               }
                if (pd)
                        claim_zero(ibv_dealloc_pd(pd));
                if (ctx)
@@ -494,6 +570,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)
 };