1/*
2 * Copyright (c) 2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef TCP_LRO_H_
30#define TCP_LRO_H_
31
32#ifdef BSD_KERNEL_PRIVATE
33
34#define TCP_LRO_NUM_FLOWS (16)	/* must be <= 255 for char lro_flow_map */
35#define TCP_LRO_FLOW_MAP  (1024)
36
37struct lro_flow {
38	struct mbuf		*lr_mhead;	/* coalesced mbuf chain head */
39	struct mbuf		*lr_mtail;	/* coalesced mbuf chain tail */
40	struct tcphdr		*lr_tcphdr;	/* ptr to TCP hdr in frame */
41	u_int32_t		*lr_tsval;	/* address of tsval in frame */
42	u_int32_t		*lr_tsecr;	/* tsecr field in TCP header */
43	tcp_seq			lr_seq;		/* next expected seq num */
44	unsigned int	 	lr_len;		/* length of LRO frame */
45	struct in_addr		lr_faddr;	/* foreign address */
46	struct in_addr		lr_laddr;	/* local address */
47	unsigned short int 	lr_fport;	/* foreign port */
48	unsigned short int	lr_lport;	/* local port */
49	u_int32_t		lr_timestamp;	/* for ejecting the flow */
50	unsigned short int	lr_hash_map;	/* back pointer to hash map */
51	unsigned short int	lr_flags;	/* pad */
52} __attribute__((aligned(8)));
53
54/* lr_flags - only 16 bits available */
55#define LRO_EJECT_REQ	0x1
56
57
58#define TCP_LRO_FLOW_UNINIT TCP_LRO_NUM_FLOWS+1
59#define TCP_LRO_FLOW_NOTFOUND TCP_LRO_FLOW_UNINIT
60
61/* Max packets to be coalesced before pushing to app */
62#define LRO_MX_COALESCE_PKTS (8)
63
64/*
65 * Min num of bytes in a packet to trigger coalescing
66 */
67#define LRO_MIN_COALESC_SZ  (1300)
68
69/*
70 * Max amount of time to wait before flushing flows in msecs.
71 * Units are in msecs.
72 * This number has been carefully chosen and should be altered with care.
73 */
74#define LRO_MX_TIME_TO_BUFFER 10
75
76/* similar to INP_PCBHASH */
77#define LRO_HASH(faddr, laddr, fport, lport, mask) \
78	(((faddr) ^ ((laddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
79#endif
80
81#endif /* TCP_LRO_H_ */
82