Introduce first version of TCP code.
[tldk.git] / lib / libtle_l4p / ctx.h
1 /*
2  * Copyright (c) 2016  Intel Corporation.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef _CTX_H_
17 #define _CTX_H_
18
19 #include <rte_spinlock.h>
20 #include <rte_vect.h>
21 #include <tle_dring.h>
22 #include <tle_ctx.h>
23
24 #include "port_bitmap.h"
25 #include "osdep.h"
26 #include "net_misc.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 struct tle_dport {
33         struct tle_pbm use; /* ports in use. */
34         struct tle_stream *streams[MAX_PORT_NUM]; /* port to stream. */
35 };
36
37 struct tle_dev {
38         struct tle_ctx *ctx;
39         struct {
40                 uint64_t ol_flags[TLE_VNUM];
41         } rx;
42         struct {
43                 /* used by FE. */
44                 uint64_t ol_flags[TLE_VNUM];
45                 rte_atomic32_t packet_id[TLE_VNUM];
46
47                 /* used by FE & BE. */
48                 struct tle_dring dr;
49         } tx;
50         struct tle_dev_param prm; /* copy of device parameters. */
51         struct tle_dport *dp[TLE_VNUM]; /* device L4 ports */
52 };
53
54 struct tle_ctx {
55         struct tle_ctx_param prm;
56         struct {
57                 rte_spinlock_t lock;
58                 uint32_t nb_free; /* number of free streams. */
59                 STAILQ_HEAD(, tle_stream) free;
60                 void *buf; /* space allocated for streams */
61         } streams;
62
63         rte_spinlock_t dev_lock;
64         uint32_t nb_dev;
65         struct tle_pbm use[TLE_VNUM]; /* all ports in use. */
66         struct tle_dev dev[RTE_MAX_ETHPORTS];
67 };
68
69 struct stream_ops {
70         int (*init_streams)(struct tle_ctx *);
71         void (*fini_streams)(struct tle_ctx *);
72         void (*free_drbs)(struct tle_stream *, struct tle_drb *[], uint32_t);
73 };
74
75 extern struct stream_ops tle_stream_ops[TLE_PROTO_NUM];
76
77 int stream_fill_ctx(struct tle_ctx *ctx, struct tle_stream *s,
78         const struct sockaddr *laddr, const struct sockaddr *raddr);
79
80 int stream_clear_ctx(struct tle_ctx *ctx, struct tle_stream *s);
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif /* _UDP_IMPL_H_ */