ethdev: get rid of device type
[dpdk.git] / drivers / net / mlx5 / mlx5.c
index 3f45d84..f1de40a 100644 (file)
@@ -37,6 +37,7 @@
 #include <assert.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <errno.h>
 #include <net/if.h>
 
 /* Verbs header. */
@@ -57,6 +58,7 @@
 #include <rte_ethdev.h>
 #include <rte_pci.h>
 #include <rte_common.h>
+#include <rte_kvargs.h>
 #ifdef PEDANTIC
 #pragma GCC diagnostic error "-pedantic"
 #endif
 #include "mlx5_autoconf.h"
 #include "mlx5_defs.h"
 
+/* Device parameter to enable RX completion queue compression. */
+#define MLX5_RXQ_CQE_COMP_EN "rxq_cqe_comp_en"
+
+/* Device parameter to configure inline send. */
+#define MLX5_TXQ_INLINE "txq_inline"
+
+/*
+ * Device parameter to configure the number of TX queues threshold for
+ * enabling inline send.
+ */
+#define MLX5_TXQS_MIN_INLINE "txqs_min_inline"
+
+/* Device parameter to enable multi-packet send WQEs. */
+#define MLX5_TXQ_MPW_EN "txq_mpw_en"
+
 /**
  * Retrieve integer value from environment variable.
  *
@@ -237,6 +254,90 @@ mlx5_dev_idx(struct rte_pci_addr *pci_addr)
        return ret;
 }
 
+/**
+ * Verify and store value for device argument.
+ *
+ * @param[in] key
+ *   Key argument to verify.
+ * @param[in] val
+ *   Value associated with key.
+ * @param opaque
+ *   User data.
+ *
+ * @return
+ *   0 on success, negative errno value on failure.
+ */
+static int
+mlx5_args_check(const char *key, const char *val, void *opaque)
+{
+       struct priv *priv = opaque;
+       unsigned long tmp;
+
+       errno = 0;
+       tmp = strtoul(val, NULL, 0);
+       if (errno) {
+               WARN("%s: \"%s\" is not a valid integer", key, val);
+               return errno;
+       }
+       if (strcmp(MLX5_RXQ_CQE_COMP_EN, key) == 0) {
+               priv->cqe_comp = !!tmp;
+       } else if (strcmp(MLX5_TXQ_INLINE, key) == 0) {
+               priv->txq_inline = tmp;
+       } else if (strcmp(MLX5_TXQS_MIN_INLINE, key) == 0) {
+               priv->txqs_inline = tmp;
+       } else if (strcmp(MLX5_TXQ_MPW_EN, key) == 0) {
+               priv->mps = !!tmp;
+       } else {
+               WARN("%s: unknown parameter", key);
+               return -EINVAL;
+       }
+       return 0;
+}
+
+/**
+ * Parse device parameters.
+ *
+ * @param priv
+ *   Pointer to private structure.
+ * @param devargs
+ *   Device arguments structure.
+ *
+ * @return
+ *   0 on success, errno value on failure.
+ */
+static int
+mlx5_args(struct priv *priv, struct rte_devargs *devargs)
+{
+       const char **params = (const char *[]){
+               MLX5_RXQ_CQE_COMP_EN,
+               MLX5_TXQ_INLINE,
+               MLX5_TXQS_MIN_INLINE,
+               MLX5_TXQ_MPW_EN,
+               NULL,
+       };
+       struct rte_kvargs *kvlist;
+       int ret = 0;
+       int i;
+
+       if (devargs == NULL)
+               return 0;
+       /* Following UGLY cast is done to pass checkpatch. */
+       kvlist = rte_kvargs_parse(devargs->args, params);
+       if (kvlist == NULL)
+               return 0;
+       /* Process parameters. */
+       for (i = 0; (params[i] != NULL); ++i) {
+               if (rte_kvargs_count(kvlist, params[i])) {
+                       ret = rte_kvargs_process(kvlist, params[i],
+                                                mlx5_args_check, priv);
+                       if (ret != 0)
+                               return ret;
+               }
+       }
+       rte_kvargs_free(kvlist);
+       return 0;
+}
+
 static struct eth_driver mlx5_driver;
 
 /**
@@ -254,7 +355,7 @@ static struct eth_driver mlx5_driver;
  *   0 on success, negative errno value on failure.
  */
 static int
-mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
+mlx5_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 {
        struct ibv_device **list;
        struct ibv_device *ibv_dev;
@@ -408,6 +509,14 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                priv->port = port;
                priv->pd = pd;
                priv->mtu = ETHER_MTU;
+               priv->mps = mps; /* Enable MPW by default if supported. */
+               priv->cqe_comp = 1; /* Enable compression by default. */
+               err = mlx5_args(priv, pci_dev->devargs);
+               if (err) {
+                       ERROR("failed to process device arguments: %s",
+                             strerror(err));
+                       goto port_error;
+               }
                if (ibv_exp_query_device(ctx, &exp_device_attr)) {
                        ERROR("ibv_exp_query_device() failed");
                        goto port_error;
@@ -449,7 +558,12 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 
                priv_get_num_vfs(priv, &num_vfs);
                priv->sriov = (num_vfs || sriov);
-               priv->mps = mps;
+               if (priv->mps && !mps) {
+                       ERROR("multi-packet send not supported on this device"
+                             " (" MLX5_TXQ_MPW_EN ")");
+                       err = ENOTSUP;
+                       goto port_error;
+               }
                /* Allocate and register default RSS hash keys. */
                priv->rss_conf = rte_calloc(__func__, hash_rxq_init_n,
                                            sizeof((*priv->rss_conf)[0]), 0);
@@ -503,7 +617,7 @@ mlx5_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 
                        snprintf(name, sizeof(name), "%s port %u",
                                 ibv_get_device_name(ibv_dev), port);
-                       eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
+                       eth_dev = rte_eth_dev_allocate(name);
                }
                if (eth_dev == NULL) {
                        ERROR("can not allocate rte ethdev");
@@ -616,7 +730,7 @@ static struct eth_driver mlx5_driver = {
        .pci_drv = {
                .name = MLX5_DRIVER_NAME,
                .id_table = mlx5_pci_id_map,
-               .devinit = mlx5_pci_devinit,
+               .probe = mlx5_pci_probe,
                .drv_flags = RTE_PCI_DRV_INTR_LSC,
        },
        .dev_private_size = sizeof(struct priv)
@@ -625,11 +739,10 @@ static struct eth_driver mlx5_driver = {
 /**
  * Driver initialization routine.
  */
-static int
-rte_mlx5_pmd_init(const char *name, const char *args)
+RTE_INIT(rte_mlx5_pmd_init);
+static void
+rte_mlx5_pmd_init(void)
 {
-       (void)name;
-       (void)args;
        /*
         * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
         * huge pages. Calling ibv_fork_init() during init allows
@@ -639,13 +752,7 @@ rte_mlx5_pmd_init(const char *name, const char *args)
        setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
        ibv_fork_init();
        rte_eal_pci_register(&mlx5_driver.pci_drv);
-       return 0;
 }
 
-static struct rte_driver rte_mlx5_driver = {
-       .type = PMD_PDEV,
-       .name = MLX5_DRIVER_NAME,
-       .init = rte_mlx5_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_mlx5_driver)
+DRIVER_EXPORT_NAME(net_mlx5, __COUNTER__);
+DRIVER_REGISTER_PCI_TABLE(net_mlx5, mlx5_pci_id_map);