Signed-off-by: Hemant Agrawal <hemant.agra...@nxp.com>
---
 drivers/net/dpaa2/base/dpaa2_hw_dpni.h |  50 +++++++++++++
 drivers/net/dpaa2/dpaa2_ethdev.c       | 130 ++++++++++++++++++++++++++++++++-
 2 files changed, 179 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/dpaa2/base/dpaa2_hw_dpni.h

diff --git a/drivers/net/dpaa2/base/dpaa2_hw_dpni.h 
b/drivers/net/dpaa2/base/dpaa2_hw_dpni.h
new file mode 100644
index 0000000..1b655e4
--- /dev/null
+++ b/drivers/net/dpaa2/base/dpaa2_hw_dpni.h
@@ -0,0 +1,50 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
+ *   Copyright (c) 2016 NXP. 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 Freescale Semiconductor, Inc 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.
+ */
+
+#ifndef _DPAA2_HW_DPNI_H_
+#define _DPAA2_HW_DPNI_H_
+
+#include <fsl_dpni.h>
+#include <fsl_mc_sys.h>
+/*! Global MCP list */
+extern void *(*mcp_ptr_list);
+
+
+struct dpaa2_dev_priv {
+       void *hw;
+       int32_t hw_id;
+       uint16_t token;
+
+       uint8_t flags; /*dpaa2 config flags */
+};
+#endif /* _DPAA2_DPNI_H_ */
diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c
index 17dfff6..daf59c1 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.c
+++ b/drivers/net/dpaa2/dpaa2_ethdev.c
@@ -43,12 +43,140 @@
 #include <rte_kvargs.h>
 #include <rte_dev.h>
 #include <rte_ethdev.h>
+#include <rte_dpaa2.h>
 
+#include <dpaa2_logs.h>
+#include <base/dpaa2_hw_dpni.h>
 /* DPDK Interfaces */
 #include <dpaa2_ethdev.h>
 
+static int
+dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
+{
+       struct rte_eth_dev_data *data = dev->data;
+       struct rte_eth_conf *eth_conf = &data->dev_conf;
+
+       PMD_INIT_FUNC_TRACE();
+
+       /* Check for correct configuration */
+       if (eth_conf->rxmode.mq_mode != ETH_MQ_RX_RSS &&
+           data->nb_rx_queues > 1) {
+               PMD_INIT_LOG(ERR, "Distribution is not enabled, "
+                           "but Rx queues more than 1\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+static int
+dpaa2_dev_start(struct rte_eth_dev *dev)
+{
+       struct dpaa2_dev_priv *priv = dev->data->dev_private;
+       struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
+       int ret;
+
+       PMD_INIT_FUNC_TRACE();
+
+       ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "Failure %d in enabling dpni %d device\n",
+                            ret, priv->hw_id);
+               return ret;
+       }
+
+       return 0;
+}
+
+/**
+ *  This routine disables all traffic on the adapter by issuing a
+ *  global reset on the MAC.
+ */
+static void
+dpaa2_dev_stop(struct rte_eth_dev *dev)
+{
+       struct dpaa2_dev_priv *priv = dev->data->dev_private;
+       struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
+       int ret;
+
+       PMD_INIT_FUNC_TRACE();
+
+       ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "Failure (ret %d) in disabling dpni %d dev\n",
+                            ret, priv->hw_id);
+               return;
+       }
+}
+
+static void
+dpaa2_dev_close(struct rte_eth_dev *dev)
+{
+       struct dpaa2_dev_priv *priv = dev->data->dev_private;
+       struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
+       int ret;
+
+       PMD_INIT_FUNC_TRACE();
+
+       /* Clean the device first */
+       ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "Failure cleaning dpni device with"
+                            " error code %d\n", ret);
+               return;
+       }
+}
+
+static struct eth_dev_ops dpaa2_ethdev_ops = {
+       .dev_configure    = dpaa2_eth_dev_configure,
+       .dev_start            = dpaa2_dev_start,
+       .dev_stop             = dpaa2_dev_stop,
+       .dev_close            = dpaa2_dev_close,
+};
+
 int
-dpaa2_dev_init(struct rte_eth_dev *eth_dev __rte_unused)
+dpaa2_dev_init(struct rte_eth_dev *eth_dev)
 {
+       struct rte_device *dev = eth_dev->device;
+       struct rte_dpaa2_device *dpaa2_dev;
+       struct fsl_mc_io *dpni_dev;
+       struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
+       int ret, hw_id;
+
+       PMD_INIT_FUNC_TRACE();
+
+       /* For secondary processes, the primary has done all the work */
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return 0;
+
+       dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
+
+       hw_id = dpaa2_dev->object_id;
+
+       dpni_dev = (struct fsl_mc_io *)malloc(sizeof(struct fsl_mc_io));
+       if (!dpni_dev) {
+               PMD_INIT_LOG(ERR, "malloc failed for dpni device\n");
+               return -1;
+       }
+
+       dpni_dev->regs = mcp_ptr_list[0];
+       ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "Failure in opening dpni@%d device with"
+                       " error code %d\n", hw_id, ret);
+               return -1;
+       }
+
+       /* Clean the device first */
+       ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "Failure cleaning dpni@%d device with"
+                       " error code %d\n", hw_id, ret);
+               return -1;
+       }
+
+       priv->hw = dpni_dev;
+       priv->hw_id = hw_id;
+       eth_dev->dev_ops = &dpaa2_ethdev_ops;
        return 0;
 }
-- 
1.9.1

Reply via email to