New upstream version 17.11.1
[deb_dpdk.git] / drivers / net / thunderx / nicvf_ethdev.c
index 2152029..c62371c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *   BSD LICENSE
  *
- *   Copyright (C) Cavium networks Ltd. 2016.
+ *   Copyright (C) Cavium, Inc. 2016.
  *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
@@ -13,7 +13,7 @@
  *       notice, this list of conditions and the following disclaimer in
  *       the documentation and/or other materials provided with the
  *       distribution.
- *     * Neither the name of Cavium networks nor the names of its
+ *     * Neither the name of Cavium, Inc nor the names of its
  *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
  *
@@ -61,6 +61,7 @@
 #include <rte_malloc.h>
 #include <rte_random.h>
 #include <rte_pci.h>
+#include <rte_bus_pci.h>
 #include <rte_tailq.h>
 
 #include "base/nicvf_plat.h"
@@ -99,7 +100,7 @@ nicvf_set_eth_link_status(struct nicvf *nic, struct rte_eth_link *link)
        else if (nic->duplex == NICVF_FULL_DUPLEX)
                link->link_duplex = ETH_LINK_FULL_DUPLEX;
        link->link_speed = nic->speed;
-       link->link_autoneg = ETH_LINK_SPEED_AUTONEG;
+       link->link_autoneg = ETH_LINK_AUTONEG;
 }
 
 static void
@@ -111,7 +112,8 @@ nicvf_interrupt(void *arg)
        if (nicvf_reg_poll_interrupts(nic) == NIC_MBOX_MSG_BGX_LINK_CHANGE) {
                if (dev->data->dev_conf.intr_conf.lsc)
                        nicvf_set_eth_link_status(nic, &dev->data->dev_link);
-               _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
+               _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
+                                             NULL, NULL);
        }
 
        rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000,
@@ -241,7 +243,7 @@ nicvf_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs)
        return -ENOTSUP;
 }
 
-static void
+static int
 nicvf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 {
        uint16_t qidx;
@@ -331,6 +333,8 @@ nicvf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
        stats->opackets += port_stats.tx_bcast_frames_ok;
        stats->opackets += port_stats.tx_mcast_frames_ok;
        stats->oerrors = port_stats.tx_drops;
+
+       return 0;
 }
 
 static const uint32_t *
@@ -601,7 +605,7 @@ nicvf_qset_cq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
 
        memset(rz->addr, 0, ring_size);
 
-       rxq->phys = rz->phys_addr;
+       rxq->phys = rz->iova;
        rxq->desc = rz->addr;
        rxq->qlen_mask = desc_cnt - 1;
 
@@ -625,7 +629,7 @@ nicvf_qset_sq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
 
        memset(rz->addr, 0, ring_size);
 
-       sq->phys = rz->phys_addr;
+       sq->phys = rz->iova;
        sq->desc = rz->addr;
        sq->qlen_mask = desc_cnt - 1;
 
@@ -659,7 +663,7 @@ nicvf_qset_rbdr_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
 
        memset(rz->addr, 0, ring_size);
 
-       rbdr->phys = rz->phys_addr;
+       rbdr->phys = rz->iova;
        rbdr->tail = 0;
        rbdr->next_tail = 0;
        rbdr->desc = rz->addr;
@@ -676,7 +680,7 @@ nicvf_qset_rbdr_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
 
 static void
 nicvf_rbdr_release_mbuf(struct rte_eth_dev *dev, struct nicvf *nic,
-                       nicvf_phys_addr_t phy)
+                       nicvf_iova_addr_t phy)
 {
        uint16_t qidx;
        void *obj;
@@ -1239,6 +1243,13 @@ nicvf_rxq_mbuf_setup(struct nicvf_rxq *rxq)
        struct rte_mbuf mb_def;
 
        RTE_BUILD_BUG_ON(sizeof(union mbuf_initializer) != 8);
+       RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
+       RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
+                               offsetof(struct rte_mbuf, data_off) != 2);
+       RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
+                               offsetof(struct rte_mbuf, data_off) != 4);
+       RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
+                               offsetof(struct rte_mbuf, data_off) != 6);
        mb_def.nb_segs = 1;
        mb_def.data_off = RTE_PKTMBUF_HEADROOM;
        mb_def.port = rxq->port_id;
@@ -1366,11 +1377,18 @@ static void
 nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
        struct nicvf *nic = nicvf_pmd_priv(dev);
-       struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
+       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 
        PMD_INIT_FUNC_TRACE();
 
-       dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
+       dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+
+       /* Autonegotiation may be disabled */
+       dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
+       dev_info->speed_capa |= ETH_LINK_SPEED_10M | ETH_LINK_SPEED_100M |
+                                ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
+       if (nicvf_hw_version(nic) != PCI_SUB_DEVICE_ID_CN81XX_NICVF)
+               dev_info->speed_capa |= ETH_LINK_SPEED_40G;
 
        dev_info->min_rx_bufsize = ETHER_MIN_MTU;
        dev_info->max_rx_pktlen = NIC_HW_MAX_FRS;
@@ -1411,7 +1429,7 @@ nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        };
 }
 
-static nicvf_phys_addr_t
+static nicvf_iova_addr_t
 rbdr_rte_mempool_get(void *dev, void *opaque)
 {
        uint16_t qidx;
@@ -2017,7 +2035,7 @@ nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
                }
        }
 
-       pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
+       pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
        rte_eth_copy_pci_info(eth_dev, pci_dev);
 
        nic->device_id = pci_dev->id.device_id;
@@ -2079,7 +2097,7 @@ nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
                        goto fail;
                }
 
-               /* Detach port by returning postive error number */
+               /* Detach port by returning positive error number */
                return ENOTSUP;
        }
 
@@ -2164,7 +2182,8 @@ static int nicvf_eth_pci_remove(struct rte_pci_device *pci_dev)
 
 static struct rte_pci_driver rte_nicvf_pmd = {
        .id_table = pci_id_nicvf_map,
-       .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+       .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_KEEP_MAPPED_RES |
+                       RTE_PCI_DRV_INTR_LSC,
        .probe = nicvf_eth_pci_probe,
        .remove = nicvf_eth_pci_remove,
 };