1235474Sbz/*-
2235474Sbz * Copyright (c) 2006, Myricom Inc.
3235474Sbz * Copyright (c) 2008, Intel Corporation.
4294327Shselasky * Copyright (c) 2016 Mellanox Technologies.
5235474Sbz * All rights reserved.
6235474Sbz *
7235474Sbz * Redistribution and use in source and binary forms, with or without
8235474Sbz * modification, are permitted provided that the following conditions
9235474Sbz * are met:
10235474Sbz * 1. Redistributions of source code must retain the above copyright
11235474Sbz *    notice, this list of conditions and the following disclaimer.
12235474Sbz * 2. Redistributions in binary form must reproduce the above copyright
13235474Sbz *    notice, this list of conditions and the following disclaimer in the
14235474Sbz *    documentation and/or other materials provided with the distribution.
15235474Sbz *
16235474Sbz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17235474Sbz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18235474Sbz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19235474Sbz * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20235474Sbz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21235474Sbz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22235474Sbz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23235474Sbz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24235474Sbz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25235474Sbz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26235474Sbz * SUCH DAMAGE.
27235474Sbz *
28235474Sbz * $FreeBSD$
29235474Sbz */
30179737Sjfv
31179737Sjfv#ifndef _TCP_LRO_H_
32179737Sjfv#define _TCP_LRO_H_
33179737Sjfv
34255010Snp#include <sys/time.h>
35255010Snp
36294327Shselasky#ifndef TCP_LRO_ENTRIES
37294327Shselasky/* Define default number of LRO entries per RX queue */
38294327Shselasky#define	TCP_LRO_ENTRIES	8
39294327Shselasky#endif
40294327Shselasky
41297483Ssephestruct lro_entry {
42297483Ssephe	LIST_ENTRY(lro_entry)	next;
43235944Sbz	struct mbuf		*m_head;
44235944Sbz	struct mbuf		*m_tail;
45235944Sbz	union {
46235944Sbz		struct ip	*ip4;
47235944Sbz		struct ip6_hdr	*ip6;
48235944Sbz	} leip;
49235944Sbz	union {
50235944Sbz		in_addr_t	s_ip4;
51235944Sbz		struct in6_addr	s_ip6;
52235944Sbz	} lesource;
53235944Sbz	union {
54235944Sbz		in_addr_t	d_ip4;
55235944Sbz		struct in6_addr	d_ip6;
56235944Sbz	} ledest;
57235944Sbz	uint16_t		source_port;
58235944Sbz	uint16_t		dest_port;
59235944Sbz	uint16_t		eh_type;	/* EthernetHeader type. */
60235944Sbz	uint16_t		append_cnt;
61235944Sbz	uint32_t		p_len;		/* IP header payload length. */
62235944Sbz	uint32_t		ulp_csum;	/* TCP, etc. checksum. */
63235944Sbz	uint32_t		next_seq;	/* tcp_seq */
64235944Sbz	uint32_t		ack_seq;	/* tcp_seq */
65235944Sbz	uint32_t		tsval;
66235944Sbz	uint32_t		tsecr;
67235944Sbz	uint16_t		window;
68235944Sbz	uint16_t		timestamp;	/* flag, not a TCP hdr field. */
69255010Snp	struct timeval		mtime;
70179737Sjfv};
71297483SsepheLIST_HEAD(lro_head, lro_entry);
72179737Sjfv
73235944Sbz#define	le_ip4			leip.ip4
74235944Sbz#define	le_ip6			leip.ip6
75235944Sbz#define	source_ip4		lesource.s_ip4
76235944Sbz#define	dest_ip4		ledest.d_ip4
77235944Sbz#define	source_ip6		lesource.s_ip6
78235944Sbz#define	dest_ip6		ledest.d_ip6
79235944Sbz
80300731Shselaskystruct lro_mbuf_sort {
81300731Shselasky	uint64_t seq;
82300731Shselasky	struct mbuf *mb;
83300731Shselasky};
84300731Shselasky
85235944Sbz/* NB: This is part of driver structs. */
86179737Sjfvstruct lro_ctrl {
87179737Sjfv	struct ifnet	*ifp;
88300731Shselasky	struct lro_mbuf_sort *lro_mbuf_data;
89294327Shselasky	uint64_t	lro_queued;
90294327Shselasky	uint64_t	lro_flushed;
91294327Shselasky	uint64_t	lro_bad_csum;
92294327Shselasky	unsigned	lro_cnt;
93294327Shselasky	unsigned	lro_mbuf_count;
94294327Shselasky	unsigned	lro_mbuf_max;
95295739Ssephe	unsigned short	lro_ackcnt_lim;		/* max # of aggregated ACKs */
96295739Ssephe	unsigned 	lro_length_lim;		/* max len of aggregated data */
97179737Sjfv
98179737Sjfv	struct lro_head	lro_active;
99179737Sjfv	struct lro_head	lro_free;
100179737Sjfv};
101179737Sjfv
102295739Ssephe#define	TCP_LRO_LENGTH_MAX	65535
103295739Ssephe#define	TCP_LRO_ACKCNT_MAX	65535		/* unlimited */
104295739Ssephe
105179737Sjfvint tcp_lro_init(struct lro_ctrl *);
106294327Shselaskyint tcp_lro_init_args(struct lro_ctrl *, struct ifnet *, unsigned, unsigned);
107179737Sjfvvoid tcp_lro_free(struct lro_ctrl *);
108255010Snpvoid tcp_lro_flush_inactive(struct lro_ctrl *, const struct timeval *);
109179737Sjfvvoid tcp_lro_flush(struct lro_ctrl *, struct lro_entry *);
110294327Shselaskyvoid tcp_lro_flush_all(struct lro_ctrl *);
111179737Sjfvint tcp_lro_rx(struct lro_ctrl *, struct mbuf *, uint32_t);
112294327Shselaskyvoid tcp_lro_queue_mbuf(struct lro_ctrl *, struct mbuf *);
113179737Sjfv
114297265Ssephe#define	TCP_LRO_NO_ENTRIES	-2
115235944Sbz#define	TCP_LRO_CANNOT		-1
116235944Sbz#define	TCP_LRO_NOT_SUPPORTED	1
117179737Sjfv
118179737Sjfv#endif /* _TCP_LRO_H_ */
119