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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * Some helper stream control functions definitions.
23 #include "tcp_stream.h"
31 tcp_stream_down(struct tle_tcp_stream *s)
38 tcp_stream_up(struct tle_tcp_stream *s)
44 /* calculate RCV.WND value based on size of stream receive buffer */
45 static inline uint32_t
46 calc_rx_wnd(const struct tle_tcp_stream *s, uint32_t scale)
50 /* peer doesn't support WSCALE option, wnd size is limited to 64K */
51 if (scale == TCP_WSCALE_NONE) {
52 wnd = _rte_ring_get_mask(s->rx.q) << TCP_WSCALE_DEFAULT;
53 return RTE_MIN(wnd, (uint32_t)UINT16_MAX);
55 return _rte_ring_get_mask(s->rx.q) << scale;
58 /* empty stream's receive queue */
60 empty_rq(struct tle_tcp_stream *s)
62 empty_mbuf_ring(s->rx.q);
63 tcp_ofo_reset(s->rx.ofo);
66 /* empty stream's listen queue */
68 empty_lq(struct tle_tcp_stream *s, struct stbl *st)
74 struct stbl_entry *se[MAX_PKT_BURST];
77 n = _rte_ring_dequeue_burst(s->rx.q, (void **)se, RTE_DIM(se));
78 for (i = 0; i != n; i++) {
79 mb = stbl_get_pkt(se[i]);
80 get_pkt_info(mb, &pi, &si);
81 stbl_del_pkt_lock(st, se[i], &pi);
88 tcp_stream_reset(struct tle_ctx *ctx, struct tle_tcp_stream *s)
93 st = CTX_TCP_STLB(ctx);
96 rte_atomic32_set(&s->tx.arm, 0);
99 uop = s->tcb.uop & ~TCP_OP_CLOSE;
100 memset(&s->tcb, 0, sizeof(s->tcb));
102 /* reset cached destination */
103 memset(&s->tx.dst, 0, sizeof(s->tx.dst));
105 if (uop != TCP_OP_ACCEPT) {
106 /* free stream's destination port */
107 stream_clear_ctx(ctx, &s->s);
108 if (uop == TCP_OP_LISTEN)
112 if (s->ste != NULL) {
113 /* remove entry from RX streams table */
114 stbl_del_stream_lock(st, s->ste, s);
120 empty_mbuf_ring(s->tx.q);
123 * mark the stream as free again.
124 * if there still are pkts queued for TX,
125 * then put this stream to the tail of free list.
127 put_stream(ctx, &s->s, TCP_STREAM_TX_FINISHED(s));
134 #endif /* _TCP_CTL_H_ */