remove useless constructor headers
[dpdk.git] / drivers / net / softnic / rte_eth_softnic.c
index 2f19159..65166c1 100644 (file)
@@ -1,48 +1,20 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2017 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2017 Intel Corporation
  */
 
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 #include <rte_ethdev_vdev.h>
 #include <rte_malloc.h>
-#include <rte_vdev.h>
+#include <rte_bus_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_errno.h>
 #include <rte_ring.h>
 #include <rte_sched.h>
+#include <rte_tm_driver.h>
 
 #include "rte_eth_softnic.h"
 #include "rte_eth_softnic_internals.h"
@@ -93,8 +65,15 @@ static const struct rte_eth_dev_info pmd_dev_info = {
                .nb_min = 0,
                .nb_align = 1,
        },
+       .rx_offload_capa = DEV_RX_OFFLOAD_CRC_STRIP,
 };
 
+static int pmd_softnic_logtype;
+
+#define PMD_LOG(level, fmt, args...) \
+       rte_log(RTE_LOG_ ## level, pmd_softnic_logtype, \
+               "%s(): " fmt "\n", __func__, ##args)
+
 static void
 pmd_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
        struct rte_eth_dev_info *dev_info)
@@ -224,6 +203,15 @@ pmd_link_update(struct rte_eth_dev *dev __rte_unused,
        return 0;
 }
 
+static int
+pmd_tm_ops_get(struct rte_eth_dev *dev, void *arg)
+{
+       *(const struct rte_tm_ops **)arg =
+               (tm_enabled(dev)) ? &pmd_tm_ops : NULL;
+
+       return 0;
+}
+
 static const struct eth_dev_ops pmd_ops = {
        .dev_configure = pmd_dev_configure,
        .dev_start = pmd_dev_start,
@@ -233,7 +221,7 @@ static const struct eth_dev_ops pmd_ops = {
        .dev_infos_get = pmd_dev_infos_get,
        .rx_queue_setup = pmd_rx_queue_setup,
        .tx_queue_setup = pmd_tx_queue_setup,
-       .tm_ops_get = NULL,
+       .tm_ops_get = pmd_tm_ops_get,
 };
 
 static uint16_t
@@ -541,13 +529,14 @@ pmd_ethdev_register(struct rte_vdev_device *vdev,
        soft_dev->data->dev_private = dev_private;
        soft_dev->data->dev_link.link_speed = hard_speed;
        soft_dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
-       soft_dev->data->dev_link.link_autoneg = ETH_LINK_SPEED_FIXED;
+       soft_dev->data->dev_link.link_autoneg = ETH_LINK_FIXED;
        soft_dev->data->dev_link.link_status = ETH_LINK_DOWN;
        soft_dev->data->mac_addrs = &eth_addr;
        soft_dev->data->promiscuous = 1;
        soft_dev->data->kdrv = RTE_KDRV_NONE;
        soft_dev->data->numa_node = numa_node;
-       soft_dev->data->dev_flags = RTE_ETH_DEV_DETACHABLE;
+
+       rte_eth_dev_probing_finish(soft_dev);
 
        return 0;
 }
@@ -745,13 +734,27 @@ pmd_probe(struct rte_vdev_device *vdev)
        uint16_t hard_port_id;
        int numa_node;
        void *dev_private;
+       struct rte_eth_dev *eth_dev;
+       const char *name = rte_vdev_device_name(vdev);
 
-       RTE_LOG(INFO, PMD,
-               "Probing device \"%s\"\n",
-               rte_vdev_device_name(vdev));
+       PMD_LOG(INFO, "Probing device \"%s\"", name);
 
        /* Parse input arguments */
        params = rte_vdev_device_args(vdev);
+
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(params) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       PMD_LOG(ERR, "Failed to probe %s", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &pmd_ops;
+               rte_eth_dev_probing_finish(eth_dev);
+               return 0;
+       }
+
        if (!params)
                return -EINVAL;
 
@@ -783,8 +786,8 @@ pmd_probe(struct rte_vdev_device *vdev)
                return -ENOMEM;
 
        /* Register soft ethdev */
-       RTE_LOG(INFO, PMD,
-               "Creating soft ethdev \"%s\" for hard ethdev \"%s\"\n",
+       PMD_LOG(INFO,
+               "Creating soft ethdev \"%s\" for hard ethdev \"%s\"",
                p.soft.name, p.hard.name);
 
        status = pmd_ethdev_register(vdev, &p, dev_private);
@@ -805,7 +808,7 @@ pmd_remove(struct rte_vdev_device *vdev)
        if (!vdev)
                return -EINVAL;
 
-       RTE_LOG(INFO, PMD, "Removing device \"%s\"\n",
+       PMD_LOG(INFO, "Removing device \"%s\"",
                rte_vdev_device_name(vdev));
 
        /* Find the ethdev entry */
@@ -840,3 +843,10 @@ RTE_PMD_REGISTER_PARAM_STRING(net_softnic,
        PMD_PARAM_SOFT_TM_DEQ_BSZ "=<int> "
        PMD_PARAM_HARD_NAME "=<string> "
        PMD_PARAM_HARD_TX_QUEUE_ID "=<int>");
+
+RTE_INIT(pmd_softnic_init_log)
+{
+       pmd_softnic_logtype = rte_log_register("pmd.net.softnic");
+       if (pmd_softnic_logtype >= 0)
+               rte_log_set_level(pmd_softnic_logtype, RTE_LOG_NOTICE);
+}