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.
25 static inline uint32_t
26 rx_ofo_enqueue(struct tle_tcp_stream *s, union seqlen *sl,
27 struct rte_mbuf *mb[], uint32_t num)
33 i = _ofo_step(s->rx.ofo, sl, mb + n, num - n);
35 } while (i != 0 && n != num);
37 _ofo_compact(s->rx.ofo);
41 static inline uint32_t
42 rx_ofo_reduce(struct tle_tcp_stream *s)
44 uint32_t i, n, end, seq;
53 for (i = 0; i != ofo->nb_elem; i++) {
57 /* gap still present */
58 if (tcp_seq_lt(seq, db->sl.seq))
61 end = db->sl.seq + db->sl.len;
63 /* this db is fully overlapped */
64 if (tcp_seq_leq(end, seq))
67 n += _ofodb_enqueue(s->rx.q, db, &sl);
69 seq = sl.seq + sl.len;
73 _ofo_remove(ofo, 0, i);
77 static inline uint32_t
78 rx_ino_enqueue(struct tle_tcp_stream *s, union seqlen *sl,
79 struct rte_mbuf *mb[], uint32_t num)
83 n = rte_ring_enqueue_burst(s->rx.q, (void * const *)mb, num);
85 /* error: can'queue some packets into receive buffer. */
86 for (i = n; i != num; i++)
87 sl->len -= mb[i]->pkt_len;
89 s->tcb.rcv.nxt = sl->seq + sl->len;
93 static inline uint32_t
94 rx_data_enqueue(struct tle_tcp_stream *s, uint32_t seq, uint32_t len,
95 struct rte_mbuf *mb[], uint32_t num)
103 r = rte_ring_count(s->rx.q);
105 /* in order packets, ready to be delivered */
106 if (seq == s->tcb.rcv.nxt) {
108 t = rx_ino_enqueue(s, &sl, mb, num);
110 /* failed to queue all input in-order packets */
113 "%s(s=%p, seq=%u, len=%u, num=%u) failed to queue "
115 __func__, s, seq, len, num, num - t);
117 /* try to consume some out-of-order packets*/
119 n = rx_ofo_reduce(s);
122 "%s(s=%p, rcv.nxt=%u) failed to queue %u "
124 __func__, s, s->tcb.rcv.nxt, n);
127 /* queue out of order packets */
129 t = rx_ofo_enqueue(s, &sl, mb, num);
132 n = rte_ring_count(s->rx.q);
135 if (s->rx.ev != NULL)
136 tle_event_raise(s->rx.ev);
137 /* if RX queue was empty invoke RX notification callback. */
138 else if (s->rx.cb.func != NULL && r == 0)
139 s->rx.cb.func(s->rx.cb.data, &s->s);
149 #endif /* _TCP_RXQ_H_ */