From owner-svn-src-head@freebsd.org Thu Mar 16 09:59:37 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1CD85D0DB1E; Thu, 16 Mar 2017 09:59:37 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CF0261CD3; Thu, 16 Mar 2017 09:59:36 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2G9xZft066575; Thu, 16 Mar 2017 09:59:35 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2G9xZMp066571; Thu, 16 Mar 2017 09:59:35 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201703160959.v2G9xZMp066571@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 16 Mar 2017 09:59:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315404 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src ofed/drivers/infiniband/core X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Mar 2017 09:59:37 -0000 Author: hselasky Date: Thu Mar 16 09:59:35 2017 New Revision: 315404 URL: https://svnweb.freebsd.org/changeset/base/315404 Log: Add basic support for VIMAGE to the LinuxKPI and ibcore. Support is implemented by mapping Linux's "struct net" into FreeBSD's "struct vnet". Currently only vnet0 is supported by ibcore. MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/inetdevice.h head/sys/compat/linuxkpi/common/include/linux/netdevice.h head/sys/compat/linuxkpi/common/src/linux_compat.c head/sys/ofed/drivers/infiniband/core/addr.c Modified: head/sys/compat/linuxkpi/common/include/linux/inetdevice.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/inetdevice.h Thu Mar 16 09:40:54 2017 (r315403) +++ head/sys/compat/linuxkpi/common/include/linux/inetdevice.h Thu Mar 16 09:59:35 2017 (r315404) @@ -34,23 +34,25 @@ #include static inline struct net_device * -ip_dev_find(struct net *net, uint32_t addr) +ip_dev_find(struct vnet *vnet, uint32_t addr) { struct sockaddr_in sin; struct ifaddr *ifa; struct ifnet *ifp; - ifp = NULL; memset(&sin, 0, sizeof(sin)); sin.sin_addr.s_addr = addr; - sin.sin_port = 0; sin.sin_len = sizeof(sin); sin.sin_family = AF_INET; + CURVNET_SET_QUIET(vnet); ifa = ifa_ifwithaddr((struct sockaddr *)&sin); + CURVNET_RESTORE(); if (ifa) { ifp = ifa->ifa_ifp; if_ref(ifp); ifa_free(ifa); + } else { + ifp = NULL; } return (ifp); } Modified: head/sys/compat/linuxkpi/common/include/linux/netdevice.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/netdevice.h Thu Mar 16 09:40:54 2017 (r315403) +++ head/sys/compat/linuxkpi/common/include/linux/netdevice.h Thu Mar 16 09:59:35 2017 (r315404) @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2017 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,25 +40,38 @@ #include #include +#include #include #include #include #include #include -struct net { -}; - -extern struct net init_net; +#ifdef VIMAGE +#define init_net *vnet0 +#else +#define init_net *((struct vnet *)0) +#endif #define MAX_ADDR_LEN 20 #define net_device ifnet -#define dev_get_by_index(n, idx) ifnet_byindex_ref((idx)) -#define dev_hold(d) if_ref((d)) -#define dev_put(d) if_rele((d)) -#define dev_net(d) (&init_net) +static inline struct ifnet * +dev_get_by_index(struct vnet *vnet, int if_index) +{ + struct ifnet *retval; + + CURVNET_SET(vnet); + retval = ifnet_byindex_ref(if_index); + CURVNET_RESTORE(); + + return (retval); +} + +#define dev_hold(d) if_ref(d) +#define dev_put(d) if_rele(d) +#define dev_net(d) ((d)->if_vnet) #define net_eq(a,b) ((a) == (b)) Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_compat.c Thu Mar 16 09:40:54 2017 (r315403) +++ head/sys/compat/linuxkpi/common/src/linux_compat.c Thu Mar 16 09:59:35 2017 (r315404) @@ -92,7 +92,6 @@ struct device linux_root_device; struct class linux_class_misc; struct list_head pci_drivers; struct list_head pci_devices; -struct net init_net; spinlock_t pci_lock; unsigned long linux_timer_hz_mask; Modified: head/sys/ofed/drivers/infiniband/core/addr.c ============================================================================== --- head/sys/ofed/drivers/infiniband/core/addr.c Thu Mar 16 09:40:54 2017 (r315403) +++ head/sys/ofed/drivers/infiniband/core/addr.c Thu Mar 16 09:59:35 2017 (r315404) @@ -161,7 +161,9 @@ int rdma_translate_ip(struct sockaddr *a scope_id = sin6->sin6_scope_id; if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) SCOPE_ID_CACHE(scope_id, sin6); + CURVNET_SET_QUIET(&init_net); ifa = ifa_ifwithaddr(addr); + CURVNET_RESTORE(); sin6->sin6_port = port; if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) SCOPE_ID_RESTORE(scope_id, sin6); @@ -231,6 +233,9 @@ static int addr_resolve(struct sockaddr int bcast; int is_gw = 0; int error = 0; + + CURVNET_SET_QUIET(&init_net); + /* * Determine whether the address is unicast, multicast, or broadcast * and whether the source interface is valid. @@ -271,7 +276,9 @@ static int addr_resolve(struct sockaddr * up first and verify that it is a local * interface: */ + CURVNET_SET_QUIET(&init_net); ifa = ifa_ifwithaddr(src_in); + CURVNET_RESTORE(); sin->sin_port = port; if (ifa == NULL) { error = ENETUNREACH; @@ -312,7 +319,9 @@ static int addr_resolve(struct sockaddr * up first and verify that it is a local * interface: */ + CURVNET_SET_QUIET(&init_net); ifa = ifa_ifwithaddr(src_in); + CURVNET_RESTORE(); sin6->sin6_port = port; if (ifa == NULL) { error = ENETUNREACH; @@ -426,6 +435,8 @@ done: #endif if (error == EWOULDBLOCK) error = ENODATA; + + CURVNET_RESTORE(); return -error; }