1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #include "rte_eth_softnic_internals.h"
6 #include "rte_eth_softnic.h"
9 flow_attr_map_set(struct pmd_internals *softnic,
12 const char *pipeline_name,
15 struct pipeline *pipeline;
16 struct flow_attr_map *map;
18 if (group_id >= SOFTNIC_FLOW_MAX_GROUPS ||
19 pipeline_name == NULL)
22 pipeline = softnic_pipeline_find(softnic, pipeline_name);
23 if (pipeline == NULL ||
24 table_id >= pipeline->n_tables)
27 map = (ingress) ? &softnic->flow.ingress_map[group_id] :
28 &softnic->flow.egress_map[group_id];
29 strcpy(map->pipeline_name, pipeline_name);
30 map->table_id = table_id;
36 struct flow_attr_map *
37 flow_attr_map_get(struct pmd_internals *softnic,
41 if (group_id >= SOFTNIC_FLOW_MAX_GROUPS)
44 return (ingress) ? &softnic->flow.ingress_map[group_id] :
45 &softnic->flow.egress_map[group_id];
49 flow_pipeline_table_get(struct pmd_internals *softnic,
50 const struct rte_flow_attr *attr,
51 const char **pipeline_name,
53 struct rte_flow_error *error)
55 struct flow_attr_map *map;
58 return rte_flow_error_set(error,
60 RTE_FLOW_ERROR_TYPE_ATTR,
64 if (!attr->ingress && !attr->egress)
65 return rte_flow_error_set(error,
67 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
69 "Ingress/egress not specified");
71 if (attr->ingress && attr->egress)
72 return rte_flow_error_set(error,
74 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
76 "Setting both ingress and egress is not allowed");
78 map = flow_attr_map_get(softnic,
83 return rte_flow_error_set(error,
85 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
90 *pipeline_name = map->pipeline_name;
93 *table_id = map->table_id;
99 pmd_flow_validate(struct rte_eth_dev *dev,
100 const struct rte_flow_attr *attr,
101 const struct rte_flow_item item[],
102 const struct rte_flow_action action[],
103 struct rte_flow_error *error)
105 struct pmd_internals *softnic = dev->data->dev_private;
106 struct pipeline *pipeline;
107 const char *pipeline_name = NULL;
108 uint32_t table_id = 0;
111 /* Check input parameters. */
113 return rte_flow_error_set(error,
115 RTE_FLOW_ERROR_TYPE_ATTR,
119 return rte_flow_error_set(error,
121 RTE_FLOW_ERROR_TYPE_ITEM,
126 return rte_flow_error_set(error,
128 RTE_FLOW_ERROR_TYPE_ACTION,
132 /* Identify the pipeline table to add this flow to. */
133 status = flow_pipeline_table_get(softnic, attr, &pipeline_name,
138 pipeline = softnic_pipeline_find(softnic, pipeline_name);
139 if (pipeline == NULL)
140 return rte_flow_error_set(error,
142 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
144 "Invalid pipeline name");
146 if (table_id >= pipeline->n_tables)
147 return rte_flow_error_set(error,
149 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
151 "Invalid pipeline table ID");
156 const struct rte_flow_ops pmd_flow_ops = {
157 .validate = pmd_flow_validate,