net/softnic: add flow flush API

Message ID 1538411914-12721-1-git-send-email-reshma.pattan@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Cristian Dumitrescu
Headers
Series net/softnic: add flow flush API |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Pattan, Reshma Oct. 1, 2018, 4:38 p.m. UTC
  Add rte flow flush api for flushing
all the flows of the port.

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
This patch depends on below patch sets
so must be applied after below patches are applied.
https://mails.dpdk.org/archives/dev/2018-September/111379.html
https://mails.dpdk.org/archives/dev/2018-September/111505.html
---
 drivers/net/softnic/rte_eth_softnic_flow.c | 46 +++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
  

Comments

Jasvinder Singh Oct. 2, 2018, 8:01 a.m. UTC | #1
<snip>
> --- a/drivers/net/softnic/rte_eth_softnic_flow.c
> +++ b/drivers/net/softnic/rte_eth_softnic_flow.c
> @@ -1915,6 +1915,50 @@ pmd_flow_destroy(struct rte_eth_dev *dev,
>  	return 0;
>  }
> 
> +static int
> +pmd_flow_flush(struct rte_eth_dev *dev,
> +	struct rte_flow_error *error)
> +{
> +	struct pmd_internals *softnic = dev->data->dev_private;
> +	struct pipeline *pipeline;
> +	int status;
> +	uint32_t i = 0;
> +
> +	TAILQ_FOREACH(pipeline, &softnic->pipeline_list, node) {

Removing elements when iterating tailq lists with TAILQ_FOREACH macro is not safe.
Instead, use TAILQ_FOREACH_SAFE  for safe tailq element removal within the loop.

> +		/* Remove all the flows added to the tables. */
> +		for (i = 0; i < pipeline->n_tables; i++) {
> +			struct softnic_table *table;
> +			struct rte_flow *flow;
> +
> +			table = &pipeline->table[i];
> +			TAILQ_FOREACH(flow, &table->flows, node) {
> +				/* Rule delete. */
> +				status = softnic_pipeline_table_rule_delete
> +						(softnic,
> +						flow->pipeline->name,
> +						flow->table_id,
> +						&flow->match);
> +				if (status)
> +					return rte_flow_error_set(error,
> +						EINVAL,
> +
> 	RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
> +						NULL,
> +						"Pipeline table rule delete
> failed");
> +
> +			/* Update dependencies */
> +			if (is_meter_action_enable(softnic, table))
> +				flow_meter_owner_reset(softnic, flow);
Fix Indentation here.
> +				/* Flow delete. */
> +				TAILQ_REMOVE(&table->flows, flow, node);
> +				free(flow);
> +			}
> +		}
> +	}
> +
> +	return 0;
> +}
> +
>  static int
>  pmd_flow_query(struct rte_eth_dev *dev __rte_unused,
>  	struct rte_flow *flow,
> @@ -1971,7 +2015,7 @@ const struct rte_flow_ops pmd_flow_ops = {
>  	.validate = pmd_flow_validate,
>  	.create = pmd_flow_create,
>  	.destroy = pmd_flow_destroy,
> -	.flush = NULL,
> +	.flush = pmd_flow_flush,
>  	.query = pmd_flow_query,
>  	.isolate = NULL,
>  };
> --
> 2.17.1
  

Patch

diff --git a/drivers/net/softnic/rte_eth_softnic_flow.c b/drivers/net/softnic/rte_eth_softnic_flow.c
index 03d41bc01..db0d81dfd 100644
--- a/drivers/net/softnic/rte_eth_softnic_flow.c
+++ b/drivers/net/softnic/rte_eth_softnic_flow.c
@@ -1915,6 +1915,50 @@  pmd_flow_destroy(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+pmd_flow_flush(struct rte_eth_dev *dev,
+	struct rte_flow_error *error)
+{
+	struct pmd_internals *softnic = dev->data->dev_private;
+	struct pipeline *pipeline;
+	int status;
+	uint32_t i = 0;
+
+	TAILQ_FOREACH(pipeline, &softnic->pipeline_list, node) {
+		/* Remove all the flows added to the tables. */
+		for (i = 0; i < pipeline->n_tables; i++) {
+			struct softnic_table *table;
+			struct rte_flow *flow;
+
+			table = &pipeline->table[i];
+			TAILQ_FOREACH(flow, &table->flows, node) {
+				/* Rule delete. */
+				status = softnic_pipeline_table_rule_delete
+						(softnic,
+						flow->pipeline->name,
+						flow->table_id,
+						&flow->match);
+				if (status)
+					return rte_flow_error_set(error,
+						EINVAL,
+						RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						NULL,
+						"Pipeline table rule delete failed");
+
+			/* Update dependencies */
+			if (is_meter_action_enable(softnic, table))
+				flow_meter_owner_reset(softnic, flow);
+
+				/* Flow delete. */
+				TAILQ_REMOVE(&table->flows, flow, node);
+				free(flow);
+			}
+		}
+	}
+
+	return 0;
+}
+
 static int
 pmd_flow_query(struct rte_eth_dev *dev __rte_unused,
 	struct rte_flow *flow,
@@ -1971,7 +2015,7 @@  const struct rte_flow_ops pmd_flow_ops = {
 	.validate = pmd_flow_validate,
 	.create = pmd_flow_create,
 	.destroy = pmd_flow_destroy,
-	.flush = NULL,
+	.flush = pmd_flow_flush,
 	.query = pmd_flow_query,
 	.isolate = NULL,
 };