Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Mar 2017 09:59:35 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
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
Message-ID:  <201703160959.v2G9xZMp066571@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <linux/netdevice.h>
 
 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 <net/if_var.h>
 #include <net/if_dl.h>
 
+#include <linux/list.h>
 #include <linux/completion.h>
 #include <linux/device.h>
 #include <linux/workqueue.h>
 #include <linux/net.h>
 #include <linux/notifier.h>
 
-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;
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703160959.v2G9xZMp066571>