2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include <rte_common.h>
21 #ifndef __rte_cache_aligned
22 #include <rte_memory.h>
26 #include "prox_globals.h"
27 #include "stats_task.h"
29 // runtime_flags 8 bits only
30 #define TASK_MPLS_TAGGING 0x0001
31 #define TASK_ROUTING 0x0002
32 #define TASK_CLASSIFY 0x0004
33 #define TASK_CTRL_HANDLE_ARP 0x0008
34 #define TASK_MARK 0x0020
35 #define TASK_FP_HANDLE_ARP 0x0040
36 #define TASK_TX_CRC 0x0080
38 // flag_features 64 bits
39 #define TASK_FEATURE_ROUTING 0x0001
40 #define TASK_FEATURE_CLASSIFY 0x0002
41 #define TASK_FEATURE_MULTI_RX 0x0004
42 #define TASK_FEATURE_NEVER_DISCARDS 0x0008
43 #define TASK_FEATURE_NO_RX 0x0010
44 #define TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS 0x0020
45 #define TASK_FEATURE_TXQ_FLAGS_NOMULTSEGS 0x0040
46 #define TASK_FEATURE_ZERO_RX 0x0080
47 #define TASK_FEATURE_TXQ_FLAGS_REFCOUNT 0x0100
48 #define TASK_FEATURE_TSC_RX 0x0200
49 #define TASK_FEATURE_THROUGHPUT_OPT 0x0400
50 #define TASK_FEATURE_GRE_ID 0x1000
51 #define TASK_FEATURE_LUT_QINQ_RSS 0x2000
52 #define TASK_FEATURE_LUT_QINQ_HASH 0x4000
53 #define TASK_FEATURE_RX_ALL 0x8000
54 #define TASK_MULTIPLE_MAC 0x10000
56 #define FLAG_TX_FLUSH 0x01
57 #define FLAG_NEVER_FLUSH 0x02
58 // Task specific flags
59 #define BASE_FLAG_LUT_QINQ_HASH 0x08
60 #define BASE_FLAG_LUT_QINQ_RSS 0x10
62 #define OUT_DISCARD 0xFF
63 #define OUT_HANDLED 0xFE
65 #define WS_MBUF_MASK (2 * MAX_PKT_BURST - 1)
67 /* struct ws_mbuf stores the working set of mbufs. It starts with a
68 prod/cons index to keep track of the number of elemenets. */
74 uint16_t pad; /* reserved */
75 } idx[MAX_RINGS_PER_TASK];
76 struct rte_mbuf *mbuf[][MAX_RING_BURST * 3] __rte_cache_aligned;
82 } __attribute__((packed));
89 uint8_t last_read_portid;
90 struct port_queue *rx_pq;
91 } __attribute__((packed));
93 struct rx_params_hw1 {
94 struct port_queue rx_pq;
95 } __attribute__((packed));
100 uint8_t rxrings_mask; /* Used if rte_is_power_of_2(nb_rxrings)*/
102 uint8_t last_read_ring;
103 struct rte_ring **rx_rings;
104 } __attribute__((packed));
106 /* If there is only one input ring, the pointer to it can be stored
107 directly into the task_base instead of having to use a pointer to a
108 set of rings which would require two dereferences. */
109 struct rx_params_sw1 {
110 struct rte_ring *rx_ring;
111 } __attribute__((packed));
113 struct tx_params_hw {
115 struct port_queue *tx_port_queue;
116 } __attribute__((packed));
118 struct tx_params_sw {
120 struct rte_ring **tx_rings;
121 } __attribute__((packed));
123 struct tx_params_hw_sw { /* Only one port supported in this mode */
125 struct rte_ring **tx_rings;
126 struct port_queue tx_port_queue;
127 } __attribute__((packed));
129 struct task_rt_dump {
135 void *pkt_mbuf_addr[MAX_RING_BURST]; /* To track reordering */
136 uint8_t pkt_cpy[MAX_RING_BURST][128];
137 uint16_t pkt_cpy_len[MAX_RING_BURST];
142 #define MAX_RX_PKT_ALL 16384
144 #define MAX_STACKED_RX_FUCTIONS 16
146 typedef uint16_t (*rx_pkt_func) (struct task_base *tbase, struct rte_mbuf ***mbufs);
148 struct task_base_aux {
149 /* Not used when PROX_STATS is not defined */
150 struct task_rt_stats stats;
151 struct task_rt_dump task_rt_dump;
153 /* Used if TASK_TSC_RX is enabled*/
159 struct rte_mbuf **all_mbufs;
163 uint16_t (*rx_pkt_prev[MAX_STACKED_RX_FUCTIONS])(struct task_base *tbase, struct rte_mbuf ***mbufs);
165 uint32_t rx_bucket[MAX_RING_BURST + 1];
166 uint32_t tx_bucket[MAX_RING_BURST + 1];
167 int (*tx_pkt_orig)(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
168 int (*tx_pkt_hw)(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
169 uint16_t (*tx_pkt_try)(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts);
170 void (*stop)(struct task_base *tbase);
171 void (*start)(struct task_base *tbase);
172 void (*stop_last)(struct task_base *tbase);
173 void (*start_first)(struct task_base *tbase);
176 /* The task_base is accessed for _all_ task types. In case
177 no debugging is needed, it has been optimized to fit
178 into a single cache line to minimize cache pollution */
180 int (*handle_bulk)(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts);
181 int (*tx_pkt)(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
182 uint16_t (*rx_pkt)(struct task_base *tbase, struct rte_mbuf ***mbufs);
184 struct task_base_aux* aux;
185 /* The working set of mbufs contains mbufs that are currently
187 struct ws_mbuf *ws_mbuf;
192 struct rx_params_hw rx_params_hw;
193 struct rx_params_hw1 rx_params_hw1;
194 struct rx_params_sw rx_params_sw;
195 struct rx_params_sw1 rx_params_sw1;
199 struct tx_params_hw tx_params_hw;
200 struct tx_params_sw tx_params_sw;
201 struct tx_params_hw_sw tx_params_hw_sw;
203 } __attribute__((packed)) __rte_cache_aligned;
205 static void task_base_add_rx_pkt_function(struct task_base *tbase, rx_pkt_func to_add)
207 if (tbase->aux->rx_prev_count == MAX_STACKED_RX_FUCTIONS) {
211 for (int16_t i = tbase->aux->rx_prev_count; i >= 0; --i) {
212 tbase->aux->rx_pkt_prev[i + 1] = tbase->aux->rx_pkt_prev[i];
214 tbase->aux->rx_pkt_prev[0] = tbase->rx_pkt;
215 tbase->rx_pkt = to_add;
216 tbase->aux->rx_prev_count++;
219 static void task_base_del_rx_pkt_function(struct task_base *tbase, rx_pkt_func to_del)
224 if (tbase->aux->rx_prev_count == 1) {
225 tbase->rx_pkt = tbase->aux->rx_pkt_prev[0];
228 for (int16_t i = 0; i < tbase->aux->rx_prev_count; ++i) {
229 if (found || tbase->aux->rx_pkt_prev[i] != to_del)
230 tbase->aux->rx_pkt_prev[cur++] = tbase->aux->rx_pkt_prev[i];
236 tbase->aux->rx_prev_count--;
239 static rx_pkt_func task_base_get_original_rx_pkt_function(struct task_base *tbase)
241 if (tbase->aux->rx_prev_count == 0)
242 return tbase->rx_pkt;
244 return tbase->aux->rx_pkt_prev[tbase->aux->rx_prev_count - 1];
247 #endif /* _TASK_BASE_H_ */