1/*
2 * Copyright (c) 2016-2017  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
29extern "C" {
30#endif
31
32struct tle_dport {
33	struct tle_pbm use; /* ports in use. */
34	struct tle_stream *streams[MAX_PORT_NUM]; /* port to stream. */
35};
36
37struct tle_dev {
38	struct tle_ctx *ctx;
39	struct {
40		/* used by FE. */
41		uint64_t ol_flags[TLE_VNUM];
42		rte_atomic32_t packet_id[TLE_VNUM];
43
44		/* used by FE & BE. */
45		struct tle_dring dr;
46	} tx;
47	struct tle_dev_param prm; /* copy of device parameters. */
48	struct tle_dport *dp[TLE_VNUM]; /* device L4 ports */
49};
50
51struct tle_ctx {
52	struct tle_ctx_param prm;
53	uint32_t cycles_ms_shift;  /* to convert from cycles to ms */
54	struct {
55		rte_spinlock_t lock;
56		uint32_t nb_free; /* number of free streams. */
57		STAILQ_HEAD(, tle_stream) free;
58		void *buf; /* space allocated for streams */
59	} streams;
60
61	rte_spinlock_t dev_lock;
62	uint32_t nb_dev;
63	struct tle_pbm use[TLE_VNUM]; /* all ports in use. */
64	struct tle_dev dev[RTE_MAX_ETHPORTS];
65};
66
67struct stream_ops {
68	int (*init_streams)(struct tle_ctx *);
69	void (*fini_streams)(struct tle_ctx *);
70	void (*free_drbs)(struct tle_stream *, struct tle_drb *[], uint32_t);
71};
72
73extern struct stream_ops tle_stream_ops[TLE_PROTO_NUM];
74
75int stream_fill_ctx(struct tle_ctx *ctx, struct tle_stream *s,
76	const struct sockaddr *laddr, const struct sockaddr *raddr);
77
78int stream_clear_ctx(struct tle_ctx *ctx, struct tle_stream *s);
79
80#ifdef __cplusplus
81}
82#endif
83
84#endif /* _UDP_IMPL_H_ */
85