tcp_ctl.h revision aa97dd1c
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/*
17 * Some helper stream control functions definitions.
18 */
19
20#ifndef _TCP_CTL_H_
21#define _TCP_CTL_H_
22
23#include "tcp_stream.h"
24#include "tcp_ofo.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30static inline void
31tcp_stream_down(struct tle_tcp_stream *s)
32{
33	rwl_down(&s->rx.use);
34	rwl_down(&s->tx.use);
35}
36
37static inline void
38tcp_stream_up(struct tle_tcp_stream *s)
39{
40	rwl_up(&s->rx.use);
41	rwl_up(&s->tx.use);
42}
43
44/* empty stream's receive queue */
45static void
46empty_rq(struct tle_tcp_stream *s)
47{
48	empty_mbuf_ring(s->rx.q);
49	tcp_ofo_reset(s->rx.ofo);
50}
51
52/* empty stream's listen queue */
53static void
54empty_lq(struct tle_tcp_stream *s, struct stbl *st)
55{
56	uint32_t i, n;
57	struct rte_mbuf *mb;
58	union pkt_info pi;
59	union seg_info si;
60	struct stbl_entry *se[MAX_PKT_BURST];
61
62	do {
63		n = rte_ring_dequeue_burst(s->rx.q, (void **)se, RTE_DIM(se));
64		for (i = 0; i != n; i++) {
65			mb = stbl_get_pkt(se[i]);
66			get_pkt_info(mb, &pi, &si);
67			stbl_del_pkt_lock(st, se[i], &pi);
68			rte_pktmbuf_free(mb);
69		}
70	} while (n != 0);
71}
72
73static inline void
74tcp_stream_reset(struct tle_ctx *ctx, struct tle_tcp_stream *s)
75{
76	struct stbl *st;
77	uint16_t uop;
78
79	st = CTX_TCP_STLB(ctx);
80
81	/* reset TX armed */
82	rte_atomic32_set(&s->tx.arm, 0);
83
84	/* reset TCB */
85	uop = s->tcb.uop & (TCP_OP_LISTEN | TCP_OP_CONNECT);
86	memset(&s->tcb, 0, sizeof(s->tcb));
87
88	/* reset cached destination */
89	memset(&s->tx.dst, 0, sizeof(s->tx.dst));
90
91	if (uop != 0) {
92		/* free stream's destination port */
93		stream_clear_ctx(ctx, &s->s);
94		if (uop == TCP_OP_LISTEN)
95			empty_lq(s, st);
96	}
97
98	if (s->ste != NULL) {
99		/* remove entry from RX streams table */
100		stbl_del_stream_lock(st, s->ste, s);
101		s->ste = NULL;
102		empty_rq(s);
103	}
104
105	/* empty TX queue */
106	empty_mbuf_ring(s->tx.q);
107
108	/*
109	 * mark the stream as free again.
110	 * if there still are pkts queued for TX,
111	 * then put this stream to the tail of free list.
112	 */
113	put_stream(ctx, &s->s, TCP_STREAM_TX_FINISHED(s));
114}
115
116#ifdef __cplusplus
117}
118#endif
119
120#endif /* _TCP_CTL_H_ */
121