#include "sfc_log.h"
#include "sfc_dp_rx.h"
+struct sfc_flow_ops_by_spec {
+ sfc_flow_parse_cb_t *parse;
+ sfc_flow_insert_cb_t *insert;
+ sfc_flow_remove_cb_t *remove;
+};
+
+static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_filter;
+static sfc_flow_insert_cb_t sfc_flow_filter_insert;
+static sfc_flow_remove_cb_t sfc_flow_filter_remove;
+
+static const struct sfc_flow_ops_by_spec sfc_flow_ops_filter = {
+ .parse = sfc_flow_parse_rte_to_filter,
+ .insert = sfc_flow_filter_insert,
+ .remove = sfc_flow_filter_remove,
+};
+
+static const struct sfc_flow_ops_by_spec *
+sfc_flow_get_ops_by_spec(struct rte_flow *flow)
+{
+ struct sfc_flow_spec *spec = &flow->spec;
+ const struct sfc_flow_ops_by_spec *ops = NULL;
+
+ switch (spec->type) {
+ case SFC_FLOW_SPEC_FILTER:
+ ops = &sfc_flow_ops_filter;
+ break;
+ default:
+ SFC_ASSERT(false);
+ break;
+ }
+
+ return ops;
+}
+
/*
* Currently, filter-based (VNIC) flow API is implemented in such a manner
* that each flow rule is converted to one or more hardware filters.
"Groups are not supported");
return -rte_errno;
}
- if (attr->priority != 0) {
- rte_flow_error_set(error, ENOTSUP,
- RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, attr,
- "Priorities are not supported");
- return -rte_errno;
- }
if (attr->egress != 0) {
rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attr,
"Egress is not supported");
return -rte_errno;
}
- if (attr->transfer != 0) {
+ if (attr->ingress == 0) {
rte_flow_error_set(error, ENOTSUP,
- RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, attr,
- "Transfer is not supported");
+ RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, attr,
+ "Ingress is compulsory");
return -rte_errno;
}
- if (attr->ingress == 0) {
+ if (attr->transfer == 0) {
+ if (attr->priority != 0) {
+ rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+ attr, "Priorities are unsupported");
+ return -rte_errno;
+ }
+ spec->type = SFC_FLOW_SPEC_FILTER;
+ spec_filter->template.efs_flags |= EFX_FILTER_FLAG_RX;
+ spec_filter->template.efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
+ } else {
rte_flow_error_set(error, ENOTSUP,
- RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, attr,
- "Only ingress is supported");
+ RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, attr,
+ "Transfer is not supported");
return -rte_errno;
}
- spec->type = SFC_FLOW_SPEC_FILTER;
- spec_filter->template.efs_flags |= EFX_FILTER_FLAG_RX;
- spec_filter->template.efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
-
return 0;
}
}
static int
-sfc_flow_parse(struct rte_eth_dev *dev,
- const struct rte_flow_attr *attr,
- const struct rte_flow_item pattern[],
- const struct rte_flow_action actions[],
- struct rte_flow *flow,
- struct rte_flow_error *error)
+sfc_flow_parse_rte_to_filter(struct rte_eth_dev *dev,
+ const struct rte_flow_item pattern[],
+ const struct rte_flow_action actions[],
+ struct rte_flow *flow,
+ struct rte_flow_error *error)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
int rc;
- rc = sfc_flow_parse_attr(attr, flow, error);
- if (rc != 0)
- goto fail_bad_value;
-
rc = sfc_flow_parse_pattern(pattern, flow, error);
if (rc != 0)
goto fail_bad_value;
return rc;
}
+static int
+sfc_flow_parse(struct rte_eth_dev *dev,
+ const struct rte_flow_attr *attr,
+ const struct rte_flow_item pattern[],
+ const struct rte_flow_action actions[],
+ struct rte_flow *flow,
+ struct rte_flow_error *error)
+{
+ const struct sfc_flow_ops_by_spec *ops;
+ int rc;
+
+ rc = sfc_flow_parse_attr(attr, flow, error);
+ if (rc != 0)
+ return rc;
+
+ ops = sfc_flow_get_ops_by_spec(flow);
+ if (ops == NULL || ops->parse == NULL) {
+ rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+ "No backend to handle this flow");
+ return -rte_errno;
+ }
+
+ return ops->parse(dev, pattern, actions, flow, error);
+}
+
static struct rte_flow *
sfc_flow_zmalloc(struct rte_flow_error *error)
{
rte_free(flow);
}
+static int
+sfc_flow_insert(struct sfc_adapter *sa, struct rte_flow *flow,
+ struct rte_flow_error *error)
+{
+ const struct sfc_flow_ops_by_spec *ops;
+ int rc;
+
+ ops = sfc_flow_get_ops_by_spec(flow);
+ if (ops == NULL || ops->insert == NULL) {
+ rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+ "No backend to handle this flow");
+ return rte_errno;
+ }
+
+ rc = ops->insert(sa, flow);
+ if (rc != 0) {
+ rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+ NULL, "Failed to insert the flow rule");
+ }
+
+ return rc;
+}
+
+static int
+sfc_flow_remove(struct sfc_adapter *sa, struct rte_flow *flow,
+ struct rte_flow_error *error)
+{
+ const struct sfc_flow_ops_by_spec *ops;
+ int rc;
+
+ ops = sfc_flow_get_ops_by_spec(flow);
+ if (ops == NULL || ops->remove == NULL) {
+ rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+ "No backend to handle this flow");
+ return rte_errno;
+ }
+
+ rc = ops->remove(sa, flow);
+ if (rc != 0) {
+ rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+ NULL, "Failed to remove the flow rule");
+ }
+
+ return rc;
+}
+
static int
sfc_flow_validate(struct rte_eth_dev *dev,
const struct rte_flow_attr *attr,
TAILQ_INSERT_TAIL(&sa->flow_list, flow, entries);
if (sa->state == SFC_ADAPTER_STARTED) {
- rc = sfc_flow_filter_insert(sa, flow);
- if (rc != 0) {
- rte_flow_error_set(error, rc,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
- "Failed to insert filter");
- goto fail_filter_insert;
- }
+ rc = sfc_flow_insert(sa, flow, error);
+ if (rc != 0)
+ goto fail_flow_insert;
}
sfc_adapter_unlock(sa);
return flow;
-fail_filter_insert:
+fail_flow_insert:
TAILQ_REMOVE(&sa->flow_list, flow, entries);
fail_bad_value:
return NULL;
}
-static int
-sfc_flow_remove(struct sfc_adapter *sa,
- struct rte_flow *flow,
- struct rte_flow_error *error)
-{
- int rc = 0;
-
- SFC_ASSERT(sfc_adapter_is_locked(sa));
-
- if (sa->state == SFC_ADAPTER_STARTED) {
- rc = sfc_flow_filter_remove(sa, flow);
- if (rc != 0)
- rte_flow_error_set(error, rc,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
- "Failed to destroy flow rule");
- }
-
- TAILQ_REMOVE(&sa->flow_list, flow, entries);
- sfc_flow_free(sa, flow);
-
- return rc;
-}
-
static int
sfc_flow_destroy(struct rte_eth_dev *dev,
struct rte_flow *flow,
goto fail_bad_value;
}
- rc = sfc_flow_remove(sa, flow, error);
+ if (sa->state == SFC_ADAPTER_STARTED)
+ rc = sfc_flow_remove(sa, flow, error);
+
+ TAILQ_REMOVE(&sa->flow_list, flow, entries);
+ sfc_flow_free(sa, flow);
fail_bad_value:
sfc_adapter_unlock(sa);
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct rte_flow *flow;
- int rc = 0;
int ret = 0;
sfc_adapter_lock(sa);
while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
- rc = sfc_flow_remove(sa, flow, error);
- if (rc != 0)
- ret = rc;
+ if (sa->state == SFC_ADAPTER_STARTED) {
+ int rc;
+
+ rc = sfc_flow_remove(sa, flow, error);
+ if (rc != 0)
+ ret = rc;
+ }
+
+ TAILQ_REMOVE(&sa->flow_list, flow, entries);
+ sfc_flow_free(sa, flow);
}
sfc_adapter_unlock(sa);
SFC_ASSERT(sfc_adapter_is_locked(sa));
TAILQ_FOREACH(flow, &sa->flow_list, entries)
- sfc_flow_filter_remove(sa, flow);
+ sfc_flow_remove(sa, flow, NULL);
}
int
SFC_ASSERT(sfc_adapter_is_locked(sa));
TAILQ_FOREACH(flow, &sa->flow_list, entries) {
- rc = sfc_flow_filter_insert(sa, flow);
+ rc = sfc_flow_insert(sa, flow, NULL);
if (rc != 0)
goto fail_bad_flow;
}