net/bnxt: add flow stats in extended stats
[dpdk.git] / drivers / net / bnxt / bnxt_flow.c
index bd6c726..4473427 100644 (file)
@@ -10,6 +10,8 @@
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
 #include <rte_tailq.h>
+#include <rte_alarm.h>
+#include <rte_cycles.h>
 
 #include "bnxt.h"
 #include "bnxt_filter.h"
@@ -1263,7 +1265,6 @@ use_vnic:
                vnic_id = attr->group;
 
                BNXT_VALID_VNIC_OR_RET(bp, vnic_id);
-
                vnic = &bp->vnic_info[vnic_id];
 
                /* Check if requested RSS config matches RSS config of VNIC
@@ -1628,6 +1629,51 @@ bnxt_match_filter(struct bnxt *bp, struct bnxt_filter_info *nf)
        return 0;
 }
 
+static void
+bnxt_setup_flow_counter(struct bnxt *bp)
+{
+       if (bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_COUNTERS &&
+           !(bp->flags & BNXT_FLAG_FC_THREAD)) {
+               rte_eal_alarm_set(US_PER_S * BNXT_FC_TIMER,
+                                 bnxt_flow_cnt_alarm_cb,
+                                 (void *)bp);
+               bp->flags |= BNXT_FLAG_FC_THREAD;
+       }
+}
+
+void bnxt_flow_cnt_alarm_cb(void *arg)
+{
+       int rc = 0;
+       struct bnxt *bp = arg;
+
+       if (!bp->rx_fc_out_tbl.va) {
+               PMD_DRV_LOG(ERR, "bp->rx_fc_out_tbl.va is NULL?\n");
+               bnxt_cancel_fc_thread(bp);
+               return;
+       }
+
+       if (!bp->flow_count) {
+               bnxt_cancel_fc_thread(bp);
+               return;
+       }
+
+       if (!bp->eth_dev->data->dev_started) {
+               bnxt_cancel_fc_thread(bp);
+               return;
+       }
+
+       rc = bnxt_flow_stats_req(bp);
+       if (rc) {
+               PMD_DRV_LOG(ERR, "Flow stat alarm not rescheduled.\n");
+               return;
+       }
+
+       rte_eal_alarm_set(US_PER_S * BNXT_FC_TIMER,
+                         bnxt_flow_cnt_alarm_cb,
+                         (void *)bp);
+}
+
+
 static struct rte_flow *
 bnxt_flow_create(struct rte_eth_dev *dev,
                 const struct rte_flow_attr *attr,
@@ -1641,7 +1687,7 @@ bnxt_flow_create(struct rte_eth_dev *dev,
        bool update_flow = false;
        struct rte_flow *flow;
        int ret = 0;
-       uint32_t tun_type;
+       uint32_t tun_type, flow_id;
 
        if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
                rte_flow_error_set(error, EINVAL,
@@ -1773,10 +1819,20 @@ done:
                        /* TCAM and EM should be 16-bit only.
                         * Other modes not supported.
                         */
-                       bp->mark_table[filter->flow_id & BNXT_FLOW_ID_MASK] =
-                               filter->mark;
+                       flow_id = filter->flow_id & BNXT_FLOW_ID_MASK;
+                       if (bp->mark_table[flow_id].valid) {
+                               PMD_DRV_LOG(ERR,
+                                           "Entry for Mark id 0x%x occupied"
+                                           " flow id 0x%x\n",
+                                           filter->mark, filter->flow_id);
+                               goto free_filter;
+                       }
+                       bp->mark_table[flow_id].valid = true;
+                       bp->mark_table[flow_id].mark_id = filter->mark;
                }
+               bp->flow_count++;
                bnxt_release_flow_lock(bp);
+               bnxt_setup_flow_counter(bp);
                return flow;
        }
 
@@ -1850,6 +1906,7 @@ _bnxt_flow_destroy(struct bnxt *bp,
        struct bnxt_filter_info *filter;
        struct bnxt_vnic_info *vnic;
        int ret = 0;
+       uint32_t flow_id;
 
        filter = flow->filter;
        vnic = flow->vnic;
@@ -1868,7 +1925,9 @@ _bnxt_flow_destroy(struct bnxt *bp,
                PMD_DRV_LOG(ERR, "Could not find matching flow\n");
 
        if (filter->valid_flags & BNXT_FLOW_MARK_FLAG) {
-               bp->mark_table[filter->flow_id & BNXT_FLOW_ID_MASK] = 0;
+               flow_id = filter->flow_id & BNXT_FLOW_ID_MASK;
+               memset(&bp->mark_table[flow_id], 0,
+                      sizeof(bp->mark_table[flow_id]));
                filter->flow_id = 0;
        }
 
@@ -1893,6 +1952,7 @@ done:
                bnxt_free_filter(bp, filter);
                STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
                rte_free(flow);
+               bp->flow_count--;
 
                /* If this was the last flow associated with this vnic,
                 * switch the queue back to RSS pool.
@@ -1945,6 +2005,12 @@ bnxt_flow_destroy(struct rte_eth_dev *dev,
        return ret;
 }
 
+void bnxt_cancel_fc_thread(struct bnxt *bp)
+{
+       bp->flags &= ~BNXT_FLAG_FC_THREAD;
+       rte_eal_alarm_cancel(bnxt_flow_cnt_alarm_cb, (void *)bp);
+}
+
 static int
 bnxt_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
 {
@@ -1971,6 +2037,8 @@ bnxt_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
                                break;
                }
        }
+
+       bnxt_cancel_fc_thread(bp);
        bnxt_release_flow_lock(bp);
 
        return ret;