109fe6320SNavdeep Parhar /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3fe267a55SPedro F. Giffuni * 409fe6320SNavdeep Parhar * Copyright (c) 2012 Chelsio Communications, Inc. 509fe6320SNavdeep Parhar * All rights reserved. 609fe6320SNavdeep Parhar * 709fe6320SNavdeep Parhar * Redistribution and use in source and binary forms, with or without 809fe6320SNavdeep Parhar * modification, are permitted provided that the following conditions 909fe6320SNavdeep Parhar * are met: 1009fe6320SNavdeep Parhar * 1. Redistributions of source code must retain the above copyright 1109fe6320SNavdeep Parhar * notice, this list of conditions and the following disclaimer. 1209fe6320SNavdeep Parhar * 2. Redistributions in binary form must reproduce the above copyright 1309fe6320SNavdeep Parhar * notice, this list of conditions and the following disclaimer in the 1409fe6320SNavdeep Parhar * documentation and/or other materials provided with the distribution. 1509fe6320SNavdeep Parhar * 1609fe6320SNavdeep Parhar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1709fe6320SNavdeep Parhar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1809fe6320SNavdeep Parhar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1909fe6320SNavdeep Parhar * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2009fe6320SNavdeep Parhar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2109fe6320SNavdeep Parhar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2209fe6320SNavdeep Parhar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2309fe6320SNavdeep Parhar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2409fe6320SNavdeep Parhar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2509fe6320SNavdeep Parhar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2609fe6320SNavdeep Parhar * SUCH DAMAGE. 2709fe6320SNavdeep Parhar */ 2809fe6320SNavdeep Parhar 2909fe6320SNavdeep Parhar #ifndef _NETINET_TOE_H_ 3009fe6320SNavdeep Parhar #define _NETINET_TOE_H_ 3109fe6320SNavdeep Parhar 3209fe6320SNavdeep Parhar #ifndef _KERNEL 3309fe6320SNavdeep Parhar #error "no user-serviceable parts inside" 3409fe6320SNavdeep Parhar #endif 3509fe6320SNavdeep Parhar 3601d74fe1SNavdeep Parhar #include <netinet/tcp.h> 37e2e050c8SConrad Meyer #include <sys/_eventhandler.h> 38e2e050c8SConrad Meyer 39*027fda80SGleb Smirnoff struct tcpcb; 4009fe6320SNavdeep Parhar struct tcpopt; 4109fe6320SNavdeep Parhar struct tcphdr; 4209fe6320SNavdeep Parhar struct in_conninfo; 43a6456410SNavdeep Parhar struct tcp_info; 448d6708baSAlexander V. Chernikov struct nhop_object; 459e14430dSJohn Baldwin struct ktls_session; 4609fe6320SNavdeep Parhar 4709fe6320SNavdeep Parhar struct toedev { 4809fe6320SNavdeep Parhar TAILQ_ENTRY(toedev) link; /* glue for toedev_list */ 4909fe6320SNavdeep Parhar void *tod_softc; /* TOE driver private data */ 5009fe6320SNavdeep Parhar 5109fe6320SNavdeep Parhar /* 5209fe6320SNavdeep Parhar * Active open. If a failure occurs, it is reported back by the driver 5309fe6320SNavdeep Parhar * via toe_connect_failed. 5409fe6320SNavdeep Parhar */ 558d6708baSAlexander V. Chernikov int (*tod_connect)(struct toedev *, struct socket *, struct nhop_object *, 5609fe6320SNavdeep Parhar struct sockaddr *); 5709fe6320SNavdeep Parhar 5809fe6320SNavdeep Parhar /* Passive open. */ 5909fe6320SNavdeep Parhar int (*tod_listen_start)(struct toedev *, struct tcpcb *); 6009fe6320SNavdeep Parhar int (*tod_listen_stop)(struct toedev *, struct tcpcb *); 6109fe6320SNavdeep Parhar 6209fe6320SNavdeep Parhar /* 6309fe6320SNavdeep Parhar * The kernel uses this routine to pass on any frame it receives for an 6409fe6320SNavdeep Parhar * offloaded connection to the TOE driver. This is an unusual event. 6509fe6320SNavdeep Parhar */ 6609fe6320SNavdeep Parhar void (*tod_input)(struct toedev *, struct tcpcb *, struct mbuf *); 6709fe6320SNavdeep Parhar 6809fe6320SNavdeep Parhar /* 6909fe6320SNavdeep Parhar * This is called by the kernel during pru_rcvd for an offloaded TCP 7009fe6320SNavdeep Parhar * connection and provides an opportunity for the TOE driver to manage 7109fe6320SNavdeep Parhar * its rx window and credits. 7209fe6320SNavdeep Parhar */ 7309fe6320SNavdeep Parhar void (*tod_rcvd)(struct toedev *, struct tcpcb *); 7409fe6320SNavdeep Parhar 7509fe6320SNavdeep Parhar /* 7609fe6320SNavdeep Parhar * Transmit routine. The kernel calls this to have the TOE driver 7709fe6320SNavdeep Parhar * evaluate whether there is data to be transmitted, and transmit it. 7809fe6320SNavdeep Parhar */ 7909fe6320SNavdeep Parhar int (*tod_output)(struct toedev *, struct tcpcb *); 8009fe6320SNavdeep Parhar 8109fe6320SNavdeep Parhar /* Immediate teardown: send RST to peer. */ 8209fe6320SNavdeep Parhar int (*tod_send_rst)(struct toedev *, struct tcpcb *); 8309fe6320SNavdeep Parhar 8409fe6320SNavdeep Parhar /* Initiate orderly disconnect by sending FIN to the peer. */ 8509fe6320SNavdeep Parhar int (*tod_send_fin)(struct toedev *, struct tcpcb *); 8609fe6320SNavdeep Parhar 8709fe6320SNavdeep Parhar /* Called to indicate that the kernel is done with this TCP PCB. */ 8809fe6320SNavdeep Parhar void (*tod_pcb_detach)(struct toedev *, struct tcpcb *); 8909fe6320SNavdeep Parhar 9009fe6320SNavdeep Parhar /* 9109fe6320SNavdeep Parhar * The kernel calls this once it has information about an L2 entry that 9209fe6320SNavdeep Parhar * the TOE driver enquired about previously (via toe_l2_resolve). 9309fe6320SNavdeep Parhar */ 9409fe6320SNavdeep Parhar void (*tod_l2_update)(struct toedev *, struct ifnet *, 9509fe6320SNavdeep Parhar struct sockaddr *, uint8_t *, uint16_t); 9609fe6320SNavdeep Parhar 9709fe6320SNavdeep Parhar /* XXX. Route has been redirected. */ 9809fe6320SNavdeep Parhar void (*tod_route_redirect)(struct toedev *, struct ifnet *, 998d6708baSAlexander V. Chernikov struct nhop_object *, struct nhop_object *); 10009fe6320SNavdeep Parhar 10109fe6320SNavdeep Parhar /* Syncache interaction. */ 10209fe6320SNavdeep Parhar void (*tod_syncache_added)(struct toedev *, void *); 10309fe6320SNavdeep Parhar void (*tod_syncache_removed)(struct toedev *, void *); 10409fe6320SNavdeep Parhar int (*tod_syncache_respond)(struct toedev *, void *, struct mbuf *); 10509fe6320SNavdeep Parhar void (*tod_offload_socket)(struct toedev *, void *, struct socket *); 10609fe6320SNavdeep Parhar 10709fe6320SNavdeep Parhar /* TCP socket option */ 10809fe6320SNavdeep Parhar void (*tod_ctloutput)(struct toedev *, struct tcpcb *, int, int); 109a6456410SNavdeep Parhar 110a6456410SNavdeep Parhar /* Update software state */ 1118c6104c4SMarius Strobl void (*tod_tcp_info)(struct toedev *, const struct tcpcb *, 112a6456410SNavdeep Parhar struct tcp_info *); 1139e14430dSJohn Baldwin 1149e14430dSJohn Baldwin /* Create a TLS session */ 1159e14430dSJohn Baldwin int (*tod_alloc_tls_session)(struct toedev *, struct tcpcb *, 116f1f93475SJohn Baldwin struct ktls_session *, int); 11701d74fe1SNavdeep Parhar 11801d74fe1SNavdeep Parhar /* ICMP fragmentation-needed received, adjust PMTU. */ 11901d74fe1SNavdeep Parhar void (*tod_pmtu_update)(struct toedev *, struct tcpcb *, tcp_seq, int); 12009fe6320SNavdeep Parhar }; 12109fe6320SNavdeep Parhar 12209fe6320SNavdeep Parhar typedef void (*tcp_offload_listen_start_fn)(void *, struct tcpcb *); 12309fe6320SNavdeep Parhar typedef void (*tcp_offload_listen_stop_fn)(void *, struct tcpcb *); 12409fe6320SNavdeep Parhar EVENTHANDLER_DECLARE(tcp_offload_listen_start, tcp_offload_listen_start_fn); 12509fe6320SNavdeep Parhar EVENTHANDLER_DECLARE(tcp_offload_listen_stop, tcp_offload_listen_stop_fn); 12609fe6320SNavdeep Parhar 12709fe6320SNavdeep Parhar void init_toedev(struct toedev *); 12809fe6320SNavdeep Parhar int register_toedev(struct toedev *); 12909fe6320SNavdeep Parhar int unregister_toedev(struct toedev *); 13009fe6320SNavdeep Parhar 13109fe6320SNavdeep Parhar /* 13209fe6320SNavdeep Parhar * General interface for looking up L2 information for an IP address. If an 13309fe6320SNavdeep Parhar * answer is not available right away then the TOE driver's tod_l2_update will 13409fe6320SNavdeep Parhar * be called later. 13509fe6320SNavdeep Parhar */ 13609fe6320SNavdeep Parhar int toe_l2_resolve(struct toedev *, struct ifnet *, struct sockaddr *, 13709fe6320SNavdeep Parhar uint8_t *, uint16_t *); 13809fe6320SNavdeep Parhar 13906fd9875SNavdeep Parhar void toe_connect_failed(struct toedev *, struct inpcb *, int); 14009fe6320SNavdeep Parhar 14109fe6320SNavdeep Parhar void toe_syncache_add(struct in_conninfo *, struct tcpopt *, struct tcphdr *, 142fa49a964SMichael Tuexen struct inpcb *, void *, void *, uint8_t); 14309fe6320SNavdeep Parhar int toe_syncache_expand(struct in_conninfo *, struct tcpopt *, struct tcphdr *, 14409fe6320SNavdeep Parhar struct socket **); 14509fe6320SNavdeep Parhar 14609fe6320SNavdeep Parhar int toe_4tuple_check(struct in_conninfo *, struct tcphdr *, struct ifnet *); 14709fe6320SNavdeep Parhar #endif 148