net/dpaa2: support statistics per queue
[dpdk.git] / drivers / net / dpaa2 / dpaa2_ethdev.c
index 54ab9eb..46fa38f 100644 (file)
 #include "dpaa2_ethdev.h"
 #include <fsl_qbman_debug.h>
 
+/* Supported Rx offloads */
+static uint64_t dev_rx_offloads_sup =
+               DEV_RX_OFFLOAD_VLAN_STRIP |
+               DEV_RX_OFFLOAD_IPV4_CKSUM |
+               DEV_RX_OFFLOAD_UDP_CKSUM |
+               DEV_RX_OFFLOAD_TCP_CKSUM |
+               DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
+               DEV_RX_OFFLOAD_VLAN_FILTER |
+               DEV_RX_OFFLOAD_JUMBO_FRAME;
+
+/* Rx offloads which cannot be disabled */
+static uint64_t dev_rx_offloads_nodis =
+               DEV_RX_OFFLOAD_SCATTER;
+
+/* Supported Tx offloads */
+static uint64_t dev_tx_offloads_sup =
+               DEV_TX_OFFLOAD_VLAN_INSERT |
+               DEV_TX_OFFLOAD_IPV4_CKSUM |
+               DEV_TX_OFFLOAD_UDP_CKSUM |
+               DEV_TX_OFFLOAD_TCP_CKSUM |
+               DEV_TX_OFFLOAD_SCTP_CKSUM |
+               DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
+
+/* Tx offloads which cannot be disabled */
+static uint64_t dev_tx_offloads_nodis =
+               DEV_TX_OFFLOAD_MULTI_SEGS |
+               DEV_TX_OFFLOAD_MT_LOCKFREE |
+               DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+
 struct rte_dpaa2_xstats_name_off {
        char name[RTE_ETH_XSTATS_NAME_SIZE];
        uint8_t page_id; /* dpni statistics page id */
@@ -170,27 +199,18 @@ dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
        dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
        dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
-       dev_info->rx_offload_capa =
-               DEV_RX_OFFLOAD_IPV4_CKSUM |
-               DEV_RX_OFFLOAD_UDP_CKSUM |
-               DEV_RX_OFFLOAD_TCP_CKSUM |
-               DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
-               DEV_RX_OFFLOAD_VLAN_FILTER |
-               DEV_RX_OFFLOAD_VLAN_STRIP |
-               DEV_RX_OFFLOAD_JUMBO_FRAME |
-               DEV_RX_OFFLOAD_SCATTER;
-       dev_info->tx_offload_capa =
-               DEV_TX_OFFLOAD_IPV4_CKSUM |
-               DEV_TX_OFFLOAD_UDP_CKSUM |
-               DEV_TX_OFFLOAD_TCP_CKSUM |
-               DEV_TX_OFFLOAD_SCTP_CKSUM |
-               DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
-               DEV_TX_OFFLOAD_VLAN_INSERT |
-               DEV_TX_OFFLOAD_MBUF_FAST_FREE |
-               DEV_TX_OFFLOAD_MULTI_SEGS;
+       dev_info->rx_offload_capa = dev_rx_offloads_sup |
+                                       dev_rx_offloads_nodis;
+       dev_info->tx_offload_capa = dev_tx_offloads_sup |
+                                       dev_tx_offloads_nodis;
        dev_info->speed_capa = ETH_LINK_SPEED_1G |
                        ETH_LINK_SPEED_2_5G |
                        ETH_LINK_SPEED_10G;
+
+       dev_info->max_hash_mac_addrs = 0;
+       dev_info->max_vfs = 0;
+       dev_info->max_vmdq_pools = ETH_16_POOLS;
+       dev_info->flow_type_rss_offloads = DPAA2_RSS_OFFLOAD_ALL;
 }
 
 static int
@@ -277,7 +297,6 @@ dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
        struct dpaa2_dev_priv *priv = dev->data->dev_private;
        struct fsl_mc_io *dpni = priv->hw;
        struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
-       struct rte_eth_dev_info dev_info;
        uint64_t rx_offloads = eth_conf->rxmode.offloads;
        uint64_t tx_offloads = eth_conf->txmode.offloads;
        int rx_l3_csum_offload = false;
@@ -288,19 +307,20 @@ dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
 
        PMD_INIT_FUNC_TRACE();
 
-       dpaa2_dev_info_get(dev, &dev_info);
-       if ((~(dev_info.rx_offload_capa) & rx_offloads) != 0) {
-               DPAA2_PMD_ERR("Some Rx offloads are not supported "
-                       "requested 0x%" PRIx64 " supported 0x%" PRIx64,
-                       rx_offloads, dev_info.rx_offload_capa);
-               return -ENOTSUP;
+       /* Rx offloads validation */
+       if (dev_rx_offloads_nodis & ~rx_offloads) {
+               DPAA2_PMD_WARN(
+               "Rx offloads non configurable - requested 0x%" PRIx64
+               " ignored 0x%" PRIx64,
+                       rx_offloads, dev_rx_offloads_nodis);
        }
 
-       if ((~(dev_info.tx_offload_capa) & tx_offloads) != 0) {
-               DPAA2_PMD_ERR("Some Tx offloads are not supported "
-                       "requested 0x%" PRIx64 " supported 0x%" PRIx64,
-                       tx_offloads, dev_info.tx_offload_capa);
-               return -ENOTSUP;
+       /* Tx offloads validation */
+       if (dev_tx_offloads_nodis & ~tx_offloads) {
+               DPAA2_PMD_WARN(
+               "Tx offloads non configurable - requested 0x%" PRIx64
+               " ignored 0x%" PRIx64,
+                       tx_offloads, dev_tx_offloads_nodis);
        }
 
        if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
@@ -385,7 +405,8 @@ dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
                }
        }
 
-       dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
+       if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
+               dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
 
        /* update the current status */
        dpaa2_dev_link_update(dev, 0);
@@ -548,7 +569,8 @@ dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
                 */
                cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
                cong_notif_cfg.message_ctx = 0;
-               cong_notif_cfg.message_iova = (size_t)dpaa2_q->cscn;
+               cong_notif_cfg.message_iova =
+                               (size_t)DPAA2_VADDR_TO_IOVA(dpaa2_q->cscn);
                cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
                cong_notif_cfg.notification_mode =
                                         DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
@@ -1096,6 +1118,8 @@ int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
        int32_t  retcode;
        uint8_t page0 = 0, page1 = 1, page2 = 2;
        union dpni_statistics value;
+       int i;
+       struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
 
        memset(&value, 0, sizeof(union dpni_statistics));
 
@@ -1143,6 +1167,21 @@ int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
        stats->oerrors = value.page_2.egress_discarded_frames;
        stats->imissed = value.page_2.ingress_nobuffer_discards;
 
+       /* Fill in per queue stats */
+       for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
+               (i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
+               dpaa2_rxq = (struct dpaa2_queue *)priv->rx_vq[i];
+               dpaa2_txq = (struct dpaa2_queue *)priv->tx_vq[i];
+               if (dpaa2_rxq)
+                       stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
+               if (dpaa2_txq)
+                       stats->q_opackets[i] = dpaa2_txq->tx_pkts;
+
+               /* Byte counting is not implemented */
+               stats->q_ibytes[i]   = 0;
+               stats->q_obytes[i]   = 0;
+       }
+
        return 0;
 
 err:
@@ -1302,6 +1341,8 @@ dpaa2_dev_stats_reset(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;
        int32_t  retcode;
+       int i;
+       struct dpaa2_queue *dpaa2_q;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -1314,6 +1355,19 @@ dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
        if (retcode)
                goto error;
 
+       /* Reset the per queue stats in dpaa2_queue structure */
+       for (i = 0; i < priv->nb_rx_queues; i++) {
+               dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
+               if (dpaa2_q)
+                       dpaa2_q->rx_pkts = 0;
+       }
+
+       for (i = 0; i < priv->nb_tx_queues; i++) {
+               dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
+               if (dpaa2_q)
+                       dpaa2_q->tx_pkts = 0;
+       }
+
        return;
 
 error:
@@ -1764,6 +1818,71 @@ static struct eth_dev_ops dpaa2_ethdev_ops = {
        .rss_hash_conf_get    = dpaa2_dev_rss_hash_conf_get,
 };
 
+/* Populate the mac address from physically available (u-boot/firmware) and/or
+ * one set by higher layers like MC (restool) etc.
+ * Returns the table of MAC entries (multiple entries)
+ */
+static int
+populate_mac_addr(struct fsl_mc_io *dpni_dev, struct dpaa2_dev_priv *priv,
+                 struct ether_addr *mac_entry)
+{
+       int ret;
+       struct ether_addr phy_mac = {}, prime_mac = {};
+
+       /* Get the physical device MAC address */
+       ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
+                                    phy_mac.addr_bytes);
+       if (ret) {
+               DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
+               goto cleanup;
+       }
+
+       ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
+                                       prime_mac.addr_bytes);
+       if (ret) {
+               DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
+               goto cleanup;
+       }
+
+       /* Now that both MAC have been obtained, do:
+        *  if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
+        *     and return phy
+        *  If empty_mac(phy), return prime.
+        *  if both are empty, create random MAC, set as prime and return
+        */
+       if (!is_zero_ether_addr(&phy_mac)) {
+               /* If the addresses are not same, overwrite prime */
+               if (!is_same_ether_addr(&phy_mac, &prime_mac)) {
+                       ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
+                                                       priv->token,
+                                                       phy_mac.addr_bytes);
+                       if (ret) {
+                               DPAA2_PMD_ERR("Unable to set MAC Address: %d",
+                                             ret);
+                               goto cleanup;
+                       }
+                       memcpy(&prime_mac, &phy_mac, sizeof(struct ether_addr));
+               }
+       } else if (is_zero_ether_addr(&prime_mac)) {
+               /* In case phys and prime, both are zero, create random MAC */
+               eth_random_addr(prime_mac.addr_bytes);
+               ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
+                                               priv->token,
+                                               prime_mac.addr_bytes);
+               if (ret) {
+                       DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
+                       goto cleanup;
+               }
+       }
+
+       /* prime_mac the final MAC address */
+       memcpy(mac_entry, &prime_mac, sizeof(struct ether_addr));
+       return 0;
+
+cleanup:
+       return -1;
+}
+
 static int
 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
 {
@@ -1846,7 +1965,10 @@ dpaa2_dev_init(struct rte_eth_dev *eth_dev)
                goto init_err;
        }
 
-       /* Allocate memory for storing MAC addresses */
+       /* Allocate memory for storing MAC addresses.
+        * Table of mac_filter_entries size is allocated so that RTE ether lib
+        * can add MAC entries when rte_eth_dev_mac_addr_add is called.
+        */
        eth_dev->data->mac_addrs = rte_zmalloc("dpni",
                ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
        if (eth_dev->data->mac_addrs == NULL) {
@@ -1857,12 +1979,11 @@ dpaa2_dev_init(struct rte_eth_dev *eth_dev)
                goto init_err;
        }
 
-       ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
-                                       priv->token,
-                       (uint8_t *)(eth_dev->data->mac_addrs[0].addr_bytes));
+       ret = populate_mac_addr(dpni_dev, priv, &eth_dev->data->mac_addrs[0]);
        if (ret) {
-               DPAA2_PMD_ERR("DPNI get mac address failed:Err Code = %d",
-                            ret);
+               DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
+               rte_free(eth_dev->data->mac_addrs);
+               eth_dev->data->mac_addrs = NULL;
                goto init_err;
        }
 
@@ -1894,7 +2015,7 @@ dpaa2_dev_init(struct rte_eth_dev *eth_dev)
        eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
        eth_dev->tx_pkt_burst = dpaa2_dev_tx;
 
-       DPAA2_PMD_INFO("%s: netdev created", eth_dev->data->name);
+       RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name);
        return 0;
 init_err:
        dpaa2_dev_uninit(eth_dev);
@@ -1987,7 +2108,6 @@ rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
        }
 
        eth_dev->device = &dpaa2_dev->device;
-       eth_dev->device->driver = &dpaa2_drv->driver;
 
        dpaa2_dev->eth_dev = eth_dev;
        eth_dev->data->rx_mbuf_alloc_failed = 0;
@@ -1997,8 +2117,10 @@ rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
 
        /* Invoke PMD device initialization function */
        diag = dpaa2_dev_init(eth_dev);
-       if (diag == 0)
+       if (diag == 0) {
+               rte_eth_dev_probing_finish(eth_dev);
                return 0;
+       }
 
        if (rte_eal_process_type() == RTE_PROC_PRIMARY)
                rte_free(eth_dev->data->dev_private);
@@ -2030,9 +2152,7 @@ static struct rte_dpaa2_driver rte_dpaa2_pmd = {
 
 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);
 
-RTE_INIT(dpaa2_pmd_init_log);
-static void
-dpaa2_pmd_init_log(void)
+RTE_INIT(dpaa2_pmd_init_log)
 {
        dpaa2_logtype_pmd = rte_log_register("pmd.net.dpaa2");
        if (dpaa2_logtype_pmd >= 0)