Author: hselasky
Date: Tue Dec  1 13:44:33 2020
New Revision: 368227
URL: https://svnweb.freebsd.org/changeset/base/368227

Log:
  MFC r366930, r366936, r366993 and r366994:
  Factor out generic IP over infiniband, IPoIB, definitions and code
  into net/if_infiniband.c and net/infiniband.h . No functional change
  intended.
  
  Differential Revision:        https://reviews.freebsd.org/D26254
  Reviewed by:          melifaro@
  Sponsored by:         Mellanox Technologies // NVIDIA Networking

Added:
  stable/12/sys/modules/if_infiniband/
     - copied from r366930, head/sys/modules/if_infiniband/
  stable/12/sys/net/if_infiniband.c
     - copied, changed from r366930, head/sys/net/if_infiniband.c
  stable/12/sys/net/infiniband.h
     - copied, changed from r366930, head/sys/net/infiniband.h
Modified:
  stable/12/sys/conf/files
  stable/12/sys/modules/Makefile
  stable/12/sys/modules/if_infiniband/Makefile
  stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib.h
  stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_cm.c
  stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_ib.c
  stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_main.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/conf/files
==============================================================================
--- stable/12/sys/conf/files    Tue Dec  1 13:10:25 2020        (r368226)
+++ stable/12/sys/conf/files    Tue Dec  1 13:44:33 2020        (r368227)
@@ -4578,6 +4578,7 @@ compat/lindebugfs/lindebugfs.c                    
optional lindebugfs \
        compile-with "${LINUXKPI_C}"
 
 # OpenFabrics Enterprise Distribution (Infiniband)
+net/if_infiniband.c                                    optional ofed
 ofed/drivers/infiniband/core/ib_addr.c                 optional ofed   \
        compile-with "${OFED_C}"
 ofed/drivers/infiniband/core/ib_agent.c                        optional ofed   
\

Modified: stable/12/sys/modules/Makefile
==============================================================================
--- stable/12/sys/modules/Makefile      Tue Dec  1 13:10:25 2020        
(r368226)
+++ stable/12/sys/modules/Makefile      Tue Dec  1 13:44:33 2020        
(r368227)
@@ -171,6 +171,7 @@ SUBDIR=     \
        ${_if_gif} \
        ${_if_gre} \
        ${_if_me} \
+       if_infiniband \
        if_lagg \
        ${_if_ndis} \
        ${_if_stf} \

Modified: stable/12/sys/modules/if_infiniband/Makefile
==============================================================================
--- head/sys/modules/if_infiniband/Makefile     Thu Oct 22 09:09:53 2020        
(r366930)
+++ stable/12/sys/modules/if_infiniband/Makefile        Tue Dec  1 13:44:33 
2020        (r368227)
@@ -4,6 +4,8 @@
 
 KMOD=  if_infiniband
 SRCS=  if_infiniband.c \
+       device_if.h \
+       bus_if.h \
        opt_inet.h \
        opt_inet6.h
 

Copied and modified: stable/12/sys/net/if_infiniband.c (from r366930, 
head/sys/net/if_infiniband.c)
==============================================================================
--- head/sys/net/if_infiniband.c        Thu Oct 22 09:09:53 2020        
(r366930, copy source)
+++ stable/12/sys/net/if_infiniband.c   Tue Dec  1 13:44:33 2020        
(r368227)
@@ -29,30 +29,30 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/bus.h>
 #include <sys/eventhandler.h>
+#include <sys/kernel.h>
+#include <sys/mbuf.h>
+#include <sys/module.h>
 #include <sys/socket.h>
 #include <sys/sysctl.h>
-#include <sys/devctl.h>
-#include <sys/module.h>
 
-#include <net/if.h>
-#include <net/if_var.h>
-#include <net/route.h>
+#include <net/bpf.h>
 #include <net/ethernet.h>
 #include <net/infiniband.h>
-#include <net/bpf.h>
-#include <net/if_llatbl.h>
-#include <net/netisr.h>
+#include <net/if.h>
+#include <net/if_var.h>
 #include <net/if_dl.h>
-#include <net/if_types.h>
 #include <net/if_media.h>
-
-#include <netinet/in.h>
+#include <net/if_llatbl.h>
+#include <net/if_types.h>
+#include <net/netisr.h>
+#include <net/route.h>
 #include <netinet/if_ether.h>
+#include <netinet/in.h>
 #include <netinet/ip6.h>
-
 #include <netinet6/in6_var.h>
 #include <netinet6/nd6.h>
 
@@ -60,8 +60,8 @@ __FBSDID("$FreeBSD$");
 
 #ifdef INET
 static inline void
-infiniband_ipv4_multicast_map(uint32_t addr,
-    const uint8_t *broadcast, uint8_t *buf)
+infiniband_ipv4_multicast_map(
+    uint32_t addr, const uint8_t *broadcast, uint8_t *buf)
 {
        uint8_t scope;
 
@@ -93,8 +93,8 @@ infiniband_ipv4_multicast_map(uint32_t addr,
 
 #ifdef INET6
 static inline void
-infiniband_ipv6_multicast_map(const struct in6_addr *addr,
-    const uint8_t *broadcast, uint8_t *buf)
+infiniband_ipv6_multicast_map(
+    const struct in6_addr *addr, const uint8_t *broadcast, uint8_t *buf)
 {
        uint8_t scope;
 
@@ -122,7 +122,7 @@ infiniband_bpf_mtap(struct ifnet *ifp, struct mbuf *mb
 {
        struct infiniband_header *ibh;
        struct ether_header eh;
-  
+
        if (mb->m_len < sizeof(*ibh))
                return;
 
@@ -155,8 +155,6 @@ infiniband_output(struct ifnet *ifp, struct mbuf *m, c
        uint16_t type;
        bool is_gw;
 
-       NET_EPOCH_ASSERT();
-
        is_gw = ((ro != NULL) && (ro->ro_flags & RT_HAS_GW) != 0);
 
 #ifdef MAC
@@ -192,7 +190,7 @@ infiniband_output(struct ifnet *ifp, struct mbuf *m, c
                        if (error) {
                                if (error == EWOULDBLOCK)
                                        error = 0;
-                               m = NULL;       /* mbuf is consumed by resolver 
*/
+                               m = NULL; /* mbuf is consumed by resolver */
                                goto bad;
                        }
                }
@@ -259,7 +257,7 @@ infiniband_output(struct ifnet *ifp, struct mbuf *m, c
                        if (error) {
                                if (error == EWOULDBLOCK)
                                        error = 0;
-                               m = NULL;       /* mbuf is consumed by resolver 
*/
+                               m = NULL; /* mbuf is consumed by resolver */
                                goto bad;
                        }
                }
@@ -386,16 +384,16 @@ infiniband_input(struct ifnet *ifp, struct mbuf *m)
        mac_ifnet_create_mbuf(ifp, m);
 #endif
        /* Allow monitor mode to claim this frame, after stats are updated. */
-       NET_EPOCH_ENTER(et);
+       NET_EPOCH_ENTER_ET(et);
        netisr_dispatch(isr, m);
-       NET_EPOCH_EXIT(et);
+       NET_EPOCH_EXIT_ET(et);
 done:
        CURVNET_RESTORE();
 }
 
 static int
-infiniband_resolvemulti(struct ifnet *ifp, struct sockaddr **llsa,
-    struct sockaddr *sa)
+infiniband_resolvemulti(
+    struct ifnet *ifp, struct sockaddr **llsa, struct sockaddr *sa)
 {
        struct sockaddr_dl *sdl;
 #ifdef INET
@@ -426,8 +424,8 @@ infiniband_resolvemulti(struct ifnet *ifp, struct sock
                sdl = link_init_sdl(ifp, *llsa, IFT_INFINIBAND);
                sdl->sdl_alen = INFINIBAND_ADDR_LEN;
                e_addr = LLADDR(sdl);
-               infiniband_ipv4_multicast_map(sin->sin_addr.s_addr, 
ifp->if_broadcastaddr,
-                   e_addr);
+               infiniband_ipv4_multicast_map(
+                   sin->sin_addr.s_addr, ifp->if_broadcastaddr, e_addr);
                *llsa = (struct sockaddr *)sdl;
                return (0);
 #endif
@@ -446,7 +444,8 @@ infiniband_resolvemulti(struct ifnet *ifp, struct sock
                sdl = link_init_sdl(ifp, *llsa, IFT_INFINIBAND);
                sdl->sdl_alen = INFINIBAND_ADDR_LEN;
                e_addr = LLADDR(sdl);
-               infiniband_ipv6_multicast_map(&sin6->sin6_addr, 
ifp->if_broadcastaddr, e_addr);
+               infiniband_ipv6_multicast_map(
+                   &sin6->sin6_addr, ifp->if_broadcastaddr, e_addr);
                *llsa = (struct sockaddr *)sdl;
                return (0);
 #endif
@@ -471,7 +470,7 @@ infiniband_ifattach(struct ifnet *ifp, const uint8_t *
        ifp->if_resolvemulti = infiniband_resolvemulti;
 
        if (ifp->if_baudrate == 0)
-               ifp->if_baudrate = IF_Gbps(10); /* default value */
+               ifp->if_baudrate = IF_Gbps(10); /* default value */
        if (llb != NULL)
                ifp->if_broadcastaddr = llb;
 

Copied and modified: stable/12/sys/net/infiniband.h (from r366930, 
head/sys/net/infiniband.h)
==============================================================================
--- head/sys/net/infiniband.h   Thu Oct 22 09:09:53 2020        (r366930, copy 
source)
+++ stable/12/sys/net/infiniband.h      Tue Dec  1 13:44:33 2020        
(r368227)
@@ -61,8 +61,6 @@ struct infiniband_address {
 
 #ifdef _KERNEL
 
-#include <sys/_eventhandler.h>
-
 struct ifnet;
 struct mbuf;
 
@@ -70,10 +68,12 @@ extern void infiniband_ifattach(struct ifnet *, const 
 extern void infiniband_ifdetach(struct ifnet *);
 extern void infiniband_bpf_mtap(struct ifnet *, struct mbuf *);
 
+#ifdef _SYS_EVENTHANDLER_H_
 /* new infiniband interface attached event */
 typedef void (*infiniband_ifattach_event_handler_t)(void *, struct ifnet *);
 
 EVENTHANDLER_DECLARE(infiniband_ifattach_event, 
infiniband_ifattach_event_handler_t);
+#endif
 
 #endif
 

Modified: stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib.h
==============================================================================
--- stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib.h     Tue Dec  1 
13:10:25 2020        (r368226)
+++ stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib.h     Tue Dec  1 
13:44:33 2020        (r368227)
@@ -438,16 +438,7 @@ struct ipoib_path {
 
 extern struct workqueue_struct *ipoib_workqueue;
 
-#define IPOIB_MTAP_PROTO(_ifp, _m, _proto)                     \
-do {                                                           \
-       if (bpf_peers_present((_ifp)->if_bpf)) {                \
-               M_ASSERTVALID(_m);                              \
-               ipoib_mtap_proto((_ifp), (_m), (_proto));       \
-       }                                                       \
-} while (0)
-
 /* functions */
-void ipoib_mtap_proto(struct ifnet *ifp, struct mbuf *mb, uint16_t proto);
 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
 void ipoib_send_comp_handler(struct ib_cq *cq, void *dev_ptr);
 
@@ -463,8 +454,6 @@ int ipoib_open(struct ipoib_dev_priv *priv);
 int ipoib_add_pkey_attr(struct ipoib_dev_priv *priv);
 int ipoib_add_umcast_attr(struct ipoib_dev_priv *priv);
 
-void ipoib_demux(struct ifnet *ifp, struct mbuf *m, u_short proto);
-
 void ipoib_send(struct ipoib_dev_priv *priv, struct mbuf *mb,
                struct ipoib_ah *address, u32 qpn);
 void ipoib_reap_ah(struct work_struct *work);
@@ -540,7 +529,7 @@ int ipoib_poll_tx(struct ipoib_dev_priv *priv, bool do
 
 void ipoib_dma_unmap_rx(struct ipoib_dev_priv *priv, struct ipoib_rx_buf 
*rx_req);
 void ipoib_dma_mb(struct ipoib_dev_priv *priv, struct mbuf *mb, unsigned int 
length);
-struct mbuf *ipoib_alloc_map_mb(struct ipoib_dev_priv *priv, struct 
ipoib_rx_buf *rx_req, int size);
+struct mbuf *ipoib_alloc_map_mb(struct ipoib_dev_priv *priv, struct 
ipoib_rx_buf *rx_req, int align, int size);
 
 
 void ipoib_set_ethtool_ops(struct ifnet *dev);

Modified: stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_cm.c
==============================================================================
--- stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_cm.c  Tue Dec  1 
13:10:25 2020        (r368226)
+++ stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_cm.c  Tue Dec  1 
13:44:33 2020        (r368227)
@@ -153,7 +153,7 @@ static struct mbuf *
 ipoib_cm_alloc_rx_mb(struct ipoib_dev_priv *priv, struct ipoib_cm_rx_buf 
*rx_req)
 {
        return ipoib_alloc_map_mb(priv, (struct ipoib_rx_buf *)rx_req,
-           priv->cm.max_cm_mtu);
+           sizeof(struct ipoib_pseudoheader), priv->cm.max_cm_mtu);
 }
 
 static void ipoib_cm_free_rx_ring(struct ipoib_dev_priv *priv,
@@ -484,10 +484,7 @@ void ipoib_cm_handle_rx_wc(struct ipoib_dev_priv *priv
        struct mbuf *mb, *newmb;
        struct ipoib_cm_rx *p;
        int has_srq;
-       u_short proto;
 
-       CURVNET_SET_QUIET(dev->if_vnet);
-
        ipoib_dbg_data(priv, "cm recv completion: id %d, status: %d\n",
                       wr_id, wc->status);
 
@@ -561,16 +558,24 @@ void ipoib_cm_handle_rx_wc(struct ipoib_dev_priv *priv
 
        ipoib_dma_mb(priv, mb, wc->byte_len);
 
-       if_inc_counter(dev, IFCOUNTER_IPACKETS, 1);
-       if_inc_counter(dev, IFCOUNTER_IBYTES, mb->m_pkthdr.len);
-
        mb->m_pkthdr.rcvif = dev;
-       proto = *mtod(mb, uint16_t *);
-       m_adj(mb, IPOIB_ENCAP_LEN);
 
-       IPOIB_MTAP_PROTO(dev, mb, proto);
-       ipoib_demux(dev, mb, ntohs(proto));
+       M_PREPEND(mb, sizeof(struct ipoib_pseudoheader), M_NOWAIT);
+       if (likely(mb != NULL)) {
+               struct ipoib_header *ibh;
 
+               if_inc_counter(dev, IFCOUNTER_IPACKETS, 1);
+               if_inc_counter(dev, IFCOUNTER_IBYTES, mb->m_pkthdr.len);
+
+               /* fixup destination infiniband address */
+               ibh = mtod(mb, struct ipoib_header *);
+               memset(ibh->hwaddr, 0, 4);
+               memcpy(ibh->hwaddr + 4, priv->local_gid.raw, sizeof(union 
ib_gid));
+
+               dev->if_input(dev, mb);
+       } else {
+               if_inc_counter(dev, IFCOUNTER_IERRORS, 1);
+       }
 repost:
        if (has_srq) {
                if (unlikely(ipoib_cm_post_receive_srq(priv, wr_id)))
@@ -587,7 +592,6 @@ repost:
                }
        }
 done:
-       CURVNET_RESTORE();
        return;
 }
 

Modified: stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_ib.c
==============================================================================
--- stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_ib.c  Tue Dec  1 
13:10:25 2020        (r368226)
+++ stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_ib.c  Tue Dec  1 
13:44:33 2020        (r368227)
@@ -112,17 +112,19 @@ ipoib_dma_mb(struct ipoib_dev_priv *priv, struct mbuf 
 
 struct mbuf *
 ipoib_alloc_map_mb(struct ipoib_dev_priv *priv, struct ipoib_rx_buf *rx_req,
-    int size)
+    int align, int size)
 {
        struct mbuf *mb, *m;
        int i, j;
 
        rx_req->mb = NULL;
-       mb = m_getm2(NULL, size, M_NOWAIT, MT_DATA, M_PKTHDR);
+       mb = m_getm2(NULL, align + size, M_NOWAIT, MT_DATA, M_PKTHDR);
        if (mb == NULL)
                return (NULL);
        for (i = 0, m = mb; m != NULL; m = m->m_next, i++) {
-               m->m_len = M_SIZE(m);
+               m->m_len = M_SIZE(m) - align;
+               m->m_data += align;
+               align = 0;
                mb->m_pkthdr.len += m->m_len;
                rx_req->mapping[i] = ib_dma_map_single(priv->ca,
                    mtod(m, void *), m->m_len, DMA_FROM_DEVICE);
@@ -174,7 +176,7 @@ ipoib_alloc_rx_mb(struct ipoib_dev_priv *priv, int id)
 {
 
        return ipoib_alloc_map_mb(priv, &priv->rx_ring[id],
-           priv->max_ib_mtu + IB_GRH_BYTES);
+           0, priv->max_ib_mtu + IB_GRH_BYTES);
 }
 
 static int ipoib_ib_post_receives(struct ipoib_dev_priv *priv)

Modified: stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_main.c
==============================================================================
--- stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_main.c        Tue Dec 
 1 13:10:25 2020        (r368226)
+++ stable/12/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_main.c        Tue Dec 
 1 13:44:33 2020        (r368227)
@@ -39,21 +39,16 @@ __FBSDID("$FreeBSD$");
 
 #include "ipoib.h"
 
-static int ipoib_resolvemulti(struct ifnet *, struct sockaddr **,
-               struct sockaddr *);
-
-
 #include <linux/module.h>
 
 #include <linux/slab.h>
 #include <linux/kernel.h>
 #include <linux/vmalloc.h>
 
-#include <linux/if_arp.h>      /* For ARPHRD_xxx */
 #include <linux/if_vlan.h>
-#include <net/ip.h>
-#include <net/ipv6.h>
 
+#include <net/infiniband.h>
+
 #include <rdma/ib_cache.h>
 
 MODULE_AUTHOR("Roland Dreier");
@@ -97,19 +92,8 @@ static struct net_device *ipoib_get_net_dev_by_params(
                const union ib_gid *gid, const struct sockaddr *addr,
                void *client_data);
 static void ipoib_start(struct ifnet *dev);
-static int ipoib_output(struct ifnet *ifp, struct mbuf *m,
-           const struct sockaddr *dst, struct route *ro);
 static int ipoib_ioctl(struct ifnet *ifp, u_long command, caddr_t data);
-static void ipoib_input(struct ifnet *ifp, struct mbuf *m);
 
-#define        IPOIB_MTAP(_ifp, _m)                                    \
-do {                                                           \
-       if (bpf_peers_present((_ifp)->if_bpf)) {                \
-               M_ASSERTVALID(_m);                              \
-               ipoib_mtap_mb((_ifp), (_m));                    \
-       }                                                       \
-} while (0)
-
 static struct unrhdr *ipoib_unrhdr;
 
 static void
@@ -135,37 +119,6 @@ ipoib_unrhdr_uninit(void *arg)
 }
 SYSUNINIT(ipoib_unrhdr_uninit, SI_SUB_KLD - 1, SI_ORDER_ANY, 
ipoib_unrhdr_uninit, NULL);
 
-/*
- * This is for clients that have an ipoib_header in the mbuf.
- */
-static void
-ipoib_mtap_mb(struct ifnet *ifp, struct mbuf *mb)
-{
-       struct ipoib_header *ih;
-       struct ether_header eh;
-
-       ih = mtod(mb, struct ipoib_header *);
-       eh.ether_type = ih->proto;
-       bcopy(ih->hwaddr, &eh.ether_dhost, ETHER_ADDR_LEN);
-       bzero(&eh.ether_shost, ETHER_ADDR_LEN);
-       mb->m_data += sizeof(struct ipoib_header);
-       mb->m_len -= sizeof(struct ipoib_header);
-       bpf_mtap2(ifp->if_bpf, &eh, sizeof(eh), mb);
-       mb->m_data -= sizeof(struct ipoib_header);
-       mb->m_len += sizeof(struct ipoib_header);
-}
-
-void
-ipoib_mtap_proto(struct ifnet *ifp, struct mbuf *mb, uint16_t proto)
-{
-       struct ether_header eh;
-
-       eh.ether_type = proto;
-       bzero(&eh.ether_shost, ETHER_ADDR_LEN);
-       bzero(&eh.ether_dhost, ETHER_ADDR_LEN);
-       bpf_mtap2(ifp->if_bpf, &eh, sizeof(eh), mb);
-}
-
 static struct ib_client ipoib_client = {
        .name   = "ipoib",
        .add    = ipoib_add_one,
@@ -783,7 +736,7 @@ ipoib_start_locked(struct ifnet *dev, struct ipoib_dev
                IFQ_DRV_DEQUEUE(&dev->if_snd, mb);
                if (mb == NULL)
                        break;
-               IPOIB_MTAP(dev, mb);
+               INFINIBAND_BPF_MTAP(dev, mb);
                ipoib_send_one(priv, mb);
        }
 }
@@ -871,8 +824,7 @@ ipoib_detach(struct ipoib_dev_priv *priv)
        dev = priv->dev;
        if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
                priv->gone = 1;
-               bpfdetach(dev);
-               if_detach(dev);
+               infiniband_ifdetach(dev);
                if_free(dev);
                free_unr(ipoib_unrhdr, priv->unit);
        } else
@@ -931,7 +883,6 @@ struct ipoib_dev_priv *
 ipoib_intf_alloc(const char *name)
 {
        struct ipoib_dev_priv *priv;
-       struct sockaddr_dl *sdl;
        struct ifnet *dev;
 
        priv = ipoib_priv_alloc();
@@ -949,24 +900,17 @@ ipoib_intf_alloc(const char *name)
        }
        if_initname(dev, name, priv->unit);
        dev->if_flags = IFF_BROADCAST | IFF_MULTICAST;
-       dev->if_addrlen = INFINIBAND_ALEN;
-       dev->if_hdrlen = IPOIB_HEADER_LEN;
-       if_attach(dev);
+
+       infiniband_ifattach(dev, NULL, priv->broadcastaddr);
+
        dev->if_init = ipoib_init;
        dev->if_ioctl = ipoib_ioctl;
        dev->if_start = ipoib_start;
-       dev->if_output = ipoib_output;
-       dev->if_input = ipoib_input;
-       dev->if_resolvemulti = ipoib_resolvemulti;
-       dev->if_baudrate = IF_Gbps(10);
-       dev->if_broadcastaddr = priv->broadcastaddr;
+
        dev->if_snd.ifq_maxlen = ipoib_sendq_size * 2;
-       sdl = (struct sockaddr_dl *)dev->if_addr->ifa_addr;
-       sdl->sdl_type = IFT_INFINIBAND;
-       sdl->sdl_alen = dev->if_addrlen;
+
        priv->dev = dev;
        if_link_state_change(dev, LINK_STATE_DOWN);
-       bpfattach(dev, DLT_EN10MB, ETHER_HDR_LEN);
 
        return dev->if_softc;
 }
@@ -1160,7 +1104,6 @@ ipoib_match_dev_addr(const struct sockaddr *addr, stru
        struct ifaddr *ifa;
        int retval = 0;
 
-       CURVNET_SET(dev->if_vnet);
        IF_ADDR_RLOCK(dev);
        CK_STAILQ_FOREACH(ifa, &dev->if_addrhead, ifa_link) {
                if (ifa->ifa_addr == NULL ||
@@ -1174,7 +1117,6 @@ ipoib_match_dev_addr(const struct sockaddr *addr, stru
                }
        }
        IF_ADDR_RUNLOCK(dev);
-       CURVNET_RESTORE();
 
        return (retval);
 }
@@ -1464,281 +1406,6 @@ ipoib_cleanup_module(void)
        ib_sa_unregister_client(&ipoib_sa_client);
        destroy_workqueue(ipoib_workqueue);
 }
-
-/*
- * Infiniband output routine.
- */
-static int
-ipoib_output(struct ifnet *ifp, struct mbuf *m,
-       const struct sockaddr *dst, struct route *ro)
-{
-       u_char edst[INFINIBAND_ALEN];
-#if defined(INET) || defined(INET6)
-       struct llentry *lle = NULL;
-#endif
-       struct ipoib_header *eh;
-       int error = 0, is_gw = 0;
-       short type;
-
-       if (ro != NULL)
-               is_gw = (ro->ro_flags & RT_HAS_GW) != 0;
-#ifdef MAC
-       error = mac_ifnet_check_transmit(ifp, m);
-       if (error)
-               goto bad;
-#endif
-
-       M_PROFILE(m);
-       if (ifp->if_flags & IFF_MONITOR) {
-               error = ENETDOWN;
-               goto bad;
-       }
-       if (!((ifp->if_flags & IFF_UP) &&
-           (ifp->if_drv_flags & IFF_DRV_RUNNING))) {
-               error = ENETDOWN;
-               goto bad;
-       }
-
-       switch (dst->sa_family) {
-#ifdef INET
-       case AF_INET:
-               if (lle != NULL && (lle->la_flags & LLE_VALID))
-                       memcpy(edst, lle->ll_addr, sizeof(edst));
-               else if (m->m_flags & M_MCAST)
-                       ip_ib_mc_map(((struct sockaddr_in 
*)dst)->sin_addr.s_addr, ifp->if_broadcastaddr, edst);
-               else
-                       error = arpresolve(ifp, is_gw, m, dst, edst, NULL, 
NULL);
-               if (error)
-                       return (error == EWOULDBLOCK ? 0 : error);
-               type = htons(ETHERTYPE_IP);
-               break;
-       case AF_ARP:
-       {
-               struct arphdr *ah;
-               ah = mtod(m, struct arphdr *);
-               ah->ar_hrd = htons(ARPHRD_INFINIBAND);
-
-               switch(ntohs(ah->ar_op)) {
-               case ARPOP_REVREQUEST:
-               case ARPOP_REVREPLY:
-                       type = htons(ETHERTYPE_REVARP);
-                       break;
-               case ARPOP_REQUEST:
-               case ARPOP_REPLY:
-               default:
-                       type = htons(ETHERTYPE_ARP);
-                       break;
-               }
-
-               if (m->m_flags & M_BCAST)
-                       bcopy(ifp->if_broadcastaddr, edst, INFINIBAND_ALEN);
-               else
-                       bcopy(ar_tha(ah), edst, INFINIBAND_ALEN);
-
-       }
-       break;
-#endif
-#ifdef INET6
-       case AF_INET6:
-               if (lle != NULL && (lle->la_flags & LLE_VALID))
-                       memcpy(edst, lle->ll_addr, sizeof(edst));
-               else if (m->m_flags & M_MCAST)
-                       ipv6_ib_mc_map(&((struct sockaddr_in6 
*)dst)->sin6_addr, ifp->if_broadcastaddr, edst);
-               else
-                       error = nd6_resolve(ifp, is_gw, m, dst, edst, NULL, 
NULL);
-               if (error)
-                       return error;
-               type = htons(ETHERTYPE_IPV6);
-               break;
-#endif
-
-       default:
-               if_printf(ifp, "can't handle af%d\n", dst->sa_family);
-               error = EAFNOSUPPORT;
-               goto bad;
-       }
-
-       /*
-        * Add local net header.  If no space in first mbuf,
-        * allocate another.
-        */
-       M_PREPEND(m, IPOIB_HEADER_LEN, M_NOWAIT);
-       if (m == NULL) {
-               error = ENOBUFS;
-               goto bad;
-       }
-       eh = mtod(m, struct ipoib_header *);
-       (void)memcpy(&eh->proto, &type, sizeof(eh->proto));
-       (void)memcpy(&eh->hwaddr, edst, sizeof (edst));
-
-       /*
-        * Queue message on interface, update output statistics if
-        * successful, and start output if interface not yet active.
-        */
-       return ((ifp->if_transmit)(ifp, m));
-bad:
-       if (m != NULL)
-               m_freem(m);
-       return (error);
-}
-
-/*
- * Upper layer processing for a received Infiniband packet.
- */
-void
-ipoib_demux(struct ifnet *ifp, struct mbuf *m, u_short proto)
-{
-       int isr;
-
-#ifdef MAC
-       /*
-        * Tag the mbuf with an appropriate MAC label before any other
-        * consumers can get to it.
-        */
-       mac_ifnet_create_mbuf(ifp, m);
-#endif
-       /* Allow monitor mode to claim this frame, after stats are updated. */
-       if (ifp->if_flags & IFF_MONITOR) {
-               if_printf(ifp, "discard frame at IFF_MONITOR\n");
-               m_freem(m);
-               return;
-       }
-       /* Direct packet to correct FIB based on interface config */
-       M_SETFIB(m, ifp->if_fib);
-       /*
-        * Dispatch frame to upper layer.
-        */
-       switch (proto) {
-#ifdef INET
-       case ETHERTYPE_IP:
-               isr = NETISR_IP;
-               break;
-
-       case ETHERTYPE_ARP:
-               if (ifp->if_flags & IFF_NOARP) {
-                       /* Discard packet if ARP is disabled on interface */
-                       m_freem(m);
-                       return;
-               }
-               isr = NETISR_ARP;
-               break;
-#endif
-#ifdef INET6
-       case ETHERTYPE_IPV6:
-               isr = NETISR_IPV6;
-               break;
-#endif
-       default:
-               goto discard;
-       }
-       netisr_dispatch(isr, m);
-       return;
-
-discard:
-       m_freem(m);
-}
-
-/*
- * Process a received Infiniband packet.
- */
-static void
-ipoib_input(struct ifnet *ifp, struct mbuf *m)
-{
-       struct ipoib_header *eh;
-
-       if ((ifp->if_flags & IFF_UP) == 0) {
-               m_freem(m);
-               return;
-       }
-       CURVNET_SET_QUIET(ifp->if_vnet);
-
-       /* Let BPF have it before we strip the header. */
-       IPOIB_MTAP(ifp, m);
-       eh = mtod(m, struct ipoib_header *);
-       /*
-        * Reset layer specific mbuf flags to avoid confusing upper layers.
-        * Strip off Infiniband header.
-        */
-       m->m_flags &= ~M_VLANTAG;
-       m_clrprotoflags(m);
-       m_adj(m, IPOIB_HEADER_LEN);
-
-       if (IPOIB_IS_MULTICAST(eh->hwaddr)) {
-               if (memcmp(eh->hwaddr, ifp->if_broadcastaddr,
-                   ifp->if_addrlen) == 0)
-                       m->m_flags |= M_BCAST;
-               else
-                       m->m_flags |= M_MCAST;
-               if_inc_counter(ifp, IFCOUNTER_IMCASTS, 1);
-       }
-
-       ipoib_demux(ifp, m, ntohs(eh->proto));
-       CURVNET_RESTORE();
-}
-
-static int
-ipoib_resolvemulti(struct ifnet *ifp, struct sockaddr **llsa,
-       struct sockaddr *sa)
-{
-       struct sockaddr_dl *sdl;
-#ifdef INET
-       struct sockaddr_in *sin;
-#endif
-#ifdef INET6
-       struct sockaddr_in6 *sin6;
-#endif
-       u_char *e_addr;
-
-       switch(sa->sa_family) {
-       case AF_LINK:
-               /*
-                * No mapping needed. Just check that it's a valid MC address.
-                */
-               sdl = (struct sockaddr_dl *)sa;
-               e_addr = LLADDR(sdl);
-               if (!IPOIB_IS_MULTICAST(e_addr))
-                       return EADDRNOTAVAIL;
-               *llsa = NULL;
-               return 0;
-
-#ifdef INET
-       case AF_INET:
-               sin = (struct sockaddr_in *)sa;
-               if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
-                       return EADDRNOTAVAIL;
-               sdl = link_init_sdl(ifp, *llsa, IFT_INFINIBAND);
-               sdl->sdl_alen = INFINIBAND_ALEN;
-               e_addr = LLADDR(sdl);
-               ip_ib_mc_map(sin->sin_addr.s_addr, ifp->if_broadcastaddr,
-                   e_addr);
-               *llsa = (struct sockaddr *)sdl;
-               return 0;
-#endif
-#ifdef INET6
-       case AF_INET6:
-               sin6 = (struct sockaddr_in6 *)sa;
-               /*
-                * An IP6 address of 0 means listen to all
-                * of the multicast address used for IP6.  
-                * This has no meaning in ipoib.
-                */
-               if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
-                       return EADDRNOTAVAIL;
-               if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
-                       return EADDRNOTAVAIL;
-               sdl = link_init_sdl(ifp, *llsa, IFT_INFINIBAND);
-               sdl->sdl_alen = INFINIBAND_ALEN;
-               e_addr = LLADDR(sdl);
-               ipv6_ib_mc_map(&sin6->sin6_addr, ifp->if_broadcastaddr, e_addr);
-               *llsa = (struct sockaddr *)sdl;
-               return 0;
-#endif
-
-       default:
-               return EAFNOSUPPORT;
-       }
-}
-
 module_init_order(ipoib_init_module, SI_ORDER_FIFTH);
 module_exit_order(ipoib_cleanup_module, SI_ORDER_FIFTH);
 
@@ -1755,4 +1422,5 @@ static moduledata_t ipoib_mod = {
 
 DECLARE_MODULE(ipoib, ipoib_mod, SI_SUB_LAST, SI_ORDER_ANY);
 MODULE_DEPEND(ipoib, ibcore, 1, 1, 1);
+MODULE_DEPEND(ipoib, if_infiniband, 1, 1, 1);
 MODULE_DEPEND(ipoib, linuxkpi, 1, 1, 1);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to