Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Nov 2017 17:02:20 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r325599 - stable/10/sys/dev/mlx5/mlx5_ib
Message-ID:  <201711091702.vA9H2Kas085698@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Thu Nov  9 17:02:20 2017
New Revision: 325599
URL: https://svnweb.freebsd.org/changeset/base/325599

Log:
  Use MAC-based GID format for the GID table entries in mlx5ib(4) to be
  compatible with the ibcore module in FreeBSD 10-stable.
  
  This fixes RDMA over VLAN, because the MAC-based GID format embeds
  the VLAN ID into the GID itself and this is what ibcore expects when
  requesting GID indexes from the GID cache.
  
  RoCE V1.5 and V2 is not supported in 10-stable by mlx5ib(4).
  This is a direct commit.
  
  Sponsored by:	Mellanox Technologies

Modified:
  stable/10/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c

Modified: stable/10/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c
==============================================================================
--- stable/10/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c	Thu Nov  9 15:43:15 2017	(r325598)
+++ stable/10/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c	Thu Nov  9 17:02:20 2017	(r325599)
@@ -541,49 +541,32 @@ int mlx5_ib_query_port(struct ib_device *ibdev, u8 por
 	}
 }
 
-static inline int
-mlx5_addrconf_ifid_eui48(u8 *eui, struct net_device *dev)
+static void
+mlx5_addrconf_ifid_eui48(u8 *eui, u16 vlan_id, struct net_device *dev)
 {
 	if (dev->if_addrlen != ETH_ALEN)
-		return -1;
+		return;
+
 	memcpy(eui, IF_LLADDR(dev), 3);
 	memcpy(eui + 5, IF_LLADDR(dev) + 3, 3);
 
-	/* NOTE: The scope ID is added by the GID to IP conversion */
-
-	eui[3] = 0xFF;
-	eui[4] = 0xFE;
+	if (vlan_id < 0x1000) {
+		eui[3] = vlan_id >> 8;
+		eui[4] = vlan_id & 0xff;
+	} else {
+		eui[3] = 0xFF;
+		eui[4] = 0xFE;
+	}
 	eui[0] ^= 2;
-	return 0;
 }
 
 static void
 mlx5_make_default_gid(struct net_device *dev, union ib_gid *gid)
 {
 	gid->global.subnet_prefix = cpu_to_be64(0xfe80000000000000LL);
-	mlx5_addrconf_ifid_eui48(&gid->raw[8], dev);
+	mlx5_addrconf_ifid_eui48(&gid->raw[8], 0xFFFF, dev);
 }
 
-static inline int
-mlx5_ip2gid(const struct sockaddr *addr, union ib_gid *gid)
-{
-	switch (addr->sa_family) {
-	case AF_INET:
-		ipv6_addr_set_v4mapped(((const struct sockaddr_in *)addr)->sin_addr.s_addr,
-		    (struct in6_addr *)gid->raw);
-		break;
-	case AF_INET6:
-		memcpy(gid->raw, &((const struct sockaddr_in6 *)addr)->sin6_addr, 16);
-		/* clear SCOPE ID */
-		gid->raw[2] = 0;
-		gid->raw[3] = 0;
-		break;
-	default:
-		return -EINVAL;
-	}
-	return 0;
-}
-
 static void
 mlx5_ib_roce_port_update(void *arg)
 {
@@ -593,7 +576,6 @@ mlx5_ib_roce_port_update(void *arg)
 	struct net_device *xdev[MLX5_IB_GID_MAX];
 	struct net_device *idev;
 	struct net_device *ndev;
-	struct ifaddr *ifa;
 	union ib_gid gid_temp;
 
 	while (port->port_gone == 0) {
@@ -626,38 +608,36 @@ mlx5_ib_roce_port_update(void *arg)
 		}
 		if (idev != NULL) {
 		    TAILQ_FOREACH(idev, &V_ifnet, if_link) {
+			u16 vid;
+
 			if (idev != ndev) {
 				if (idev->if_type != IFT_L2VLAN)
 					continue;
 				if (ndev != rdma_vlan_dev_real_dev(idev))
 					continue;
 			}
-			/* clone address information for IPv4 and IPv6 */
-			IF_ADDR_RLOCK(idev);
-			TAILQ_FOREACH(ifa, &idev->if_addrhead, ifa_link) {
-				if (ifa->ifa_addr == NULL ||
-				    (ifa->ifa_addr->sa_family != AF_INET &&
-				     ifa->ifa_addr->sa_family != AF_INET6) ||
-				    gid_index >= MLX5_IB_GID_MAX)
-					continue;
-				memset(&gid_temp, 0, sizeof(gid_temp));
-				mlx5_ip2gid(ifa->ifa_addr, &gid_temp);
-				/* check for existing entry */
-				for (j = 0; j != gid_index; j++) {
-					if (bcmp(&gid_temp, &port->gid_table[j], sizeof(gid_temp)) == 0)
-						break;
+
+			/* setup valid MAC-based GID */
+			memset(&gid_temp, 0, sizeof(gid_temp));
+			gid_temp.global.subnet_prefix = cpu_to_be64(0xfe80000000000000LL);
+			vid = rdma_vlan_dev_vlan_id(idev);
+			mlx5_addrconf_ifid_eui48(&gid_temp.raw[8], vid, idev);
+
+			/* check for existing entry */
+			for (j = 0; j != gid_index; j++) {
+				if (bcmp(&gid_temp, &port->gid_table[j], sizeof(gid_temp)) == 0)
+					break;
+			}
+
+			/* check if new entry should be added */
+			if (j == gid_index && gid_index < MLX5_IB_GID_MAX) {
+				if (bcmp(&gid_temp, &port->gid_table[gid_index], sizeof(gid_temp))) {
+					port->gid_table[gid_index] = gid_temp;
+					update = 1;
 				}
-				/* check if new entry must be added */
-				if (j == gid_index) {
-					if (bcmp(&gid_temp, &port->gid_table[gid_index], sizeof(gid_temp))) {
-						port->gid_table[gid_index] = gid_temp;
-						update = 1;
-					}
-					xdev[gid_index] = idev;
-					gid_index++;
-				}
+				xdev[gid_index] = idev;
+				gid_index++;
 			}
-			IF_ADDR_RUNLOCK(idev);
 		    }
 		}
 		IFNET_RUNLOCK();



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