Date: Tue, 17 Apr 2012 17:59:02 +0000 (UTC) From: Navdeep Parhar <np@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r234389 - in user/np/toe_iwarp/sys: dev/cxgb/ulp/toecore modules modules/cxgb/toecore modules/toecore netinet Message-ID: <201204171759.q3HHx2oN092782@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: np Date: Tue Apr 17 17:59:01 2012 New Revision: 234389 URL: http://svn.freebsd.org/changeset/base/234389 Log: Replacement toedev/toecore interface. Interfaces in the toedev struct are all the hooks a TOE driver exposes to the kernel (toe_usrreqs etc. will all be retired). A few helper functions for use by a TOE driver will also be added to this module. All TOE drivers are expected to have a dependency on the toecore module. Added: user/np/toe_iwarp/sys/modules/toecore/ user/np/toe_iwarp/sys/modules/toecore/Makefile (contents, props changed) user/np/toe_iwarp/sys/netinet/toecore.c (contents, props changed) user/np/toe_iwarp/sys/netinet/toecore.h (contents, props changed) Deleted: user/np/toe_iwarp/sys/dev/cxgb/ulp/toecore/cxgb_toedev.h user/np/toe_iwarp/sys/dev/cxgb/ulp/toecore/toedev.c user/np/toe_iwarp/sys/modules/cxgb/toecore/Makefile user/np/toe_iwarp/sys/netinet/toedev.h Modified: user/np/toe_iwarp/sys/modules/Makefile Modified: user/np/toe_iwarp/sys/modules/Makefile ============================================================================== --- user/np/toe_iwarp/sys/modules/Makefile Tue Apr 17 17:08:50 2012 (r234388) +++ user/np/toe_iwarp/sys/modules/Makefile Tue Apr 17 17:59:01 2012 (r234389) @@ -309,6 +309,7 @@ SUBDIR= ${_3dfx} \ ${_ti} \ tl \ tmpfs \ + ${_toecore} \ ${_tpm} \ trm \ ${_twa} \ @@ -383,6 +384,7 @@ _random= random .if (${MK_INET_SUPPORT} != "no" || ${MK_INET6_SUPPORT} != "no") || \ defined(ALL_MODULES) _carp= carp +_toecore= toecore .endif .if ${MK_INET_SUPPORT} != "no" || defined(ALL_MODULES) Added: user/np/toe_iwarp/sys/modules/toecore/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/np/toe_iwarp/sys/modules/toecore/Makefile Tue Apr 17 17:59:01 2012 (r234389) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../netinet + +KMOD= toecore +SRCS= toecore.c + +.include <bsd.kmod.mk> Added: user/np/toe_iwarp/sys/netinet/toecore.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/np/toe_iwarp/sys/netinet/toecore.c Tue Apr 17 17:59:01 2012 (r234389) @@ -0,0 +1,480 @@ +/*- + * Copyright (c) 2012 Chelsio Communications, Inc. + * All rights reserved. + * Written by: Navdeep Parhar <np@FreeBSD.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/systm.h> +#include <sys/mbuf.h> +#include <sys/module.h> +#include <sys/types.h> +#include <sys/sockopt.h> +#include <sys/sysctl.h> +#include <sys/socket.h> +#include <net/ethernet.h> +#include <net/if.h> +#include <net/if_types.h> +#include <net/if_vlan_var.h> +#include <net/if_llatbl.h> +#include <net/route.h> +#include <netinet/if_ether.h> +#include <netinet/in.h> +#include <netinet/in_var.h> +#include <netinet6/nd6.h> +#include <netinet/in_pcb.h> +#define TCPSTATES +#include <netinet/tcp.h> +#include <netinet/tcp_fsm.h> +#include <netinet/tcp_var.h> +#include <netinet/tcp_syncache.h> +#include <netinet/tcp_offload.h> +#include <netinet/toecore.h> + +static struct mtx toedev_lock; +static TAILQ_HEAD(, toedev) toedev_list; +static eventhandler_tag listen_start_eh, listen_stop_eh; +static eventhandler_tag lle_event_eh, route_redirect_eh; + +static int +toedev_connect(struct toedev *tod __unused, struct socket *so __unused, + struct rtentry *rt __unused, struct sockaddr *nam __unused) +{ + + return (ENOTSUP); +} + +static int +toedev_listen_start(struct toedev *tod __unused, struct tcpcb *tp __unused) +{ + + return (ENOTSUP); +} + +static int +toedev_listen_stop(struct toedev *tod __unused, struct tcpcb *tp __unused) +{ + + return (ENOTSUP); +} + +static void +toedev_input(struct toedev *tod __unused, struct tcpcb *tp __unused, + struct mbuf *m __unused, int hlen __unused) +{ + + m_freem(m); + return; +} + +static void +toedev_rcvd(struct toedev *tod __unused, struct tcpcb *tp __unused) +{ + + return; +} + +static int +toedev_output(struct toedev *tod __unused, struct tcpcb *tp __unused) +{ + + return (ENOTSUP); +} + +static void +toedev_pcb_detach(struct toedev *tod __unused, struct tcpcb *tp __unused) +{ + + return; +} + +static void +toedev_l2_update(struct toedev *tod __unused, struct ifnet *ifp __unused, + struct sockaddr *sa __unused, uint8_t *lladdr __unused, + uint16_t vtag __unused) +{ + + return; +} + +static void +toedev_route_redirect(struct toedev *tod __unused, struct ifnet *ifp __unused, + struct rtentry *rt0 __unused, struct rtentry *rt1 __unused) +{ + + return; +} + +static void +toedev_syncache_added(struct toedev *tod __unused, void *ctx __unused) +{ + + return; +} + +static void +toedev_syncache_removed(struct toedev *tod __unused, void *ctx __unused) +{ + + return; +} + +static int +toedev_syncache_respond(struct toedev *tod __unused, void *ctx __unused, + struct mbuf *m) +{ + + m_freem(m); + return (0); +} + +static void +toedev_ctloutput(struct toedev *tod __unused, struct tcpcb *tp __unused, + int sopt_dir __unused, int sopt_name __unused) +{ + + return; +} + +/* + * Inform one or more TOE devices about a listening socket. + */ +static void +toe_listen_start(struct inpcb *inp, void *arg) +{ + struct toedev *t = arg, *tod; + struct tcpcb *tp; + + INP_WLOCK_ASSERT(inp); + KASSERT(inp->inp_pcbinfo == &V_tcbinfo, + ("%s: inp is not a TCP inp", __func__)); + + if (inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) + return; + + tp = intotcpcb(inp); + if (tp->t_state != TCPS_LISTEN) + return; + + mtx_lock(&toedev_lock); + TAILQ_FOREACH(tod, &toedev_list, link) { + if (t == NULL || t == tod) + tod->tod_listen_start(tod, tp); + } + mtx_unlock(&toedev_lock); +} + +static void +toe_listen_start_event(void *arg __unused, struct tcpcb *tp) +{ + struct inpcb *inp = tp->t_inpcb; + + INP_WLOCK_ASSERT(inp); + KASSERT(tp->t_state == TCPS_LISTEN, + ("%s: t_state %s", __func__, tcpstates[tp->t_state])); + + toe_listen_start(inp, NULL); +} + +static void +toe_listen_stop_event(void *arg __unused, struct tcpcb *tp) +{ + struct toedev *tod; +#ifdef INVARIANTS + struct inpcb *inp = tp->t_inpcb; +#endif + + INP_WLOCK_ASSERT(inp); + KASSERT(tp->t_state == TCPS_LISTEN, + ("%s: t_state %s", __func__, tcpstates[tp->t_state])); + + mtx_lock(&toedev_lock); + TAILQ_FOREACH(tod, &toedev_list, link) + tod->tod_listen_stop(tod, tp); + mtx_unlock(&toedev_lock); +} + +/* + * Fill up a freshly allocated toedev struct with reasonable defaults. + */ +void +init_toedev(struct toedev *tod) +{ + + tod->tod_softc = NULL; + + /* + * Provide no-op defaults so that the kernel can call any toedev + * function without having to check whether the TOE driver supplied one + * or not. + */ + tod->tod_connect = toedev_connect; + tod->tod_listen_start = toedev_listen_start; + tod->tod_listen_stop = toedev_listen_stop; + tod->tod_input = toedev_input; + tod->tod_rcvd = toedev_rcvd; + tod->tod_output = toedev_output; + tod->tod_send_rst = toedev_output; + tod->tod_send_fin = toedev_output; + tod->tod_pcb_detach = toedev_pcb_detach; + tod->tod_l2_update = toedev_l2_update; + tod->tod_route_redirect = toedev_route_redirect; + tod->tod_syncache_added = toedev_syncache_added; + tod->tod_syncache_removed = toedev_syncache_removed; + tod->tod_syncache_respond = toedev_syncache_respond; + tod->tod_ctloutput = toedev_ctloutput; +} + +/* + * Register an active TOE device with the system. This allows it to receive + * notifications from the kernel. + */ +int +register_toedev(struct toedev *tod) +{ + struct toedev *t; + + mtx_lock(&toedev_lock); + TAILQ_FOREACH(t, &toedev_list, link) { + if (t == tod) { + mtx_unlock(&toedev_lock); + return (EEXIST); + } + } + + TAILQ_INSERT_TAIL(&toedev_list, tod, link); + registered_toedevs++; + mtx_unlock(&toedev_lock); + + inp_apply_all(toe_listen_start, tod); + + return (0); +} + +/* + * Remove the TOE device from the global list of active TOE devices. It is the + * caller's responsibility to ensure that the TOE device is quiesced prior to + * this call. + */ +int +unregister_toedev(struct toedev *tod) +{ + struct toedev *t, *t2; + int rc = ENODEV; + + mtx_lock(&toedev_lock); + TAILQ_FOREACH_SAFE(t, &toedev_list, link, t2) { + if (t == tod) { + TAILQ_REMOVE(&toedev_list, tod, link); + registered_toedevs--; + rc = 0; + break; + } + } + KASSERT(registered_toedevs >= 0, + ("%s: registered_toedevs < 0", __func__)); + mtx_unlock(&toedev_lock); + return (rc); +} + +void +toe_syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, + struct inpcb *inp, void *tod, void *todctx) +{ + struct socket *lso = inp->inp_socket; + + INP_INFO_WLOCK_ASSERT(&V_tcbinfo); + INP_WLOCK_ASSERT(inp); + + syncache_add(inc, to, th, inp, &lso, NULL, tod, todctx); +} + +int +toe_syncache_expand(struct in_conninfo *inc, struct tcpopt *to, + struct tcphdr *th, struct socket **lsop) +{ + + INP_INFO_WLOCK_ASSERT(&V_tcbinfo); + + return (syncache_expand(inc, to, th, lsop, NULL)); +} + +static void +toe_lle_event(void *arg __unused, struct llentry *lle, int evt) +{ + struct toedev *tod; + struct ifnet *ifp; + uint8_t *lladdr; + uint16_t vtag = 0xfff; + struct sockaddr *sa; + + LLE_WLOCK_ASSERT(lle); + + ifp = lle->lle_tbl->llt_ifp; + sa = L3_ADDR(lle); + + KASSERT(sa->sa_family == AF_INET || sa->sa_family == AF_INET6, + ("%s: lle_event but sa !INET && !INET6", __func__)); + + /* + * Not interested if the interface's TOE capability is not enabled. + */ + if ((sa->sa_family == AF_INET && !(ifp->if_capenable & IFCAP_TOE4)) || + (sa->sa_family == AF_INET6 && !(ifp->if_capenable & IFCAP_TOE6))) + return; + + tod = TOEDEV(ifp); + if (tod == NULL) + return; + + if (evt != LLENTRY_RESOLVED) { + + /* + * LLENTRY_TIMEDOUT, LLENTRY_DELETED, LLENTRY_EXPIRED all mean + * this entry is going to be deleted. + */ + + lladdr = NULL; + } else { + + KASSERT(lle->la_flags & LLE_VALID, + ("%s: %p resolved but not valid?", __func__, lle)); + + lladdr = (uint8_t *)&lle->ll_addr; +#ifdef VLAN_TAG + VLAN_TAG(ifp, &vtag); +#endif + } + + tod->tod_l2_update(tod, ifp, sa, lladdr, vtag); +} + +/* + * XXX: implement. + */ +static void +toe_route_redirect_event(void *arg __unused, struct rtentry *rt0, + struct rtentry *rt1, struct sockaddr *sa) +{ + return; +} + +/* + * Returns 0 or EWOULDBLOCK on success (any other value is an error). 0 means + * lladdr and vtag are valid on return, EWOULDBLOCK means the TOE driver's + * tod_l2_update will be called later, when the entry is resolved or times out. + */ +int +toe_l2_resolve(struct toedev *tod, struct ifnet *ifp, struct sockaddr *sa, + uint8_t *lladdr, uint16_t *vtag) +{ + struct llentry *lle; + int rc; + + switch (sa->sa_family) { + case AF_INET: + rc = arpresolve(ifp, NULL, NULL, sa, lladdr, &lle); + break; + case AF_INET6: + rc = nd6_storelladdr(ifp, NULL, sa, lladdr, &lle); + break; + default: + return (EPROTONOSUPPORT); + } + + if (rc == 0) { +#ifdef VLAN_TAG + if (VLAN_TAG(ifp, vtag) != 0) +#endif + *vtag = 0xfff; + } + + return (rc); +} + +static int +toecore_load(void) +{ + + mtx_init(&toedev_lock, "toedev lock", NULL, MTX_DEF); + TAILQ_INIT(&toedev_list); + + listen_start_eh = EVENTHANDLER_REGISTER(tcp_offload_listen_start, + toe_listen_start_event, NULL, EVENTHANDLER_PRI_ANY); + listen_stop_eh = EVENTHANDLER_REGISTER(tcp_offload_listen_stop, + toe_listen_stop_event, NULL, EVENTHANDLER_PRI_ANY); + lle_event_eh = EVENTHANDLER_REGISTER(lle_event, toe_lle_event, NULL, + EVENTHANDLER_PRI_ANY); + route_redirect_eh = EVENTHANDLER_REGISTER(route_redirect_event, + toe_route_redirect_event, NULL, EVENTHANDLER_PRI_ANY); + + return (0); +} + +static int +toecore_unload(void) +{ + + mtx_lock(&toedev_lock); + if (!TAILQ_EMPTY(&toedev_list)) { + mtx_unlock(&toedev_lock); + return (EBUSY); + } + + EVENTHANDLER_DEREGISTER(tcp_offload_listen_start, listen_start_eh); + EVENTHANDLER_DEREGISTER(tcp_offload_listen_stop, listen_stop_eh); + EVENTHANDLER_DEREGISTER(lle_event, lle_event_eh); + EVENTHANDLER_DEREGISTER(route_redirect_event, route_redirect_eh); + + mtx_unlock(&toedev_lock); + mtx_destroy(&toedev_lock); + + return (0); +} + +static int +toecore_mod_handler(module_t mod, int cmd, void *arg) +{ + + if (cmd == MOD_LOAD) + return (toecore_load()); + + if (cmd == MOD_UNLOAD) + return (toecore_unload()); + + return (0); +} + +static moduledata_t mod_data= { + "toecore", + toecore_mod_handler, + 0 +}; + +MODULE_VERSION(toecore, 1); +DECLARE_MODULE(toecore, mod_data, SI_SUB_EXEC, SI_ORDER_ANY); Added: user/np/toe_iwarp/sys/netinet/toecore.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/np/toe_iwarp/sys/netinet/toecore.h Tue Apr 17 17:59:01 2012 (r234389) @@ -0,0 +1,112 @@ +/*- + * Copyright (c) 2012 Chelsio Communications, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + */ + +#ifndef _NETINET_TOE_H_ +#define _NETINET_TOE_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +struct tcpopt; +struct tcphdr; +struct in_conninfo; + +struct toedev { + TAILQ_ENTRY(toedev) link; /* glue for toedev_list */ + void *tod_softc; /* TOE driver private data */ + + /* Active open. */ + int (*tod_connect)(struct toedev *, struct socket *, struct rtentry *, + struct sockaddr *); + + /* Passive open. */ + int (*tod_listen_start)(struct toedev *, struct tcpcb *); + int (*tod_listen_stop)(struct toedev *, struct tcpcb *); + + /* Frame received by kernel for an offloaded connection */ + void (*tod_input)(struct toedev *, struct tcpcb *, struct mbuf *, int); + + /* Some data read */ + void (*tod_rcvd)(struct toedev *, struct tcpcb *); + + /* Output data, if any is waiting to be sent out. */ + int (*tod_output)(struct toedev *, struct tcpcb *); + + /* Immediate teardown, send RST to peer */ + int (*tod_send_rst)(struct toedev *, struct tcpcb *); + + /* Orderly disconnect, send FIN to the peer */ + int (*tod_send_fin)(struct toedev *, struct tcpcb *); + + /* Kernel is done with the TCP PCB */ + void (*tod_pcb_detach)(struct toedev *, struct tcpcb *); + + /* Information about an L2 entry is now available. */ + void (*tod_l2_update)(struct toedev *, struct ifnet *, + struct sockaddr *, uint8_t *, uint16_t); + + /* XXX. Route has been redirected. */ + void (*tod_route_redirect)(struct toedev *, struct ifnet *, + struct rtentry *, struct rtentry *); + + /* Syncache interaction. */ + void (*tod_syncache_added)(struct toedev *, void *); + void (*tod_syncache_removed)(struct toedev *, void *); + int (*tod_syncache_respond)(struct toedev *, void *, struct mbuf *); + + /* TCP socket option */ + void (*tod_ctloutput)(struct toedev *, struct tcpcb *, int, int); +}; + +#define TOEDEV(ifp) ((ifp)->if_llsoftc) + +#include <sys/eventhandler.h> +typedef void (*tcp_offload_listen_start_fn)(void *, struct tcpcb *); +typedef void (*tcp_offload_listen_stop_fn)(void *, struct tcpcb *); +EVENTHANDLER_DECLARE(tcp_offload_listen_start, tcp_offload_listen_start_fn); +EVENTHANDLER_DECLARE(tcp_offload_listen_stop, tcp_offload_listen_stop_fn); + +void init_toedev(struct toedev *); +int register_toedev(struct toedev *); +int unregister_toedev(struct toedev *); + +/* + * General interface for looking up L2 information for an IP or IPv6 address. + * If an answer is not available right away then the TOE driver's tod_l2_update + * will be called later. + */ +int toe_l2_resolve(struct toedev *, struct ifnet *, struct sockaddr *, + uint8_t *, uint16_t *); + +void toe_syncache_add(struct in_conninfo *, struct tcpopt *, struct tcphdr *, + struct inpcb *, void *, void *); +int toe_syncache_expand(struct in_conninfo *, struct tcpopt *, struct tcphdr *, + struct socket **); +#endif
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204171759.q3HHx2oN092782>