net/dpaa2: support statistics per queue
[dpdk.git] / drivers / net / dpaa2 / dpaa2_ethdev.c
index ec96a1c..46fa38f 100644 (file)
@@ -39,7 +39,6 @@ static uint64_t dev_rx_offloads_sup =
 
 /* Rx offloads which cannot be disabled */
 static uint64_t dev_rx_offloads_nodis =
-               DEV_RX_OFFLOAD_CRC_STRIP |
                DEV_RX_OFFLOAD_SCATTER;
 
 /* Supported Tx offloads */
@@ -406,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);
@@ -569,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 |
@@ -1117,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));
 
@@ -1164,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:
@@ -1323,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();
 
@@ -1335,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:
@@ -1785,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)
 {
@@ -1867,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) {
@@ -1878,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;
        }
 
@@ -2008,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;
@@ -2018,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);
@@ -2051,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)