ethdev: separate driver APIs
[dpdk.git] / drivers / net / enic / enic_main.c
index f0b15ac..9274def 100644 (file)
@@ -1,35 +1,6 @@
-/*
- * Copyright 2008-2014 Cisco Systems, Inc.  All rights reserved.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
- *
- * Copyright (c) 2014, Cisco Systems, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. 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.
- *
- * 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 HOLDER 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.
- *
  */
 
 #include <stdio.h>
 #include <libgen.h>
 
 #include <rte_pci.h>
+#include <rte_bus_pci.h>
 #include <rte_memzone.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
 #include <rte_string_fns.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 
 #include "enic_compat.h"
 #include "enic.h"
@@ -97,11 +69,6 @@ enic_rxmbuf_queue_release(__rte_unused struct enic *enic, struct vnic_rq *rq)
        }
 }
 
-void enic_set_hdr_split_size(struct enic *enic, u16 split_hdr_size)
-{
-       vnic_set_hdr_split_size(enic->vdev, split_hdr_size);
-}
-
 static void enic_free_wq_buf(struct vnic_wq_buf *buf)
 {
        struct rte_mbuf *mbuf = (struct rte_mbuf *)buf->mb;
@@ -137,6 +104,7 @@ static void enic_clear_soft_stats(struct enic *enic)
        struct enic_soft_stats *soft_stats = &enic->soft_stats;
        rte_atomic64_clear(&soft_stats->rx_nombuf);
        rte_atomic64_clear(&soft_stats->rx_packet_errors);
+       rte_atomic64_clear(&soft_stats->tx_oversized);
 }
 
 static void enic_init_soft_stats(struct enic *enic)
@@ -144,6 +112,7 @@ static void enic_init_soft_stats(struct enic *enic)
        struct enic_soft_stats *soft_stats = &enic->soft_stats;
        rte_atomic64_init(&soft_stats->rx_nombuf);
        rte_atomic64_init(&soft_stats->rx_packet_errors);
+       rte_atomic64_init(&soft_stats->tx_oversized);
        enic_clear_soft_stats(enic);
 }
 
@@ -154,16 +123,17 @@ void enic_dev_stats_clear(struct enic *enic)
        enic_clear_soft_stats(enic);
 }
 
-void enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
+int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
 {
        struct vnic_stats *stats;
        struct enic_soft_stats *soft_stats = &enic->soft_stats;
        int64_t rx_truncated;
        uint64_t rx_packet_errors;
+       int ret = vnic_dev_stats_dump(enic->vdev, &stats);
 
-       if (vnic_dev_stats_dump(enic->vdev, &stats)) {
+       if (ret) {
                dev_err(enic, "Error in getting stats\n");
-               return;
+               return ret;
        }
 
        /* The number of truncated packets can only be calculated by
@@ -183,42 +153,37 @@ void enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
        r_stats->obytes = stats->tx.tx_bytes_ok;
 
        r_stats->ierrors = stats->rx.rx_errors + stats->rx.rx_drop;
-       r_stats->oerrors = stats->tx.tx_errors;
+       r_stats->oerrors = stats->tx.tx_errors
+                          + rte_atomic64_read(&soft_stats->tx_oversized);
 
        r_stats->imissed = stats->rx.rx_no_bufs + rx_truncated;
 
        r_stats->rx_nombuf = rte_atomic64_read(&soft_stats->rx_nombuf);
+       return 0;
 }
 
-void enic_del_mac_address(struct enic *enic)
+void enic_del_mac_address(struct enic *enic, int mac_index)
 {
-       if (vnic_dev_del_addr(enic->vdev, enic->mac_addr))
+       struct rte_eth_dev *eth_dev = enic->rte_dev;
+       uint8_t *mac_addr = eth_dev->data->mac_addrs[mac_index].addr_bytes;
+
+       if (vnic_dev_del_addr(enic->vdev, mac_addr))
                dev_err(enic, "del mac addr failed\n");
 }
 
-void enic_set_mac_address(struct enic *enic, uint8_t *mac_addr)
+int enic_set_mac_address(struct enic *enic, uint8_t *mac_addr)
 {
        int err;
 
        if (!is_eth_addr_valid(mac_addr)) {
                dev_err(enic, "invalid mac address\n");
-               return;
-       }
-
-       err = vnic_dev_del_addr(enic->vdev, enic->mac_addr);
-       if (err) {
-               dev_err(enic, "del mac addr failed\n");
-               return;
+               return -EINVAL;
        }
 
-       ether_addr_copy((struct ether_addr *)mac_addr,
-               (struct ether_addr *)enic->mac_addr);
-
        err = vnic_dev_add_addr(enic->vdev, mac_addr);
-       if (err) {
+       if (err)
                dev_err(enic, "add mac addr failed\n");
-               return;
-       }
+       return err;
 }
 
 static void
@@ -228,7 +193,7 @@ enic_free_rq_buf(struct rte_mbuf **mbuf)
                return;
 
        rte_pktmbuf_free(*mbuf);
-       mbuf = NULL;
+       *mbuf = NULL;
 }
 
 void enic_init_vnic_resources(struct enic *enic)
@@ -284,7 +249,7 @@ void enic_init_vnic_resources(struct enic *enic)
                        0 /* cq_entry_enable */,
                        1 /* cq_message_enable */,
                        0 /* interrupt offset */,
-                       (u64)enic->wq[index].cqmsg_rz->phys_addr);
+                       (u64)enic->wq[index].cqmsg_rz->iova);
        }
 
        vnic_intr_init(&enic->intr,
@@ -317,7 +282,7 @@ enic_alloc_rx_queue_mbufs(struct enic *enic, struct vnic_rq *rq)
                }
 
                mb->data_off = RTE_PKTMBUF_HEADROOM;
-               dma_addr = (dma_addr_t)(mb->buf_physaddr
+               dma_addr = (dma_addr_t)(mb->buf_iova
                           + RTE_PKTMBUF_HEADROOM);
                rq_enet_desc_enc(rqd, dma_addr,
                                (rq->is_sop ? RQ_ENET_TYPE_ONLY_SOP
@@ -363,7 +328,7 @@ enic_alloc_consistent(void *priv, size_t size,
        }
 
        vaddr = rz->addr;
-       *dma_handle = (dma_addr_t)rz->phys_addr;
+       *dma_handle = (dma_addr_t)rz->iova;
 
        mze = rte_malloc("enic memzone entry",
                         sizeof(struct enic_memzone_entry), 0);
@@ -372,6 +337,7 @@ enic_alloc_consistent(void *priv, size_t size,
                pr_err("%s : Failed to allocate memory for memzone list\n",
                       __func__);
                rte_memzone_free(rz);
+               return NULL;
        }
 
        mze->rz = rz;
@@ -395,7 +361,7 @@ enic_free_consistent(void *priv,
        rte_spinlock_lock(&enic->memzone_list_lock);
        LIST_FOREACH(mze, &enic->memzone_list, entries) {
                if (mze->rz->addr == vaddr &&
-                   mze->rz->phys_addr == dma_handle)
+                   mze->rz->iova == dma_handle)
                        break;
        }
        if (mze == NULL) {
@@ -426,8 +392,7 @@ int enic_link_update(struct enic *enic)
 }
 
 static void
-enic_intr_handler(__rte_unused struct rte_intr_handle *handle,
-       void *arg)
+enic_intr_handler(void *arg)
 {
        struct rte_eth_dev *dev = (struct rte_eth_dev *)arg;
        struct enic *enic = pmd_priv(dev);
@@ -635,7 +600,8 @@ int enic_alloc_rq(struct enic *enic, uint16_t queue_idx,
        mbuf_size = (uint16_t)(rte_pktmbuf_data_room_size(mp) -
                               RTE_PKTMBUF_HEADROOM);
 
-       if (enic->rte_dev->data->dev_conf.rxmode.enable_scatter) {
+       if (enic->rte_dev->data->dev_conf.rxmode.offloads &
+           DEV_RX_OFFLOAD_SCATTER) {
                dev_info(enic, "Rq %u Scatter rx mode enabled\n", queue_idx);
                /* ceil((mtu + ETHER_HDR_LEN + 4)/mbuf_size) */
                mbufs_per_pkt = ((mtu + ETHER_HDR_LEN + 4) +
@@ -1121,11 +1087,12 @@ static int
 enic_reinit_rq(struct enic *enic, unsigned int rq_idx)
 {
        struct vnic_rq *sop_rq, *data_rq;
-       unsigned int cq_idx = enic_cq_rq(enic, rq_idx);
+       unsigned int cq_idx;
        int rc = 0;
 
        sop_rq = &enic->rq[enic_rte_rq_idx_to_sop_idx(rq_idx)];
        data_rq = &enic->rq[enic_rte_rq_idx_to_data_idx(rq_idx)];
+       cq_idx = rq_idx;
 
        vnic_cq_clean(&enic->cq[cq_idx]);
        vnic_cq_init(&enic->cq[cq_idx],
@@ -1185,6 +1152,9 @@ int enic_set_mtu(struct enic *enic, uint16_t new_mtu)
        old_mtu = eth_dev->data->mtu;
        config_mtu = enic->config.mtu;
 
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return -E_RTE_SECONDARY;
+
        if (new_mtu > enic->max_mtu) {
                dev_err(enic,
                        "MTU not updated: requested (%u) greater than max (%u)\n",
@@ -1205,7 +1175,8 @@ int enic_set_mtu(struct enic *enic, uint16_t new_mtu)
        /* The easy case is when scatter is disabled. However if the MTU
         * becomes greater than the mbuf data size, packet drops will ensue.
         */
-       if (!enic->rte_dev->data->dev_conf.rxmode.enable_scatter) {
+       if (!(enic->rte_dev->data->dev_conf.rxmode.offloads &
+             DEV_RX_OFFLOAD_SCATTER)) {
                eth_dev->data->mtu = new_mtu;
                goto set_mtu_done;
        }
@@ -1230,7 +1201,7 @@ int enic_set_mtu(struct enic *enic, uint16_t new_mtu)
                }
        }
 
-       /* replace Rx funciton with a no-op to avoid getting stale pkts */
+       /* replace Rx function with a no-op to avoid getting stale pkts */
        eth_dev->rx_pkt_burst = enic_dummy_recv_pkts;
        rte_mb();
 
@@ -1308,16 +1279,20 @@ static int enic_dev_init(struct enic *enic)
        /* Get the supported filters */
        enic_fdir_info(enic);
 
-       eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr", ETH_ALEN, 0);
+       eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr", ETH_ALEN
+                                               * ENIC_MAX_MAC_ADDR, 0);
        if (!eth_dev->data->mac_addrs) {
                dev_err(enic, "mac addr storage alloc failed, aborting.\n");
                return -1;
        }
        ether_addr_copy((struct ether_addr *) enic->mac_addr,
-               &eth_dev->data->mac_addrs[0]);
+                       eth_dev->data->mac_addrs);
 
        vnic_dev_set_reset_flag(enic->vdev, 0);
 
+       LIST_INIT(&enic->flows);
+       rte_spinlock_init(&enic->flows_lock);
+
        /* set up link status checking */
        vnic_dev_notify_set(enic->vdev, -1); /* No Intr for notify */
 
@@ -1332,6 +1307,10 @@ int enic_probe(struct enic *enic)
 
        dev_debug(enic, " Initializing ENIC PMD\n");
 
+       /* if this is a secondary process the hardware is already initialized */
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return 0;
+
        enic->bar0.vaddr = (void *)pdev->mem_resource[0].addr;
        enic->bar0.len = pdev->mem_resource[0].len;