xref: /dpdk/drivers/net/sfc/sfc_flow.h (revision f5057be340e44f3edc0fe90fa875eb89a4c49b4f)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2020 Xilinx, Inc.
4  * Copyright(c) 2017-2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9 
10 #ifndef _SFC_FLOW_H
11 #define _SFC_FLOW_H
12 
13 #include <rte_tailq.h>
14 #include <rte_flow_driver.h>
15 
16 #include "efx.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /*
23  * The maximum number of fully elaborated hardware filter specifications
24  * which can be produced from a template by means of multiplication, if
25  * missing match flags are needed to be taken into account
26  */
27 #define SF_FLOW_SPEC_NB_FILTERS_MAX 8
28 
29 /* RSS configuration storage */
30 struct sfc_flow_rss {
31 	unsigned int	rxq_hw_index_min;
32 	unsigned int	rxq_hw_index_max;
33 	unsigned int	rss_hash_types;
34 	uint8_t		rss_key[EFX_RSS_KEY_SIZE];
35 	unsigned int	rss_tbl[EFX_RSS_TBL_SIZE];
36 };
37 
38 /* Flow engines supported by the implementation */
39 enum sfc_flow_spec_type {
40 	SFC_FLOW_SPEC_FILTER = 0,
41 
42 	SFC_FLOW_SPEC_NTYPES
43 };
44 
45 /* VNIC-specific flow specification */
46 struct sfc_flow_spec_filter {
47 	/* partial specification from flow rule */
48 	efx_filter_spec_t template;
49 	/* fully elaborated hardware filters specifications */
50 	efx_filter_spec_t filters[SF_FLOW_SPEC_NB_FILTERS_MAX];
51 	/* number of complete specifications */
52 	unsigned int count;
53 	/* RSS toggle */
54 	boolean_t rss;
55 	/* RSS hash toggle */
56 	boolean_t rss_hash_required;
57 	/* RSS configuration */
58 	struct sfc_flow_rss rss_conf;
59 };
60 
61 /* Flow specification */
62 struct sfc_flow_spec {
63 	/* Flow specification type (engine-based) */
64 	enum sfc_flow_spec_type type;
65 
66 	RTE_STD_C11
67 	union {
68 		/* Filter-based (VNIC level flows) specification */
69 		struct sfc_flow_spec_filter filter;
70 	};
71 };
72 
73 /* PMD-specific definition of the opaque type from rte_flow.h */
74 struct rte_flow {
75 	struct sfc_flow_spec spec;	/* flow specification */
76 	TAILQ_ENTRY(rte_flow) entries;	/* flow list entries */
77 };
78 
79 TAILQ_HEAD(sfc_flow_list, rte_flow);
80 
81 extern const struct rte_flow_ops sfc_flow_ops;
82 
83 enum sfc_flow_item_layers {
84 	SFC_FLOW_ITEM_ANY_LAYER,
85 	SFC_FLOW_ITEM_START_LAYER,
86 	SFC_FLOW_ITEM_L2,
87 	SFC_FLOW_ITEM_L3,
88 	SFC_FLOW_ITEM_L4,
89 };
90 
91 /* Flow parse context types */
92 enum sfc_flow_parse_ctx_type {
93 	SFC_FLOW_PARSE_CTX_FILTER = 0,
94 
95 	SFC_FLOW_PARSE_CTX_NTYPES
96 };
97 
98 /* Flow parse context */
99 struct sfc_flow_parse_ctx {
100 	enum sfc_flow_parse_ctx_type type;
101 
102 	RTE_STD_C11
103 	union {
104 		/* Context pointer valid for filter-based (VNIC) flows */
105 		efx_filter_spec_t *filter;
106 	};
107 };
108 
109 typedef int (sfc_flow_item_parse)(const struct rte_flow_item *item,
110 				  struct sfc_flow_parse_ctx *parse_ctx,
111 				  struct rte_flow_error *error);
112 
113 struct sfc_flow_item {
114 	enum rte_flow_item_type type;		/* Type of item */
115 	enum sfc_flow_item_layers layer;	/* Layer of item */
116 	enum sfc_flow_item_layers prev_layer;	/* Previous layer of item */
117 	enum sfc_flow_parse_ctx_type ctx_type;	/* Parse context type */
118 	sfc_flow_item_parse *parse;		/* Parsing function */
119 };
120 
121 int sfc_flow_parse_pattern(const struct sfc_flow_item *flow_items,
122 			   unsigned int nb_flow_items,
123 			   const struct rte_flow_item pattern[],
124 			   struct sfc_flow_parse_ctx *parse_ctx,
125 			   struct rte_flow_error *error);
126 
127 int sfc_flow_parse_init(const struct rte_flow_item *item,
128 			const void **spec_ptr,
129 			const void **mask_ptr,
130 			const void *supp_mask,
131 			const void *def_mask,
132 			unsigned int size,
133 			struct rte_flow_error *error);
134 
135 struct sfc_adapter;
136 
137 void sfc_flow_init(struct sfc_adapter *sa);
138 void sfc_flow_fini(struct sfc_adapter *sa);
139 int sfc_flow_start(struct sfc_adapter *sa);
140 void sfc_flow_stop(struct sfc_adapter *sa);
141 
142 typedef int (sfc_flow_parse_cb_t)(struct rte_eth_dev *dev,
143 				  const struct rte_flow_item items[],
144 				  const struct rte_flow_action actions[],
145 				  struct rte_flow *flow,
146 				  struct rte_flow_error *error);
147 
148 typedef int (sfc_flow_insert_cb_t)(struct sfc_adapter *sa,
149 				   struct rte_flow *flow);
150 
151 typedef int (sfc_flow_remove_cb_t)(struct sfc_adapter *sa,
152 				   struct rte_flow *flow);
153 
154 #ifdef __cplusplus
155 }
156 #endif
157 #endif /* _SFC_FLOW_H */
158