/*
- * Copyright (c) 2016 Intel Corporation.
+ * Copyright (c) 2016-2017 Intel Corporation.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
#include "net_misc.h"
#include <rte_tcp.h>
#include <rte_cycles.h>
+#include <tle_tcp.h>
#ifdef __cplusplus
extern "C" {
#define TCP_WSCALE_DEFAULT 7
#define TCP_WSCALE_NONE 0
-#define TCP_TX_HDR_MAX (sizeof(struct tcp_hdr) + TCP_TX_OPT_LEN_MAX)
+#define TCP_TX_HDR_MAX (sizeof(struct rte_tcp_hdr) + TCP_TX_OPT_LEN_MAX)
/* max header size for normal data+ack packet */
-#define TCP_TX_HDR_DACK (sizeof(struct tcp_hdr) + TCP_TX_OPT_LEN_TMS)
+#define TCP_TX_HDR_DACK (sizeof(struct rte_tcp_hdr) + TCP_TX_OPT_LEN_TMS)
#define TCP4_MIN_MSS 536
/* default MTU, no TCP options. */
#define TCP4_NOP_MSS \
- (ETHER_MTU - sizeof(struct ipv4_hdr) - sizeof(struct tcp_hdr))
+ (RTE_ETHER_MTU - sizeof(struct rte_ipv4_hdr) - \
+ sizeof(struct rte_tcp_hdr))
#define TCP6_NOP_MSS \
- (ETHER_MTU - sizeof(struct ipv6_hdr) - sizeof(struct tcp_hdr))
+ (RTE_ETHER_MTU - sizeof(struct rte_ipv6_hdr) - \
+ sizeof(struct rte_tcp_hdr))
/* default MTU, TCP options present */
#define TCP4_OP_MSS (TCP4_NOP_MSS - TCP_TX_OPT_LEN_MAX)
#define TCP6_OP_MSS (TCP6_NOP_MSS - TCP_TX_OPT_LEN_MAX)
+/* Initial Window Configuration parameter, probably will be configured during
+ * the startup in future */
+#define TCP_INITIAL_CWND_MAX 14600
+
/*
* TCP flags
*/
struct {
uint32_t seq;
uint32_t ack;
- uint16_t hole1;
uint16_t wnd;
+ uint16_t mss; /* valid only at SYN time */
};
};
#define TCP_OPT_KL_WSC TCP_OPT_KL(TCP_OPT_KIND_WSC, TCP_OPT_LEN_WSC)
#define TCP_OPT_KL_TMS TCP_OPT_KL(TCP_OPT_KIND_TMS, TCP_OPT_LEN_TMS)
-/*
- * Timestamp option.
- */
-union tsopt {
- uint64_t raw;
- struct {
- uint32_t val;
- uint32_t ecr;
- };
-};
-
struct tcpopt {
union {
uint16_t raw;
union {
uint16_t mss;
uint8_t wscale;
- union tsopt ts;
+ union tle_tcp_tsopt ts;
};
} __attribute__((__packed__));
-struct syn_opts {
- uint16_t mss;
- uint8_t wscale;
- union tsopt ts;
-};
-
struct resp_info {
uint32_t flags;
};
uint32_t badseq; /* bad seq/ack */
uint32_t ofo; /* OFO incoming data */
} segs;
- uint32_t ack; /* highest received ACK */
- union tsopt ts; /* TS of highest ACK */
- union wui wu; /* window update information */
+ uint32_t ack; /* highest received ACK */
+ union tle_tcp_tsopt ts; /* TS of highest ACK */
+ union wui wu; /* window update information */
uint32_t wnd;
struct { /* 3 duplicate ACKs were observed after */
uint32_t seg; /* # of meaningful ACK segments */
/* get current timestamp in ms */
static inline uint32_t
-tcp_get_tms(void)
+tcp_get_tms(uint32_t mshift)
{
- uint64_t ts, ms;
- ms = (rte_get_tsc_hz() + MS_PER_S - 1) / MS_PER_S;
- ts = rte_get_tsc_cycles() / ms;
+ uint64_t ts;
+ ts = rte_get_tsc_cycles() >> mshift;
return ts;
}
return (int32_t)(l - r) <= 0;
}
+static inline uint32_t
+tcp_seq_min(uint32_t l, uint32_t r)
+{
+ if (tcp_seq_lt(l, r))
+ return l;
+ else
+ return r;
+}
static inline void
-get_seg_info(const struct tcp_hdr *th, union seg_info *si)
+get_seg_info(const struct rte_tcp_hdr *th, union seg_info *si)
{
__m128i v;
- const __m128i bswap_mask = _mm_set_epi8(15, 14, 13, 12, 10, 11, 9, 8,
- 4, 5, 6, 7, 0, 1, 2, 3);
+ const __m128i bswap_mask =
+ _mm_set_epi8(UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX,
+ UINT8_MAX, UINT8_MAX, 10, 11,
+ 4, 5, 6, 7,
+ 0, 1, 2, 3);
v = _mm_loadu_si128((const __m128i *)&th->sent_seq);
si->raw.x = _mm_shuffle_epi8(v, bswap_mask);
}
static inline void
-get_syn_opts(struct syn_opts *so, uintptr_t p, uint32_t len)
+get_syn_opts(struct tle_tcp_syn_opts *so, uintptr_t p, uint32_t len)
{
uint32_t i, kind;
const struct tcpopt *opt;
* at least TCP_TX_OPT_LEN_MAX bytes available.
*/
static inline void
-fill_syn_opts(void *p, const struct syn_opts *so)
+fill_syn_opts(void *p, const struct tle_tcp_syn_opts *so)
{
uint8_t *to;
struct tcpopt *opt;
opt[2] = rte_cpu_to_be_32(ecr);
}
-static inline union tsopt
+static inline union tle_tcp_tsopt
get_tms_opts(uintptr_t p, uint32_t len)
{
- union tsopt ts;
+ union tle_tcp_tsopt ts;
uint32_t i, kind;
const uint32_t *opt;
const struct tcpopt *to;
get_pkt_info(const struct rte_mbuf *m, union pkt_info *pi, union seg_info *si)
{
uint32_t len, type;
- const struct tcp_hdr *tcph;
+ const struct rte_tcp_hdr *tcph;
const union l4_ports *prt;
const union ipv4_addrs *pa4;
if (type == TLE_V4) {
pa4 = rte_pktmbuf_mtod_offset(m, const union ipv4_addrs *,
- len + offsetof(struct ipv4_hdr, src_addr));
+ len + offsetof(struct rte_ipv4_hdr, src_addr));
pi->addr4.raw = pa4->raw;
} else if (type == TLE_V6) {
pi->addr6 = rte_pktmbuf_mtod_offset(m, const union ipv6_addrs *,
- len + offsetof(struct ipv6_hdr, src_addr));
+ len + offsetof(struct rte_ipv6_hdr, src_addr));
}
len += m->l3_len;
- tcph = rte_pktmbuf_mtod_offset(m, const struct tcp_hdr *, len);
+ tcph = rte_pktmbuf_mtod_offset(m, const struct rte_tcp_hdr *, len);
prt = (const union l4_ports *)
- ((uintptr_t)tcph + offsetof(struct tcp_hdr, src_port));
+ ((uintptr_t)tcph + offsetof(struct rte_tcp_hdr, src_port));
pi->tf.flags = tcph->tcp_flags;
pi->tf.type = type;
- pi->csf = m->ol_flags & (PKT_RX_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD);
+ pi->csf = m->ol_flags & (PKT_RX_IP_CKSUM_MASK | PKT_RX_L4_CKSUM_MASK);
pi->port.raw = prt->raw;
get_seg_info(tcph, si);