components/open-fabrics/libibverbs/solaris_compatibility.c
changeset 636 da28b1dc61e7
parent 369 cc8c00719da9
child 715 eed3ed08f692
equal deleted inserted replaced
635:d4b487f99c39 636:da28b1dc61e7
   116 
   116 
   117 /*
   117 /*
   118  * duplicate ABI definitions for HCAs as the HCA abi headers are not
   118  * duplicate ABI definitions for HCAs as the HCA abi headers are not
   119  * installed in proto.
   119  * installed in proto.
   120  */ 
   120  */ 
   121 #define	MTHCA_UVERBS_ABI_VERSION	1 /* mthca-abi.h */
       
   122 #define	MLX4_UVERBS_MAX_ABI_VERSION	3 /* mlx4-abi.h */
   121 #define	MLX4_UVERBS_MAX_ABI_VERSION	3 /* mlx4-abi.h */
   123 #define	RDMA_USER_CM_MIN_ABI_VERSION	3 /* rdma_cma_abi.h */
   122 #define	RDMA_USER_CM_MIN_ABI_VERSION	3 /* rdma_cma_abi.h */
   124 #define	RDMA_USER_CM_MAX_ABI_VERSION	4 /* rdma_cma_abi.h */
   123 #define	RDMA_USER_CM_MAX_ABI_VERSION	4 /* rdma_cma_abi.h */
   125 
   124 
   126 #define	MLX4	0
   125 #define	MLX4	0
   127 #define	MTHCA	1
       
   128 #define	MAX_HCAS				16
   126 #define	MAX_HCAS				16
   129 #define	MAX_HCA_PORTS				16
   127 #define	MAX_HCA_PORTS				16
   130 #define	HW_DRIVER_MAX_NAME_LEN			20
   128 #define	HW_DRIVER_MAX_NAME_LEN			20
   131 #define	UVERBS_KERNEL_SYSFS_NAME_BASE		"uverbs"
   129 #define	UVERBS_KERNEL_SYSFS_NAME_BASE		"uverbs"
   132 #define	UMAD_KERNEL_SYSFS_NAME_BASE		"umad"
   130 #define	UMAD_KERNEL_SYSFS_NAME_BASE		"umad"
   133 #define	IB_HCA_DEVPATH_PREFIX			"/dev/infiniband/hca"
   131 #define	IB_HCA_DEVPATH_PREFIX			"/dev/infiniband/hca"
   134 #define	IB_OFS_DEVPATH_PREFIX			"/dev/infiniband/ofs"
   132 #define	IB_OFS_DEVPATH_PREFIX			"/dev/infiniband/ofs"
   135 #define	CONNECTX_NAME				"mlx4_"
   133 #define	CONNECTX_NAME				"mlx4_"
   136 #define	INFINIHOST_NAME				"mthca"
       
   137 
   134 
   138 #define	MELLANOX_VENDOR_ID			0x15b3
   135 #define	MELLANOX_VENDOR_ID			0x15b3
   139 #define	PCI_DEVICE_ID_MELLANOX_TAVOR		0x5a44
       
   140 #define	PCI_DEVICE_ID_MELLANOX_ARBEL		0x6282
       
   141 #define	PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT	0x6278
       
   142 #define	PCI_DEVICE_ID_MELLANOX_HERMON_SDR	0x6340
   136 #define	PCI_DEVICE_ID_MELLANOX_HERMON_SDR	0x6340
   143 #define	PCI_DEVICE_ID_MELLANOX_HERMON_DDR	0x634a
   137 #define	PCI_DEVICE_ID_MELLANOX_HERMON_DDR	0x634a
   144 #define	PCI_DEVICE_ID_MELLANOX_HERMON_QDR	0x6354
   138 #define	PCI_DEVICE_ID_MELLANOX_HERMON_QDR	0x6354
   145 #define	PCI_DEVICE_ID_MELLANOX_HERMON_DDR_PCIE2	0x6732
   139 #define	PCI_DEVICE_ID_MELLANOX_HERMON_DDR_PCIE2	0x6732
   146 #define	PCI_DEVICE_ID_MELLANOX_HERMON_QDR_PCIE2	0x673c
   140 #define	PCI_DEVICE_ID_MELLANOX_HERMON_QDR_PCIE2	0x673c
   166 	CP_SOL_UVERBS		= 1,
   160 	CP_SOL_UVERBS		= 1,
   167 	CP_DEVICE		= 2,
   161 	CP_DEVICE		= 2,
   168 	CP_D			= 3,
   162 	CP_D			= 3,
   169 	CP_GIDS			= 4,
   163 	CP_GIDS			= 4,
   170 	CP_PKEYS		= 5,
   164 	CP_PKEYS		= 5,
   171 	CP_MTHCA		= 6,
   165 	CP_MLX4			= 6,
   172 	CP_MLX4			= 7,
   166 	CP_PORTS		= 7,
   173 	CP_PORTS		= 8,
   167 	CP_UMAD			= 8,
   174 	CP_UMAD			= 9,
   168 	CP_SLASH		= 9,
   175 	CP_SLASH		= 10,
   169 	CP_SYS			= 10,
   176 	CP_SYS			= 11,
   170 	CP_CLASS		= 11,
   177 	CP_CLASS		= 12,
   171 	CP_INFINIBAND_VERBS	= 12,
   178 	CP_INFINIBAND_VERBS	= 13,
   172 	CP_INFINIBAND		= 13,
   179 	CP_INFINIBAND		= 14,
   173 	CP_INFINIBAND_MAD	= 14,
   180 	CP_INFINIBAND_MAD	= 15,
   174 	CP_MISC			= 15,
   181 	CP_MISC			= 16,
   175 	CP_RDMA_CM		= 16
   182 	CP_RDMA_CM		= 17
       
   183 } cp_prefix_t;
   176 } cp_prefix_t;
   184 
   177 
   185 /*
   178 /*
   186  * Some temporary cache code, until things are cleaned up as part of DR
   179  * Some temporary cache code, until things are cleaned up as part of DR
   187  * work. This will speed up the sysfs emulation.
   180  * work. This will speed up the sysfs emulation.
   194 	char		ibd_fw_ver[16];
   187 	char		ibd_fw_ver[16];
   195 	char		ibd_name[8];
   188 	char		ibd_name[8];
   196 	int		ibd_boardid_index;
   189 	int		ibd_boardid_index;
   197 } ibdev_cache_info_t;
   190 } ibdev_cache_info_t;
   198 
   191 
   199 /* tavor and hermon - hence 2 */
   192 /* hermon - hence 2 */
   200 static ibdev_cache_info_t ibdev_cache[2][MAX_HCAS];
   193 static ibdev_cache_info_t ibdev_cache[2][MAX_HCAS];
   201 
   194 
   202 typedef struct uverbs_cache_info_s {
   195 typedef struct uverbs_cache_info_s {
   203 	uint_t		uvc_valid;
   196 	uint_t		uvc_valid;
   204 	uint_t		uvc_ibdev_abi_version;
   197 	uint_t		uvc_ibdev_abi_version;
   482 	if (!(strncmp(info_p->ibd_name, "mlx4", 4))) {
   475 	if (!(strncmp(info_p->ibd_name, "mlx4", 4))) {
   483 		memcpy(&(ibdev_cache[MLX4][dev_num]), info_p,
   476 		memcpy(&(ibdev_cache[MLX4][dev_num]), info_p,
   484 		    sizeof (ibdev_cache_info_t));
   477 		    sizeof (ibdev_cache_info_t));
   485 		ibdev_cache[MLX4][dev_num].ibd_valid = 1;
   478 		ibdev_cache[MLX4][dev_num].ibd_valid = 1;
   486 	} else {
   479 	} else {
   487 		memcpy(&(ibdev_cache[MTHCA][dev_num]), info_p,
   480 		fprintf(stderr, "dev %d: has no proper ibdev name\n", dev_num);
   488 		    sizeof (ibdev_cache_info_t));
   481 		return (1);
   489 		ibdev_cache[MTHCA][dev_num].ibd_valid = 1;
       
   490 	}
   482 	}
   491 
   483 
   492 	ibdev_cache_cnt++;
   484 	ibdev_cache_cnt++;
   493 	return (0);
   485 	return (0);
   494 }
   486 }
   649 		    hca_infop->uverbs_hca_driver_instance);
   641 		    hca_infop->uverbs_hca_driver_instance);
   650 
   642 
   651 		if (! strncmp(hca_infop->uverbs_hca_ibdev_name, "mlx4_", 5))
   643 		if (! strncmp(hca_infop->uverbs_hca_ibdev_name, "mlx4_", 5))
   652 			info.uvc_ibdev_abi_version =
   644 			info.uvc_ibdev_abi_version =
   653 			    MLX4_UVERBS_MAX_ABI_VERSION;
   645 			    MLX4_UVERBS_MAX_ABI_VERSION;
   654 		else
   646 		else {
   655 			info.uvc_ibdev_abi_version = MTHCA_UVERBS_ABI_VERSION;
   647 			fprintf(stderr, "libibverbs: sol_uverbs unsupported "
       
   648 			    "device: %s\n", hca_infop->uverbs_hca_ibdev_name);
       
   649 			goto error_exit2;
       
   650 		}
   656 
   651 
   657 		strcpy(info.uvc_ibdev_name, hca_infop->uverbs_hca_ibdev_name);
   652 		strcpy(info.uvc_ibdev_name, hca_infop->uverbs_hca_ibdev_name);
   658 
   653 
   659 		dev_num = hca_infop->uverbs_hca_devidx;
   654 		dev_num = hca_infop->uverbs_hca_devidx;
   660 		if (uverbs_cache_add(dev_num, &info)) {
   655 		if (uverbs_cache_add(dev_num, &info)) {
   829 			ret = sscanf(path, "gids%n/", &pos);
   824 			ret = sscanf(path, "gids%n/", &pos);
   830 			break;
   825 			break;
   831 		case CP_PKEYS:
   826 		case CP_PKEYS:
   832 			ret = sscanf(path, "pkeys%n/", &pos);
   827 			ret = sscanf(path, "pkeys%n/", &pos);
   833 			break;
   828 			break;
   834 		case CP_MTHCA:
       
   835 			ret = sscanf(path, "mthca%d%n/", arg, &pos);
       
   836 			break;
       
   837 		case CP_MLX4:
   829 		case CP_MLX4:
   838 			ret = sscanf(path, "mlx4_%d%n/", arg, &pos);
   830 			ret = sscanf(path, "mlx4_%d%n/", arg, &pos);
   839 			break;
   831 			break;
   840 		case CP_PORTS:
   832 		case CP_PORTS:
   841 			ret = sscanf(path, "ports%n/", &pos);
   833 			ret = sscanf(path, "ports%n/", &pos);
   885 }
   877 }
   886 
   878 
   887 static ibdev_cache_info_t *
   879 static ibdev_cache_info_t *
   888 get_device_info(const char *devname)
   880 get_device_info(const char *devname)
   889 {
   881 {
   890 	ibdev_cache_info_t 	*info;
   882 	ibdev_cache_info_t 	*info = NULL;
   891 	const char		*p = devname;
   883 	const char		*p = devname;
   892 	int			dev_num;
   884 	int			dev_num;
   893 
   885 
   894 	if (pthread_mutex_lock(&ibdev_cache_mutex) != 0) {
   886 	if (pthread_mutex_lock(&ibdev_cache_mutex) != 0) {
   895 		fprintf(stderr, "failed: to acquire ibdev_cache_mutex %s\n",
   887 		fprintf(stderr, "failed: to acquire ibdev_cache_mutex %s\n",
   920 		if (ibdev_cache[MLX4][dev_num].ibd_valid)
   912 		if (ibdev_cache[MLX4][dev_num].ibd_valid)
   921 			info = &(ibdev_cache[MLX4][dev_num]);
   913 			info = &(ibdev_cache[MLX4][dev_num]);
   922 		else
   914 		else
   923 			info = NULL;
   915 			info = NULL;
   924 	} else {
   916 	} else {
   925 		if (ibdev_cache[MTHCA][dev_num].ibd_valid)
   917 		fprintf(stderr, "libibverbs: sol_uverbs unsupported "
   926 			info = &(ibdev_cache[MTHCA][dev_num]);
   918 		    "device: %s\n", devname);
   927 		else
   919 		info = NULL;
   928 			info = NULL;
       
   929 	}
   920 	}
   930 
   921 
   931 	return (info);
   922 	return (info);
   932 }
   923 }
   933 
   924 
  1365  */
  1356  */
  1366 static int
  1357 static int
  1367 get_hca_hwpn_str(char *ibd_name, int fd, char *hca_hwpn)
  1358 get_hca_hwpn_str(char *ibd_name, int fd, char *hca_hwpn)
  1368 {
  1359 {
  1369 	hermon_flash_init_ioctl_t	hermon_flash_info;
  1360 	hermon_flash_init_ioctl_t	hermon_flash_info;
  1370 	tavor_flash_init_ioctl_t	tavor_flash_info;
       
  1371 	int				rc;
  1361 	int				rc;
  1372 
  1362 
  1373 	if (strncmp(ibd_name, "mthca", 5) == 0) {
  1363 	if (strncmp(ibd_name, "mlx4_", 5) == 0) {
  1374 		if ((rc = ioctl(fd, TAVOR_IOCTL_FLASH_INIT,
       
  1375 		    &tavor_flash_info)) != 0)
       
  1376 			return (rc);
       
  1377 		strncpy(hca_hwpn, tavor_flash_info.tf_hwpn, 64);
       
  1378 	} else {
       
  1379 		if ((rc = ioctl(fd, HERMON_IOCTL_FLASH_INIT,
  1364 		if ((rc = ioctl(fd, HERMON_IOCTL_FLASH_INIT,
  1380 		    &hermon_flash_info)) != 0)
  1365 		    &hermon_flash_info)) != 0)
  1381 			return (rc);
  1366 			return (rc);
  1382 		strncpy(hca_hwpn, hermon_flash_info.af_hwpn, 64);
  1367 		strncpy(hca_hwpn, hermon_flash_info.af_hwpn, 64);
       
  1368 	} else {
       
  1369 		fprintf(stderr, "libibverbs: sol_uverbs unsupported "
       
  1370 		    "device: %s\n", ibd_name);
       
  1371 		return (1);
  1383 	}
  1372 	}
  1384 	return (0);
  1373 	return (0);
  1385 }
  1374 }
  1386 
  1375 
  1387 static void
  1376 static void
  1460 	char			dev_name[10];
  1449 	char			dev_name[10];
  1461 	ibdev_cache_info_t	*info;
  1450 	ibdev_cache_info_t	*info;
  1462 
  1451 
  1463 	memset(dev_name, 0, 10);
  1452 	memset(dev_name, 0, 10);
  1464 
  1453 
  1465 	if (check_path(path, CP_MTHCA, &device_num)) {
  1454 	if (check_path(path, CP_MLX4, &device_num)) {
  1466 		sprintf(dev_name, "mthca%d", device_num);
       
  1467 	} else if (check_path(path, CP_MLX4, &device_num)) {
       
  1468 		sprintf(dev_name, "mlx4_%d", device_num);
  1455 		sprintf(dev_name, "mlx4_%d", device_num);
  1469 	} else {
  1456 	} else {
  1470 		goto exit;
  1457 		goto exit;
  1471 	}
  1458 	}
  1472 
  1459