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