1237263Snp/*-
2237263Snp * Copyright (c) 2012 Chelsio Communications, Inc.
3237263Snp * All rights reserved.
4237263Snp *
5237263Snp * Redistribution and use in source and binary forms, with or without
6237263Snp * modification, are permitted provided that the following conditions
7237263Snp * are met:
8237263Snp * 1. Redistributions of source code must retain the above copyright
9237263Snp *    notice, this list of conditions and the following disclaimer.
10237263Snp * 2. Redistributions in binary form must reproduce the above copyright
11237263Snp *    notice, this list of conditions and the following disclaimer in the
12237263Snp *    documentation and/or other materials provided with the distribution.
13237263Snp *
14237263Snp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15237263Snp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16237263Snp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17237263Snp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18237263Snp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19237263Snp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20237263Snp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21237263Snp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22237263Snp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23237263Snp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24237263Snp * SUCH DAMAGE.
25237263Snp *
26237263Snp * $FreeBSD$
27237263Snp */
28237263Snp
29237263Snp#ifndef _NETINET_TOE_H_
30237263Snp#define	_NETINET_TOE_H_
31237263Snp
32237263Snp#ifndef _KERNEL
33237263Snp#error "no user-serviceable parts inside"
34237263Snp#endif
35237263Snp
36237263Snpstruct tcpopt;
37237263Snpstruct tcphdr;
38237263Snpstruct in_conninfo;
39237263Snp
40237263Snpstruct toedev {
41237263Snp	TAILQ_ENTRY(toedev) link;	/* glue for toedev_list */
42237263Snp	void *tod_softc;		/* TOE driver private data */
43237263Snp
44237263Snp	/*
45237263Snp	 * Active open.  If a failure occurs, it is reported back by the driver
46237263Snp	 * via toe_connect_failed.
47237263Snp	 */
48237263Snp	int (*tod_connect)(struct toedev *, struct socket *, struct rtentry *,
49237263Snp	    struct sockaddr *);
50237263Snp
51237263Snp	/* Passive open. */
52237263Snp	int (*tod_listen_start)(struct toedev *, struct tcpcb *);
53237263Snp	int (*tod_listen_stop)(struct toedev *, struct tcpcb *);
54237263Snp
55237263Snp	/*
56237263Snp	 * The kernel uses this routine to pass on any frame it receives for an
57237263Snp	 * offloaded connection to the TOE driver.  This is an unusual event.
58237263Snp	 */
59237263Snp	void (*tod_input)(struct toedev *, struct tcpcb *, struct mbuf *);
60237263Snp
61237263Snp	/*
62237263Snp	 * This is called by the kernel during pru_rcvd for an offloaded TCP
63237263Snp	 * connection and provides an opportunity for the TOE driver to manage
64237263Snp	 * its rx window and credits.
65237263Snp	 */
66237263Snp	void (*tod_rcvd)(struct toedev *, struct tcpcb *);
67237263Snp
68237263Snp	/*
69237263Snp	 * Transmit routine.  The kernel calls this to have the TOE driver
70237263Snp	 * evaluate whether there is data to be transmitted, and transmit it.
71237263Snp	 */
72237263Snp	int (*tod_output)(struct toedev *, struct tcpcb *);
73237263Snp
74237263Snp	/* Immediate teardown: send RST to peer. */
75237263Snp	int (*tod_send_rst)(struct toedev *, struct tcpcb *);
76237263Snp
77237263Snp	/* Initiate orderly disconnect by sending FIN to the peer. */
78237263Snp	int (*tod_send_fin)(struct toedev *, struct tcpcb *);
79237263Snp
80237263Snp	/* Called to indicate that the kernel is done with this TCP PCB. */
81237263Snp	void (*tod_pcb_detach)(struct toedev *, struct tcpcb *);
82237263Snp
83237263Snp	/*
84237263Snp	 * The kernel calls this once it has information about an L2 entry that
85237263Snp	 * the TOE driver enquired about previously (via toe_l2_resolve).
86237263Snp	 */
87237263Snp	void (*tod_l2_update)(struct toedev *, struct ifnet *,
88237263Snp	    struct sockaddr *, uint8_t *, uint16_t);
89237263Snp
90237263Snp	/* XXX.  Route has been redirected. */
91237263Snp	void (*tod_route_redirect)(struct toedev *, struct ifnet *,
92237263Snp	    struct rtentry *, struct rtentry *);
93237263Snp
94237263Snp	/* Syncache interaction. */
95237263Snp	void (*tod_syncache_added)(struct toedev *, void *);
96237263Snp	void (*tod_syncache_removed)(struct toedev *, void *);
97237263Snp	int (*tod_syncache_respond)(struct toedev *, void *, struct mbuf *);
98237263Snp	void (*tod_offload_socket)(struct toedev *, void *, struct socket *);
99237263Snp
100237263Snp	/* TCP socket option */
101237263Snp	void (*tod_ctloutput)(struct toedev *, struct tcpcb *, int, int);
102237263Snp};
103237263Snp
104237263Snp#include <sys/eventhandler.h>
105237263Snptypedef	void (*tcp_offload_listen_start_fn)(void *, struct tcpcb *);
106237263Snptypedef	void (*tcp_offload_listen_stop_fn)(void *, struct tcpcb *);
107237263SnpEVENTHANDLER_DECLARE(tcp_offload_listen_start, tcp_offload_listen_start_fn);
108237263SnpEVENTHANDLER_DECLARE(tcp_offload_listen_stop, tcp_offload_listen_stop_fn);
109237263Snp
110237263Snpvoid init_toedev(struct toedev *);
111237263Snpint register_toedev(struct toedev *);
112237263Snpint unregister_toedev(struct toedev *);
113237263Snp
114237263Snp/*
115237263Snp * General interface for looking up L2 information for an IP address.  If an
116237263Snp * answer is not available right away then the TOE driver's tod_l2_update will
117237263Snp * be called later.
118237263Snp */
119237263Snpint toe_l2_resolve(struct toedev *, struct ifnet *, struct sockaddr *,
120237263Snp    uint8_t *, uint16_t *);
121237263Snp
122239511Snpvoid toe_connect_failed(struct toedev *, struct inpcb *, int);
123237263Snp
124237263Snpvoid toe_syncache_add(struct in_conninfo *, struct tcpopt *, struct tcphdr *,
125237263Snp    struct inpcb *, void *, void *);
126237263Snpint  toe_syncache_expand(struct in_conninfo *, struct tcpopt *, struct tcphdr *,
127237263Snp    struct socket **);
128237263Snp
129237263Snpint toe_4tuple_check(struct in_conninfo *, struct tcphdr *, struct ifnet *);
130237263Snp#endif
131