net/dpaa2: add support for MAC address filtering
[dpdk.git] / drivers / net / dpaa2 / dpaa2_ethdev.c
index 797e71d..5180871 100644 (file)
@@ -177,8 +177,13 @@ dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
 
        for (i = 0; i < priv->nb_tx_queues; i++) {
                mc_q->dev = dev;
-               mc_q->flow_id = DPNI_NEW_FLOW_ID;
+               mc_q->flow_id = 0xffff;
                priv->tx_vq[i] = mc_q++;
+               dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
+               dpaa2_q->cscn = rte_malloc(NULL,
+                                          sizeof(struct qbman_result), 16);
+               if (!dpaa2_q->cscn)
+                       goto fail_tx;
        }
 
        vq_id = 0;
@@ -191,6 +196,14 @@ dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
        }
 
        return 0;
+fail_tx:
+       i -= 1;
+       while (i >= 0) {
+               dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
+               rte_free(dpaa2_q->cscn);
+               priv->tx_vq[i--] = NULL;
+       }
+       i = priv->nb_rx_queues;
 fail:
        i -= 1;
        mc_q = priv->rx_vq[0];
@@ -296,6 +309,25 @@ dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
                return -1;
        }
 
+       if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
+               struct dpni_taildrop taildrop;
+
+               taildrop.enable = 1;
+               /*enabling per rx queue congestion control */
+               taildrop.threshold = CONG_THRESHOLD_RX_Q;
+               taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
+               PMD_INIT_LOG(DEBUG, "Enabling Early Drop on queue = %d",
+                            rx_queue_id);
+               ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
+                                       DPNI_CP_QUEUE, DPNI_QUEUE_RX,
+                                       dpaa2_q->tc_index, flow_id, &taildrop);
+               if (ret) {
+                       PMD_INIT_LOG(ERR, "Error in setting the rx flow"
+                                    " err : = %d\n", ret);
+                       return -1;
+               }
+       }
+
        dev->data->rx_queues[rx_queue_id] = dpaa2_q;
        return 0;
 }
@@ -320,7 +352,7 @@ dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
        PMD_INIT_FUNC_TRACE();
 
        /* Return if queue already configured */
-       if (dpaa2_q->flow_id != DPNI_NEW_FLOW_ID)
+       if (dpaa2_q->flow_id != 0xffff)
                return 0;
 
        memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
@@ -358,6 +390,36 @@ dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
        }
        dpaa2_q->tc_index = tc_id;
 
+       if (priv->flags & DPAA2_TX_CGR_SUPPORT) {
+               struct dpni_congestion_notification_cfg cong_notif_cfg;
+
+               cong_notif_cfg.units = DPNI_CONGESTION_UNIT_BYTES;
+               /* Notify about congestion when the queue size is 32 KB */
+               cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
+               /* Notify that the queue is not congested when the data in
+                * the queue is below this thershold.
+                */
+               cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
+               cong_notif_cfg.message_ctx = 0;
+               cong_notif_cfg.message_iova = (uint64_t)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 |
+                                        DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
+                                        DPNI_CONG_OPT_COHERENT_WRITE;
+
+               ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
+                                                      priv->token,
+                                                      DPNI_QUEUE_TX,
+                                                      tc_id,
+                                                      &cong_notif_cfg);
+               if (ret) {
+                       PMD_INIT_LOG(ERR,
+                          "Error in setting tx congestion notification: = %d",
+                          -ret);
+                       return -ret;
+               }
+       }
        dev->data->tx_queues[tx_queue_id] = dpaa2_q;
        return 0;
 }
@@ -513,12 +575,22 @@ dpaa2_dev_stop(struct rte_eth_dev *dev)
 static void
 dpaa2_dev_close(struct rte_eth_dev *dev)
 {
+       struct rte_eth_dev_data *data = dev->data;
        struct dpaa2_dev_priv *priv = dev->data->dev_private;
        struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
-       int ret;
+       int i, ret;
+       struct dpaa2_queue *dpaa2_q;
 
        PMD_INIT_FUNC_TRACE();
 
+       for (i = 0; i < data->nb_tx_queues; i++) {
+               dpaa2_q = (struct dpaa2_queue *)data->tx_queues[i];
+               if (!dpaa2_q->cscn) {
+                       rte_free(dpaa2_q->cscn);
+                       dpaa2_q->cscn = NULL;
+               }
+       }
+
        /* Clean the device first */
        ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
        if (ret) {
@@ -600,6 +672,78 @@ dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        return 0;
 }
 
+static int
+dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
+                      struct ether_addr *addr,
+                      __rte_unused uint32_t index,
+                      __rte_unused uint32_t pool)
+{
+       int ret;
+       struct dpaa2_dev_priv *priv = dev->data->dev_private;
+       struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
+
+       PMD_INIT_FUNC_TRACE();
+
+       if (dpni == NULL) {
+               RTE_LOG(ERR, PMD, "dpni is NULL");
+               return -1;
+       }
+
+       ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
+                               priv->token, addr->addr_bytes);
+       if (ret)
+               RTE_LOG(ERR, PMD, "error: Adding the MAC ADDR failed:"
+                       " err = %d", ret);
+       return 0;
+}
+
+static void
+dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
+                         uint32_t index)
+{
+       int ret;
+       struct dpaa2_dev_priv *priv = dev->data->dev_private;
+       struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
+       struct rte_eth_dev_data *data = dev->data;
+       struct ether_addr *macaddr;
+
+       PMD_INIT_FUNC_TRACE();
+
+       macaddr = &data->mac_addrs[index];
+
+       if (dpni == NULL) {
+               RTE_LOG(ERR, PMD, "dpni is NULL");
+               return;
+       }
+
+       ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
+                                  priv->token, macaddr->addr_bytes);
+       if (ret)
+               RTE_LOG(ERR, PMD, "error: Removing the MAC ADDR failed:"
+                       " err = %d", ret);
+}
+
+static void
+dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
+                      struct ether_addr *addr)
+{
+       int ret;
+       struct dpaa2_dev_priv *priv = dev->data->dev_private;
+       struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
+
+       PMD_INIT_FUNC_TRACE();
+
+       if (dpni == NULL) {
+               RTE_LOG(ERR, PMD, "dpni is NULL");
+               return;
+       }
+
+       ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
+                                       priv->token, addr->addr_bytes);
+
+       if (ret)
+               RTE_LOG(ERR, PMD, "error: Setting the MAC ADDR failed %d", ret);
+}
 static
 void dpaa2_dev_stats_get(struct rte_eth_dev *dev,
                         struct rte_eth_stats *stats)
@@ -648,7 +792,11 @@ void dpaa2_dev_stats_get(struct rte_eth_dev *dev,
        if (retcode)
                goto err;
 
-       stats->ierrors = value.page_2.ingress_discarded_frames;
+       /* Ingress drop frame count due to configured rules */
+       stats->ierrors = value.page_2.ingress_filtered_frames;
+       /* Ingress drop frame count due to error */
+       stats->ierrors += value.page_2.ingress_discarded_frames;
+
        stats->oerrors = value.page_2.egress_discarded_frames;
        stats->imissed = value.page_2.ingress_nobuffer_discards;
 
@@ -750,6 +898,9 @@ static struct eth_dev_ops dpaa2_ethdev_ops = {
        .rx_queue_release  = dpaa2_dev_rx_queue_release,
        .tx_queue_setup    = dpaa2_dev_tx_queue_setup,
        .tx_queue_release  = dpaa2_dev_tx_queue_release,
+       .mac_addr_add         = dpaa2_dev_add_mac_addr,
+       .mac_addr_remove      = dpaa2_dev_remove_mac_addr,
+       .mac_addr_set         = dpaa2_dev_set_mac_addr,
 };
 
 static int
@@ -832,6 +983,9 @@ dpaa2_dev_init(struct rte_eth_dev *eth_dev)
        priv->max_vlan_filters = attr.vlan_filter_entries;
        priv->flags = 0;
 
+       priv->flags |= DPAA2_TX_CGR_SUPPORT;
+       PMD_INIT_LOG(INFO, "Enable the tx congestion control support");
+
        /* Allocate memory for hardware structure for queues */
        ret = dpaa2_alloc_rx_tx_queues(eth_dev);
        if (ret) {